Mercurial > pidgin
diff console/libgnt/wms/s.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 |
line wrap: on
line diff
--- a/console/libgnt/wms/s.c Sat Aug 26 07:11:55 2006 +0000 +++ b/console/libgnt/wms/s.c Sat Aug 26 12:54:39 2006 +0000 @@ -1,8 +1,12 @@ #include "gntbox.h" #include "gntwm.h" +#include "gntblist.h" + #include <string.h> +static GntWM *gwm; + static PANEL * s_new_window(GntWidget *win) { @@ -31,12 +35,14 @@ mvwin(win->window, y, x); gnt_widget_set_size(win, w, h); + gnt_widget_draw(win); } else if (name && strcmp(name, "conversation-window") == 0) { /* Put the conversation windows to the far-right */ x = maxx - w; y = 0; gnt_widget_set_position(win, x, y); mvwin(win->window, y, x); + gnt_widget_draw(win); } else if (!GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_TRANSIENT)) { /* In the middle of the screen */ x = (maxx - w) / 2; @@ -49,8 +55,42 @@ return new_panel(win->window); } +static GntWidget * +find_widget(const char *wname) +{ + const GList *iter = gwm->window_list(); + for (; iter; iter = iter->next) { + GntWidget *widget = iter->data; + const char *name = gnt_widget_get_name(widget); + if (name && strcmp(name, wname) == 0) { + return widget; + } + } + return NULL; +} + +static const char* +s_key_pressed(const char *key) +{ + /* Alt+b to toggle the buddylist */ + if (key[0] == 27 && key[1] == 'b' && key[2] == '\0') { + GntWidget *w = find_widget("buddylist"); + if (w == NULL) { + gg_blist_show(); + w = find_widget("buddylist"); + gwm->give_focus(w); + } else { + gnt_widget_destroy(w); + } + return NULL; + } + return key; +} + void gntwm_init(GntWM *wm) { + gwm = wm; wm->new_window = s_new_window; + wm->key_pressed = s_key_pressed; }