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