comparison console/libgnt/gntmain.c @ 14310:a766441af5ea

[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 <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 23 Aug 2006 12:29:08 +0000
parents ea5193c23171
children 8b8188fa98f4
comparison
equal deleted inserted replaced
14309:578a2c9af05e 14310:a766441af5ea
29 static int X_MAX; 29 static int X_MAX;
30 static int Y_MIN; 30 static int Y_MIN;
31 static int Y_MAX; 31 static int Y_MAX;
32 32
33 static gboolean ascii_only; 33 static gboolean ascii_only;
34 static gboolean mouse_enabled;
34 35
35 static GMainLoop *loop; 36 static GMainLoop *loop;
36 static struct 37 static struct
37 { 38 {
38 GntWidget *window; 39 GntWidget *window;
478 nh = MIN(h, Y_MAX); 479 nh = MIN(h, Y_MAX);
479 if (nw != w || nh != h) 480 if (nw != w || nh != h)
480 gnt_screen_resize_widget(widget, nw, nh); 481 gnt_screen_resize_widget(widget, nw, nh);
481 } 482 }
482 483
484 /**
485 * Mouse support:
486 * - bring a window on top if you click on its taskbar
487 * - click on the top-bar of the active window and drag+drop to move a window
488 * wishlist:
489 * - have a little [X] on the windows, and clicking it will close that window.
490 * - click on a window to bring it to focus
491 * - allow scrolling in tree/textview on wheel-scroll event
492 * - click to activate button or select a row in tree
493 * - all these can be fulfilled by adding a "clicked" event for GntWidget
494 * which will send the (x,y) to the widget. (look at "key_pressed" for hints)
495 */
496 static gboolean
497 detect_mouse_action(const char *buffer)
498 {
499 int x, y;
500 static enum {
501 MOUSE_NONE,
502 MOUSE_LEFT,
503 MOUSE_RIGHT,
504 MOUSE_MIDDLE
505 } button = MOUSE_NONE;
506 static GntWidget *remember = NULL;
507 static int offset = 0;
508
509 if (buffer[0] != 27)
510 return FALSE;
511
512 buffer++;
513 if (strlen(buffer) < 5)
514 return FALSE;
515
516 x = buffer[3];
517 y = buffer[4];
518 if (x < 0) x += 256;
519 if (y < 0) y += 256;
520 x -= 33;
521 y -= 33;
522
523 if (strncmp(buffer, "[M ", 3) == 0) {
524 /* left button down */
525 /* If you clicked on the top-bar of the active window, then you can move it by dragging it */
526 if (focus_list) {
527 GntWidget *wid = focus_list->data;
528 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width &&
529 y == wid->priv.y) {
530 offset = x - wid->priv.x;
531 remember = wid;
532 button = MOUSE_LEFT;
533 }
534 }
535 } else if (strncmp(buffer, "[M\"", 3) == 0) {
536 /* right button down */
537 } else if (strncmp(buffer, "[M!", 3) == 0) {
538 /* middle button down */
539 } else if (strncmp(buffer, "[M`", 3) == 0) {
540 /* wheel up*/
541 } else if (strncmp(buffer, "[Ma", 3) == 0) {
542 /* wheel down */
543 } else if (strncmp(buffer, "[M#", 3) == 0) {
544 /* button up */
545 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) {
546 int n = g_list_length(g_list_first(focus_list));
547 if (n) {
548 int width = getmaxx(stdscr) / n;
549 switch_window_n(x / width);
550 }
551 } else if (button == MOUSE_LEFT && remember) {
552 x -= offset;
553 if (x < 0) x = 0;
554 if (y < 0) y = 0;
555 gnt_screen_move_widget(remember, x, y);
556 refresh_node(remember, NULL, NULL);
557 }
558 button = MOUSE_NONE;
559 remember = NULL;
560 offset = 0;
561 } else
562 return FALSE;
563 return TRUE;
564 }
565
483 static gboolean 566 static gboolean
484 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) 567 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null)
485 { 568 {
486 char buffer[256]; 569 char buffer[256];
487 gboolean ret = FALSE; 570 gboolean ret = FALSE;
508 /* This dumps the screen contents in an html file */ 591 /* This dumps the screen contents in an html file */
509 dump_screen(); 592 dump_screen();
510 } 593 }
511 594
512 gnt_keys_refine(buffer); 595 gnt_keys_refine(buffer);
596
597 if (mouse_enabled && detect_mouse_action(buffer))
598 return TRUE;
513 599
514 if (mode == GNT_KP_MODE_NORMAL) 600 if (mode == GNT_KP_MODE_NORMAL)
515 { 601 {
516 if (focus_list) 602 if (focus_list)
517 { 603 {
796 882
797 nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); 883 nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node);
798 884
799 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); 885 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
800 refresh(); 886 refresh();
801 #if 0 887
802 mousemask(NCURSES_BUTTON_PRESSED | NCURSES_BUTTON_RELEASED | REPORT_MOUSE_POSITION, NULL); 888 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE)))
803 #endif 889 mousemask(NCURSES_BUTTON_PRESSED | NCURSES_BUTTON_RELEASED , NULL);
890
804 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); 891 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL));
805 werase(stdscr); 892 werase(stdscr);
806 wrefresh(stdscr); 893 wrefresh(stdscr);
807 894
808 #ifdef SIGWINCH 895 #ifdef SIGWINCH