Mercurial > pidgin
annotate finch/libgnt/gntwm.c @ 18045:08e93462f189
Update the irssi WM to allow tiling the conversation windows.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 06 Jun 2007 14:34:58 +0000 |
parents | c0c17a81f5fe |
children | 1cedd520cd18 |
rev | line source |
---|---|
15817 | 1 #define _GNU_SOURCE |
17812
c0c17a81f5fe
Fix libgnt compilation on BSD and solaris. This references #516.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17745
diff
changeset
|
2 #if defined(__APPLE__) || defined(__unix__) |
15817 | 3 #define _XOPEN_SOURCE_EXTENDED |
4 #endif | |
5 | |
6 #include "config.h" | |
7 | |
8 #include <ctype.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <time.h> | |
12 | |
13 #include "gntwm.h" | |
14 #include "gntstyle.h" | |
15 #include "gntmarshal.h" | |
16 #include "gnt.h" | |
17 #include "gntbox.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
18 #include "gntlabel.h" |
15817 | 19 #include "gntmenu.h" |
20 #include "gnttextview.h" | |
21 #include "gnttree.h" | |
22 #include "gntutils.h" | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
23 #include "gntwindow.h" |
15817 | 24 |
25 #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ | |
26 | |
27 enum | |
28 { | |
29 SIG_NEW_WIN, | |
30 SIG_DECORATE_WIN, | |
31 SIG_CLOSE_WIN, | |
32 SIG_CONFIRM_RESIZE, | |
33 SIG_RESIZED, | |
34 SIG_CONFIRM_MOVE, | |
35 SIG_MOVED, | |
36 SIG_UPDATE_WIN, | |
37 SIG_GIVE_FOCUS, | |
38 SIG_KEY_PRESS, | |
39 SIG_MOUSE_CLICK, | |
40 SIGS | |
41 }; | |
42 | |
43 static guint signals[SIGS] = { 0 }; | |
44 static void gnt_wm_new_window_real(GntWM *wm, GntWidget *widget); | |
45 static void gnt_wm_win_resized(GntWM *wm, GntNode *node); | |
46 static void gnt_wm_win_moved(GntWM *wm, GntNode *node); | |
47 static void gnt_wm_give_focus(GntWM *wm, GntWidget *widget); | |
48 static void update_window_in_list(GntWM *wm, GntWidget *wid); | |
49 static void shift_window(GntWM *wm, GntWidget *widget, int dir); | |
50 | |
17048
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
diff
changeset
|
53 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
54 |
15817 | 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 | |
17048
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
143 /** |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
diff
changeset
|
146 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
150 * |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
diff
changeset
|
153 */ |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
diff
changeset
|
156 { |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
163 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
168 |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
172 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
diff
changeset
|
175 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
185 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
186 right: |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
diff
changeset
|
188 continue; |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
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:
16518
diff
changeset
|
195 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
196 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
197 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
198 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
199 #endif |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
200 } |
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
201 |
15817 | 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 } | |
17048
f1abdde52538
A workaround for an ncurses bug about multi-cell characters and panels.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16518
diff
changeset
|
214 work_around_for_ncurses_bug(); |
15817 | 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); |
15817 | 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 |
15817 | 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 ',': |
15817 | 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 '.': |
15817 | 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"); | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
631 struct { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
632 char ascii; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
633 char *unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
634 } unis[] = { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
635 {'q', "─"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
636 {'t', "├"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
637 {'u', "┤"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
638 {'x', "│"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
639 {'-', "↑"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
640 {'.', "↓"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
641 {'l', "┌"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
642 {'k', "┐"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
643 {'m', "└"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
644 {'j', "┘"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
645 {'a', "▒"}, |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
646 {'\0', NULL} |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
647 }; |
15817 | 648 |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
649 fprintf(file, "<head>\n <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />\n</head>\n<body>\n"); |
15817 | 650 fprintf(file, "<pre>"); |
651 for (y = 0; y < getmaxy(stdscr); y++) { | |
652 for (x = 0; x < getmaxx(stdscr); x++) { | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
653 char ch[2] = {0, 0}, *print; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
654 #ifdef NO_WIDECHAR |
15817 | 655 now = mvwinch(curscr, y, x); |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
656 ch[0] = now & A_CHARTEXT; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
657 now ^= ch[0]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
658 #else |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
659 cchar_t wch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
660 char unicode[12]; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
661 mvwin_wch(curscr, y, x, &wch); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
662 now = wch.attr; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
663 ch[0] = (char)(wch.chars[0] & 0xff); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
664 #endif |
15817 | 665 |
666 #define CHECK(attr, start, end) \ | |
667 do \ | |
668 { \ | |
669 if (now & attr) \ | |
670 { \ | |
671 if (!(old & attr)) \ | |
672 fprintf(file, "%s", start); \ | |
673 } \ | |
674 else if (old & attr) \ | |
675 { \ | |
676 fprintf(file, "%s", end); \ | |
677 } \ | |
678 } while (0) | |
679 | |
680 CHECK(A_BOLD, "<b>", "</b>"); | |
681 CHECK(A_UNDERLINE, "<u>", "</u>"); | |
682 CHECK(A_BLINK, "<blink>", "</blink>"); | |
683 | |
684 if ((now & A_COLOR) != (old & A_COLOR) || | |
685 (now & A_REVERSE) != (old & A_REVERSE)) | |
686 { | |
687 int ret; | |
688 short fgp, bgp, r, g, b; | |
689 struct | |
690 { | |
691 int r, g, b; | |
692 } fg, bg; | |
693 | |
694 ret = pair_content(PAIR_NUMBER(now & A_COLOR), &fgp, &bgp); | |
695 if (fgp == -1) | |
696 fgp = COLOR_BLACK; | |
697 if (bgp == -1) | |
698 bgp = COLOR_WHITE; | |
699 if (now & A_REVERSE) | |
17146
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17117
diff
changeset
|
700 { |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17117
diff
changeset
|
701 short tmp = fgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17117
diff
changeset
|
702 fgp = bgp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17117
diff
changeset
|
703 bgp = tmp; |
e5cc13b1e0ca
Fix a compiler warning by using a temporary variable for swapping.
Richard Laager <rlaager@wiktel.com>
parents:
17117
diff
changeset
|
704 } |
15817 | 705 ret = color_content(fgp, &r, &g, &b); |
706 fg.r = r; fg.b = b; fg.g = g; | |
707 ret = color_content(bgp, &r, &g, &b); | |
708 bg.r = r; bg.b = b; bg.g = g; | |
709 #define ADJUST(x) (x = x * 255 / 1000) | |
710 ADJUST(fg.r); | |
711 ADJUST(fg.g); | |
712 ADJUST(fg.b); | |
713 ADJUST(bg.r); | |
714 ADJUST(bg.b); | |
715 ADJUST(bg.g); | |
716 | |
717 if (x) fprintf(file, "</span>"); | |
718 fprintf(file, "<span style=\"background:#%02x%02x%02x;color:#%02x%02x%02x\">", | |
719 bg.r, bg.g, bg.b, fg.r, fg.g, fg.b); | |
720 } | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
721 print = ch; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
722 #ifndef NO_WIDECHAR |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
723 if (wch.chars[0] > 255) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
724 snprintf(unicode, sizeof(unicode), "&#x%x;", wch.chars[0]); |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
725 print = unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
726 } |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
727 #endif |
15817 | 728 if (now & A_ALTCHARSET) |
729 { | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
730 int u; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
731 for (u = 0; unis[u].ascii; u++) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
732 if (ch[0] == unis[u].ascii) { |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
733 print = unis[u].unicode; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
734 break; |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
735 } |
15817 | 736 } |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
737 if (!unis[u].ascii) |
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
738 print = " "; |
15817 | 739 } |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
740 if (ch[0] == '&') |
15817 | 741 fprintf(file, "&"); |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
742 else if (ch[0] == '<') |
15817 | 743 fprintf(file, "<"); |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
744 else if (ch[0] == '>') |
15817 | 745 fprintf(file, ">"); |
746 else | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
747 fprintf(file, "%s", print); |
15817 | 748 old = now; |
749 } | |
750 fprintf(file, "</span>\n"); | |
751 old = 0; | |
752 } | |
17117
3c4280387259
Generate nicer HTML dumps.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17048
diff
changeset
|
753 fprintf(file, "</pre>\n</body>"); |
15817 | 754 fclose(file); |
755 return TRUE; | |
756 } | |
757 | |
758 static void | |
759 shift_window(GntWM *wm, GntWidget *widget, int dir) | |
760 { | |
761 GList *all = wm->list; | |
762 GList *list = g_list_find(all, widget); | |
763 int length, pos; | |
764 if (!list) | |
765 return; | |
766 | |
767 length = g_list_length(all); | |
768 pos = g_list_position(all, list); | |
769 | |
770 pos += dir; | |
771 if (dir > 0) | |
772 pos++; | |
773 | |
774 if (pos < 0) | |
775 pos = length; | |
776 else if (pos > length) | |
777 pos = 0; | |
778 | |
779 all = g_list_insert(all, widget, pos); | |
780 all = g_list_delete_link(all, list); | |
781 wm->list = all; | |
782 draw_taskbar(wm, FALSE); | |
783 } | |
784 | |
785 static gboolean | |
786 shift_left(GntBindable *bindable, GList *null) | |
787 { | |
788 GntWM *wm = GNT_WM(bindable); | |
789 if (wm->_list.window) | |
790 return TRUE; | |
791 | |
792 shift_window(wm, wm->ordered->data, -1); | |
793 return TRUE; | |
794 } | |
795 | |
796 static gboolean | |
797 shift_right(GntBindable *bindable, GList *null) | |
798 { | |
799 GntWM *wm = GNT_WM(bindable); | |
800 if (wm->_list.window) | |
801 return TRUE; | |
802 | |
803 shift_window(wm, wm->ordered->data, 1); | |
804 return TRUE; | |
805 } | |
806 | |
807 static void | |
808 action_list_activate(GntTree *tree, GntWM *wm) | |
809 { | |
810 GntAction *action = gnt_tree_get_selection_data(tree); | |
811 action->callback(); | |
812 gnt_widget_destroy(wm->_list.window); | |
813 } | |
814 | |
815 static int | |
816 compare_action(gconstpointer p1, gconstpointer p2) | |
817 { | |
818 const GntAction *a1 = p1; | |
819 const GntAction *a2 = p2; | |
820 | |
821 return g_utf8_collate(a1->label, a2->label); | |
822 } | |
823 | |
824 static gboolean | |
825 list_actions(GntBindable *bindable, GList *null) | |
826 { | |
827 GntWidget *tree, *win; | |
828 GList *iter; | |
829 GntWM *wm = GNT_WM(bindable); | |
830 if (wm->_list.window || wm->menu) | |
831 return TRUE; | |
832 | |
833 if (wm->acts == NULL) | |
834 return TRUE; | |
835 | |
836 setup__list(wm); | |
837 wm->actions = &wm->_list; | |
838 | |
839 win = wm->actions->window; | |
840 tree = wm->actions->tree; | |
841 | |
842 gnt_box_set_title(GNT_BOX(win), "Actions"); | |
843 GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER); | |
844 /* XXX: Do we really want this? */ | |
845 gnt_tree_set_compare_func(GNT_TREE(tree), compare_action); | |
846 | |
847 for (iter = wm->acts; iter; iter = iter->next) { | |
848 GntAction *action = iter->data; | |
849 gnt_tree_add_row_last(GNT_TREE(tree), action, | |
850 gnt_tree_create_row(GNT_TREE(tree), action->label), NULL); | |
851 } | |
852 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(action_list_activate), wm); | |
853 gnt_widget_set_size(tree, 0, g_list_length(wm->acts)); | |
854 gnt_widget_set_position(win, 0, getmaxy(stdscr) - 3 - g_list_length(wm->acts)); | |
855 | |
856 gnt_widget_show(win); | |
857 return TRUE; | |
858 } | |
859 | |
860 #ifndef NO_WIDECHAR | |
861 static int | |
862 widestringwidth(wchar_t *wide) | |
863 { | |
864 int len, ret; | |
865 char *string; | |
866 | |
867 len = wcstombs(NULL, wide, 0) + 1; | |
868 string = g_new0(char, len); | |
869 wcstombs(string, wide, len); | |
870 ret = gnt_util_onscreen_width(string, NULL); | |
871 g_free(string); | |
872 return ret; | |
873 } | |
874 #endif | |
875 | |
876 /* Returns the onscreen width of the character at the position */ | |
877 static int | |
878 reverse_char(WINDOW *d, int y, int x, gboolean set) | |
879 { | |
880 #define DECIDE(ch) (set ? ((ch) | A_REVERSE) : ((ch) & ~A_REVERSE)) | |
881 | |
882 #ifdef NO_WIDECHAR | |
883 chtype ch; | |
884 ch = mvwinch(d, y, x); | |
885 mvwaddch(d, y, x, DECIDE(ch)); | |
886 return 1; | |
887 #else | |
888 cchar_t ch; | |
889 int wc = 1; | |
890 if (mvwin_wch(d, y, x, &ch) == OK) { | |
891 wc = widestringwidth(ch.chars); | |
892 ch.attr = DECIDE(ch.attr); | |
893 ch.attr &= WA_ATTRIBUTES; /* XXX: This is a workaround for a bug */ | |
894 mvwadd_wch(d, y, x, &ch); | |
895 } | |
896 | |
897 return wc; | |
898 #endif | |
899 } | |
900 | |
901 static void | |
902 window_reverse(GntWidget *win, gboolean set, GntWM *wm) | |
903 { | |
904 int i; | |
905 int w, h; | |
906 WINDOW *d; | |
907 | |
908 if (GNT_WIDGET_IS_FLAG_SET(win, GNT_WIDGET_NO_BORDER)) | |
909 return; | |
910 | |
911 d = win->window; | |
912 gnt_widget_get_size(win, &w, &h); | |
913 | |
914 if (gnt_widget_has_shadow(win)) { | |
915 --w; | |
916 --h; | |
917 } | |
918 | |
919 /* the top and bottom */ | |
920 for (i = 0; i < w; i += reverse_char(d, 0, i, set)); | |
921 for (i = 0; i < w; i += reverse_char(d, h-1, i, set)); | |
922 | |
923 /* the left and right */ | |
924 for (i = 0; i < h; i += reverse_char(d, i, 0, set)); | |
925 for (i = 0; i < h; i += reverse_char(d, i, w-1, set)); | |
926 | |
927 copy_win(win, g_hash_table_lookup(wm->nodes, win)); | |
928 update_screen(wm); | |
929 } | |
930 | |
931 static gboolean | |
932 start_move(GntBindable *bindable, GList *null) | |
933 { | |
934 GntWM *wm = GNT_WM(bindable); | |
935 if (wm->_list.window || wm->menu) | |
936 return TRUE; | |
937 if (!wm->ordered) | |
938 return TRUE; | |
939 | |
940 wm->mode = GNT_KP_MODE_MOVE; | |
941 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
942 | |
943 return TRUE; | |
944 } | |
945 | |
946 static gboolean | |
947 start_resize(GntBindable *bindable, GList *null) | |
948 { | |
949 GntWM *wm = GNT_WM(bindable); | |
950 if (wm->_list.window || wm->menu) | |
951 return TRUE; | |
952 if (!wm->ordered) | |
953 return TRUE; | |
954 | |
955 wm->mode = GNT_KP_MODE_RESIZE; | |
956 window_reverse(GNT_WIDGET(wm->ordered->data), TRUE, wm); | |
957 | |
958 return TRUE; | |
959 } | |
960 | |
961 static gboolean | |
962 wm_quit(GntBindable *bindable, GList *list) | |
963 { | |
964 GntWM *wm = GNT_WM(bindable); | |
965 if (write_timeout) | |
966 write_already(wm); | |
967 g_main_loop_quit(wm->loop); | |
968 return TRUE; | |
969 } | |
970 | |
971 static gboolean | |
972 return_true(GntWM *wm, GntWidget *w, int *a, int *b) | |
973 { | |
974 return TRUE; | |
975 } | |
976 | |
977 static gboolean | |
978 refresh_screen(GntBindable *bindable, GList *null) | |
979 { | |
980 GntWM *wm = GNT_WM(bindable); | |
981 | |
982 endwin(); | |
983 | |
984 g_hash_table_foreach(wm->nodes, (GHFunc)refresh_node, NULL); | |
985 update_screen(wm); | |
986 draw_taskbar(wm, TRUE); | |
17745
8d3c28521112
I think this fixes #532.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17146
diff
changeset
|
987 curs_set(0); /* endwin resets the cursor to normal */ |
15817 | 988 |
989 return FALSE; | |
990 } | |
991 | |
16518
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
992 static gboolean |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
993 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
|
994 { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
995 static GntWidget *clip; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
996 gchar *text; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
997 int maxx, maxy; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
998 if (clip) { |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
999 gnt_widget_destroy(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1000 clip = NULL; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1001 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1002 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1003 getmaxyx(stdscr, maxy, maxx); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 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
|
1011 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
|
1012 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
|
1013 gnt_widget_draw(clip); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1014 g_free(text); |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1015 return TRUE; |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1016 } |
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1017 |
15817 | 1018 static void |
1019 gnt_wm_class_init(GntWMClass *klass) | |
1020 { | |
1021 int i; | |
1022 | |
1023 klass->new_window = gnt_wm_new_window_real; | |
1024 klass->decorate_window = NULL; | |
1025 klass->close_window = NULL; | |
1026 klass->window_resize_confirm = return_true; | |
1027 klass->window_resized = gnt_wm_win_resized; | |
1028 klass->window_move_confirm = return_true; | |
1029 klass->window_moved = gnt_wm_win_moved; | |
1030 klass->window_update = NULL; | |
1031 klass->key_pressed = NULL; | |
1032 klass->mouse_clicked = NULL; | |
1033 klass->give_focus = gnt_wm_give_focus; | |
1034 | |
1035 signals[SIG_NEW_WIN] = | |
1036 g_signal_new("new_win", | |
1037 G_TYPE_FROM_CLASS(klass), | |
1038 G_SIGNAL_RUN_LAST, | |
1039 G_STRUCT_OFFSET(GntWMClass, new_window), | |
1040 NULL, NULL, | |
1041 g_cclosure_marshal_VOID__POINTER, | |
1042 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1043 signals[SIG_DECORATE_WIN] = | |
1044 g_signal_new("decorate_win", | |
1045 G_TYPE_FROM_CLASS(klass), | |
1046 G_SIGNAL_RUN_LAST, | |
1047 G_STRUCT_OFFSET(GntWMClass, decorate_window), | |
1048 NULL, NULL, | |
1049 g_cclosure_marshal_VOID__POINTER, | |
1050 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1051 signals[SIG_CLOSE_WIN] = | |
1052 g_signal_new("close_win", | |
1053 G_TYPE_FROM_CLASS(klass), | |
1054 G_SIGNAL_RUN_LAST, | |
1055 G_STRUCT_OFFSET(GntWMClass, close_window), | |
1056 NULL, NULL, | |
1057 g_cclosure_marshal_VOID__POINTER, | |
1058 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1059 signals[SIG_CONFIRM_RESIZE] = | |
1060 g_signal_new("confirm_resize", | |
1061 G_TYPE_FROM_CLASS(klass), | |
1062 G_SIGNAL_RUN_LAST, | |
1063 G_STRUCT_OFFSET(GntWMClass, window_resize_confirm), | |
1064 gnt_boolean_handled_accumulator, NULL, | |
1065 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1066 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1067 | |
1068 signals[SIG_CONFIRM_MOVE] = | |
1069 g_signal_new("confirm_move", | |
1070 G_TYPE_FROM_CLASS(klass), | |
1071 G_SIGNAL_RUN_LAST, | |
1072 G_STRUCT_OFFSET(GntWMClass, window_move_confirm), | |
1073 gnt_boolean_handled_accumulator, NULL, | |
1074 gnt_closure_marshal_BOOLEAN__POINTER_POINTER_POINTER, | |
1075 G_TYPE_BOOLEAN, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_POINTER); | |
1076 | |
1077 signals[SIG_RESIZED] = | |
1078 g_signal_new("window_resized", | |
1079 G_TYPE_FROM_CLASS(klass), | |
1080 G_SIGNAL_RUN_LAST, | |
1081 G_STRUCT_OFFSET(GntWMClass, window_resized), | |
1082 NULL, NULL, | |
1083 g_cclosure_marshal_VOID__POINTER, | |
1084 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1085 signals[SIG_MOVED] = | |
1086 g_signal_new("window_moved", | |
1087 G_TYPE_FROM_CLASS(klass), | |
1088 G_SIGNAL_RUN_LAST, | |
1089 G_STRUCT_OFFSET(GntWMClass, window_moved), | |
1090 NULL, NULL, | |
1091 g_cclosure_marshal_VOID__POINTER, | |
1092 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1093 signals[SIG_UPDATE_WIN] = | |
1094 g_signal_new("window_update", | |
1095 G_TYPE_FROM_CLASS(klass), | |
1096 G_SIGNAL_RUN_LAST, | |
1097 G_STRUCT_OFFSET(GntWMClass, window_update), | |
1098 NULL, NULL, | |
1099 g_cclosure_marshal_VOID__POINTER, | |
1100 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1101 | |
1102 signals[SIG_GIVE_FOCUS] = | |
1103 g_signal_new("give_focus", | |
1104 G_TYPE_FROM_CLASS(klass), | |
1105 G_SIGNAL_RUN_LAST, | |
1106 G_STRUCT_OFFSET(GntWMClass, give_focus), | |
1107 NULL, NULL, | |
1108 g_cclosure_marshal_VOID__POINTER, | |
1109 G_TYPE_NONE, 1, G_TYPE_POINTER); | |
1110 | |
1111 signals[SIG_MOUSE_CLICK] = | |
1112 g_signal_new("mouse_clicked", | |
1113 G_TYPE_FROM_CLASS(klass), | |
1114 G_SIGNAL_RUN_LAST, | |
1115 G_STRUCT_OFFSET(GntWMClass, mouse_clicked), | |
1116 gnt_boolean_handled_accumulator, NULL, | |
1117 gnt_closure_marshal_BOOLEAN__INT_INT_INT_POINTER, | |
1118 G_TYPE_BOOLEAN, 4, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_POINTER); | |
1119 | |
1120 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-next", window_next, | |
1121 "\033" "n", NULL); | |
1122 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-prev", window_prev, | |
1123 "\033" "p", NULL); | |
1124 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-close", window_close, | |
1125 "\033" "c", NULL); | |
1126 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-list", window_list, | |
1127 "\033" "w", NULL); | |
1128 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "dump-screen", dump_screen, | |
1129 "\033" "d", NULL); | |
1130 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-left", shift_left, | |
1131 "\033" ",", NULL); | |
1132 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "shift-right", shift_right, | |
1133 "\033" ".", NULL); | |
1134 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "action-list", list_actions, | |
1135 "\033" "a", NULL); | |
1136 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-move", start_move, | |
1137 "\033" "m", NULL); | |
1138 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "start-resize", start_resize, | |
1139 "\033" "r", NULL); | |
1140 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "wm-quit", wm_quit, | |
1141 "\033" "q", NULL); | |
1142 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "refresh-screen", refresh_screen, | |
1143 "\033" "l", NULL); | |
1144 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "switch-window-n", switch_window_n, | |
1145 NULL, NULL); | |
1146 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-down", window_scroll_down, | |
1147 "\033" GNT_KEY_CTRL_J, NULL); | |
1148 gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "window-scroll-up", window_scroll_up, | |
1149 "\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
|
1150 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
|
1151 "\033" "/", NULL); |
16518
403332494b92
Move the toggle-clipboard operation to the default wm.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
1152 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
|
1153 toggle_clipboard, "\033" "C", NULL); |
15817 | 1154 |
1155 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); | |
1156 | |
1157 /* Make sure Alt+x are detected properly. */ | |
1158 for (i = '0'; i <= '9'; i++) { | |
1159 char str[] = "\033X"; | |
1160 str[1] = i; | |
1161 gnt_keys_add_combination(str); | |
1162 } | |
1163 | |
1164 GNTDEBUG; | |
1165 } | |
1166 | |
1167 /****************************************************************************** | |
1168 * GntWM API | |
1169 *****************************************************************************/ | |
1170 GType | |
1171 gnt_wm_get_gtype(void) | |
1172 { | |
1173 static GType type = 0; | |
1174 | |
1175 if(type == 0) { | |
1176 static const GTypeInfo info = { | |
1177 sizeof(GntWMClass), | |
1178 NULL, /* base_init */ | |
1179 NULL, /* base_finalize */ | |
1180 (GClassInitFunc)gnt_wm_class_init, | |
1181 NULL, | |
1182 NULL, /* class_data */ | |
1183 sizeof(GntWM), | |
1184 0, /* n_preallocs */ | |
1185 gnt_wm_init, /* instance_init */ | |
1186 NULL /* value_table */ | |
1187 }; | |
1188 | |
1189 type = g_type_register_static(GNT_TYPE_BINDABLE, | |
1190 "GntWM", | |
1191 &info, 0); | |
1192 } | |
1193 | |
1194 return type; | |
1195 } | |
1196 static void | |
1197 update_window_in_list(GntWM *wm, GntWidget *wid) | |
1198 { | |
1199 GntTextFormatFlags flag = 0; | |
1200 | |
1201 if (wm->windows == NULL) | |
1202 return; | |
1203 | |
1204 if (wid == wm->ordered->data) | |
1205 flag |= GNT_TEXT_FLAG_DIM; | |
1206 else if (GNT_WIDGET_IS_FLAG_SET(wid, GNT_WIDGET_URGENT)) | |
1207 flag |= GNT_TEXT_FLAG_BOLD; | |
1208 | |
1209 gnt_tree_set_row_flags(GNT_TREE(wm->windows->tree), wid, flag); | |
1210 } | |
1211 | |
1212 static void | |
1213 gnt_wm_new_window_real(GntWM *wm, GntWidget *widget) | |
1214 { | |
1215 GntNode *node; | |
1216 gboolean transient = FALSE; | |
1217 | |
1218 if (widget->window == NULL) | |
1219 return; | |
1220 | |
1221 node = g_new0(GntNode, 1); | |
1222 node->me = widget; | |
1223 node->scroll = 0; | |
1224 | |
1225 g_hash_table_replace(wm->nodes, widget, node); | |
1226 | |
1227 refresh_node(widget, node, NULL); | |
1228 | |
1229 transient = !!GNT_WIDGET_IS_FLAG_SET(node->me, GNT_WIDGET_TRANSIENT); | |
1230 | |
1231 #if 1 | |
1232 { | |
1233 int x, y, w, h, maxx, maxy; | |
1234 gboolean shadow = TRUE; | |
1235 | |
1236 if (!gnt_widget_has_shadow(widget)) | |
1237 shadow = FALSE; | |
1238 x = widget->priv.x; | |
1239 y = widget->priv.y; | |
1240 w = widget->priv.width; | |
1241 h = widget->priv.height; | |
1242 | |
1243 getmaxyx(stdscr, maxy, maxx); | |
1244 maxy -= 1; /* room for the taskbar */ | |
1245 maxy -= shadow; | |
1246 maxx -= shadow; | |
1247 | |
1248 x = MAX(0, x); | |
1249 y = MAX(0, y); | |
1250 if (x + w >= maxx) | |
1251 x = MAX(0, maxx - w); | |
1252 if (y + h >= maxy) | |
1253 y = MAX(0, maxy - h); | |
1254 | |
1255 w = MIN(w, maxx); | |
1256 h = MIN(h, maxy); | |
1257 node->window = newwin(h + shadow, w + shadow, y, x); | |
1258 copy_win(widget, node); | |
1259 } | |
1260 #endif | |
1261 | |
1262 node->panel = new_panel(node->window); | |
1263 set_panel_userptr(node->panel, node); | |
1264 | |
1265 if (!transient) { | |
1266 if (node->me != wm->_list.window) { | |
1267 GntWidget *w = NULL; | |
1268 | |
1269 if (wm->ordered) | |
1270 w = wm->ordered->data; | |
1271 | |
1272 wm->list = g_list_append(wm->list, widget); | |
1273 | |
1274 if (wm->event_stack) | |
1275 wm->ordered = g_list_prepend(wm->ordered, widget); | |
1276 else | |
1277 wm->ordered = g_list_append(wm->ordered, widget); | |
1278 | |
1279 gnt_widget_set_focus(widget, TRUE); | |
1280 if (w) | |
1281 gnt_widget_set_focus(w, FALSE); | |
1282 } | |
1283 | |
1284 if (wm->event_stack || node->me == wm->_list.window) { | |
1285 gnt_wm_raise_window(wm, node->me); | |
1286 } else { | |
1287 bottom_panel(node->panel); /* New windows should not grab focus */ | |
1288 gnt_widget_set_urgent(node->me); | |
1289 } | |
1290 } | |
1291 } | |
1292 | |
1293 void gnt_wm_new_window(GntWM *wm, GntWidget *widget) | |
1294 { | |
1295 while (widget->parent) | |
1296 widget = widget->parent; | |
1297 | |
1298 if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_INVISIBLE) || | |
1299 g_hash_table_lookup(wm->nodes, widget)) { | |
1300 update_screen(wm); | |
1301 return; | |
1302 } | |
1303 | |
1304 if (GNT_IS_BOX(widget)) { | |
1305 const char *title = GNT_BOX(widget)->title; | |
1306 GntPosition *p = NULL; | |
1307 if (title && (p = g_hash_table_lookup(wm->positions, title)) != NULL) { | |
1308 sanitize_position(widget, &p->x, &p->y); | |
1309 gnt_widget_set_position(widget, p->x, p->y); | |
1310 mvwin(widget->window, p->y, p->x); | |
1311 } | |
1312 } | |
1313 | |
1314 g_signal_emit(wm, signals[SIG_NEW_WIN], 0, widget); | |
1315 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1316 | |
1317 if (wm->windows && !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
1318 if ((GNT_IS_BOX(widget) && GNT_BOX(widget)->title) && wm->_list.window != widget | |
1319 && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_CAN_TAKE_FOCUS)) { | |
1320 gnt_tree_add_row_last(GNT_TREE(wm->windows->tree), widget, | |
1321 gnt_tree_create_row(GNT_TREE(wm->windows->tree), GNT_BOX(widget)->title), | |
1322 NULL); | |
1323 update_window_in_list(wm, widget); | |
1324 } | |
1325 } | |
1326 | |
1327 update_screen(wm); | |
1328 draw_taskbar(wm, FALSE); | |
1329 } | |
1330 | |
1331 void gnt_wm_window_decorate(GntWM *wm, GntWidget *widget) | |
1332 { | |
1333 g_signal_emit(wm, signals[SIG_DECORATE_WIN], 0, widget); | |
1334 } | |
1335 | |
1336 void gnt_wm_window_close(GntWM *wm, GntWidget *widget) | |
1337 { | |
1338 GntNode *node; | |
1339 int pos; | |
1340 | |
1341 if ((node = g_hash_table_lookup(wm->nodes, widget)) == NULL) | |
1342 return; | |
1343 | |
1344 g_signal_emit(wm, signals[SIG_CLOSE_WIN], 0, widget); | |
1345 g_hash_table_remove(wm->nodes, widget); | |
1346 | |
1347 if (wm->windows) { | |
1348 gnt_tree_remove(GNT_TREE(wm->windows->tree), widget); | |
1349 } | |
1350 | |
1351 pos = g_list_index(wm->list, widget); | |
1352 | |
1353 if (pos != -1) { | |
1354 wm->list = g_list_remove(wm->list, widget); | |
1355 wm->ordered = g_list_remove(wm->ordered, widget); | |
1356 | |
1357 if (wm->ordered) | |
1358 gnt_wm_raise_window(wm, wm->ordered->data); | |
1359 } | |
1360 | |
1361 update_screen(wm); | |
1362 draw_taskbar(wm, FALSE); | |
1363 } | |
1364 | |
1365 time_t gnt_wm_get_idle_time() | |
1366 { | |
1367 return time(NULL) - last_active_time; | |
1368 } | |
1369 | |
1370 gboolean gnt_wm_process_input(GntWM *wm, const char *keys) | |
1371 { | |
1372 gboolean ret = FALSE; | |
1373 | |
1374 keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); | |
1375 | |
1376 idle_update = TRUE; | |
1377 | |
16126
d07f5128dd6b
alt-/ to get a list of keybindings for the focused widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15995
diff
changeset
|
1378 if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { |
15817 | 1379 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
|
1380 } |
15817 | 1381 |
1382 /* Do some manual checking */ | |
1383 if (wm->ordered && wm->mode != GNT_KP_MODE_NORMAL) { | |
1384 int xmin = 0, ymin = 0, xmax = getmaxx(stdscr), ymax = getmaxy(stdscr) - 1; | |
1385 int x, y, w, h; | |
1386 GntWidget *widget = GNT_WIDGET(wm->ordered->data); | |
1387 int ox, oy, ow, oh; | |
1388 | |
1389 gnt_widget_get_position(widget, &x, &y); | |
1390 gnt_widget_get_size(widget, &w, &h); | |
1391 ox = x; oy = y; | |
1392 ow = w; oh = h; | |
1393 | |
1394 if (wm->mode == GNT_KP_MODE_MOVE) { | |
1395 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1396 if (x > xmin) | |
1397 x--; | |
1398 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1399 if (x + w < xmax) | |
1400 x++; | |
1401 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1402 if (y > ymin) | |
1403 y--; | |
1404 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1405 if (y + h < ymax) | |
1406 y++; | |
1407 } | |
1408 if (ox != x || oy != y) { | |
1409 gnt_screen_move_widget(widget, x, y); | |
1410 window_reverse(widget, TRUE, wm); | |
1411 return TRUE; | |
1412 } | |
1413 } else if (wm->mode == GNT_KP_MODE_RESIZE) { | |
1414 if (strcmp(keys, GNT_KEY_LEFT) == 0) { | |
1415 w--; | |
1416 } else if (strcmp(keys, GNT_KEY_RIGHT) == 0) { | |
1417 if (x + w < xmax) | |
1418 w++; | |
1419 } else if (strcmp(keys, GNT_KEY_UP) == 0) { | |
1420 h--; | |
1421 } else if (strcmp(keys, GNT_KEY_DOWN) == 0) { | |
1422 if (y + h < ymax) | |
1423 h++; | |
1424 } | |
1425 if (oh != h || ow != w) { | |
1426 gnt_screen_resize_widget(widget, w, h); | |
1427 window_reverse(widget, TRUE, wm); | |
1428 return TRUE; | |
1429 } | |
1430 } | |
1431 if (strcmp(keys, "\r") == 0 || strcmp(keys, "\033") == 0) { | |
1432 window_reverse(widget, FALSE, wm); | |
1433 wm->mode = GNT_KP_MODE_NORMAL; | |
1434 } | |
1435 return TRUE; | |
1436 } | |
1437 | |
1438 /* Escape to close the window-list or action-list window */ | |
1439 if (strcmp(keys, "\033") == 0) { | |
1440 if (wm->_list.window) { | |
1441 gnt_widget_destroy(wm->_list.window); | |
1442 return TRUE; | |
1443 } | |
1444 } else if (keys[0] == '\033' && isdigit(keys[1]) && keys[2] == '\0') { | |
1445 /* Alt+x for quick switch */ | |
1446 int n = *(keys + 1) - '0'; | |
1447 GList *list = NULL; | |
1448 | |
1449 if (n == 0) | |
1450 n = 10; | |
1451 | |
1452 list = g_list_append(list, GINT_TO_POINTER(n - 1)); | |
1453 switch_window_n(GNT_BINDABLE(wm), list); | |
1454 g_list_free(list); | |
1455 return TRUE; | |
1456 } | |
1457 | |
1458 if (wm->menu) | |
1459 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->menu), keys); | |
1460 else if (wm->_list.window) | |
1461 ret = gnt_widget_key_pressed(wm->_list.window, keys); | |
1462 else if (wm->ordered) | |
1463 ret = gnt_widget_key_pressed(GNT_WIDGET(wm->ordered->data), keys); | |
1464 return ret; | |
1465 } | |
1466 | |
1467 static void | |
1468 gnt_wm_win_resized(GntWM *wm, GntNode *node) | |
1469 { | |
1470 /*refresh_node(node->me, node, NULL);*/ | |
1471 } | |
1472 | |
1473 static void | |
1474 gnt_wm_win_moved(GntWM *wm, GntNode *node) | |
1475 { | |
1476 refresh_node(node->me, node, NULL); | |
1477 } | |
1478 | |
1479 void gnt_wm_resize_window(GntWM *wm, GntWidget *widget, int width, int height) | |
1480 { | |
1481 gboolean ret = TRUE; | |
1482 GntNode *node; | |
1483 int shadow; | |
1484 int maxx, maxy; | |
1485 | |
1486 while (widget->parent) | |
1487 widget = widget->parent; | |
1488 node = g_hash_table_lookup(wm->nodes, widget); | |
1489 if (!node) | |
1490 return; | |
1491 | |
1492 g_signal_emit(wm, signals[SIG_CONFIRM_RESIZE], 0, widget, &width, &height, &ret); | |
1493 if (!ret) | |
1494 return; /* resize is not permitted */ | |
1495 hide_panel(node->panel); | |
1496 gnt_widget_set_size(widget, width, height); | |
1497 gnt_widget_draw(widget); | |
1498 | |
1499 shadow = gnt_widget_has_shadow(widget) ? 1 : 0; | |
1500 maxx = getmaxx(stdscr) - shadow; | |
1501 maxy = getmaxy(stdscr) - 1 - shadow; | |
1502 height = MIN(height, maxy); | |
1503 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
|
1504 wresize(node->window, height, width); |
15817 | 1505 replace_panel(node->panel, node->window); |
1506 | |
1507 g_signal_emit(wm, signals[SIG_RESIZED], 0, node); | |
1508 | |
1509 show_panel(node->panel); | |
1510 update_screen(wm); | |
1511 } | |
1512 | |
1513 static void | |
1514 write_gdi(gpointer key, gpointer value, gpointer data) | |
1515 { | |
1516 GntPosition *p = value; | |
1517 fprintf(data, ".%s = %d;%d\n", (char *)key, p->x, p->y); | |
1518 } | |
1519 | |
1520 static gboolean | |
1521 write_already(gpointer data) | |
1522 { | |
1523 GntWM *wm = data; | |
1524 FILE *file; | |
1525 char *filename; | |
1526 | |
1527 filename = g_build_filename(g_get_home_dir(), ".gntpositions", NULL); | |
1528 | |
1529 file = fopen(filename, "wb"); | |
1530 if (file == NULL) { | |
1531 g_printerr("GntWM: error opening file to save positions\n"); | |
1532 } else { | |
1533 fprintf(file, "[positions]\n"); | |
1534 g_hash_table_foreach(wm->positions, write_gdi, file); | |
1535 fclose(file); | |
1536 } | |
1537 | |
1538 g_free(filename); | |
1539 g_source_remove(write_timeout); | |
1540 write_timeout = 0; | |
1541 return FALSE; | |
1542 } | |
1543 | |
1544 static void | |
1545 write_positions_to_file(GntWM *wm) | |
1546 { | |
1547 if (write_timeout) { | |
1548 g_source_remove(write_timeout); | |
1549 } | |
1550 write_timeout = g_timeout_add(10000, write_already, wm); | |
1551 } | |
1552 | |
1553 void gnt_wm_move_window(GntWM *wm, GntWidget *widget, int x, int y) | |
1554 { | |
1555 gboolean ret = TRUE; | |
1556 GntNode *node; | |
1557 | |
1558 while (widget->parent) | |
1559 widget = widget->parent; | |
1560 node = g_hash_table_lookup(wm->nodes, widget); | |
1561 if (!node) | |
1562 return; | |
1563 | |
1564 g_signal_emit(wm, signals[SIG_CONFIRM_MOVE], 0, widget, &x, &y, &ret); | |
1565 if (!ret) | |
1566 return; /* resize is not permitted */ | |
1567 | |
1568 gnt_widget_set_position(widget, x, y); | |
1569 move_panel(node->panel, y, x); | |
1570 | |
1571 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
|
1572 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
|
1573 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { |
15817 | 1574 const char *title = GNT_BOX(widget)->title; |
1575 if (title) { | |
1576 GntPosition *p = g_new0(GntPosition, 1); | |
1577 GntWidget *wid = node->me; | |
1578 p->x = wid->priv.x; | |
1579 p->y = wid->priv.y; | |
1580 g_hash_table_replace(wm->positions, g_strdup(title), p); | |
1581 write_positions_to_file(wm); | |
1582 } | |
1583 } | |
1584 | |
1585 update_screen(wm); | |
1586 } | |
1587 | |
1588 static void | |
1589 gnt_wm_give_focus(GntWM *wm, GntWidget *widget) | |
1590 { | |
1591 GntNode *node = g_hash_table_lookup(wm->nodes, widget); | |
1592 | |
1593 if (!node) | |
1594 return; | |
1595 | |
1596 if (widget != wm->_list.window && !GNT_IS_MENU(widget) && | |
1597 wm->ordered->data != widget) { | |
1598 GntWidget *w = wm->ordered->data; | |
1599 wm->ordered = g_list_bring_to_front(wm->ordered, widget); | |
1600 gnt_widget_set_focus(w, FALSE); | |
1601 } | |
1602 | |
1603 gnt_widget_set_focus(widget, TRUE); | |
1604 GNT_WIDGET_UNSET_FLAGS(widget, GNT_WIDGET_URGENT); | |
1605 gnt_widget_draw(widget); | |
1606 top_panel(node->panel); | |
1607 | |
1608 if (wm->_list.window) { | |
1609 GntNode *nd = g_hash_table_lookup(wm->nodes, wm->_list.window); | |
1610 top_panel(nd->panel); | |
1611 } | |
1612 update_screen(wm); | |
1613 draw_taskbar(wm, FALSE); | |
1614 } | |
1615 | |
1616 void gnt_wm_update_window(GntWM *wm, GntWidget *widget) | |
1617 { | |
1618 GntNode *node; | |
1619 | |
1620 while (widget->parent) | |
1621 widget = widget->parent; | |
1622 if (!GNT_IS_MENU(widget)) | |
1623 gnt_box_sync_children(GNT_BOX(widget)); | |
1624 | |
1625 node = g_hash_table_lookup(wm->nodes, widget); | |
1626 if (node == NULL) { | |
1627 gnt_wm_new_window(wm, widget); | |
1628 } else | |
1629 g_signal_emit(wm, signals[SIG_UPDATE_WIN], 0, node); | |
1630 | |
1631 copy_win(widget, node); | |
1632 update_screen(wm); | |
1633 draw_taskbar(wm, FALSE); | |
1634 } | |
1635 | |
1636 gboolean gnt_wm_process_click(GntWM *wm, GntMouseEvent event, int x, int y, GntWidget *widget) | |
1637 { | |
1638 gboolean ret = TRUE; | |
1639 idle_update = TRUE; | |
1640 g_signal_emit(wm, signals[SIG_MOUSE_CLICK], 0, event, x, y, widget, &ret); | |
1641 return ret; | |
1642 } | |
1643 | |
1644 void gnt_wm_raise_window(GntWM *wm, GntWidget *widget) | |
1645 { | |
1646 g_signal_emit(wm, signals[SIG_GIVE_FOCUS], 0, widget); | |
1647 } | |
1648 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1649 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
|
1650 { |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1651 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
|
1652 } |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16127
diff
changeset
|
1653 |