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