Mercurial > pidgin
comparison console/libgnt/gntmain.c @ 14343:0387a167f342
[gaim-migrate @ 17044]
A WM can now act on keystrokes. As an example, the sample WM will toggle
the buddylist on pressing Alt+b.
Mouse clicking and scrolling is now supported in most/all widgets.
To use a WM, you need to add "wm=/path/to/wm.so" under [general] in ~/.gntrc.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 26 Aug 2006 12:54:39 +0000 |
parents | b1b76fb9c739 |
children | 665b814f8fd7 |
comparison
equal
deleted
inserted
replaced
14342:12156328fb4f | 14343:0387a167f342 |
---|---|
39 static int Y_MAX; | 39 static int Y_MAX; |
40 | 40 |
41 static gboolean ascii_only; | 41 static gboolean ascii_only; |
42 static gboolean mouse_enabled; | 42 static gboolean mouse_enabled; |
43 | 43 |
44 static GntWM wm; | |
45 | |
46 static GMainLoop *loop; | 44 static GMainLoop *loop; |
47 static struct | 45 static struct |
48 { | 46 { |
49 GntWidget *window; | 47 GntWidget *window; |
50 GntWidget *tree; | 48 GntWidget *tree; |
71 static void free_node(gpointer data); | 69 static void free_node(gpointer data); |
72 static void draw_taskbar(gboolean reposition); | 70 static void draw_taskbar(gboolean reposition); |
73 static void bring_on_top(GntWidget *widget); | 71 static void bring_on_top(GntWidget *widget); |
74 | 72 |
75 static gboolean refresh_screen(); | 73 static gboolean refresh_screen(); |
74 static const GList *list_all_windows(); | |
75 | |
76 static GntWM wm = | |
77 { | |
78 NULL, /* new_window */ | |
79 NULL, /* close_window */ | |
80 NULL, /* key_pressed */ | |
81 NULL, /* mouse clicked */ | |
82 bring_on_top, /* give_focus */ | |
83 NULL, /* uninit */ | |
84 list_all_windows, /* window_list */ | |
85 }; | |
86 | |
87 static const GList *list_all_windows() | |
88 { | |
89 return focus_list; | |
90 } | |
76 | 91 |
77 static GList * | 92 static GList * |
78 g_list_bring_to_front(GList *list, gpointer data) | 93 g_list_bring_to_front(GList *list, gpointer data) |
79 { | 94 { |
80 list = g_list_remove(list, data); | 95 list = g_list_remove(list, data); |
125 focus_list = g_list_remove(focus_list, widget); | 140 focus_list = g_list_remove(focus_list, widget); |
126 ordered = g_list_remove(ordered, widget); | 141 ordered = g_list_remove(ordered, widget); |
127 | 142 |
128 if (ordered) | 143 if (ordered) |
129 { | 144 { |
130 bring_on_top(ordered->data); | 145 wm.give_focus(ordered->data); |
131 } | 146 } |
132 draw_taskbar(FALSE); | 147 draw_taskbar(FALSE); |
133 } | 148 } |
134 | 149 |
135 static void | 150 static void |
137 { | 152 { |
138 GntNode *node = g_hash_table_lookup(nodes, widget); | 153 GntNode *node = g_hash_table_lookup(nodes, widget); |
139 | 154 |
140 if (!node) | 155 if (!node) |
141 return; | 156 return; |
157 | |
158 if (ordered->data != widget) { | |
159 GntWidget *w = ordered->data; | |
160 ordered = g_list_bring_to_front(ordered, widget); | |
161 gnt_widget_set_focus(w, FALSE); | |
162 } | |
142 | 163 |
143 gnt_widget_set_focus(widget, TRUE); | 164 gnt_widget_set_focus(widget, TRUE); |
144 gnt_widget_draw(widget); | 165 gnt_widget_draw(widget); |
145 top_panel(node->panel); | 166 top_panel(node->panel); |
146 | 167 |
245 else if (pos >= 0) | 266 else if (pos >= 0) |
246 wid = g_list_nth_data(focus_list, pos); | 267 wid = g_list_nth_data(focus_list, pos); |
247 | 268 |
248 ordered = g_list_bring_to_front(ordered, wid); | 269 ordered = g_list_bring_to_front(ordered, wid); |
249 | 270 |
250 bring_on_top(ordered->data); | 271 wm.give_focus(ordered->data); |
251 | 272 |
252 if (w != wid) | 273 if (w != wid) |
253 { | 274 { |
254 gnt_widget_set_focus(w, FALSE); | 275 gnt_widget_set_focus(w, FALSE); |
255 } | 276 } |
267 w = ordered->data; | 288 w = ordered->data; |
268 | 289 |
269 if ((l = g_list_nth(focus_list, n)) != NULL) | 290 if ((l = g_list_nth(focus_list, n)) != NULL) |
270 { | 291 { |
271 ordered = g_list_bring_to_front(ordered, l->data); | 292 ordered = g_list_bring_to_front(ordered, l->data); |
272 bring_on_top(ordered->data); | 293 wm.give_focus(ordered->data); |
273 } | 294 } |
274 | 295 |
275 if (l && w != l->data) | 296 if (l && w != l->data) |
276 { | 297 { |
277 gnt_widget_set_focus(w, FALSE); | 298 gnt_widget_set_focus(w, FALSE); |
287 if (!ordered || !widget) | 308 if (!ordered || !widget) |
288 return; | 309 return; |
289 | 310 |
290 old = ordered->data; | 311 old = ordered->data; |
291 ordered = g_list_bring_to_front(ordered, widget); | 312 ordered = g_list_bring_to_front(ordered, widget); |
292 bring_on_top(widget); | 313 wm.give_focus(widget); |
293 | 314 |
294 if (old != widget) | 315 if (old != widget) |
295 { | 316 { |
296 gnt_widget_set_focus(old, FALSE); | 317 gnt_widget_set_focus(old, FALSE); |
297 } | 318 } |
512 MOUSE_RIGHT, | 533 MOUSE_RIGHT, |
513 MOUSE_MIDDLE | 534 MOUSE_MIDDLE |
514 } button = MOUSE_NONE; | 535 } button = MOUSE_NONE; |
515 static GntWidget *remember = NULL; | 536 static GntWidget *remember = NULL; |
516 static int offset = 0; | 537 static int offset = 0; |
517 | 538 GntMouseEvent event; |
518 if (buffer[0] != 27) | 539 |
540 if (!ordered || buffer[0] != 27) | |
519 return FALSE; | 541 return FALSE; |
520 | 542 |
521 buffer++; | 543 buffer++; |
522 if (strlen(buffer) < 5) | 544 if (strlen(buffer) < 5) |
523 return FALSE; | 545 return FALSE; |
539 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { | 561 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { |
540 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { | 562 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { |
541 if (iter != ordered) { | 563 if (iter != ordered) { |
542 GntWidget *w = ordered->data; | 564 GntWidget *w = ordered->data; |
543 ordered = g_list_bring_to_front(ordered, iter->data); | 565 ordered = g_list_bring_to_front(ordered, iter->data); |
544 bring_on_top(ordered->data); | 566 wm.give_focus(ordered->data); |
545 gnt_widget_set_focus(w, FALSE); | 567 gnt_widget_set_focus(w, FALSE); |
546 } | 568 } |
547 if (y == wid->priv.y) { | 569 if (y == wid->priv.y) { |
548 offset = x - wid->priv.x; | 570 offset = x - wid->priv.x; |
549 remember = wid; | 571 remember = wid; |
551 } | 573 } |
552 break; | 574 break; |
553 } | 575 } |
554 } | 576 } |
555 } | 577 } |
578 event = GNT_LEFT_MOUSE_DOWN; | |
556 } else if (strncmp(buffer, "[M\"", 3) == 0) { | 579 } else if (strncmp(buffer, "[M\"", 3) == 0) { |
557 /* right button down */ | 580 /* right button down */ |
581 event = GNT_RIGHT_MOUSE_DOWN; | |
558 } else if (strncmp(buffer, "[M!", 3) == 0) { | 582 } else if (strncmp(buffer, "[M!", 3) == 0) { |
559 /* middle button down */ | 583 /* middle button down */ |
584 event = GNT_MIDDLE_MOUSE_DOWN; | |
560 } else if (strncmp(buffer, "[M`", 3) == 0) { | 585 } else if (strncmp(buffer, "[M`", 3) == 0) { |
561 /* wheel up*/ | 586 /* wheel up*/ |
587 event = GNT_MOUSE_SCROLL_UP; | |
562 } else if (strncmp(buffer, "[Ma", 3) == 0) { | 588 } else if (strncmp(buffer, "[Ma", 3) == 0) { |
563 /* wheel down */ | 589 /* wheel down */ |
590 event = GNT_MOUSE_SCROLL_DOWN; | |
564 } else if (strncmp(buffer, "[M#", 3) == 0) { | 591 } else if (strncmp(buffer, "[M#", 3) == 0) { |
565 /* button up */ | 592 /* button up */ |
566 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { | 593 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { |
567 int n = g_list_length(focus_list); | 594 int n = g_list_length(focus_list); |
568 if (n) { | 595 if (n) { |
577 refresh_node(remember, NULL, NULL); | 604 refresh_node(remember, NULL, NULL); |
578 } | 605 } |
579 button = MOUSE_NONE; | 606 button = MOUSE_NONE; |
580 remember = NULL; | 607 remember = NULL; |
581 offset = 0; | 608 offset = 0; |
609 event = GNT_MOUSE_UP; | |
582 } else | 610 } else |
583 return FALSE; | 611 return FALSE; |
612 | |
613 gnt_widget_clicked(ordered->data, event, x, y); | |
584 return FALSE; /* XXX: this should be TRUE */ | 614 return FALSE; /* XXX: this should be TRUE */ |
585 } | 615 } |
586 | 616 |
587 static gboolean | 617 static gboolean |
588 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | 618 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) |
589 { | 619 { |
590 char buffer[256]; | 620 char keys[256]; |
591 gboolean ret = FALSE; | 621 gboolean ret = FALSE; |
592 static GntKeyPressMode mode = GNT_KP_MODE_NORMAL; | 622 static GntKeyPressMode mode = GNT_KP_MODE_NORMAL; |
593 | 623 const char *buffer; |
594 int rd = read(STDIN_FILENO, buffer, sizeof(buffer) - 1); | 624 |
625 int rd = read(STDIN_FILENO, keys, sizeof(keys) - 1); | |
595 if (rd < 0) | 626 if (rd < 0) |
596 { | 627 { |
597 endwin(); | 628 endwin(); |
598 printf("ERROR!\n"); | 629 printf("ERROR!\n"); |
599 exit(1); | 630 exit(1); |
603 endwin(); | 634 endwin(); |
604 printf("EOF\n"); | 635 printf("EOF\n"); |
605 exit(1); | 636 exit(1); |
606 } | 637 } |
607 | 638 |
608 buffer[rd] = 0; | 639 keys[rd] = 0; |
609 | 640 |
610 if (buffer[0] == 27 && buffer[1] == 'd' && buffer[2] == 0) | 641 if (keys[0] == 27 && keys[1] == 'd' && keys[2] == 0) |
611 { | 642 { |
612 /* This dumps the screen contents in an html file */ | 643 /* This dumps the screen contents in an html file */ |
613 dump_screen(); | 644 dump_screen(); |
614 } | 645 } |
615 | 646 |
616 gnt_keys_refine(buffer); | 647 gnt_keys_refine(keys); |
617 | 648 |
618 if (mouse_enabled && detect_mouse_action(buffer)) | 649 if (mouse_enabled && detect_mouse_action(keys)) |
619 return TRUE; | 650 return TRUE; |
651 | |
652 if (wm.key_pressed) { | |
653 buffer = wm.key_pressed(keys); | |
654 if (buffer == NULL) | |
655 return TRUE; | |
656 } else | |
657 buffer = keys; | |
620 | 658 |
621 if (mode == GNT_KP_MODE_NORMAL) | 659 if (mode == GNT_KP_MODE_NORMAL) |
622 { | 660 { |
623 if (ordered) | 661 if (ordered) |
624 { | 662 { |