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