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