Mercurial > pidgin.yaz
annotate finch/libgnt/gntwm.c @ 17713:3177ef1d6824
Fixed a few names that weren't formatted properly.
Rebinding of actions now works on focusable widgets. Currently, binding a new key comp to an action cause both the new and old bindings to work. I will work on replacing the old binding instead, in a future commit.
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Tue, 05 Jun 2007 19:37:32 +0000 |
parents | 43a55528ff26 |
children | 1abacdef8205 |
rev | line source |
---|---|
15818 | 1 #define _GNU_SOURCE |
2 #if defined(__APPLE__) | |
3 #define _XOPEN_SOURCE_EXTENDED | |
4 #endif | |
5 | |
6 #include "config.h" | |
7 | |
8 #include <ctype.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <time.h> | |
12 | |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
13 #include "gntbutton.h" |
15818 | 14 #include "gntwm.h" |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
15 #include "gntentry.h" |
15818 | 16 #include "gntstyle.h" |
17 #include "gntmarshal.h" | |
18 #include "gnt.h" | |
19 #include "gntbox.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
20 #include "gntlabel.h" |
15818 | 21 #include "gntmenu.h" |
22 #include "gnttextview.h" | |
23 #include "gnttree.h" | |
24 #include "gntutils.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
25 #include "gntwindow.h" |
15818 | 26 |
27 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ | |
28 | |
29 enum | |
30 { | |
31 SIG_NEW_WIN, | |
32 SIG_DECORATE_WIN, | |
33 SIG_CLOSE_WIN, | |
34 SIG_CONFIRM_RESIZE, | |
35 SIG_RESIZED, | |
36 SIG_CONFIRM_MOVE, | |
37 SIG_MOVED, | |
38 SIG_UPDATE_WIN, | |
39 SIG_GIVE_FOCUS, | |
40 SIG_KEY_PRESS, | |
41 SIG_MOUSE_CLICK, | |
42 SIGS | |
43 }; | |
44 | |
45 static guint signals[SIGS] = { 0 }; | |
46 static void gnt_wm_new_window_real(GntWM *wm, GntWidget *widget); | |
47 static void gnt_wm_win_resized(GntWM *wm, GntNode *node); | |
48 static void gnt_wm_win_moved(GntWM *wm, GntNode *node); | |
49 static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); | |
50 static void update_window_in_list(GntWM *wm, GntWidget *wid); | |
51 static void shift_window(GntWM *wm, GntWidget *widget, int dir); | |
52 | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
53 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
54 static int widestringwidth(wchar_t *wide); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
55 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
56 |
15818 | 57 static gboolean write_already(gpointer data); |
58 static int write_timeout; | |
59 static time_t last_active_time; | |
60 static gboolean idle_update; | |
61 | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
62 static gboolean ignore_keys = FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
63 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
64 typedef struct |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
65 { |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
66 const char * keys; /* Keystrokes being bound to the action */ |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
67 GntBindableClass * klass; /* Class of the object that's getting keys rebound */ |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
68 const char * name; /* The name of the action */ |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
69 GList * params; /* The list of paramaters */ |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
70 |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
71 } RebindInfo; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
72 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
73 RebindInfo * rebind_info; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
74 |
15818 | 75 static GList * |
76 g_list_bring_to_front(GList *list, gpointer data) | |
77 { | |
78 list = g_list_remove(list, data); | |
79 list = g_list_prepend(list, data); | |
80 return list; | |
81 } | |
82 | |
83 static void | |
84 free_node(gpointer data) | |
85 { | |
86 GntNode *node = data; | |
87 hide_panel(node->panel); | |
88 del_panel(node->panel); | |
89 g_free(node); | |
90 } | |
91 | |
92 static void | |
93 draw_taskbar(GntWM *wm, gboolean reposition) | |
94 { | |
95 static WINDOW *taskbar = NULL; | |
96 GList *iter; | |
97 int n, width = 0; | |
98 int i; | |
99 | |
100 if (taskbar == NULL) { | |
101 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
102 } else if (reposition) { | |
103 int Y_MAX = getmaxy(stdscr) - 1; | |
104 mvwin(taskbar, Y_MAX, 0); | |
105 } | |
106 | |
107 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
108 werase(taskbar); | |
109 | |
110 n = g_list_length(wm->list); | |
111 if (n) | |
112 width = getmaxx(stdscr) / n; | |
113 | |
114 for (i = 0, iter = wm->list; iter; iter = iter->next, i++) | |
115 { | |
116 GntWidget *w = iter->data; | |
117 int color; | |
118 const char *title; | |
119 | |
120 if (w == wm->ordered->data) { | |
121 /* This is the current window in focus */ | |
122 color = GNT_COLOR_TITLE; | |
123 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
124 /* This is a window with the URGENT hint set */ | |
125 color = GNT_COLOR_URGENT; | |
126 } else { | |
127 color = GNT_COLOR_NORMAL; | |
128 } | |
129 wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); | |
130 if (iter->next) | |
131 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); | |
132 else | |
133 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i); | |
134 title = GNT_BOX(w)->title; | |
135 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); | |
136 if (i) | |
137 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
138 | |
139 update_window_in_list(wm, w); | |
140 } | |
141 | |
142 wrefresh(taskbar); | |
143 } | |
144 | |
145 static void | |
146 copy_win(GntWidget *widget, GntNode *node) | |
147 { | |
148 WINDOW *src, *dst; | |
149 int shadow; | |
150 if (!node) | |
151 return; | |
152 src = widget->window; | |
153 dst = node->window; | |
154 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
155 copywin(src, dst, node->scroll, 0, 0, 0, getmaxy(dst) - 1, getmaxx(dst) - 1, 0); | |
156 } | |
157 | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
158 /** |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
159 * The following is a workaround for a bug in most versions of ncursesw. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
160 * Read about it in: http://article.gmane.org/gmane.comp.lib.ncurses.bugs/2751 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
161 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
162 * In short, if a panel hides one cell of a multi-cell character, then the rest |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
163 * of the characters in that line get screwed. The workaround here is to erase |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
164 * any such character preemptively. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
165 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
166 * Caveat: If a wide character is erased, and the panel above it is moved enough |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
167 * to expose the entire character, it is not always redrawn. |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
168 */ |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
169 static void |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
170 work_around_for_ncurses_bug() |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
171 { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
172 #ifndef NO_WIDECHAR |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
173 PANEL *panel = NULL; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
174 while ((panel = panel_below(panel)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
175 int sx, ex, sy, ey, w, y; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
176 cchar_t ch; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
177 PANEL *below = panel; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
178 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
179 sx = panel->win->_begx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
180 ex = panel->win->_maxx + sx; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
181 sy = panel->win->_begy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
182 ey = panel->win->_maxy + sy; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
183 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
184 while ((below = panel_below(below)) != NULL) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
185 if (sy > below->win->_begy + below->win->_maxy || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
186 ey < below->win->_begy) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
187 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
188 if (sx > below->win->_begx + below->win->_maxx || |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
189 ex < below->win->_begx) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
190 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
191 for (y = MAX(sy, below->win->_begy); y <= MIN(ey, below->win->_begy + below->win->_maxy); y++) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
192 if (mvwin_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
193 goto right; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
194 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
195 if (w > 1 && (ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
196 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
197 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
198 mvwadd_wch(below->win, y - below->win->_begy, sx - 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
199 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
200 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
201 right: |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
202 if (mvwin_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch) != OK) |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
203 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
204 w = widestringwidth(ch.chars); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
205 if (w > 1 && !(ch.attr & 1)) { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
206 ch.chars[0] = ' '; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
207 ch.attr &= ~ A_CHARTEXT; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
208 mvwadd_wch(below->win, y - below->win->_begy, ex + 1 - below->win->_begx, &ch); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
209 touchline(below->win, y - below->win->_begy, 1); |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
210 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
211 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
212 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
213 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
214 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
215 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
216 |
15818 | 217 static gboolean |
218 update_screen(GntWM *wm) | |
219 { | |
220 if (wm->menu) { | |
221 GntMenu *top = wm->menu; | |
222 while (top) { | |
223 GntNode *node = g_hash_table_lookup(wm->nodes, top); | |
224 if (node) | |
225 top_panel(node->panel); | |
226 top = top->submenu; | |
227 } | |
228 } | |
17059
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16526
diff
changeset
|
229 work_around_for_ncurses_bug(); |
15818 | 230 update_panels(); |
231 doupdate(); | |
232 return TRUE; | |
233 } | |
234 | |
235 static gboolean | |
236 sanitize_position(GntWidget *widget, int *x, int *y) | |
237 { | |
238 int X_MAX = getmaxx(stdscr); | |
239 int Y_MAX = getmaxy(stdscr) - 1; | |
240 int w, h; | |
241 int nx, ny; | |
242 gboolean changed = FALSE; | |
243 | |
244 gnt_widget_get_size(widget, &w, &h); | |
245 if (x) { | |
246 if (*x + w > X_MAX) { | |
247 nx = MAX(0, X_MAX - w); | |
248 if (nx != *x) { | |
249 *x = nx; | |
250 changed = TRUE; | |
251 } | |
252 } | |
253 } | |
254 if (y) { | |
255 if (*y + h > Y_MAX) { | |
256 ny = MAX(0, Y_MAX - h); | |
257 if (ny != *y) { | |
258 *y = ny; | |
259 changed = TRUE; | |
260 } | |
261 } | |
262 } | |
263 return changed; | |
264 } | |
265 | |
266 static void | |
267 refresh_node(GntWidget *widget, GntNode *node, gpointer null) | |
268 { | |
269 int x, y, w, h; | |
270 int nw, nh; | |
271 | |
272 int X_MAX = getmaxx(stdscr); | |
273 int Y_MAX = getmaxy(stdscr) - 1; | |
274 | |
275 gnt_widget_get_position(widget, &x, &y); | |
276 gnt_widget_get_size(widget, &w, &h); | |
277 | |
278 if (sanitize_position(widget, &x, &y)) | |
279 gnt_screen_move_widget(widget, x, y); | |
280 | |
281 nw = MIN(w, X_MAX); | |
282 nh = MIN(h, Y_MAX); | |
283 if (nw != w || nh != h) | |
284 gnt_screen_resize_widget(widget, nw, nh); | |
285 } | |
286 | |
287 static void | |
288 read_window_positions(GntWM *wm) | |
289 { | |
290 #if GLIB_CHECK_VERSION(2,6,0) | |
291 GKeyFile *gfile = g_key_file_new(); | |
292 char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
293 GError *error = NULL; | |
294 char **keys; | |
295 gsize nk; | |
296 | |
297 if (!g_key_file_load_from_file(gfile, filename, G_KEY_FILE_NONE, &error)) { | |
298 g_printerr("GntWM: %s\n", error->message); | |
299 g_error_free(error); | |
300 g_free(filename); | |
301 return; | |
302 } | |
303 | |
304 keys = g_key_file_get_keys(gfile, "positions", &nk, &error); | |
305 if (error) { | |
306 g_printerr("GntWM: %s\n", error->message); | |
307 g_error_free(error); | |
308 error = NULL; | |
309 } else { | |
310 while (nk--) { | |
311 char *title = keys[nk]; | |
312 gsize l; | |
313 char **coords = g_key_file_get_string_list(gfile, "positions", title, &l, NULL); | |
314 if (l == 2) { | |
315 int x = atoi(coords[0]); | |
316 int y = atoi(coords[1]); | |
317 GntPosition *p = g_new0(GntPosition, 1); | |
318 p->x = x; | |
319 p->y = y; | |
320 g_hash_table_replace(wm->positions, g_strdup(title + 1), p); | |
321 } else { | |
322 g_printerr("GntWM: Invalid number of arguments for positioing a window.\n"); | |
323 } | |
324 g_strfreev(coords); | |
325 } | |
326 g_strfreev(keys); | |
327 } | |
328 | |
329 g_free(filename); | |
15964 | 330 g_key_file_free(gfile); |
15818 | 331 #endif |
332 } | |
333 | |
334 static gboolean check_idle(gpointer n) | |
335 { | |
336 if (idle_update) { | |
337 time(&last_active_time); | |
338 idle_update = FALSE; | |
339 } | |
340 return TRUE; | |
341 } | |
342 | |
343 static void | |
344 gnt_wm_init(GTypeInstance *instance, gpointer class) | |
345 { | |
346 GntWM *wm = GNT_WM(instance); | |
347 wm->list = NULL; | |
348 wm->ordered = NULL; | |
349 wm->event_stack = FALSE; | |
350 wm->windows = NULL; | |
351 wm->actions = NULL; | |
352 wm->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); | |
353 wm->positions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
354 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE)) | |
355 read_window_positions(wm); | |
356 g_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idle, NULL); | |
357 time(&last_active_time); | |
358 } | |
359 | |
360 static void | |
361 switch_window(GntWM *wm, int direction) | |
362 { | |
363 GntWidget *w = NULL, *wid = NULL; | |
364 int pos; | |
365 | |
366 if (wm->_list.window || wm->menu) | |
367 return; | |
368 | |
369 if (!wm->ordered || !wm->ordered->next) | |
370 return; | |
371 | |
372 w = wm->ordered->data; | |
373 pos = g_list_index(wm->list, w); | |
374 pos += direction; | |
375 | |
376 if (pos < 0) | |
377 wid = g_list_last(wm->list)->data; | |
378 else if (pos >= g_list_length(wm->list)) | |
379 wid = wm->list->data; | |
380 else if (pos >= 0) | |
381 wid = g_list_nth_data(wm->list, pos); | |
382 | |
383 wm->ordered = g_list_bring_to_front(wm->ordered, wid); | |
384 | |
385 gnt_wm_raise_window(wm, wm->ordered->data); | |
386 | |
387 if (w != wid) { | |
388 gnt_widget_set_focus(w, FALSE); | |
389 } | |
390 } | |
391 | |
392 static gboolean | |
393 window_next(GntBindable *bindable, GList *null) | |
394 { | |
395 GntWM *wm = GNT_WM(bindable); | |
396 switch_window(wm, 1); | |
397 return TRUE; | |
398 } | |
399 | |
400 static gboolean | |
401 window_prev(GntBindable *bindable, GList *null) | |
402 { | |
403 GntWM *wm = GNT_WM(bindable); | |
404 switch_window(wm, -1); | |
405 return TRUE; | |
406 } | |
407 | |
408 static gboolean | |
409 switch_window_n(GntBindable *bind, GList *list) | |
410 { | |
411 GntWM *wm = GNT_WM(bind); | |
412 GntWidget *w = NULL; | |
413 GList *l; | |
414 int n; | |
415 | |
416 if (!wm->ordered) | |
417 return TRUE; | |
418 | |
419 if (list) | |
420 n = GPOINTER_TO_INT(list->data); | |
421 else | |
422 n = 0; | |
423 | |
424 w = wm->ordered->data; | |
425 | |
426 if ((l = g_list_nth(wm->list, n)) != NULL) | |
427 { | |
428 gnt_wm_raise_window(wm, l->data); | |
429 } | |
430 | |
431 if (l && w != l->data) | |
432 { | |
433 gnt_widget_set_focus(w, FALSE); | |
434 } | |
435 return TRUE; | |
436 } | |
437 | |
438 static gboolean | |
439 window_scroll_up(GntBindable *bindable, GList *null) | |
440 { | |
441 GntWM *wm = GNT_WM(bindable); | |
442 GntWidget *window; | |
443 GntNode *node; | |
444 | |
445 if (!wm->ordered) | |
446 return TRUE; | |
447 | |
448 window = wm->ordered->data; | |
449 node = g_hash_table_lookup(wm->nodes, window); | |
450 if (!node) | |
451 return TRUE; | |
452 | |
453 if (node->scroll) { | |
454 node->scroll--; | |
455 copy_win(window, node); | |
456 update_screen(wm); | |
457 } | |
458 return TRUE; | |
459 } | |
460 | |
461 static gboolean | |
462 window_scroll_down(GntBindable *bindable, GList *null) | |
463 { | |
464 GntWM *wm = GNT_WM(bindable); | |
465 GntWidget *window; | |
466 GntNode *node; | |
467 int w, h; | |
468 | |
469 if (!wm->ordered) | |
470 return TRUE; | |
471 | |
472 window = wm->ordered->data; | |
473 node = g_hash_table_lookup(wm->nodes, window); | |
474 if (!node) | |
475 return TRUE; | |
476 | |
477 gnt_widget_get_size(window, &w, &h); | |
478 if (h - node->scroll > getmaxy(node->window)) { | |
479 node->scroll++; | |
480 copy_win(window, node); | |
481 update_screen(wm); | |
482 } | |
483 return TRUE; | |
484 } | |
485 | |
486 static gboolean | |
487 window_close(GntBindable *bindable, GList *null) | |
488 { | |
489 GntWM *wm = GNT_WM(bindable); | |
490 | |
491 if (wm->_list.window) | |
492 return TRUE; | |
493 | |
494 if (wm->ordered) { | |
495 gnt_widget_destroy(wm->ordered->data); | |
496 } | |
497 | |
498 return TRUE; | |
499 } | |
500 | |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
501 static void |
17541
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
502 free_rebind_info() |
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
503 { |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
504 g_free(rebind_info->name); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
505 g_free(rebind_info->keys); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
506 g_free(rebind_info); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
507 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
508 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
509 static gboolean |
17541
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
510 help_for_widget_cancel_button_activate(GntBindable *bindable, gpointer data) |
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
511 { |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
512 free_rebind_info(); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
513 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
514 gnt_widget_destroy(GNT_WIDGET(data)); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
515 return TRUE; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
516 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
517 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
518 static gboolean |
17541
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
519 help_for_widget_bind_button_activate(GntBindable *bindable, gpointer data) |
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
520 { |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
521 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
522 gnt_bindable_register_binding(rebind_info->klass, |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
523 rebind_info->name, |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
524 rebind_info->keys, |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
525 rebind_info->params); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
526 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
527 free_rebind_info(); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
528 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
529 gnt_widget_destroy(GNT_WIDGET(data)); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
530 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
531 return TRUE; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
532 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
533 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
534 static gboolean |
17541
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
535 help_for_widget_grab_key(GntBindable *bindable, const char *text, gpointer *data) |
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
536 { |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
537 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
538 GntLabel *label = GNT_LABEL(data); |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
539 char *new_text; |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
540 const char *tmp; |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
541 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
542 if(text && *text){ |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
543 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
544 if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){ |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
545 return FALSE; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
546 } |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
547 |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
548 tmp = gnt_key_lookup(text); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
549 new_text = g_strdup_printf("KEY: \"%s\"",tmp); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
550 gnt_label_set_text(label,new_text); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
551 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
552 rebind_info->keys = g_strdup(text); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
553 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
554 g_free(new_text); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
555 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
556 return TRUE; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
557 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
558 return FALSE; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
559 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
560 static void |
17541
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
561 help_for_widget_activate(GntBindable *bindable, gpointer widget) |
aeb8c9fbb577
Fixed some curlies for functions
Eric Polino <aluink@pidgin.im>
parents:
17540
diff
changeset
|
562 { |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
563 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
564 GntTree * tree = GNT_TREE(bindable); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
565 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
566 GntWidget *vbox = gnt_box_new(FALSE,TRUE); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
567 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
568 GntWidget *label; |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
569 const char * widget_name = g_type_name(G_OBJECT_TYPE(widget)); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
570 char * keys; |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
571 |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
572 GntWidget *key_label; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
573 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
574 GntWidget *bind_button, *cancel_button; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
575 GntWidget *button_box; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
576 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
577 GntWidget *win = gnt_window_new(); |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
578 GList * current_row_data,*itr; |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
579 char * tmp; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
580 |
17542
ab71a09600ad
Changed a malloc use to g_new0
Eric Polino <aluink@pidgin.im>
parents:
17541
diff
changeset
|
581 rebind_info = g_new0(RebindInfo,1); |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
582 |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
583 rebind_info->klass = GNT_BINDABLE_GET_CLASS(widget); |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
584 |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
585 current_row_data = gnt_tree_get_selection_text_list(tree); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
586 rebind_info->name = g_strdup(g_list_nth_data(current_row_data,1)); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
587 |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
588 keys = gnt_tree_get_selection_data(tree); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
589 rebind_info->keys = g_strdup(gnt_key_translate(keys)); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
590 |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
591 rebind_info->params = NULL; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
592 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
593 fprintf(stderr,"name: '%s' keys: '%s'\n",rebind_info->name,keys); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
594 |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
595 itr = current_row_data; |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
596 while(itr){ |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
597 g_free(itr->data); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
598 itr = itr->next; |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
599 } |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
600 g_list_free(current_row_data); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
601 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
602 gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
603 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
604 gnt_box_set_title(GNT_BOX(win),"Key Capture"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
605 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
606 tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info->name,widget_name); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
607 label = gnt_label_new(tmp); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
608 g_free(tmp); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
609 gnt_box_add_widget(GNT_BOX(vbox),label); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
610 |
17713
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
611 tmp = g_strdup_printf("KEY: \"%s\"",keys); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
612 key_label = gnt_label_new(tmp); |
3177ef1d6824
Fixed a few names that weren't formatted properly.
Eric Polino <aluink@pidgin.im>
parents:
17712
diff
changeset
|
613 g_free(tmp); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
614 gnt_widget_set_name(key_label,"keystroke"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
615 gnt_box_add_widget(GNT_BOX(vbox),key_label); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
616 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
617 g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(help_for_widget_grab_key),key_label); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
618 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
619 button_box = gnt_box_new(FALSE,FALSE); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
620 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
621 bind_button = gnt_button_new("BIND"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
622 gnt_widget_set_name(bind_button,"bind"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
623 gnt_box_add_widget(GNT_BOX(button_box), bind_button); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
624 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
625 cancel_button = gnt_button_new("Cancel"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
626 gnt_widget_set_name(cancel_button,"cancel"); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
627 gnt_box_add_widget(GNT_BOX(button_box),cancel_button); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
628 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
629 g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(help_for_widget_bind_button_activate),win); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
630 g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(help_for_widget_cancel_button_activate),win); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
631 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
632 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
633 gnt_box_add_widget(GNT_BOX(vbox),button_box); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
634 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
635 gnt_box_add_widget(GNT_BOX(win),vbox); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
636 gnt_widget_show(win); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
637 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
638 } |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
639 |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
640 static gboolean |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
641 help_for_widget(GntBindable *bindable, GList *null) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
642 { |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
643 GntWM *wm = GNT_WM(bindable); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
644 GntWidget *widget, *tree, *win, *active; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
645 char *title; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
646 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
647 if (!wm->ordered) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
648 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
649 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
650 widget = wm->ordered->data; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
651 if (!GNT_IS_BOX(widget)) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
652 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
653 active = GNT_BOX(widget)->active; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
654 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
655 tree = gnt_widget_bindings_view(active); |
17540
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
656 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(help_for_widget_activate), active); |
b242187b3591
Created a new window that will be used for key-rebinding. Right now it doesn't rebind the keys, but that can be added soon. A bit of esthetical work remains.
Eric Polino <aluink@pidgin.im>
parents:
17539
diff
changeset
|
657 |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
658 win = gnt_window_new(); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
659 title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active))); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
660 gnt_box_set_title(GNT_BOX(win), title); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
661 if (tree) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
662 gnt_box_add_widget(GNT_BOX(win), tree); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
663 else |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
664 gnt_box_add_widget(GNT_BOX(win), gnt_label_new("This widget has no customizable bindings.")); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
665 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
666 gnt_widget_show(win); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
667 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
668 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
669 } |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
670 |
15818 | 671 static void |
672 destroy__list(GntWidget *widget, GntWM *wm) | |
673 { | |
674 wm->_list.window = NULL; | |
675 wm->_list.tree = NULL; | |
676 wm->windows = NULL; | |
677 wm->actions = NULL; | |
678 update_screen(wm); | |
679 } | |
680 | |
681 static void | |
682 setup__list(GntWM *wm) | |
683 { | |
684 GntWidget *tree, *win; | |
685 win = wm->_list.window = gnt_box_new(FALSE, FALSE); | |
686 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | |
687 gnt_box_set_pad(GNT_BOX(win), 0); | |
688 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_TRANSIENT); | |
689 | |
690 tree = wm->_list.tree = gnt_tree_new(); | |
691 gnt_box_add_widget(GNT_BOX(win), tree); | |
692 | |
693 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy__list), wm); | |
694 } | |
695 | |
696 static void | |
697 window_list_activate(GntTree *tree, GntWM *wm) | |
698 { | |
699 GntWidget *widget = gnt_tree_get_selection_data(GNT_TREE(tree)); | |
700 | |
701 if (!wm->ordered || !widget) | |
702 return; | |
703 | |
704 gnt_widget_destroy(wm->_list.window); | |
705 gnt_wm_raise_window(wm, widget); | |
706 } | |
707 | |
708 static void | |
709 populate_window_list(GntWM *wm) | |
710 { | |
711 GList *iter; | |
712 GntTree *tree = GNT_TREE(wm->windows->tree); | |
713 for (iter = wm->list; iter; iter = iter->next) { | |
714 GntBox *box = GNT_BOX(iter->data); | |
715 | |
716 gnt_tree_add_row_last(tree, box, | |
717 gnt_tree_create_row(tree, box->title), NULL); | |
718 update_window_in_list(wm, GNT_WIDGET(box)); | |
719 } | |
720 } | |
721 | |
722 static gboolean | |
723 window_list_key_pressed(GntWidget *widget, const char *text, GntWM *wm) | |
724 { | |
725 if (text[1] == 0 && wm->ordered) { | |
726 GntWidget *sel = gnt_tree_get_selection_data(GNT_TREE(widget)); | |
727 switch (text[0]) { | |
728 case '-': | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
729 case ',': |
15818 | 730 shift_window(wm, sel, -1); |
731 break; | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
732 case '=': |
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
733 case '.': |
15818 | 734 shift_window(wm, sel, 1); |
735 break; | |
736 default: | |
737 return FALSE; | |
738 } | |
739 gnt_tree_remove_all(GNT_TREE(widget)); | |
740 populate_window_list(wm); | |
741 gnt_tree_set_selected(GNT_TREE(widget), sel); | |
742 return TRUE; | |
743 } | |
744 return FALSE; | |
745 } | |
746 | |
747 static gboolean | |
748 window_list(GntBindable *bindable, GList *null) | |
749 { | |
750 GntWM *wm = GNT_WM(bindable); | |
751 GntWidget *tree, *win; | |
752 | |
753 if (wm->_list.window || wm->menu) | |
754 return TRUE; | |
755 | |
756 if (!wm->ordered) | |
757 return TRUE; | |
758 | |
759 setup__list(wm); | |
760 wm->windows = &wm->_list; | |
761 | |
762 win = wm->windows->window; | |
763 tree = wm->windows->tree; | |
764 | |
765 gnt_box_set_title(GNT_BOX(win), "Window List"); | |
766 | |
767 populate_window_list(wm); | |
768 | |
769 gnt_tree_set_selected(GNT_TREE(tree), wm->ordered->data); | |
770 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), wm); | |
771 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(window_list_key_pressed), wm); | |
772 | |
773 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); | |
774 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); | |
775 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); | |
776 | |
777 gnt_widget_show(win); | |
778 return TRUE; | |
779 } | |
780 | |
781 static gboolean | |
782 dump_screen(GntBindable *bindable, GList *null) | |
783 { | |
784 int x, y; | |
785 chtype old = 0, now = 0; | |
786 FILE *file = fopen("dump.html", "w"); | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
787 struct { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
788 char ascii; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
789 char *unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
790 } unis[] = { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
791 {'q', "─"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
792 {'t', "├"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
793 {'u', "┤"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
794 {'x', "│"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
795 {'-', "↑"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
796 {'.', "↓"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
797 {'l', "┌"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
798 {'k', "┐"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
799 {'m', "└"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
800 {'j', "┘"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
801 {'a', "▒"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
802 {'\0', NULL} |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
803 }; |
15818 | 804 |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
805 fprintf(file, "<head>\n <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n</head>\n<body>\n"); |
15818 | 806 fprintf(file, "<pre>"); |
807 for (y = 0; y < getmaxy(stdscr); y++) { | |
808 for (x = 0; x < getmaxx(stdscr); x++) { | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
809 char ch[2] = {0, 0}, *print; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
810 #ifdef NO_WIDECHAR |
15818 | 811 now = mvwinch(curscr, y, x); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
812 ch[0] = now & A_CHARTEXT; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
813 now ^= ch[0]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
814 #else |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
815 cchar_t wch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
816 char unicode[12]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
817 mvwin_wch(curscr, y, x, &wch); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
818 now = wch.attr; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
819 ch[0] = (char)(wch.chars[0] & 0xff); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
820 #endif |
15818 | 821 |
822 #define CHECK(attr, start, end) \ | |
823 do \ | |
824 { \ | |
825 if (now & attr) \ | |
826 { \ | |
827 if (!(old & attr)) \ | |
828 fprintf(file, "%s", start); \ | |
829 } \ | |
830 else if (old & attr) \ | |
831 { \ | |
832 fprintf(file, "%s", end); \ | |
833 } \ | |
834 } while (0) | |
835 | |
836 CHECK(A_BOLD, "<b>", "</b>"); | |
837 CHECK(A_UNDERLINE, "<u>", "</u>"); | |
838 CHECK(A_BLINK, "<blink>", "</blink>"); | |
839 | |
840 if ((now & A_COLOR) != (old & A_COLOR) || | |
841 (now & A_REVERSE) != (old & A_REVERSE)) | |
842 { | |
843 int ret; | |
844 short fgp, bgp, r, g, b; | |
845 struct | |
846 { | |
847 int r, g, b; | |
848 } fg, bg; | |
849 | |
850 ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); | |
851 if (fgp == -1) | |
852 fgp = COLOR_BLACK; | |
853 if (bgp == -1) | |
854 bgp = COLOR_WHITE; | |
855 if (now & A_REVERSE) | |
17174
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
856 { |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
857 short tmp = fgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
858 fgp = bgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
859 bgp = tmp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17140
diff
changeset
|
860 } |
15818 | 861 ret = color_content(fgp, &r, &g, &b); |
862 fg.r = r; fg.b = b; fg.g = g; | |
863 ret = color_content(bgp, &r, &g, &b); | |
864 bg.r = r; bg.b = b; bg.g = g; | |
865 #define ADJUST(x) (x = x * 255 / 1000) | |
866 ADJUST(fg.r); | |
867 ADJUST(fg.g); | |
868 ADJUST(fg.b); | |
869 ADJUST(bg.r); | |
870 ADJUST(bg.b); | |
871 ADJUST(bg.g); | |
872 | |
873 if (x) fprintf(file, "</span>"); | |
874 fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", | |
875 bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); | |
876 } | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
877 print = ch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
878 #ifndef NO_WIDECHAR |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
879 if (wch.chars[0] > 255) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
880 snprintf(unicode, sizeof(unicode), "&#x%x;", wch.chars[0]); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
881 print = unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
882 } |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
883 #endif |
15818 | 884 if (now & A_ALTCHARSET) |
885 { | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
886 int u; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
887 for (u = 0; unis[u].ascii; u++) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
888 if (ch[0] == unis[u].ascii) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
889 print = unis[u].unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
890 break; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
891 } |
15818 | 892 } |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
893 if (!unis[u].ascii) |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
894 print = " "; |
15818 | 895 } |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
896 if (ch[0] == '&') |
15818 | 897 fprintf(file, "&"); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
898 else if (ch[0] == '<') |
15818 | 899 fprintf(file, "<"); |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
900 else if (ch[0] == '>') |
15818 | 901 fprintf(file, ">"); |
902 else | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
903 fprintf(file, "%s", print); |
15818 | 904 old = now; |
905 } | |
906 fprintf(file, "</span>\n"); | |
907 old = 0; | |
908 } | |
17140
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17059
diff
changeset
|
909 fprintf(file, "</pre>\n</body>"); |
15818 | 910 fclose(file); |
911 return TRUE; | |
912 } | |
913 | |
914 static void | |
915 shift_window(GntWM *wm, GntWidget *widget, int dir) | |
916 { | |
917 GList *all = wm->list; | |
918 GList *list = g_list_find(all, widget); | |
919 int length, pos; | |
920 if (!list) | |
921 return; | |
922 | |
923 length = g_list_length(all); | |
924 pos = g_list_position(all, list); | |
925 | |
926 pos += dir; | |
927 if (dir > 0) | |
928 pos++; | |
929 | |
930 if (pos < 0) | |
931 pos = length; | |
932 else if (pos > length) | |
933 pos = 0; | |
934 | |
935 all = g_list_insert(all, widget, pos); | |
936 all = g_list_delete_link(all, list); | |
937 wm->list = all; | |
938 draw_taskbar(wm, FALSE); | |
939 } | |
940 | |
941 static gboolean | |
942 shift_left(GntBindable *bindable, GList *null) | |
943 { | |
944 GntWM *wm = GNT_WM(bindable); | |
945 if (wm->_list.window) | |
946 return TRUE; | |
947 | |
948 shift_window(wm, wm->ordered->data, -1); | |
949 return TRUE; | |
950 } | |
951 | |
952 static gboolean | |
953 shift_right(GntBindable *bindable, GList *null) | |
954 { | |
955 GntWM *wm = GNT_WM(bindable); | |
956 if (wm->_list.window) | |
957 return TRUE; | |
958 | |
959 shift_window(wm, wm->ordered->data, 1); | |
960 return TRUE; | |
961 } | |
962 | |
963 static void | |
964 action_list_activate(GntTree *tree, GntWM *wm) | |
965 { | |
966 GntAction *action = gnt_tree_get_selection_data(tree); | |
967 action->callback(); | |
968 gnt_widget_destroy(wm->_list.window); | |
969 } | |
970 | |
971 static int | |
972 compare_action(gconstpointer p1, gconstpointer p2) | |
973 { | |
974 const GntAction *a1 = p1; | |
975 const GntAction *a2 = p2; | |
976 | |
977 return g_utf8_collate(a1->label, a2->label); | |
978 } | |
979 | |
980 static gboolean | |
981 list_actions(GntBindable *bindable, GList *null) | |
982 { | |
983 GntWidget *tree, *win; | |
984 GList *iter; | |
985 GntWM *wm = GNT_WM(bindable); | |
986 if (wm->_list.window || wm->menu) | |
987 return TRUE; | |
988 | |
989 if (wm->acts == NULL) | |
990 return TRUE; | |
991 | |
992 setup__list(wm); | |
993 wm->actions = &wm->_list; | |
994 | |
995 win = wm->actions->window; | |
996 tree = wm->actions->tree; | |
997 | |
998 gnt_box_set_title(GNT_BOX(win), "Actions"); | |
999 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
1000 /* XXX: Do we really want this? */ | |
1001 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); | |
1002 | |
1003 for (iter = wm->acts; iter; iter = iter->next) { | |
1004 GntAction *action = iter->data; | |
1005 gnt_tree_add_row_last(GNT_TREE(tree), action, | |
1006 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); | |
1007 } | |
1008 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm); | |
1009 gnt_widget_set_size(tree, 0, g_list_length(wm->acts)); | |
1010 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts)); | |
1011 | |
1012 gnt_widget_show(win); | |
1013 return TRUE; | |
1014 } | |
1015 | |
1016 #ifndef NO_WIDECHAR | |
1017 static int | |
1018 widestringwidth(wchar_t *wide) | |
1019 { | |
1020 int len, ret; | |
1021 char *string; | |
1022 | |
1023 len = wcstombs(NULL, wide, 0) + 1; | |
1024 string = g_new0(char, len); | |
1025 wcstombs(string, wide, len); | |
1026 ret = gnt_util_onscreen_width(string, NULL); | |
1027 g_free(string); | |
1028 return ret; | |
1029 } | |
1030 #endif | |
1031 | |
1032 /* Returns the onscreen width of the character at the position */ | |
1033 static int | |
1034 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
1035 { | |
1036 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
1037 | |
1038 #ifdef NO_WIDECHAR | |
1039 chtype ch; | |
1040 ch = mvwinch(d, y, x); | |
1041 mvwaddch(d, y, x, DECIDE(ch)); | |
1042 return 1; | |
1043 #else | |
1044 cchar_t ch; | |
1045 int wc = 1; | |
1046 if (mvwin_wch(d, y, x, &ch) == OK) { | |
1047 wc = widestringwidth(ch.chars); | |
1048 ch.attr = DECIDE(ch.attr); | |
1049 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ | |
1050 mvwadd_wch(d, y, x, &ch); | |
1051 } | |
1052 | |
1053 return wc; | |
1054 #endif | |
1055 } | |
1056 | |
1057 static void | |
1058 window_reverse(GntWidget *win, gboolean set, GntWM *wm) | |
1059 { | |
1060 int i; | |
1061 int w, h; | |
1062 WINDOW *d; | |
1063 | |
1064 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) | |
1065 return; | |
1066 | |
1067 d = win->window; | |
1068 gnt_widget_get_size(win, &w, &h); | |
1069 | |
1070 if (gnt_widget_has_shadow(win)) { | |
1071 --w; | |
1072 --h; | |
1073 } | |
1074 | |
1075 /* the top and bottom */ | |
1076 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); | |
1077 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); | |
1078 | |
1079 /* the left and right */ | |
1080 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); | |
1081 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); | |
1082 | |
1083 copy_win(win, g_hash_table_lookup(wm->nodes, win)); | |
1084 update_screen(wm); | |
1085 } | |
1086 | |
1087 static gboolean | |
1088 start_move(GntBindable *bindable, GList *null) | |
1089 { | |
1090 GntWM *wm = GNT_WM(bindable); | |
1091 if (wm->_list.window || wm->menu) | |
1092 return TRUE; | |
1093 if (!wm->ordered) | |
1094 return TRUE; | |
1095 | |
1096 wm->mode = GNT_KP_MODE_MOVE; | |
1097 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
1098 | |
1099 return TRUE; | |
1100 } | |
1101 | |
1102 static gboolean | |
1103 start_resize(GntBindable *bindable, GList *null) | |
1104 { | |
1105 GntWM *wm = GNT_WM(bindable); | |
1106 if (wm->_list.window || wm->menu) | |
1107 return TRUE; | |
1108 if (!wm->ordered) | |
1109 return TRUE; | |
1110 | |
1111 wm->mode = GNT_KP_MODE_RESIZE; | |
1112 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
1113 | |
1114 return TRUE; | |
1115 } | |
1116 | |
1117 static gboolean | |
1118 wm_quit(GntBindable *bindable, GList *list) | |
1119 { | |
1120 GntWM *wm = GNT_WM(bindable); | |
1121 if (write_timeout) | |
1122 write_already(wm); | |
1123 g_main_loop_quit(wm->loop); | |
1124 return TRUE; | |
1125 } | |
1126 | |
1127 static gboolean | |
1128 return_true(GntWM *wm, GntWidget *w, int *a, int *b) | |
1129 { | |
1130 return TRUE; | |
1131 } | |
1132 | |
1133 static gboolean | |
1134 refresh_screen(GntBindable *bindable, GList *null) | |
1135 { | |
1136 GntWM *wm = GNT_WM(bindable); | |
1137 | |
1138 endwin(); | |
1139 refresh(); | |
1140 curs_set(0); /* endwin resets the cursor to normal */ | |
1141 | |
1142 g_hash_table_foreach(wm->nodes, (GHFunc)refresh_node, NULL); | |
1143 update_screen(wm); | |
1144 draw_taskbar(wm, TRUE); | |
1145 | |
1146 return FALSE; | |
1147 } | |
1148 | |
16526
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1149 static gboolean |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1150 toggle_clipboard(GntBindable *bindable, GList *n) |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1151 { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1152 static GntWidget *clip; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1153 gchar *text; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1154 int maxx, maxy; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1155 if (clip) { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1156 gnt_widget_destroy(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1157 clip = NULL; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1158 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1159 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1160 getmaxyx(stdscr, maxy, maxx); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1161 text = gnt_get_clipboard_string(); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1162 clip = gnt_hwindow_new(FALSE); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1163 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_TRANSIENT); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1164 GNT_WIDGET_SET_FLAGS(clip, GNT_WIDGET_NO_BORDER); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1165 gnt_box_set_pad(GNT_BOX(clip), 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1166 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1167 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(text)); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1168 gnt_box_add_widget(GNT_BOX(clip), gnt_label_new(" ")); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1169 gnt_widget_set_position(clip, 0, 0); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1170 gnt_widget_draw(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1171 g_free(text); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1172 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1173 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1174 |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1175 static gboolean |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1176 ignore_keys_start(GntBindable *bindable, GList *n){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1177 GntWM *wm = GNT_WM(bindable); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1178 |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1179 if(!wm->menu && !wm->_list.window && wm->mode == GNT_KP_MODE_NORMAL){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1180 ignore_keys = TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1181 return TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1182 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1183 return FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1184 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1185 |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1186 static gboolean |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1187 ignore_keys_end(GntBindable *bindable, GList *n){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1188 return ignore_keys ? !(ignore_keys = FALSE) : FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1189 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1190 |
15818 | 1191 static void |
1192 gnt_wm_class_init(GntWMClass *klass) | |
1193 { | |
1194 int i; | |
1195 | |
1196 klass->new_window = gnt_wm_new_window_real; | |
1197 klass->decorate_window = NULL; | |
1198 klass->close_window = NULL; | |
1199 klass->window_resize_confirm = return_true; | |
1200 klass->window_resized = gnt_wm_win_resized; | |
1201 klass->window_move_confirm = return_true; | |
1202 klass->window_moved = gnt_wm_win_moved; | |
1203 klass->window_update = NULL; | |
1204 klass->key_pressed = NULL; | |
1205 klass->mouse_clicked = NULL; | |
1206 klass->give_focus = gnt_wm_give_focus; | |
1207 | |
1208 signals[SIG_NEW_WIN] = | |
1209 g_signal_new("new_win", | |
1210 G_TYPE_FROM_CLASS(klass), | |
1211 G_SIGNAL_RUN_LAST, | |
1212 G_STRUCT_OFFSET(GntWMClass, new_window), | |
1213 NULL, NULL, | |
1214 g_cclosure_marshal_VOID__POINTER, | |
1215 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1216 signals[SIG_DECORATE_WIN] = | |
1217 g_signal_new("decorate_win", | |
1218 G_TYPE_FROM_CLASS(klass), | |
1219 G_SIGNAL_RUN_LAST, | |
1220 G_STRUCT_OFFSET(GntWMClass, decorate_window), | |
1221 NULL, NULL, | |
1222 g_cclosure_marshal_VOID__POINTER, | |
1223 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1224 signals[SIG_CLOSE_WIN] = | |
1225 g_signal_new("close_win", | |
1226 G_TYPE_FROM_CLASS(klass), | |
1227 G_SIGNAL_RUN_LAST, | |
1228 G_STRUCT_OFFSET(GntWMClass, close_window), | |
1229 NULL, NULL, | |
1230 g_cclosure_marshal_VOID__POINTER, | |
1231 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1232 signals[SIG_CONFIRM_RESIZE] = | |
1233 g_signal_new("confirm_resize", | |
1234 G_TYPE_FROM_CLASS(klass), | |
1235 G_SIGNAL_RUN_LAST, | |
1236 G_STRUCT_OFFSET(GntWMClass, window_resize_confirm), | |
1237 gnt_boolean_handled_accumulator, NULL, | |
1238 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1239 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1240 | |
1241 signals[SIG_CONFIRM_MOVE] = | |
1242 g_signal_new("confirm_move", | |
1243 G_TYPE_FROM_CLASS(klass), | |
1244 G_SIGNAL_RUN_LAST, | |
1245 G_STRUCT_OFFSET(GntWMClass, window_move_confirm), | |
1246 gnt_boolean_handled_accumulator, NULL, | |
1247 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1248 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1249 | |
1250 signals[SIG_RESIZED] = | |
1251 g_signal_new("window_resized", | |
1252 G_TYPE_FROM_CLASS(klass), | |
1253 G_SIGNAL_RUN_LAST, | |
1254 G_STRUCT_OFFSET(GntWMClass, window_resized), | |
1255 NULL, NULL, | |
1256 g_cclosure_marshal_VOID__POINTER, | |
1257 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1258 signals[SIG_MOVED] = | |
1259 g_signal_new("window_moved", | |
1260 G_TYPE_FROM_CLASS(klass), | |
1261 G_SIGNAL_RUN_LAST, | |
1262 G_STRUCT_OFFSET(GntWMClass, window_moved), | |
1263 NULL, NULL, | |
1264 g_cclosure_marshal_VOID__POINTER, | |
1265 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1266 signals[SIG_UPDATE_WIN] = | |
1267 g_signal_new("window_update", | |
1268 G_TYPE_FROM_CLASS(klass), | |
1269 G_SIGNAL_RUN_LAST, | |
1270 G_STRUCT_OFFSET(GntWMClass, window_update), | |
1271 NULL, NULL, | |
1272 g_cclosure_marshal_VOID__POINTER, | |
1273 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1274 signals[SIG_GIVE_FOCUS] = | |
1275 g_signal_new("give_focus", | |
1276 G_TYPE_FROM_CLASS(klass), | |
1277 G_SIGNAL_RUN_LAST, | |
1278 G_STRUCT_OFFSET(GntWMClass, give_focus), | |
1279 NULL, NULL, | |
1280 g_cclosure_marshal_VOID__POINTER, | |
1281 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1282 | |
1283 signals[SIG_MOUSE_CLICK] = | |
1284 g_signal_new("mouse_clicked", | |
1285 G_TYPE_FROM_CLASS(klass), | |
1286 G_SIGNAL_RUN_LAST, | |
1287 G_STRUCT_OFFSET(GntWMClass, mouse_clicked), | |
1288 gnt_boolean_handled_accumulator, NULL, | |
1289 gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER, | |
1290 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); | |
1291 | |
1292 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next", window_next, | |
1293 "\033" "n", NULL); | |
1294 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev", window_prev, | |
1295 "\033" "p", NULL); | |
1296 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-close", window_close, | |
1297 "\033" "c", NULL); | |
1298 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-list", window_list, | |
1299 "\033" "w", NULL); | |
1300 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "dump-screen", dump_screen, | |
1301 "\033" "d", NULL); | |
1302 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-left", shift_left, | |
1303 "\033" ",", NULL); | |
1304 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-right", shift_right, | |
1305 "\033" ".", NULL); | |
1306 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "action-list", list_actions, | |
1307 "\033" "a", NULL); | |
1308 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-move", start_move, | |
1309 "\033" "m", NULL); | |
1310 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-resize", start_resize, | |
1311 "\033" "r", NULL); | |
1312 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "wm-quit", wm_quit, | |
1313 "\033" "q", NULL); | |
1314 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "refresh-screen", refresh_screen, | |
1315 "\033" "l", NULL); | |
1316 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "switch-window-n", switch_window_n, | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1317 NULL, NULL); |
15818 | 1318 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-down", window_scroll_down, |
1319 "\033" GNT_KEY_CTRL_J, NULL); | |
1320 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-up", window_scroll_up, | |
1321 "\033" GNT_KEY_CTRL_K, NULL); | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1322 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-widget", help_for_widget, |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1323 "\033" "/", NULL); |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1324 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", toggle_clipboard, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1325 "\033" "C", NULL); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1326 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-start", ignore_keys_start, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1327 GNT_KEY_CTRL_G, NULL); |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1328 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end, |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1329 "\033" GNT_KEY_CTRL_G, NULL); |
15818 | 1330 |
1331 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
1332 | |
1333 /* Make sure Alt+x are detected properly. */ | |
1334 for (i = '0'; i <= '9'; i++) { | |
1335 char str[] = "\033X"; | |
1336 str[1] = i; | |
1337 gnt_keys_add_combination(str); | |
1338 } | |
1339 | |
1340 GNTDEBUG; | |
1341 } | |
1342 | |
1343 /****************************************************************************** | |
1344 * GntWM API | |
1345 *****************************************************************************/ | |
1346 GType | |
1347 gnt_wm_get_gtype(void) | |
1348 { | |
1349 static GType type = 0; | |
1350 | |
1351 if(type == 0) { | |
1352 static const GTypeInfo info = { | |
1353 sizeof(GntWMClass), | |
1354 NULL, /* base_init */ | |
1355 NULL, /* base_finalize */ | |
1356 (GClassInitFunc)gnt_wm_class_init, | |
1357 NULL, | |
1358 NULL, /* class_data */ | |
1359 sizeof(GntWM), | |
1360 0, /* n_preallocs */ | |
1361 gnt_wm_init, /* instance_init */ | |
1362 NULL /* value_table */ | |
1363 }; | |
1364 | |
1365 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
1366 "GntWM", | |
1367 &info, 0); | |
1368 } | |
1369 | |
1370 return type; | |
1371 } | |
1372 static void | |
1373 update_window_in_list(GntWM *wm, GntWidget *wid) | |
1374 { | |
1375 GntTextFormatFlags flag = 0; | |
1376 | |
1377 if (wm->windows == NULL) | |
1378 return; | |
1379 | |
1380 if (wid == wm->ordered->data) | |
1381 flag |= GNT_TEXT_FLAG_DIM; | |
1382 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) | |
1383 flag |= GNT_TEXT_FLAG_BOLD; | |
1384 | |
1385 gnt_tree_set_row_flags(GNT_TREE(wm->windows->tree), wid, flag); | |
1386 } | |
1387 | |
1388 static void | |
1389 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) | |
1390 { | |
1391 GntNode *node; | |
1392 gboolean transient = FALSE; | |
1393 | |
1394 if (widget->window == NULL) | |
1395 return; | |
1396 | |
1397 node = g_new0(GntNode, 1); | |
1398 node->me = widget; | |
1399 node->scroll = 0; | |
1400 | |
1401 g_hash_table_replace(wm->nodes, widget, node); | |
1402 | |
1403 refresh_node(widget, node, NULL); | |
1404 | |
1405 transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT); | |
1406 | |
1407 #if 1 | |
1408 { | |
1409 int x, y, w, h, maxx, maxy; | |
1410 gboolean shadow = TRUE; | |
1411 | |
1412 if (!gnt_widget_has_shadow(widget)) | |
1413 shadow = FALSE; | |
1414 x = widget->priv.x; | |
1415 y = widget->priv.y; | |
1416 w = widget->priv.width; | |
1417 h = widget->priv.height; | |
1418 | |
1419 getmaxyx(stdscr, maxy, maxx); | |
1420 maxy -= 1; /* room for the taskbar */ | |
1421 maxy -= shadow; | |
1422 maxx -= shadow; | |
1423 | |
1424 x = MAX(0, x); | |
1425 y = MAX(0, y); | |
1426 if (x + w >= maxx) | |
1427 x = MAX(0, maxx - w); | |
1428 if (y + h >= maxy) | |
1429 y = MAX(0, maxy - h); | |
1430 | |
1431 w = MIN(w, maxx); | |
1432 h = MIN(h, maxy); | |
1433 node->window = newwin(h + shadow, w + shadow, y, x); | |
1434 copy_win(widget, node); | |
1435 } | |
1436 #endif | |
1437 | |
1438 node->panel = new_panel(node->window); | |
1439 set_panel_userptr(node->panel, node); | |
1440 | |
1441 if (!transient) { | |
1442 if (node->me != wm->_list.window) { | |
1443 GntWidget *w = NULL; | |
1444 | |
1445 if (wm->ordered) | |
1446 w = wm->ordered->data; | |
1447 | |
1448 wm->list = g_list_append(wm->list, widget); | |
1449 | |
1450 if (wm->event_stack) | |
1451 wm->ordered = g_list_prepend(wm->ordered, widget); | |
1452 else | |
1453 wm->ordered = g_list_append(wm->ordered, widget); | |
1454 | |
1455 gnt_widget_set_focus(widget, TRUE); | |
1456 if (w) | |
1457 gnt_widget_set_focus(w, FALSE); | |
1458 } | |
1459 | |
1460 if (wm->event_stack || node->me == wm->_list.window) { | |
1461 gnt_wm_raise_window(wm, node->me); | |
1462 } else { | |
1463 bottom_panel(node->panel); /* New windows should not grab focus */ | |
1464 gnt_widget_set_urgent(node->me); | |
1465 } | |
1466 } | |
1467 } | |
1468 | |
1469 void gnt_wm_new_window(GntWM *wm, GntWidget *widget) | |
1470 { | |
1471 while (widget->parent) | |
1472 widget = widget->parent; | |
1473 | |
1474 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_INVISIBLE) || | |
1475 g_hash_table_lookup(wm->nodes, widget)) { | |
1476 update_screen(wm); | |
1477 return; | |
1478 } | |
1479 | |
1480 if (GNT_IS_BOX(widget)) { | |
1481 const char *title = GNT_BOX(widget)->title; | |
1482 GntPosition *p = NULL; | |
1483 if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { | |
1484 sanitize_position(widget, &p->x, &p->y); | |
1485 gnt_widget_set_position(widget, p->x, p->y); | |
1486 mvwin(widget->window, p->y, p->x); | |
1487 } | |
1488 } | |
1489 | |
1490 g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); | |
1491 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1492 | |
1493 if (wm->windows && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
1494 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && wm->_list.window != widget | |
1495 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
1496 gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget, | |
1497 gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title), | |
1498 NULL); | |
1499 update_window_in_list(wm, widget); | |
1500 } | |
1501 } | |
1502 | |
1503 update_screen(wm); | |
1504 draw_taskbar(wm, FALSE); | |
1505 } | |
1506 | |
1507 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget) | |
1508 { | |
1509 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1510 } | |
1511 | |
1512 void gnt_wm_window_close(GntWM *wm, GntWidget *widget) | |
1513 { | |
1514 GntNode *node; | |
1515 int pos; | |
1516 | |
1517 if ((node = g_hash_table_lookup(wm->nodes, widget)) == NULL) | |
1518 return; | |
1519 | |
1520 g_signal_emit(wm, signals[SIG_CLOSE_WIN], 0, widget); | |
1521 g_hash_table_remove(wm->nodes, widget); | |
1522 | |
1523 if (wm->windows) { | |
1524 gnt_tree_remove(GNT_TREE(wm->windows->tree), widget); | |
1525 } | |
1526 | |
1527 pos = g_list_index(wm->list, widget); | |
1528 | |
1529 if (pos != -1) { | |
1530 wm->list = g_list_remove(wm->list, widget); | |
1531 wm->ordered = g_list_remove(wm->ordered, widget); | |
1532 | |
1533 if (wm->ordered) | |
1534 gnt_wm_raise_window(wm, wm->ordered->data); | |
1535 } | |
1536 | |
1537 update_screen(wm); | |
1538 draw_taskbar(wm, FALSE); | |
1539 } | |
1540 | |
1541 time_t gnt_wm_get_idle_time() | |
1542 { | |
1543 return time(NULL) - last_active_time; | |
1544 } | |
1545 | |
1546 gboolean gnt_wm_process_input(GntWM *wm, const char *keys) | |
1547 { | |
1548 gboolean ret = FALSE; | |
1549 | |
1550 keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); | |
1551 | |
1552 idle_update = TRUE; | |
1553 | |
17539
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1554 if(ignore_keys){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1555 if(keys && !strcmp(keys, "\033" GNT_KEY_CTRL_G)){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1556 if(gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)){ |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1557 return TRUE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1558 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1559 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1560 return wm->ordered ? gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys) : FALSE; |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1561 } |
c609b4009dbe
1. Cleaned up a bit of dirty formatting in the _register_action lines in _class_init
Eric Polino <aluink@pidgin.im>
parents:
17140
diff
changeset
|
1562 |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1563 if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { |
15818 | 1564 return TRUE; |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1565 } |
15818 | 1566 |
1567 /* Do some manual checking */ | |
1568 if (wm->ordered && wm->mode != GNT_KP_MODE_NORMAL) { | |
1569 int xmin = 0, ymin = 0, xmax = getmaxx(stdscr), ymax = getmaxy(stdscr) - 1; | |
1570 int x, y, w, h; | |
1571 GntWidget *widget = GNT_WIDGET(wm->ordered->data); | |
1572 int ox, oy, ow, oh; | |
1573 | |
1574 gnt_widget_get_position(widget, &x, &y); | |
1575 gnt_widget_get_size(widget, &w, &h); | |
1576 ox = x; oy = y; | |
1577 ow = w; oh = h; | |
1578 | |
1579 if (wm->mode == GNT_KP_MODE_MOVE) { | |
1580 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1581 if (x > xmin) | |
1582 x--; | |
1583 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1584 if (x + w < xmax) | |
1585 x++; | |
1586 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1587 if (y > ymin) | |
1588 y--; | |
1589 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1590 if (y + h < ymax) | |
1591 y++; | |
1592 } | |
1593 if (ox != x || oy != y) { | |
1594 gnt_screen_move_widget(widget, x, y); | |
1595 window_reverse(widget, TRUE, wm); | |
1596 return TRUE; | |
1597 } | |
1598 } else if (wm->mode == GNT_KP_MODE_RESIZE) { | |
1599 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1600 w--; | |
1601 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1602 if (x + w < xmax) | |
1603 w++; | |
1604 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1605 h--; | |
1606 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1607 if (y + h < ymax) | |
1608 h++; | |
1609 } | |
1610 if (oh != h || ow != w) { | |
1611 gnt_screen_resize_widget(widget, w, h); | |
1612 window_reverse(widget, TRUE, wm); | |
1613 return TRUE; | |
1614 } | |
1615 } | |
1616 if (strcmp(keys, "\r") == 0 || strcmp(keys, "\033") == 0) { | |
1617 window_reverse(widget, FALSE, wm); | |
1618 wm->mode = GNT_KP_MODE_NORMAL; | |
1619 } | |
1620 return TRUE; | |
1621 } | |
1622 | |
1623 /* Escape to close the window-list or action-list window */ | |
1624 if (strcmp(keys, "\033") == 0) { | |
1625 if (wm->_list.window) { | |
1626 gnt_widget_destroy(wm->_list.window); | |
1627 return TRUE; | |
1628 } | |
1629 } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') { | |
1630 /* Alt+x for quick switch */ | |
1631 int n = *(keys + 1) - '0'; | |
1632 GList *list = NULL; | |
1633 | |
1634 if (n == 0) | |
1635 n = 10; | |
1636 | |
1637 list = g_list_append(list, GINT_TO_POINTER(n - 1)); | |
1638 switch_window_n(GNT_BINDABLE(wm), list); | |
1639 g_list_free(list); | |
1640 return TRUE; | |
1641 } | |
1642 | |
1643 if (wm->menu) | |
1644 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys); | |
1645 else if (wm->_list.window) | |
1646 ret = gnt_widget_key_pressed(wm->_list.window, keys); | |
1647 else if (wm->ordered) | |
1648 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys); | |
1649 return ret; | |
1650 } | |
1651 | |
1652 static void | |
1653 gnt_wm_win_resized(GntWM *wm, GntNode *node) | |
1654 { | |
1655 /*refresh_node(node->me, node, NULL);*/ | |
1656 } | |
1657 | |
1658 static void | |
1659 gnt_wm_win_moved(GntWM *wm, GntNode *node) | |
1660 { | |
1661 refresh_node(node->me, node, NULL); | |
1662 } | |
1663 | |
1664 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height) | |
1665 { | |
1666 gboolean ret = TRUE; | |
1667 GntNode *node; | |
1668 int shadow; | |
1669 int maxx, maxy; | |
1670 | |
1671 while (widget->parent) | |
1672 widget = widget->parent; | |
1673 node = g_hash_table_lookup(wm->nodes, widget); | |
1674 if (!node) | |
1675 return; | |
1676 | |
1677 g_signal_emit(wm, signals[SIG_CONFIRM_RESIZE], 0, widget, &width, &height, &ret); | |
1678 if (!ret) | |
1679 return; /* resize is not permitted */ | |
1680 hide_panel(node->panel); | |
1681 gnt_widget_set_size(widget, width, height); | |
1682 gnt_widget_draw(widget); | |
1683 | |
1684 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
1685 maxx = getmaxx(stdscr) - shadow; | |
1686 maxy = getmaxy(stdscr) - 1 - shadow; | |
1687 height = MIN(height, maxy); | |
1688 width = MIN(width, maxx); | |
15978
2a82bc8d57f7
More fixes for resizing when shadow is turned on.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
1689 wresize(node->window, height, width); |
15818 | 1690 replace_panel(node->panel, node->window); |
1691 | |
1692 g_signal_emit(wm, signals[SIG_RESIZED], 0, node); | |
1693 | |
1694 show_panel(node->panel); | |
1695 update_screen(wm); | |
1696 } | |
1697 | |
1698 static void | |
1699 write_gdi(gpointer key, gpointer value, gpointer data) | |
1700 { | |
1701 GntPosition *p = value; | |
1702 fprintf(data, ".%s = %d;%d\n", (char *)key, p->x, p->y); | |
1703 } | |
1704 | |
1705 static gboolean | |
1706 write_already(gpointer data) | |
1707 { | |
1708 GntWM *wm = data; | |
1709 FILE *file; | |
1710 char *filename; | |
1711 | |
1712 filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
1713 | |
1714 file = fopen(filename, "wb"); | |
1715 if (file == NULL) { | |
1716 g_printerr("GntWM: error opening file to save positions\n"); | |
1717 } else { | |
1718 fprintf(file, "[positions]\n"); | |
1719 g_hash_table_foreach(wm->positions, write_gdi, file); | |
1720 fclose(file); | |
1721 } | |
1722 | |
1723 g_free(filename); | |
1724 g_source_remove(write_timeout); | |
1725 write_timeout = 0; | |
1726 return FALSE; | |
1727 } | |
1728 | |
1729 static void | |
1730 write_positions_to_file(GntWM *wm) | |
1731 { | |
1732 if (write_timeout) { | |
1733 g_source_remove(write_timeout); | |
1734 } | |
1735 write_timeout = g_timeout_add(10000, write_already, wm); | |
1736 } | |
1737 | |
1738 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) | |
1739 { | |
1740 gboolean ret = TRUE; | |
1741 GntNode *node; | |
1742 | |
1743 while (widget->parent) | |
1744 widget = widget->parent; | |
1745 node = g_hash_table_lookup(wm->nodes, widget); | |
1746 if (!node) | |
1747 return; | |
1748 | |
1749 g_signal_emit(wm, signals[SIG_CONFIRM_MOVE], 0, widget, &x, &y, &ret); | |
1750 if (!ret) | |
1751 return; /* resize is not permitted */ | |
1752 | |
1753 gnt_widget_set_position(widget, x, y); | |
1754 move_panel(node->panel, y, x); | |
1755 | |
1756 g_signal_emit(wm, signals[SIG_MOVED], 0, node); | |
15995
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1757 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE) && GNT_IS_BOX(widget) && |
bc2dd3358d46
Don't remember the position of transient windows
Richard Nelson <wabz@pidgin.im>
parents:
15978
diff
changeset
|
1758 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
15818 | 1759 const char *title = GNT_BOX(widget)->title; |
1760 if (title) { | |
1761 GntPosition *p = g_new0(GntPosition, 1); | |
1762 GntWidget *wid = node->me; | |
1763 p->x = wid->priv.x; | |
1764 p->y = wid->priv.y; | |
1765 g_hash_table_replace(wm->positions, g_strdup(title), p); | |
1766 write_positions_to_file(wm); | |
1767 } | |
1768 } | |
1769 | |
1770 update_screen(wm); | |
1771 } | |
1772 | |
1773 static void | |
1774 gnt_wm_give_focus(GntWM *wm, GntWidget *widget) | |
1775 { | |
1776 GntNode *node = g_hash_table_lookup(wm->nodes, widget); | |
1777 | |
1778 if (!node) | |
1779 return; | |
1780 | |
1781 if (widget != wm->_list.window && !GNT_IS_MENU(widget) && | |
1782 wm->ordered->data != widget) { | |
1783 GntWidget *w = wm->ordered->data; | |
1784 wm->ordered = g_list_bring_to_front(wm->ordered, widget); | |
1785 gnt_widget_set_focus(w, FALSE); | |
1786 } | |
1787 | |
1788 gnt_widget_set_focus(widget, TRUE); | |
1789 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_URGENT); | |
1790 gnt_widget_draw(widget); | |
1791 top_panel(node->panel); | |
1792 | |
1793 if (wm->_list.window) { | |
1794 GntNode *nd = g_hash_table_lookup(wm->nodes, wm->_list.window); | |
1795 top_panel(nd->panel); | |
1796 } | |
1797 update_screen(wm); | |
1798 draw_taskbar(wm, FALSE); | |
1799 } | |
1800 | |
1801 void gnt_wm_update_window(GntWM *wm, GntWidget *widget) | |
1802 { | |
1803 GntNode *node; | |
1804 | |
1805 while (widget->parent) | |
1806 widget = widget->parent; | |
1807 if (!GNT_IS_MENU(widget)) | |
1808 gnt_box_sync_children(GNT_BOX(widget)); | |
1809 | |
1810 node = g_hash_table_lookup(wm->nodes, widget); | |
1811 if (node == NULL) { | |
1812 gnt_wm_new_window(wm, widget); | |
1813 } else | |
1814 g_signal_emit(wm, signals[SIG_UPDATE_WIN], 0, node); | |
1815 | |
1816 copy_win(widget, node); | |
1817 update_screen(wm); | |
1818 draw_taskbar(wm, FALSE); | |
1819 } | |
1820 | |
1821 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget) | |
1822 { | |
1823 gboolean ret = TRUE; | |
1824 idle_update = TRUE; | |
1825 g_signal_emit(wm, signals[SIG_MOUSE_CLICK], 0, event, x, y, widget, &ret); | |
1826 return ret; | |
1827 } | |
1828 | |
1829 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget) | |
1830 { | |
1831 g_signal_emit(wm, signals[SIG_GIVE_FOCUS], 0, widget); | |
1832 } | |
1833 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1834 void gnt_wm_set_event_stack(GntWM *wm, gboolean set) |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1835 { |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1836 wm->event_stack = set; |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1837 } |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1838 |