Mercurial > pidgin
annotate finch/libgnt/gntwm.c @ 16983:b4720d213f31
merge of 'c0fb147adcf6f18b147249c26e510fed206697ea'
and 'ed3f09c2af33db942ef45b9acc2a75f126aadcfa'
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Wed, 09 May 2007 23:44:49 +0000 |
parents | 403332494b92 |
children | f1abdde52538 3af867ef5a15 |
rev | line source |
---|---|
15817 | 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 | |
13 #include "gntwm.h" | |
14 #include "gntstyle.h" | |
15 #include "gntmarshal.h" | |
16 #include "gnt.h" | |
17 #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
|
18 #include "gntlabel.h" |
15817 | 19 #include "gntmenu.h" |
20 #include "gnttextview.h" | |
21 #include "gnttree.h" | |
22 #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
|
23 #include "gntwindow.h" |
15817 | 24 |
25 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ | |
26 | |
27 enum | |
28 { | |
29 SIG_NEW_WIN, | |
30 SIG_DECORATE_WIN, | |
31 SIG_CLOSE_WIN, | |
32 SIG_CONFIRM_RESIZE, | |
33 SIG_RESIZED, | |
34 SIG_CONFIRM_MOVE, | |
35 SIG_MOVED, | |
36 SIG_UPDATE_WIN, | |
37 SIG_GIVE_FOCUS, | |
38 SIG_KEY_PRESS, | |
39 SIG_MOUSE_CLICK, | |
40 SIGS | |
41 }; | |
42 | |
43 static guint signals[SIGS] = { 0 }; | |
44 static void gnt_wm_new_window_real(GntWM *wm, GntWidget *widget); | |
45 static void gnt_wm_win_resized(GntWM *wm, GntNode *node); | |
46 static void gnt_wm_win_moved(GntWM *wm, GntNode *node); | |
47 static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); | |
48 static void update_window_in_list(GntWM *wm, GntWidget *wid); | |
49 static void shift_window(GntWM *wm, GntWidget *widget, int dir); | |
50 | |
51 static gboolean write_already(gpointer data); | |
52 static int write_timeout; | |
53 static time_t last_active_time; | |
54 static gboolean idle_update; | |
55 | |
56 static GList * | |
57 g_list_bring_to_front(GList *list, gpointer data) | |
58 { | |
59 list = g_list_remove(list, data); | |
60 list = g_list_prepend(list, data); | |
61 return list; | |
62 } | |
63 | |
64 static void | |
65 free_node(gpointer data) | |
66 { | |
67 GntNode *node = data; | |
68 hide_panel(node->panel); | |
69 del_panel(node->panel); | |
70 g_free(node); | |
71 } | |
72 | |
73 static void | |
74 draw_taskbar(GntWM *wm, gboolean reposition) | |
75 { | |
76 static WINDOW *taskbar = NULL; | |
77 GList *iter; | |
78 int n, width = 0; | |
79 int i; | |
80 | |
81 if (taskbar == NULL) { | |
82 taskbar = newwin(1, getmaxx(stdscr), getmaxy(stdscr) - 1, 0); | |
83 } else if (reposition) { | |
84 int Y_MAX = getmaxy(stdscr) - 1; | |
85 mvwin(taskbar, Y_MAX, 0); | |
86 } | |
87 | |
88 wbkgdset(taskbar, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
89 werase(taskbar); | |
90 | |
91 n = g_list_length(wm->list); | |
92 if (n) | |
93 width = getmaxx(stdscr) / n; | |
94 | |
95 for (i = 0, iter = wm->list; iter; iter = iter->next, i++) | |
96 { | |
97 GntWidget *w = iter->data; | |
98 int color; | |
99 const char *title; | |
100 | |
101 if (w == wm->ordered->data) { | |
102 /* This is the current window in focus */ | |
103 color = GNT_COLOR_TITLE; | |
104 } else if (GNT_WIDGET_IS_FLAG_SET(w, GNT_WIDGET_URGENT)) { | |
105 /* This is a window with the URGENT hint set */ | |
106 color = GNT_COLOR_URGENT; | |
107 } else { | |
108 color = GNT_COLOR_NORMAL; | |
109 } | |
110 wbkgdset(taskbar, '\0' | COLOR_PAIR(color)); | |
111 if (iter->next) | |
112 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), width); | |
113 else | |
114 mvwhline(taskbar, 0, width * i, ' ' | COLOR_PAIR(color), getmaxx(stdscr) - width * i); | |
115 title = GNT_BOX(w)->title; | |
116 mvwprintw(taskbar, 0, width * i, "%s", title ? title : "<gnt>"); | |
117 if (i) | |
118 mvwaddch(taskbar, 0, width *i - 1, ACS_VLINE | A_STANDOUT | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
119 | |
120 update_window_in_list(wm, w); | |
121 } | |
122 | |
123 wrefresh(taskbar); | |
124 } | |
125 | |
126 static void | |
127 copy_win(GntWidget *widget, GntNode *node) | |
128 { | |
129 WINDOW *src, *dst; | |
130 int shadow; | |
131 if (!node) | |
132 return; | |
133 src = widget->window; | |
134 dst = node->window; | |
135 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
136 copywin(src, dst, node->scroll, 0, 0, 0, getmaxy(dst) - 1, getmaxx(dst) - 1, 0); | |
137 } | |
138 | |
139 static gboolean | |
140 update_screen(GntWM *wm) | |
141 { | |
142 if (wm->menu) { | |
143 GntMenu *top = wm->menu; | |
144 while (top) { | |
145 GntNode *node = g_hash_table_lookup(wm->nodes, top); | |
146 if (node) | |
147 top_panel(node->panel); | |
148 top = top->submenu; | |
149 } | |
150 } | |
151 update_panels(); | |
152 doupdate(); | |
153 return TRUE; | |
154 } | |
155 | |
156 static gboolean | |
157 sanitize_position(GntWidget *widget, int *x, int *y) | |
158 { | |
159 int X_MAX = getmaxx(stdscr); | |
160 int Y_MAX = getmaxy(stdscr) - 1; | |
161 int w, h; | |
162 int nx, ny; | |
163 gboolean changed = FALSE; | |
164 | |
165 gnt_widget_get_size(widget, &w, &h); | |
166 if (x) { | |
167 if (*x + w > X_MAX) { | |
168 nx = MAX(0, X_MAX - w); | |
169 if (nx != *x) { | |
170 *x = nx; | |
171 changed = TRUE; | |
172 } | |
173 } | |
174 } | |
175 if (y) { | |
176 if (*y + h > Y_MAX) { | |
177 ny = MAX(0, Y_MAX - h); | |
178 if (ny != *y) { | |
179 *y = ny; | |
180 changed = TRUE; | |
181 } | |
182 } | |
183 } | |
184 return changed; | |
185 } | |
186 | |
187 static void | |
188 refresh_node(GntWidget *widget, GntNode *node, gpointer null) | |
189 { | |
190 int x, y, w, h; | |
191 int nw, nh; | |
192 | |
193 int X_MAX = getmaxx(stdscr); | |
194 int Y_MAX = getmaxy(stdscr) - 1; | |
195 | |
196 gnt_widget_get_position(widget, &x, &y); | |
197 gnt_widget_get_size(widget, &w, &h); | |
198 | |
199 if (sanitize_position(widget, &x, &y)) | |
200 gnt_screen_move_widget(widget, x, y); | |
201 | |
202 nw = MIN(w, X_MAX); | |
203 nh = MIN(h, Y_MAX); | |
204 if (nw != w || nh != h) | |
205 gnt_screen_resize_widget(widget, nw, nh); | |
206 } | |
207 | |
208 static void | |
209 read_window_positions(GntWM *wm) | |
210 { | |
211 #if GLIB_CHECK_VERSION(2,6,0) | |
212 GKeyFile *gfile = g_key_file_new(); | |
213 char *filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
214 GError *error = NULL; | |
215 char **keys; | |
216 gsize nk; | |
217 | |
218 if (!g_key_file_load_from_file(gfile, filename, G_KEY_FILE_NONE, &error)) { | |
219 g_printerr("GntWM: %s\n", error->message); | |
220 g_error_free(error); | |
221 g_free(filename); | |
222 return; | |
223 } | |
224 | |
225 keys = g_key_file_get_keys(gfile, "positions", &nk, &error); | |
226 if (error) { | |
227 g_printerr("GntWM: %s\n", error->message); | |
228 g_error_free(error); | |
229 error = NULL; | |
230 } else { | |
231 while (nk--) { | |
232 char *title = keys[nk]; | |
233 gsize l; | |
234 char **coords = g_key_file_get_string_list(gfile, "positions", title, &l, NULL); | |
235 if (l == 2) { | |
236 int x = atoi(coords[0]); | |
237 int y = atoi(coords[1]); | |
238 GntPosition *p = g_new0(GntPosition, 1); | |
239 p->x = x; | |
240 p->y = y; | |
241 g_hash_table_replace(wm->positions, g_strdup(title + 1), p); | |
242 } else { | |
243 g_printerr("GntWM: Invalid number of arguments for positioing a window.\n"); | |
244 } | |
245 g_strfreev(coords); | |
246 } | |
247 g_strfreev(keys); | |
248 } | |
249 | |
250 g_free(filename); | |
15964 | 251 g_key_file_free(gfile); |
15817 | 252 #endif |
253 } | |
254 | |
255 static gboolean check_idle(gpointer n) | |
256 { | |
257 if (idle_update) { | |
258 time(&last_active_time); | |
259 idle_update = FALSE; | |
260 } | |
261 return TRUE; | |
262 } | |
263 | |
264 static void | |
265 gnt_wm_init(GTypeInstance *instance, gpointer class) | |
266 { | |
267 GntWM *wm = GNT_WM(instance); | |
268 wm->list = NULL; | |
269 wm->ordered = NULL; | |
270 wm->event_stack = FALSE; | |
271 wm->windows = NULL; | |
272 wm->actions = NULL; | |
273 wm->nodes = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_node); | |
274 wm->positions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
275 if (gnt_style_get_bool(GNT_STYLE_REMPOS, TRUE)) | |
276 read_window_positions(wm); | |
277 g_timeout_add(IDLE_CHECK_INTERVAL * 1000, check_idle, NULL); | |
278 time(&last_active_time); | |
279 } | |
280 | |
281 static void | |
282 switch_window(GntWM *wm, int direction) | |
283 { | |
284 GntWidget *w = NULL, *wid = NULL; | |
285 int pos; | |
286 | |
287 if (wm->_list.window || wm->menu) | |
288 return; | |
289 | |
290 if (!wm->ordered || !wm->ordered->next) | |
291 return; | |
292 | |
293 w = wm->ordered->data; | |
294 pos = g_list_index(wm->list, w); | |
295 pos += direction; | |
296 | |
297 if (pos < 0) | |
298 wid = g_list_last(wm->list)->data; | |
299 else if (pos >= g_list_length(wm->list)) | |
300 wid = wm->list->data; | |
301 else if (pos >= 0) | |
302 wid = g_list_nth_data(wm->list, pos); | |
303 | |
304 wm->ordered = g_list_bring_to_front(wm->ordered, wid); | |
305 | |
306 gnt_wm_raise_window(wm, wm->ordered->data); | |
307 | |
308 if (w != wid) { | |
309 gnt_widget_set_focus(w, FALSE); | |
310 } | |
311 } | |
312 | |
313 static gboolean | |
314 window_next(GntBindable *bindable, GList *null) | |
315 { | |
316 GntWM *wm = GNT_WM(bindable); | |
317 switch_window(wm, 1); | |
318 return TRUE; | |
319 } | |
320 | |
321 static gboolean | |
322 window_prev(GntBindable *bindable, GList *null) | |
323 { | |
324 GntWM *wm = GNT_WM(bindable); | |
325 switch_window(wm, -1); | |
326 return TRUE; | |
327 } | |
328 | |
329 static gboolean | |
330 switch_window_n(GntBindable *bind, GList *list) | |
331 { | |
332 GntWM *wm = GNT_WM(bind); | |
333 GntWidget *w = NULL; | |
334 GList *l; | |
335 int n; | |
336 | |
337 if (!wm->ordered) | |
338 return TRUE; | |
339 | |
340 if (list) | |
341 n = GPOINTER_TO_INT(list->data); | |
342 else | |
343 n = 0; | |
344 | |
345 w = wm->ordered->data; | |
346 | |
347 if ((l = g_list_nth(wm->list, n)) != NULL) | |
348 { | |
349 gnt_wm_raise_window(wm, l->data); | |
350 } | |
351 | |
352 if (l && w != l->data) | |
353 { | |
354 gnt_widget_set_focus(w, FALSE); | |
355 } | |
356 return TRUE; | |
357 } | |
358 | |
359 static gboolean | |
360 window_scroll_up(GntBindable *bindable, GList *null) | |
361 { | |
362 GntWM *wm = GNT_WM(bindable); | |
363 GntWidget *window; | |
364 GntNode *node; | |
365 | |
366 if (!wm->ordered) | |
367 return TRUE; | |
368 | |
369 window = wm->ordered->data; | |
370 node = g_hash_table_lookup(wm->nodes, window); | |
371 if (!node) | |
372 return TRUE; | |
373 | |
374 if (node->scroll) { | |
375 node->scroll--; | |
376 copy_win(window, node); | |
377 update_screen(wm); | |
378 } | |
379 return TRUE; | |
380 } | |
381 | |
382 static gboolean | |
383 window_scroll_down(GntBindable *bindable, GList *null) | |
384 { | |
385 GntWM *wm = GNT_WM(bindable); | |
386 GntWidget *window; | |
387 GntNode *node; | |
388 int w, h; | |
389 | |
390 if (!wm->ordered) | |
391 return TRUE; | |
392 | |
393 window = wm->ordered->data; | |
394 node = g_hash_table_lookup(wm->nodes, window); | |
395 if (!node) | |
396 return TRUE; | |
397 | |
398 gnt_widget_get_size(window, &w, &h); | |
399 if (h - node->scroll > getmaxy(node->window)) { | |
400 node->scroll++; | |
401 copy_win(window, node); | |
402 update_screen(wm); | |
403 } | |
404 return TRUE; | |
405 } | |
406 | |
407 static gboolean | |
408 window_close(GntBindable *bindable, GList *null) | |
409 { | |
410 GntWM *wm = GNT_WM(bindable); | |
411 | |
412 if (wm->_list.window) | |
413 return TRUE; | |
414 | |
415 if (wm->ordered) { | |
416 gnt_widget_destroy(wm->ordered->data); | |
417 } | |
418 | |
419 return TRUE; | |
420 } | |
421 | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
422 static gboolean |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
423 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
|
424 { |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
425 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
|
426 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
|
427 char *title; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
428 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
429 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
|
430 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
431 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
432 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
|
433 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
|
434 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
435 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
|
436 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
437 tree = gnt_widget_bindings_view(active); |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
438 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
|
439 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
|
440 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
|
441 if (tree) |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
442 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
|
443 else |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
444 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
|
445 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
446 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
|
447 |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
448 return TRUE; |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
449 } |
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
450 |
15817 | 451 static void |
452 destroy__list(GntWidget *widget, GntWM *wm) | |
453 { | |
454 wm->_list.window = NULL; | |
455 wm->_list.tree = NULL; | |
456 wm->windows = NULL; | |
457 wm->actions = NULL; | |
458 update_screen(wm); | |
459 } | |
460 | |
461 static void | |
462 setup__list(GntWM *wm) | |
463 { | |
464 GntWidget *tree, *win; | |
465 win = wm->_list.window = gnt_box_new(FALSE, FALSE); | |
466 gnt_box_set_toplevel(GNT_BOX(win), TRUE); | |
467 gnt_box_set_pad(GNT_BOX(win), 0); | |
468 GNT_WIDGET_SET_FLAGS(win, GNT_WIDGET_TRANSIENT); | |
469 | |
470 tree = wm->_list.tree = gnt_tree_new(); | |
471 gnt_box_add_widget(GNT_BOX(win), tree); | |
472 | |
473 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy__list), wm); | |
474 } | |
475 | |
476 static void | |
477 window_list_activate(GntTree *tree, GntWM *wm) | |
478 { | |
479 GntWidget *widget = gnt_tree_get_selection_data(GNT_TREE(tree)); | |
480 | |
481 if (!wm->ordered || !widget) | |
482 return; | |
483 | |
484 gnt_widget_destroy(wm->_list.window); | |
485 gnt_wm_raise_window(wm, widget); | |
486 } | |
487 | |
488 static void | |
489 populate_window_list(GntWM *wm) | |
490 { | |
491 GList *iter; | |
492 GntTree *tree = GNT_TREE(wm->windows->tree); | |
493 for (iter = wm->list; iter; iter = iter->next) { | |
494 GntBox *box = GNT_BOX(iter->data); | |
495 | |
496 gnt_tree_add_row_last(tree, box, | |
497 gnt_tree_create_row(tree, box->title), NULL); | |
498 update_window_in_list(wm, GNT_WIDGET(box)); | |
499 } | |
500 } | |
501 | |
502 static gboolean | |
503 window_list_key_pressed(GntWidget *widget, const char *text, GntWM *wm) | |
504 { | |
505 if (text[1] == 0 && wm->ordered) { | |
506 GntWidget *sel = gnt_tree_get_selection_data(GNT_TREE(widget)); | |
507 switch (text[0]) { | |
508 case '-': | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
509 case ',': |
15817 | 510 shift_window(wm, sel, -1); |
511 break; | |
16127
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
512 case '=': |
063274e9cb27
These bindings are easier for changing window order.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16126
diff
changeset
|
513 case '.': |
15817 | 514 shift_window(wm, sel, 1); |
515 break; | |
516 default: | |
517 return FALSE; | |
518 } | |
519 gnt_tree_remove_all(GNT_TREE(widget)); | |
520 populate_window_list(wm); | |
521 gnt_tree_set_selected(GNT_TREE(widget), sel); | |
522 return TRUE; | |
523 } | |
524 return FALSE; | |
525 } | |
526 | |
527 static gboolean | |
528 window_list(GntBindable *bindable, GList *null) | |
529 { | |
530 GntWM *wm = GNT_WM(bindable); | |
531 GntWidget *tree, *win; | |
532 | |
533 if (wm->_list.window || wm->menu) | |
534 return TRUE; | |
535 | |
536 if (!wm->ordered) | |
537 return TRUE; | |
538 | |
539 setup__list(wm); | |
540 wm->windows = &wm->_list; | |
541 | |
542 win = wm->windows->window; | |
543 tree = wm->windows->tree; | |
544 | |
545 gnt_box_set_title(GNT_BOX(win), "Window List"); | |
546 | |
547 populate_window_list(wm); | |
548 | |
549 gnt_tree_set_selected(GNT_TREE(tree), wm->ordered->data); | |
550 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(window_list_activate), wm); | |
551 g_signal_connect(G_OBJECT(tree), "key_pressed", G_CALLBACK(window_list_key_pressed), wm); | |
552 | |
553 gnt_tree_set_col_width(GNT_TREE(tree), 0, getmaxx(stdscr) / 3); | |
554 gnt_widget_set_size(tree, 0, getmaxy(stdscr) / 2); | |
555 gnt_widget_set_position(win, getmaxx(stdscr) / 3, getmaxy(stdscr) / 4); | |
556 | |
557 gnt_widget_show(win); | |
558 return TRUE; | |
559 } | |
560 | |
561 static gboolean | |
562 dump_screen(GntBindable *bindable, GList *null) | |
563 { | |
564 int x, y; | |
565 chtype old = 0, now = 0; | |
566 FILE *file = fopen("dump.html", "w"); | |
567 | |
568 fprintf(file, "<pre>"); | |
569 for (y = 0; y < getmaxy(stdscr); y++) { | |
570 for (x = 0; x < getmaxx(stdscr); x++) { | |
571 char ch; | |
572 now = mvwinch(curscr, y, x); | |
573 ch = now & A_CHARTEXT; | |
574 now ^= ch; | |
575 | |
576 #define CHECK(attr, start, end) \ | |
577 do \ | |
578 { \ | |
579 if (now & attr) \ | |
580 { \ | |
581 if (!(old & attr)) \ | |
582 fprintf(file, "%s", start); \ | |
583 } \ | |
584 else if (old & attr) \ | |
585 { \ | |
586 fprintf(file, "%s", end); \ | |
587 } \ | |
588 } while (0) | |
589 | |
590 CHECK(A_BOLD, "<b>", "</b>"); | |
591 CHECK(A_UNDERLINE, "<u>", "</u>"); | |
592 CHECK(A_BLINK, "<blink>", "</blink>"); | |
593 | |
594 if ((now & A_COLOR) != (old & A_COLOR) || | |
595 (now & A_REVERSE) != (old & A_REVERSE)) | |
596 { | |
597 int ret; | |
598 short fgp, bgp, r, g, b; | |
599 struct | |
600 { | |
601 int r, g, b; | |
602 } fg, bg; | |
603 | |
604 ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); | |
605 if (fgp == -1) | |
606 fgp = COLOR_BLACK; | |
607 if (bgp == -1) | |
608 bgp = COLOR_WHITE; | |
609 if (now & A_REVERSE) | |
610 fgp ^= bgp ^= fgp ^= bgp; /* *wink* */ | |
611 ret = color_content(fgp, &r, &g, &b); | |
612 fg.r = r; fg.b = b; fg.g = g; | |
613 ret = color_content(bgp, &r, &g, &b); | |
614 bg.r = r; bg.b = b; bg.g = g; | |
615 #define ADJUST(x) (x = x * 255 / 1000) | |
616 ADJUST(fg.r); | |
617 ADJUST(fg.g); | |
618 ADJUST(fg.b); | |
619 ADJUST(bg.r); | |
620 ADJUST(bg.b); | |
621 ADJUST(bg.g); | |
622 | |
623 if (x) fprintf(file, "</span>"); | |
624 fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", | |
625 bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); | |
626 } | |
627 if (now & A_ALTCHARSET) | |
628 { | |
629 switch (ch) | |
630 { | |
631 case 'q': | |
632 ch = '-'; break; | |
633 case 't': | |
634 case 'u': | |
635 case 'x': | |
636 ch = '|'; break; | |
637 case 'v': | |
638 case 'w': | |
639 case 'l': | |
640 case 'm': | |
641 case 'k': | |
642 case 'j': | |
643 case 'n': | |
644 ch = '+'; break; | |
645 case '-': | |
646 ch = '^'; break; | |
647 case '.': | |
648 ch = 'v'; break; | |
649 case 'a': | |
650 ch = '#'; break; | |
651 default: | |
652 ch = ' '; break; | |
653 } | |
654 } | |
655 if (ch == '&') | |
656 fprintf(file, "&"); | |
657 else if (ch == '<') | |
658 fprintf(file, "<"); | |
659 else if (ch == '>') | |
660 fprintf(file, ">"); | |
661 else | |
662 fprintf(file, "%c", ch); | |
663 old = now; | |
664 } | |
665 fprintf(file, "</span>\n"); | |
666 old = 0; | |
667 } | |
668 fprintf(file, "</pre>"); | |
669 fclose(file); | |
670 return TRUE; | |
671 } | |
672 | |
673 static void | |
674 shift_window(GntWM *wm, GntWidget *widget, int dir) | |
675 { | |
676 GList *all = wm->list; | |
677 GList *list = g_list_find(all, widget); | |
678 int length, pos; | |
679 if (!list) | |
680 return; | |
681 | |
682 length = g_list_length(all); | |
683 pos = g_list_position(all, list); | |
684 | |
685 pos += dir; | |
686 if (dir > 0) | |
687 pos++; | |
688 | |
689 if (pos < 0) | |
690 pos = length; | |
691 else if (pos > length) | |
692 pos = 0; | |
693 | |
694 all = g_list_insert(all, widget, pos); | |
695 all = g_list_delete_link(all, list); | |
696 wm->list = all; | |
697 draw_taskbar(wm, FALSE); | |
698 } | |
699 | |
700 static gboolean | |
701 shift_left(GntBindable *bindable, GList *null) | |
702 { | |
703 GntWM *wm = GNT_WM(bindable); | |
704 if (wm->_list.window) | |
705 return TRUE; | |
706 | |
707 shift_window(wm, wm->ordered->data, -1); | |
708 return TRUE; | |
709 } | |
710 | |
711 static gboolean | |
712 shift_right(GntBindable *bindable, GList *null) | |
713 { | |
714 GntWM *wm = GNT_WM(bindable); | |
715 if (wm->_list.window) | |
716 return TRUE; | |
717 | |
718 shift_window(wm, wm->ordered->data, 1); | |
719 return TRUE; | |
720 } | |
721 | |
722 static void | |
723 action_list_activate(GntTree *tree, GntWM *wm) | |
724 { | |
725 GntAction *action = gnt_tree_get_selection_data(tree); | |
726 action->callback(); | |
727 gnt_widget_destroy(wm->_list.window); | |
728 } | |
729 | |
730 static int | |
731 compare_action(gconstpointer p1, gconstpointer p2) | |
732 { | |
733 const GntAction *a1 = p1; | |
734 const GntAction *a2 = p2; | |
735 | |
736 return g_utf8_collate(a1->label, a2->label); | |
737 } | |
738 | |
739 static gboolean | |
740 list_actions(GntBindable *bindable, GList *null) | |
741 { | |
742 GntWidget *tree, *win; | |
743 GList *iter; | |
744 GntWM *wm = GNT_WM(bindable); | |
745 if (wm->_list.window || wm->menu) | |
746 return TRUE; | |
747 | |
748 if (wm->acts == NULL) | |
749 return TRUE; | |
750 | |
751 setup__list(wm); | |
752 wm->actions = &wm->_list; | |
753 | |
754 win = wm->actions->window; | |
755 tree = wm->actions->tree; | |
756 | |
757 gnt_box_set_title(GNT_BOX(win), "Actions"); | |
758 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
759 /* XXX: Do we really want this? */ | |
760 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); | |
761 | |
762 for (iter = wm->acts; iter; iter = iter->next) { | |
763 GntAction *action = iter->data; | |
764 gnt_tree_add_row_last(GNT_TREE(tree), action, | |
765 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); | |
766 } | |
767 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm); | |
768 gnt_widget_set_size(tree, 0, g_list_length(wm->acts)); | |
769 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts)); | |
770 | |
771 gnt_widget_show(win); | |
772 return TRUE; | |
773 } | |
774 | |
775 #ifndef NO_WIDECHAR | |
776 static int | |
777 widestringwidth(wchar_t *wide) | |
778 { | |
779 int len, ret; | |
780 char *string; | |
781 | |
782 len = wcstombs(NULL, wide, 0) + 1; | |
783 string = g_new0(char, len); | |
784 wcstombs(string, wide, len); | |
785 ret = gnt_util_onscreen_width(string, NULL); | |
786 g_free(string); | |
787 return ret; | |
788 } | |
789 #endif | |
790 | |
791 /* Returns the onscreen width of the character at the position */ | |
792 static int | |
793 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
794 { | |
795 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
796 | |
797 #ifdef NO_WIDECHAR | |
798 chtype ch; | |
799 ch = mvwinch(d, y, x); | |
800 mvwaddch(d, y, x, DECIDE(ch)); | |
801 return 1; | |
802 #else | |
803 cchar_t ch; | |
804 int wc = 1; | |
805 if (mvwin_wch(d, y, x, &ch) == OK) { | |
806 wc = widestringwidth(ch.chars); | |
807 ch.attr = DECIDE(ch.attr); | |
808 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ | |
809 mvwadd_wch(d, y, x, &ch); | |
810 } | |
811 | |
812 return wc; | |
813 #endif | |
814 } | |
815 | |
816 static void | |
817 window_reverse(GntWidget *win, gboolean set, GntWM *wm) | |
818 { | |
819 int i; | |
820 int w, h; | |
821 WINDOW *d; | |
822 | |
823 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) | |
824 return; | |
825 | |
826 d = win->window; | |
827 gnt_widget_get_size(win, &w, &h); | |
828 | |
829 if (gnt_widget_has_shadow(win)) { | |
830 --w; | |
831 --h; | |
832 } | |
833 | |
834 /* the top and bottom */ | |
835 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); | |
836 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); | |
837 | |
838 /* the left and right */ | |
839 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); | |
840 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); | |
841 | |
842 copy_win(win, g_hash_table_lookup(wm->nodes, win)); | |
843 update_screen(wm); | |
844 } | |
845 | |
846 static gboolean | |
847 start_move(GntBindable *bindable, GList *null) | |
848 { | |
849 GntWM *wm = GNT_WM(bindable); | |
850 if (wm->_list.window || wm->menu) | |
851 return TRUE; | |
852 if (!wm->ordered) | |
853 return TRUE; | |
854 | |
855 wm->mode = GNT_KP_MODE_MOVE; | |
856 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
857 | |
858 return TRUE; | |
859 } | |
860 | |
861 static gboolean | |
862 start_resize(GntBindable *bindable, GList *null) | |
863 { | |
864 GntWM *wm = GNT_WM(bindable); | |
865 if (wm->_list.window || wm->menu) | |
866 return TRUE; | |
867 if (!wm->ordered) | |
868 return TRUE; | |
869 | |
870 wm->mode = GNT_KP_MODE_RESIZE; | |
871 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
872 | |
873 return TRUE; | |
874 } | |
875 | |
876 static gboolean | |
877 wm_quit(GntBindable *bindable, GList *list) | |
878 { | |
879 GntWM *wm = GNT_WM(bindable); | |
880 if (write_timeout) | |
881 write_already(wm); | |
882 g_main_loop_quit(wm->loop); | |
883 return TRUE; | |
884 } | |
885 | |
886 static gboolean | |
887 return_true(GntWM *wm, GntWidget *w, int *a, int *b) | |
888 { | |
889 return TRUE; | |
890 } | |
891 | |
892 static gboolean | |
893 refresh_screen(GntBindable *bindable, GList *null) | |
894 { | |
895 GntWM *wm = GNT_WM(bindable); | |
896 | |
897 endwin(); | |
898 refresh(); | |
899 curs_set(0); /* endwin resets the cursor to normal */ | |
900 | |
901 g_hash_table_foreach(wm->nodes, (GHFunc)refresh_node, NULL); | |
902 update_screen(wm); | |
903 draw_taskbar(wm, TRUE); | |
904 | |
905 return FALSE; | |
906 } | |
907 | |
16518
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
908 static gboolean |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
909 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
|
910 { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
911 static GntWidget *clip; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
912 gchar *text; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
913 int maxx, maxy; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
914 if (clip) { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
915 gnt_widget_destroy(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
916 clip = NULL; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
917 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
918 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
919 getmaxyx(stdscr, maxy, maxx); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 gnt_widget_draw(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
930 g_free(text); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
931 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
932 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
933 |
15817 | 934 static void |
935 gnt_wm_class_init(GntWMClass *klass) | |
936 { | |
937 int i; | |
938 | |
939 klass->new_window = gnt_wm_new_window_real; | |
940 klass->decorate_window = NULL; | |
941 klass->close_window = NULL; | |
942 klass->window_resize_confirm = return_true; | |
943 klass->window_resized = gnt_wm_win_resized; | |
944 klass->window_move_confirm = return_true; | |
945 klass->window_moved = gnt_wm_win_moved; | |
946 klass->window_update = NULL; | |
947 klass->key_pressed = NULL; | |
948 klass->mouse_clicked = NULL; | |
949 klass->give_focus = gnt_wm_give_focus; | |
950 | |
951 signals[SIG_NEW_WIN] = | |
952 g_signal_new("new_win", | |
953 G_TYPE_FROM_CLASS(klass), | |
954 G_SIGNAL_RUN_LAST, | |
955 G_STRUCT_OFFSET(GntWMClass, new_window), | |
956 NULL, NULL, | |
957 g_cclosure_marshal_VOID__POINTER, | |
958 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
959 signals[SIG_DECORATE_WIN] = | |
960 g_signal_new("decorate_win", | |
961 G_TYPE_FROM_CLASS(klass), | |
962 G_SIGNAL_RUN_LAST, | |
963 G_STRUCT_OFFSET(GntWMClass, decorate_window), | |
964 NULL, NULL, | |
965 g_cclosure_marshal_VOID__POINTER, | |
966 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
967 signals[SIG_CLOSE_WIN] = | |
968 g_signal_new("close_win", | |
969 G_TYPE_FROM_CLASS(klass), | |
970 G_SIGNAL_RUN_LAST, | |
971 G_STRUCT_OFFSET(GntWMClass, close_window), | |
972 NULL, NULL, | |
973 g_cclosure_marshal_VOID__POINTER, | |
974 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
975 signals[SIG_CONFIRM_RESIZE] = | |
976 g_signal_new("confirm_resize", | |
977 G_TYPE_FROM_CLASS(klass), | |
978 G_SIGNAL_RUN_LAST, | |
979 G_STRUCT_OFFSET(GntWMClass, window_resize_confirm), | |
980 gnt_boolean_handled_accumulator, NULL, | |
981 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
982 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
983 | |
984 signals[SIG_CONFIRM_MOVE] = | |
985 g_signal_new("confirm_move", | |
986 G_TYPE_FROM_CLASS(klass), | |
987 G_SIGNAL_RUN_LAST, | |
988 G_STRUCT_OFFSET(GntWMClass, window_move_confirm), | |
989 gnt_boolean_handled_accumulator, NULL, | |
990 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
991 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
992 | |
993 signals[SIG_RESIZED] = | |
994 g_signal_new("window_resized", | |
995 G_TYPE_FROM_CLASS(klass), | |
996 G_SIGNAL_RUN_LAST, | |
997 G_STRUCT_OFFSET(GntWMClass, window_resized), | |
998 NULL, NULL, | |
999 g_cclosure_marshal_VOID__POINTER, | |
1000 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1001 signals[SIG_MOVED] = | |
1002 g_signal_new("window_moved", | |
1003 G_TYPE_FROM_CLASS(klass), | |
1004 G_SIGNAL_RUN_LAST, | |
1005 G_STRUCT_OFFSET(GntWMClass, window_moved), | |
1006 NULL, NULL, | |
1007 g_cclosure_marshal_VOID__POINTER, | |
1008 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1009 signals[SIG_UPDATE_WIN] = | |
1010 g_signal_new("window_update", | |
1011 G_TYPE_FROM_CLASS(klass), | |
1012 G_SIGNAL_RUN_LAST, | |
1013 G_STRUCT_OFFSET(GntWMClass, window_update), | |
1014 NULL, NULL, | |
1015 g_cclosure_marshal_VOID__POINTER, | |
1016 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1017 | |
1018 signals[SIG_GIVE_FOCUS] = | |
1019 g_signal_new("give_focus", | |
1020 G_TYPE_FROM_CLASS(klass), | |
1021 G_SIGNAL_RUN_LAST, | |
1022 G_STRUCT_OFFSET(GntWMClass, give_focus), | |
1023 NULL, NULL, | |
1024 g_cclosure_marshal_VOID__POINTER, | |
1025 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1026 | |
1027 signals[SIG_MOUSE_CLICK] = | |
1028 g_signal_new("mouse_clicked", | |
1029 G_TYPE_FROM_CLASS(klass), | |
1030 G_SIGNAL_RUN_LAST, | |
1031 G_STRUCT_OFFSET(GntWMClass, mouse_clicked), | |
1032 gnt_boolean_handled_accumulator, NULL, | |
1033 gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER, | |
1034 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); | |
1035 | |
1036 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next", window_next, | |
1037 "\033" "n", NULL); | |
1038 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev", window_prev, | |
1039 "\033" "p", NULL); | |
1040 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-close", window_close, | |
1041 "\033" "c", NULL); | |
1042 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-list", window_list, | |
1043 "\033" "w", NULL); | |
1044 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "dump-screen", dump_screen, | |
1045 "\033" "d", NULL); | |
1046 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-left", shift_left, | |
1047 "\033" ",", NULL); | |
1048 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-right", shift_right, | |
1049 "\033" ".", NULL); | |
1050 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "action-list", list_actions, | |
1051 "\033" "a", NULL); | |
1052 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-move", start_move, | |
1053 "\033" "m", NULL); | |
1054 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-resize", start_resize, | |
1055 "\033" "r", NULL); | |
1056 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "wm-quit", wm_quit, | |
1057 "\033" "q", NULL); | |
1058 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "refresh-screen", refresh_screen, | |
1059 "\033" "l", NULL); | |
1060 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "switch-window-n", switch_window_n, | |
1061 NULL, NULL); | |
1062 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-down", window_scroll_down, | |
1063 "\033" GNT_KEY_CTRL_J, NULL); | |
1064 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-up", window_scroll_up, | |
1065 "\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
|
1066 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
|
1067 "\033" "/", NULL); |
16518
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1068 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1069 toggle_clipboard, "\033" "C", NULL); |
15817 | 1070 |
1071 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
1072 | |
1073 /* Make sure Alt+x are detected properly. */ | |
1074 for (i = '0'; i <= '9'; i++) { | |
1075 char str[] = "\033X"; | |
1076 str[1] = i; | |
1077 gnt_keys_add_combination(str); | |
1078 } | |
1079 | |
1080 GNTDEBUG; | |
1081 } | |
1082 | |
1083 /****************************************************************************** | |
1084 * GntWM API | |
1085 *****************************************************************************/ | |
1086 GType | |
1087 gnt_wm_get_gtype(void) | |
1088 { | |
1089 static GType type = 0; | |
1090 | |
1091 if(type == 0) { | |
1092 static const GTypeInfo info = { | |
1093 sizeof(GntWMClass), | |
1094 NULL, /* base_init */ | |
1095 NULL, /* base_finalize */ | |
1096 (GClassInitFunc)gnt_wm_class_init, | |
1097 NULL, | |
1098 NULL, /* class_data */ | |
1099 sizeof(GntWM), | |
1100 0, /* n_preallocs */ | |
1101 gnt_wm_init, /* instance_init */ | |
1102 NULL /* value_table */ | |
1103 }; | |
1104 | |
1105 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
1106 "GntWM", | |
1107 &info, 0); | |
1108 } | |
1109 | |
1110 return type; | |
1111 } | |
1112 static void | |
1113 update_window_in_list(GntWM *wm, GntWidget *wid) | |
1114 { | |
1115 GntTextFormatFlags flag = 0; | |
1116 | |
1117 if (wm->windows == NULL) | |
1118 return; | |
1119 | |
1120 if (wid == wm->ordered->data) | |
1121 flag |= GNT_TEXT_FLAG_DIM; | |
1122 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) | |
1123 flag |= GNT_TEXT_FLAG_BOLD; | |
1124 | |
1125 gnt_tree_set_row_flags(GNT_TREE(wm->windows->tree), wid, flag); | |
1126 } | |
1127 | |
1128 static void | |
1129 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) | |
1130 { | |
1131 GntNode *node; | |
1132 gboolean transient = FALSE; | |
1133 | |
1134 if (widget->window == NULL) | |
1135 return; | |
1136 | |
1137 node = g_new0(GntNode, 1); | |
1138 node->me = widget; | |
1139 node->scroll = 0; | |
1140 | |
1141 g_hash_table_replace(wm->nodes, widget, node); | |
1142 | |
1143 refresh_node(widget, node, NULL); | |
1144 | |
1145 transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT); | |
1146 | |
1147 #if 1 | |
1148 { | |
1149 int x, y, w, h, maxx, maxy; | |
1150 gboolean shadow = TRUE; | |
1151 | |
1152 if (!gnt_widget_has_shadow(widget)) | |
1153 shadow = FALSE; | |
1154 x = widget->priv.x; | |
1155 y = widget->priv.y; | |
1156 w = widget->priv.width; | |
1157 h = widget->priv.height; | |
1158 | |
1159 getmaxyx(stdscr, maxy, maxx); | |
1160 maxy -= 1; /* room for the taskbar */ | |
1161 maxy -= shadow; | |
1162 maxx -= shadow; | |
1163 | |
1164 x = MAX(0, x); | |
1165 y = MAX(0, y); | |
1166 if (x + w >= maxx) | |
1167 x = MAX(0, maxx - w); | |
1168 if (y + h >= maxy) | |
1169 y = MAX(0, maxy - h); | |
1170 | |
1171 w = MIN(w, maxx); | |
1172 h = MIN(h, maxy); | |
1173 node->window = newwin(h + shadow, w + shadow, y, x); | |
1174 copy_win(widget, node); | |
1175 } | |
1176 #endif | |
1177 | |
1178 node->panel = new_panel(node->window); | |
1179 set_panel_userptr(node->panel, node); | |
1180 | |
1181 if (!transient) { | |
1182 if (node->me != wm->_list.window) { | |
1183 GntWidget *w = NULL; | |
1184 | |
1185 if (wm->ordered) | |
1186 w = wm->ordered->data; | |
1187 | |
1188 wm->list = g_list_append(wm->list, widget); | |
1189 | |
1190 if (wm->event_stack) | |
1191 wm->ordered = g_list_prepend(wm->ordered, widget); | |
1192 else | |
1193 wm->ordered = g_list_append(wm->ordered, widget); | |
1194 | |
1195 gnt_widget_set_focus(widget, TRUE); | |
1196 if (w) | |
1197 gnt_widget_set_focus(w, FALSE); | |
1198 } | |
1199 | |
1200 if (wm->event_stack || node->me == wm->_list.window) { | |
1201 gnt_wm_raise_window(wm, node->me); | |
1202 } else { | |
1203 bottom_panel(node->panel); /* New windows should not grab focus */ | |
1204 gnt_widget_set_urgent(node->me); | |
1205 } | |
1206 } | |
1207 } | |
1208 | |
1209 void gnt_wm_new_window(GntWM *wm, GntWidget *widget) | |
1210 { | |
1211 while (widget->parent) | |
1212 widget = widget->parent; | |
1213 | |
1214 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_INVISIBLE) || | |
1215 g_hash_table_lookup(wm->nodes, widget)) { | |
1216 update_screen(wm); | |
1217 return; | |
1218 } | |
1219 | |
1220 if (GNT_IS_BOX(widget)) { | |
1221 const char *title = GNT_BOX(widget)->title; | |
1222 GntPosition *p = NULL; | |
1223 if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { | |
1224 sanitize_position(widget, &p->x, &p->y); | |
1225 gnt_widget_set_position(widget, p->x, p->y); | |
1226 mvwin(widget->window, p->y, p->x); | |
1227 } | |
1228 } | |
1229 | |
1230 g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); | |
1231 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1232 | |
1233 if (wm->windows && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
1234 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && wm->_list.window != widget | |
1235 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
1236 gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget, | |
1237 gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title), | |
1238 NULL); | |
1239 update_window_in_list(wm, widget); | |
1240 } | |
1241 } | |
1242 | |
1243 update_screen(wm); | |
1244 draw_taskbar(wm, FALSE); | |
1245 } | |
1246 | |
1247 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget) | |
1248 { | |
1249 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1250 } | |
1251 | |
1252 void gnt_wm_window_close(GntWM *wm, GntWidget *widget) | |
1253 { | |
1254 GntNode *node; | |
1255 int pos; | |
1256 | |
1257 if ((node = g_hash_table_lookup(wm->nodes, widget)) == NULL) | |
1258 return; | |
1259 | |
1260 g_signal_emit(wm, signals[SIG_CLOSE_WIN], 0, widget); | |
1261 g_hash_table_remove(wm->nodes, widget); | |
1262 | |
1263 if (wm->windows) { | |
1264 gnt_tree_remove(GNT_TREE(wm->windows->tree), widget); | |
1265 } | |
1266 | |
1267 pos = g_list_index(wm->list, widget); | |
1268 | |
1269 if (pos != -1) { | |
1270 wm->list = g_list_remove(wm->list, widget); | |
1271 wm->ordered = g_list_remove(wm->ordered, widget); | |
1272 | |
1273 if (wm->ordered) | |
1274 gnt_wm_raise_window(wm, wm->ordered->data); | |
1275 } | |
1276 | |
1277 update_screen(wm); | |
1278 draw_taskbar(wm, FALSE); | |
1279 } | |
1280 | |
1281 time_t gnt_wm_get_idle_time() | |
1282 { | |
1283 return time(NULL) - last_active_time; | |
1284 } | |
1285 | |
1286 gboolean gnt_wm_process_input(GntWM *wm, const char *keys) | |
1287 { | |
1288 gboolean ret = FALSE; | |
1289 | |
1290 keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); | |
1291 | |
1292 idle_update = TRUE; | |
1293 | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1294 if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { |
15817 | 1295 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
|
1296 } |
15817 | 1297 |
1298 /* Do some manual checking */ | |
1299 if (wm->ordered && wm->mode != GNT_KP_MODE_NORMAL) { | |
1300 int xmin = 0, ymin = 0, xmax = getmaxx(stdscr), ymax = getmaxy(stdscr) - 1; | |
1301 int x, y, w, h; | |
1302 GntWidget *widget = GNT_WIDGET(wm->ordered->data); | |
1303 int ox, oy, ow, oh; | |
1304 | |
1305 gnt_widget_get_position(widget, &x, &y); | |
1306 gnt_widget_get_size(widget, &w, &h); | |
1307 ox = x; oy = y; | |
1308 ow = w; oh = h; | |
1309 | |
1310 if (wm->mode == GNT_KP_MODE_MOVE) { | |
1311 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1312 if (x > xmin) | |
1313 x--; | |
1314 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1315 if (x + w < xmax) | |
1316 x++; | |
1317 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1318 if (y > ymin) | |
1319 y--; | |
1320 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1321 if (y + h < ymax) | |
1322 y++; | |
1323 } | |
1324 if (ox != x || oy != y) { | |
1325 gnt_screen_move_widget(widget, x, y); | |
1326 window_reverse(widget, TRUE, wm); | |
1327 return TRUE; | |
1328 } | |
1329 } else if (wm->mode == GNT_KP_MODE_RESIZE) { | |
1330 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1331 w--; | |
1332 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1333 if (x + w < xmax) | |
1334 w++; | |
1335 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1336 h--; | |
1337 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1338 if (y + h < ymax) | |
1339 h++; | |
1340 } | |
1341 if (oh != h || ow != w) { | |
1342 gnt_screen_resize_widget(widget, w, h); | |
1343 window_reverse(widget, TRUE, wm); | |
1344 return TRUE; | |
1345 } | |
1346 } | |
1347 if (strcmp(keys, "\r") == 0 || strcmp(keys, "\033") == 0) { | |
1348 window_reverse(widget, FALSE, wm); | |
1349 wm->mode = GNT_KP_MODE_NORMAL; | |
1350 } | |
1351 return TRUE; | |
1352 } | |
1353 | |
1354 /* Escape to close the window-list or action-list window */ | |
1355 if (strcmp(keys, "\033") == 0) { | |
1356 if (wm->_list.window) { | |
1357 gnt_widget_destroy(wm->_list.window); | |
1358 return TRUE; | |
1359 } | |
1360 } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') { | |
1361 /* Alt+x for quick switch */ | |
1362 int n = *(keys + 1) - '0'; | |
1363 GList *list = NULL; | |
1364 | |
1365 if (n == 0) | |
1366 n = 10; | |
1367 | |
1368 list = g_list_append(list, GINT_TO_POINTER(n - 1)); | |
1369 switch_window_n(GNT_BINDABLE(wm), list); | |
1370 g_list_free(list); | |
1371 return TRUE; | |
1372 } | |
1373 | |
1374 if (wm->menu) | |
1375 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys); | |
1376 else if (wm->_list.window) | |
1377 ret = gnt_widget_key_pressed(wm->_list.window, keys); | |
1378 else if (wm->ordered) | |
1379 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys); | |
1380 return ret; | |
1381 } | |
1382 | |
1383 static void | |
1384 gnt_wm_win_resized(GntWM *wm, GntNode *node) | |
1385 { | |
1386 /*refresh_node(node->me, node, NULL);*/ | |
1387 } | |
1388 | |
1389 static void | |
1390 gnt_wm_win_moved(GntWM *wm, GntNode *node) | |
1391 { | |
1392 refresh_node(node->me, node, NULL); | |
1393 } | |
1394 | |
1395 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height) | |
1396 { | |
1397 gboolean ret = TRUE; | |
1398 GntNode *node; | |
1399 int shadow; | |
1400 int maxx, maxy; | |
1401 | |
1402 while (widget->parent) | |
1403 widget = widget->parent; | |
1404 node = g_hash_table_lookup(wm->nodes, widget); | |
1405 if (!node) | |
1406 return; | |
1407 | |
1408 g_signal_emit(wm, signals[SIG_CONFIRM_RESIZE], 0, widget, &width, &height, &ret); | |
1409 if (!ret) | |
1410 return; /* resize is not permitted */ | |
1411 hide_panel(node->panel); | |
1412 gnt_widget_set_size(widget, width, height); | |
1413 gnt_widget_draw(widget); | |
1414 | |
1415 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
1416 maxx = getmaxx(stdscr) - shadow; | |
1417 maxy = getmaxy(stdscr) - 1 - shadow; | |
1418 height = MIN(height, maxy); | |
1419 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
|
1420 wresize(node->window, height, width); |
15817 | 1421 replace_panel(node->panel, node->window); |
1422 | |
1423 g_signal_emit(wm, signals[SIG_RESIZED], 0, node); | |
1424 | |
1425 show_panel(node->panel); | |
1426 update_screen(wm); | |
1427 } | |
1428 | |
1429 static void | |
1430 write_gdi(gpointer key, gpointer value, gpointer data) | |
1431 { | |
1432 GntPosition *p = value; | |
1433 fprintf(data, ".%s = %d;%d\n", (char *)key, p->x, p->y); | |
1434 } | |
1435 | |
1436 static gboolean | |
1437 write_already(gpointer data) | |
1438 { | |
1439 GntWM *wm = data; | |
1440 FILE *file; | |
1441 char *filename; | |
1442 | |
1443 filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
1444 | |
1445 file = fopen(filename, "wb"); | |
1446 if (file == NULL) { | |
1447 g_printerr("GntWM: error opening file to save positions\n"); | |
1448 } else { | |
1449 fprintf(file, "[positions]\n"); | |
1450 g_hash_table_foreach(wm->positions, write_gdi, file); | |
1451 fclose(file); | |
1452 } | |
1453 | |
1454 g_free(filename); | |
1455 g_source_remove(write_timeout); | |
1456 write_timeout = 0; | |
1457 return FALSE; | |
1458 } | |
1459 | |
1460 static void | |
1461 write_positions_to_file(GntWM *wm) | |
1462 { | |
1463 if (write_timeout) { | |
1464 g_source_remove(write_timeout); | |
1465 } | |
1466 write_timeout = g_timeout_add(10000, write_already, wm); | |
1467 } | |
1468 | |
1469 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) | |
1470 { | |
1471 gboolean ret = TRUE; | |
1472 GntNode *node; | |
1473 | |
1474 while (widget->parent) | |
1475 widget = widget->parent; | |
1476 node = g_hash_table_lookup(wm->nodes, widget); | |
1477 if (!node) | |
1478 return; | |
1479 | |
1480 g_signal_emit(wm, signals[SIG_CONFIRM_MOVE], 0, widget, &x, &y, &ret); | |
1481 if (!ret) | |
1482 return; /* resize is not permitted */ | |
1483 | |
1484 gnt_widget_set_position(widget, x, y); | |
1485 move_panel(node->panel, y, x); | |
1486 | |
1487 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
|
1488 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
|
1489 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
15817 | 1490 const char *title = GNT_BOX(widget)->title; |
1491 if (title) { | |
1492 GntPosition *p = g_new0(GntPosition, 1); | |
1493 GntWidget *wid = node->me; | |
1494 p->x = wid->priv.x; | |
1495 p->y = wid->priv.y; | |
1496 g_hash_table_replace(wm->positions, g_strdup(title), p); | |
1497 write_positions_to_file(wm); | |
1498 } | |
1499 } | |
1500 | |
1501 update_screen(wm); | |
1502 } | |
1503 | |
1504 static void | |
1505 gnt_wm_give_focus(GntWM *wm, GntWidget *widget) | |
1506 { | |
1507 GntNode *node = g_hash_table_lookup(wm->nodes, widget); | |
1508 | |
1509 if (!node) | |
1510 return; | |
1511 | |
1512 if (widget != wm->_list.window && !GNT_IS_MENU(widget) && | |
1513 wm->ordered->data != widget) { | |
1514 GntWidget *w = wm->ordered->data; | |
1515 wm->ordered = g_list_bring_to_front(wm->ordered, widget); | |
1516 gnt_widget_set_focus(w, FALSE); | |
1517 } | |
1518 | |
1519 gnt_widget_set_focus(widget, TRUE); | |
1520 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_URGENT); | |
1521 gnt_widget_draw(widget); | |
1522 top_panel(node->panel); | |
1523 | |
1524 if (wm->_list.window) { | |
1525 GntNode *nd = g_hash_table_lookup(wm->nodes, wm->_list.window); | |
1526 top_panel(nd->panel); | |
1527 } | |
1528 update_screen(wm); | |
1529 draw_taskbar(wm, FALSE); | |
1530 } | |
1531 | |
1532 void gnt_wm_update_window(GntWM *wm, GntWidget *widget) | |
1533 { | |
1534 GntNode *node; | |
1535 | |
1536 while (widget->parent) | |
1537 widget = widget->parent; | |
1538 if (!GNT_IS_MENU(widget)) | |
1539 gnt_box_sync_children(GNT_BOX(widget)); | |
1540 | |
1541 node = g_hash_table_lookup(wm->nodes, widget); | |
1542 if (node == NULL) { | |
1543 gnt_wm_new_window(wm, widget); | |
1544 } else | |
1545 g_signal_emit(wm, signals[SIG_UPDATE_WIN], 0, node); | |
1546 | |
1547 copy_win(widget, node); | |
1548 update_screen(wm); | |
1549 draw_taskbar(wm, FALSE); | |
1550 } | |
1551 | |
1552 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget) | |
1553 { | |
1554 gboolean ret = TRUE; | |
1555 idle_update = TRUE; | |
1556 g_signal_emit(wm, signals[SIG_MOUSE_CLICK], 0, event, x, y, widget, &ret); | |
1557 return ret; | |
1558 } | |
1559 | |
1560 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget) | |
1561 { | |
1562 g_signal_emit(wm, signals[SIG_GIVE_FOCUS], 0, widget); | |
1563 } | |
1564 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1565 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
|
1566 { |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1567 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
|
1568 } |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1569 |