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