# HG changeset patch # User Sadrul Habib Chowdhury # Date 1156336148 0 # Node ID a766441af5ea61f59bba774e03d877b240ef5f6c # Parent 578a2c9af05e70a15832c193a0cdc7fc13c58bd9 [gaim-migrate @ 17000] Add support for mouse. Currently you can: - click on the taskbar to bring a window on top - click on the topmost line of the *active* window and drag+drop to move the window. This is disabled by default. You can enable it by setting "mouse = 1" in ~/.gntrc. If you enable mouse support, then do shift+click to get the usual behaviours (eg. shift+middleclick to paste etc.) committer: Tailor Script diff -r 578a2c9af05e -r a766441af5ea console/libgnt/gntmain.c --- a/console/libgnt/gntmain.c Wed Aug 23 10:48:21 2006 +0000 +++ b/console/libgnt/gntmain.c Wed Aug 23 12:29:08 2006 +0000 @@ -31,6 +31,7 @@ static int Y_MAX; static gboolean ascii_only; +static gboolean mouse_enabled; static GMainLoop *loop; static struct @@ -480,6 +481,88 @@ gnt_screen_resize_widget(widget, nw, nh); } +/** + * Mouse support: + * - bring a window on top if you click on its taskbar + * - click on the top-bar of the active window and drag+drop to move a window + * wishlist: + * - have a little [X] on the windows, and clicking it will close that window. + * - click on a window to bring it to focus + * - allow scrolling in tree/textview on wheel-scroll event + * - click to activate button or select a row in tree + * - all these can be fulfilled by adding a "clicked" event for GntWidget + * which will send the (x,y) to the widget. (look at "key_pressed" for hints) + */ +static gboolean +detect_mouse_action(const char *buffer) +{ + int x, y; + static enum { + MOUSE_NONE, + MOUSE_LEFT, + MOUSE_RIGHT, + MOUSE_MIDDLE + } button = MOUSE_NONE; + static GntWidget *remember = NULL; + static int offset = 0; + + if (buffer[0] != 27) + return FALSE; + + buffer++; + if (strlen(buffer) < 5) + return FALSE; + + x = buffer[3]; + y = buffer[4]; + if (x < 0) x += 256; + if (y < 0) y += 256; + x -= 33; + y -= 33; + + if (strncmp(buffer, "[M ", 3) == 0) { + /* left button down */ + /* If you clicked on the top-bar of the active window, then you can move it by dragging it */ + if (focus_list) { + GntWidget *wid = focus_list->data; + if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width && + y == wid->priv.y) { + offset = x - wid->priv.x; + remember = wid; + button = MOUSE_LEFT; + } + } + } else if (strncmp(buffer, "[M\"", 3) == 0) { + /* right button down */ + } else if (strncmp(buffer, "[M!", 3) == 0) { + /* middle button down */ + } else if (strncmp(buffer, "[M`", 3) == 0) { + /* wheel up*/ + } else if (strncmp(buffer, "[Ma", 3) == 0) { + /* wheel down */ + } else if (strncmp(buffer, "[M#", 3) == 0) { + /* button up */ + if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { + int n = g_list_length(g_list_first(focus_list)); + if (n) { + int width = getmaxx(stdscr) / n; + switch_window_n(x / width); + } + } else if (button == MOUSE_LEFT && remember) { + x -= offset; + if (x < 0) x = 0; + if (y < 0) y = 0; + gnt_screen_move_widget(remember, x, y); + refresh_node(remember, NULL, NULL); + } + button = MOUSE_NONE; + remember = NULL; + offset = 0; + } else + return FALSE; + return TRUE; +} + static gboolean io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) { @@ -511,6 +594,9 @@ gnt_keys_refine(buffer); + if (mouse_enabled && detect_mouse_action(buffer)) + return TRUE; + if (mode == GNT_KP_MODE_NORMAL) { if (focus_list) @@ -798,9 +884,10 @@ wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); refresh(); -#if 0 - mousemask(NCURSES_BUTTON_PRESSED | NCURSES_BUTTON_RELEASED | REPORT_MOUSE_POSITION, NULL); -#endif + + if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) + mousemask(NCURSES_BUTTON_PRESSED | NCURSES_BUTTON_RELEASED , NULL); + wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); werase(stdscr); wrefresh(stdscr); diff -r 578a2c9af05e -r a766441af5ea console/libgnt/gntstyle.c --- a/console/libgnt/gntstyle.c Wed Aug 23 10:48:21 2006 +0000 +++ b/console/libgnt/gntstyle.c Wed Aug 23 12:29:08 2006 +0000 @@ -142,6 +142,7 @@ GntStyle en; } styles[] = {{"shadow", GNT_STYLE_SHADOW}, {"customcolor", GNT_STYLE_COLOR}, + {"mouse", GNT_STYLE_MOUSE}, {NULL, 0}}; if (error) diff -r 578a2c9af05e -r a766441af5ea console/libgnt/gntstyle.h --- a/console/libgnt/gntstyle.h Wed Aug 23 10:48:21 2006 +0000 +++ b/console/libgnt/gntstyle.h Wed Aug 23 12:29:08 2006 +0000 @@ -4,6 +4,7 @@ { GNT_STYLE_SHADOW = 0, GNT_STYLE_COLOR = 1, + GNT_STYLE_MOUSE = 2, GNT_STYLES } GntStyle; diff -r 578a2c9af05e -r a766441af5ea console/libgnt/test/keys.c --- a/console/libgnt/test/keys.c Wed Aug 23 10:48:21 2006 +0000 +++ b/console/libgnt/test/keys.c Wed Aug 23 12:29:08 2006 +0000 @@ -10,7 +10,25 @@ gnt_entry_set_text(entry, s); g_free(s); if (text[0] == 27) - return FALSE; + { + if (strncmp(text + 1, "[M ", 3) == 0) + { + int x = (unsigned)text[4]; + int y = (unsigned)text[5]; + if (x < 0) x += 256; + if (y < 0) y += 256; + x -= 33; + y -= 33; + s = g_strdup_printf("ldown %d %d", x, y); + gnt_entry_set_text(entry, s); + g_free(s); + } + else if (strncmp(text + 1, "[M#", 3) == 0) + gnt_entry_set_text(entry, "up"); + else + return FALSE; + return TRUE; + } else return TRUE; }