]> Pileus Git - lackey/blobdiff - src/main.c
Add some mouse support
[lackey] / src / main.c
index 41e1c81c180cf62c047d7bf87a93df0a6856f3b4..5de195da34a006558770a10cc66a8d9be5e22b41 100644 (file)
@@ -7,12 +7,7 @@
 #include "main.h"
 #include "screen.h"
 
-/* Global data */
-int win_rows = 0;
-int win_cols = 0;
-
 /* Static data */
-static WINDOW *win = NULL;
 static FILE *debug_fd = NULL;
 
 /* Control-C handler, so we don't hose the therminal */
@@ -23,21 +18,12 @@ static void on_sigint(int signum)
        exit(0);
 }
 
-/* Window change */
-static void update(void)
-{
-       getmaxyx(win, win_rows, win_cols);
-       win_rows++;
-       win_cols++;
-       screen_draw();
-}
-
 /* Window change */
 static void on_sigwinch(int signum)
 {
        endwin();
        refresh();
-       update();
+       screen_draw();
 }
 
 /* Debugging functions */
@@ -45,9 +31,21 @@ int debug(char *fmt, ...)
 {
        int rval;
        va_list ap;
+
+       /* Log to debug file */
        va_start(ap, fmt);
        vfprintf(debug_fd, "debug: ", ap);
        rval = vfprintf(debug_fd, fmt, ap);
+
+       /* Log to status bar */
+       va_start(ap, fmt);
+       mvhline(LINES-2, 0, ACS_HLINE, COLS);
+       move(LINES-1, 0);
+       attron(COLOR_PAIR(COLOR_ERROR));
+       vwprintw(stdscr, fmt, ap);
+       attroff(COLOR_PAIR(COLOR_ERROR));
+       clrtoeol();
+
        va_end(ap);
        return rval;
 }
@@ -68,26 +66,37 @@ int main(int argc, char **argv)
                debug("sigwinch error\n");
 
        /* Curses setup */
-       win = initscr();
+       initscr();
        cbreak();
        noecho();
+       keypad(stdscr, TRUE);
        start_color();
        curs_set(false);
+       mousemask(ALL_MOUSE_EVENTS, NULL);
+       init_pair(COLOR_TITLE, COLOR_GREEN, COLOR_BLACK);
+       init_pair(COLOR_ERROR, COLOR_RED,   COLOR_BLACK);
        screen_init();
 
        /* Run */
        while (1) {
+               MEVENT btn;
                int chr = getch();
+               if (chr == KEY_MOUSE)
+                       if (getmouse(&btn) != OK)
+                               continue;
                if (chr == 'q')
                        break;
+               if (KEY_MOUSE)
+                       //debug("mouse xyz=%d,%d,%d id=%hd state=%lx\n",
+                       //      btn.x, btn.y, btn.z, btn.id, btn.bstate);
                switch (chr) {
                        case 'L':
                                clear();
                        case 'l':
-                               update();
+                               screen_draw();
                                break;
                        default:
-                               screen_run(chr);
+                               screen_run(chr, btn.bstate, btn.y, btn.x);
                                break;
                }
        }