Mercurial > pidgin.yaz
annotate finch/libgnt/gntmain.c @ 19120:b25cb0775be3
explicit merge of 'e53fe113efde971f9f1d14d8a7af937542ee2732'
and 'fac895a331d8ffa475b42a0eaf193587799661b9'
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Thu, 28 Jun 2007 03:09:03 +0000 |
parents | 1cb69ea47a6e |
children | 576edd9c4f72 |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
22 |
15818 | 23 #define _GNU_SOURCE |
17528
c0c17a81f5fe
Fix libgnt compilation on BSD and solaris. This references #516.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17251
diff
changeset
|
24 #if defined(__APPLE__) || defined(__unix__) |
15818 | 25 #define _XOPEN_SOURCE_EXTENDED |
26 #endif | |
27 | |
28 #include "config.h" | |
29 | |
30 #include <gmodule.h> | |
31 | |
32 #include <sys/types.h> | |
33 #include <sys/wait.h> | |
34 | |
35 #include "gnt.h" | |
36 #include "gntbox.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
37 #include "gntbutton.h" |
15818 | 38 #include "gntcolors.h" |
39 #include "gntclipboard.h" | |
40 #include "gntkeys.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
41 #include "gntlabel.h" |
15818 | 42 #include "gntmenu.h" |
43 #include "gntstyle.h" | |
44 #include "gnttree.h" | |
45 #include "gntutils.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
46 #include "gntwindow.h" |
15818 | 47 #include "gntwm.h" |
48 | |
49 #include <panel.h> | |
50 | |
51 #include <stdio.h> | |
52 #include <stdlib.h> | |
53 #include <locale.h> | |
54 #include <unistd.h> | |
55 #include <signal.h> | |
56 #include <string.h> | |
57 #include <ctype.h> | |
58 #include <errno.h> | |
59 | |
60 /** | |
61 * Notes: Interesting functions to look at: | |
62 * scr_dump, scr_init, scr_restore: for workspaces | |
63 * | |
64 * Need to wattrset for colors to use with PDCurses. | |
65 */ | |
66 | |
67 static GIOChannel *channel = NULL; | |
68 | |
69 static gboolean ascii_only; | |
70 static gboolean mouse_enabled; | |
71 | |
72 static void setup_io(void); | |
73 | |
74 static gboolean refresh_screen(); | |
75 | |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
76 static GntWM *wm; |
15818 | 77 static GntClipboard *clipboard; |
78 | |
79 #define HOLDING_ESCAPE (escape_stuff.timer != 0) | |
80 | |
81 static struct { | |
82 int timer; | |
83 } escape_stuff; | |
84 | |
85 static gboolean | |
86 escape_timeout(gpointer data) | |
87 { | |
88 gnt_wm_process_input(wm, "\033"); | |
89 escape_stuff.timer = 0; | |
90 return FALSE; | |
91 } | |
92 | |
93 /** | |
94 * Mouse support: | |
95 * - bring a window on top if you click on its taskbar | |
96 * - click on the top-bar of the active window and drag+drop to move a window | |
97 * - click on a window to bring it to focus | |
98 * - allow scrolling in tree/textview on wheel-scroll event | |
99 * - click to activate button or select a row in tree | |
100 * wishlist: | |
101 * - have a little [X] on the windows, and clicking it will close that window. | |
102 */ | |
103 static gboolean | |
104 detect_mouse_action(const char *buffer) | |
105 { | |
106 int x, y; | |
107 static enum { | |
108 MOUSE_NONE, | |
109 MOUSE_LEFT, | |
110 MOUSE_RIGHT, | |
111 MOUSE_MIDDLE | |
112 } button = MOUSE_NONE; | |
113 static GntWidget *remember = NULL; | |
114 static int offset = 0; | |
115 GntMouseEvent event; | |
116 GntWidget *widget = NULL; | |
117 PANEL *p = NULL; | |
118 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
119 if (!wm->cws->ordered || buffer[0] != 27) |
15818 | 120 return FALSE; |
121 | |
122 buffer++; | |
123 if (strlen(buffer) < 5) | |
124 return FALSE; | |
125 | |
126 x = buffer[3]; | |
127 y = buffer[4]; | |
128 if (x < 0) x += 256; | |
129 if (y < 0) y += 256; | |
130 x -= 33; | |
131 y -= 33; | |
132 | |
133 while ((p = panel_below(p)) != NULL) { | |
134 const GntNode *node = panel_userptr(p); | |
135 GntWidget *wid; | |
136 if (!node) | |
137 continue; | |
138 wid = node->me; | |
139 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { | |
140 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { | |
141 widget = wid; | |
142 break; | |
143 } | |
144 } | |
145 } | |
146 | |
147 if (strncmp(buffer, "[M ", 3) == 0) { | |
148 /* left button down */ | |
149 /* Bring the window you clicked on to front */ | |
150 /* If you click on the topbar, then you can drag to move the window */ | |
151 event = GNT_LEFT_MOUSE_DOWN; | |
152 } else if (strncmp(buffer, "[M\"", 3) == 0) { | |
153 /* right button down */ | |
154 event = GNT_RIGHT_MOUSE_DOWN; | |
155 } else if (strncmp(buffer, "[M!", 3) == 0) { | |
156 /* middle button down */ | |
157 event = GNT_MIDDLE_MOUSE_DOWN; | |
158 } else if (strncmp(buffer, "[M`", 3) == 0) { | |
159 /* wheel up*/ | |
160 event = GNT_MOUSE_SCROLL_UP; | |
161 } else if (strncmp(buffer, "[Ma", 3) == 0) { | |
162 /* wheel down */ | |
163 event = GNT_MOUSE_SCROLL_DOWN; | |
164 } else if (strncmp(buffer, "[M#", 3) == 0) { | |
165 /* button up */ | |
166 event = GNT_MOUSE_UP; | |
167 } else | |
168 return FALSE; | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
169 |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
170 if (widget && gnt_wm_process_click(wm, event, x, y, widget)) |
15818 | 171 return TRUE; |
172 | |
173 if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window && | |
174 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
175 if (widget != wm->cws->ordered->data) { |
15818 | 176 gnt_wm_raise_window(wm, widget); |
177 } | |
178 if (y == widget->priv.y) { | |
179 offset = x - widget->priv.x; | |
180 remember = widget; | |
181 button = MOUSE_LEFT; | |
182 } | |
183 } else if (event == GNT_MOUSE_UP) { | |
184 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { | |
185 /* Clicked on the taskbar */ | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
186 int n = g_list_length(wm->cws->list); |
15818 | 187 if (n) { |
188 int width = getmaxx(stdscr) / n; | |
189 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL); | |
190 } | |
191 } else if (button == MOUSE_LEFT && remember) { | |
192 x -= offset; | |
193 if (x < 0) x = 0; | |
194 if (y < 0) y = 0; | |
195 gnt_screen_move_widget(remember, x, y); | |
196 } | |
197 button = MOUSE_NONE; | |
198 remember = NULL; | |
199 offset = 0; | |
200 } | |
201 | |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
202 if (widget) |
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
203 gnt_widget_clicked(widget, event, x, y); |
15818 | 204 return TRUE; |
205 } | |
206 | |
207 static gboolean | |
208 io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) | |
209 { | |
210 int id = GPOINTER_TO_INT(data); | |
211 g_source_remove(id); | |
212 g_io_channel_unref(source); | |
213 | |
214 channel = NULL; | |
215 setup_io(); | |
216 return TRUE; | |
217 } | |
218 | |
219 static gboolean | |
220 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | |
221 { | |
222 char keys[256]; | |
223 int rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); | |
224 char *k; | |
225 if (rd < 0) | |
226 { | |
227 int ch = getch(); /* This should return ERR, but let's see what it really returns */ | |
228 endwin(); | |
229 printf("ERROR: %s\n", strerror(errno)); | |
230 printf("File descriptor is: %d\n\nGIOChannel is: %p\ngetch() = %d\n", STDIN_FILENO, source, ch); | |
231 raise(SIGABRT); | |
232 } | |
233 else if (rd == 0) | |
234 { | |
235 endwin(); | |
236 printf("EOF\n"); | |
237 raise(SIGABRT); | |
238 } | |
239 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
240 gnt_wm_set_event_stack(wm, TRUE); |
15818 | 241 rd += HOLDING_ESCAPE; |
242 keys[rd] = 0; | |
243 if (mouse_enabled && detect_mouse_action(keys)) | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
244 goto end; |
15818 | 245 |
246 if (HOLDING_ESCAPE) | |
247 keys[0] = '\033'; | |
248 k = keys; | |
17538
cfa84fed6ecd
Cleaned up some comment garbage
Eric Polino <aluink@pidgin.im>
parents:
17535
diff
changeset
|
249 if(*k < 0){ /* Alt not sending ESC* */ |
17535
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17064
diff
changeset
|
250 *(k + 1) = 128 - *k; |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17064
diff
changeset
|
251 *k = 27; |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17064
diff
changeset
|
252 *(k + 2) = 0; |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17064
diff
changeset
|
253 rd++; |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17064
diff
changeset
|
254 } |
15818 | 255 while (rd) { |
256 char back; | |
257 int p; | |
258 | |
259 if (k[0] == '\033' && rd == 1) { | |
260 if (escape_stuff.timer) { | |
261 gnt_wm_process_input(wm, "\033\033"); | |
262 g_source_remove(escape_stuff.timer); | |
263 escape_stuff.timer = 0; | |
264 break; | |
265 } | |
266 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
267 break; | |
268 } | |
269 | |
270 gnt_keys_refine(k); | |
271 p = MAX(1, gnt_keys_find_combination(k)); | |
272 back = k[p]; | |
273 k[p] = '\0'; | |
274 gnt_wm_process_input(wm, k); /* XXX: */ | |
275 k[p] = back; | |
276 rd -= p; | |
277 k += p; | |
278 } | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
279 end: |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
280 gnt_wm_set_event_stack(wm, FALSE); |
15818 | 281 return TRUE; |
282 } | |
283 | |
284 static void | |
285 setup_io() | |
286 { | |
287 int result; | |
288 channel = g_io_channel_unix_new(STDIN_FILENO); | |
289 g_io_channel_set_close_on_unref(channel, TRUE); | |
290 | |
291 #if 0 | |
292 g_io_channel_set_encoding(channel, NULL, NULL); | |
293 g_io_channel_set_buffered(channel, FALSE); | |
294 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | |
295 #endif | |
296 | |
297 result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
298 (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), | |
299 io_invoke, NULL, NULL); | |
300 | |
301 g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
302 (G_IO_NVAL), | |
303 io_invoke_error, GINT_TO_POINTER(result), NULL); | |
304 | |
305 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. | |
306 But irssi does this, so I am going to assume the | |
307 crashes were caused by some other stuff. */ | |
308 | |
309 g_printerr("gntmain: setting up IO\n"); | |
310 } | |
311 | |
312 static gboolean | |
313 refresh_screen() | |
314 { | |
315 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); | |
316 return FALSE; | |
317 } | |
318 | |
319 /* Xerox */ | |
320 static void | |
321 clean_pid(void) | |
322 { | |
323 int status; | |
324 pid_t pid; | |
325 | |
326 do { | |
327 pid = waitpid(-1, &status, WNOHANG); | |
328 } while (pid != 0 && pid != (pid_t)-1); | |
329 | |
330 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
331 char errmsg[BUFSIZ]; | |
332 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
333 perror(errmsg); | |
334 } | |
335 } | |
336 | |
337 static void | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
338 exit_confirmed(gpointer null) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
339 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
340 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "wm-quit", NULL); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
341 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
342 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
343 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
344 exit_win_close(GntWidget *w, GntWidget **win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
345 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
346 *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
347 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
348 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
349 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
350 ask_before_exit() |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
351 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
352 static GntWidget *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
353 GntWidget *bbox, *button; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
354 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
355 if (win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
356 goto raise; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
357 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
358 win = gnt_vwindow_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
359 gnt_box_add_widget(GNT_BOX(win), gnt_label_new("Are you sure you want to quit?")); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
360 gnt_box_set_title(GNT_BOX(win), "Quit?"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
361 gnt_box_set_alignment(GNT_BOX(win), GNT_ALIGN_MID); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
362 g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(exit_win_close), &win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
363 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
364 bbox = gnt_hbox_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
365 gnt_box_add_widget(GNT_BOX(win), bbox); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
366 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
367 button = gnt_button_new("Quit"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
368 g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(exit_confirmed), NULL); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
369 gnt_box_add_widget(GNT_BOX(bbox), button); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
370 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
371 button = gnt_button_new("Cancel"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
372 g_signal_connect_swapped(G_OBJECT(button), "activate", G_CALLBACK(gnt_widget_destroy), win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
373 gnt_box_add_widget(GNT_BOX(bbox), button); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
374 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
375 gnt_widget_show(win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
376 raise: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
377 gnt_wm_raise_window(wm, win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
378 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
379 |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
380 #ifdef SIGWINCH |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
381 static void (*org_winch_handler)(int); |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
382 #endif |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
383 |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
384 static void |
15818 | 385 sighandler(int sig) |
386 { | |
387 switch (sig) { | |
388 #ifdef SIGWINCH | |
389 case SIGWINCH: | |
17251
8d3c28521112
I think this fixes #532.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17064
diff
changeset
|
390 erase(); |
15818 | 391 g_idle_add(refresh_screen, NULL); |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
392 org_winch_handler(sig); |
15818 | 393 signal(SIGWINCH, sighandler); |
394 break; | |
395 #endif | |
396 case SIGCHLD: | |
397 clean_pid(); | |
398 signal(SIGCHLD, sighandler); | |
399 break; | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
400 case SIGINT: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
401 ask_before_exit(); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
402 signal(SIGINT, sighandler); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
403 break; |
15818 | 404 } |
405 } | |
406 | |
407 static void | |
408 init_wm() | |
409 { | |
410 const char *name = gnt_style_get(GNT_STYLE_WM); | |
411 gpointer handle; | |
412 | |
413 if (name && *name) { | |
414 handle = g_module_open(name, G_MODULE_BIND_LAZY); | |
415 if (handle) { | |
416 gboolean (*init)(GntWM **); | |
417 if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { | |
418 init(&wm); | |
419 } | |
420 } | |
421 } | |
422 if (wm == NULL) | |
423 wm = g_object_new(GNT_TYPE_WM, NULL); | |
424 } | |
425 | |
426 void gnt_init() | |
427 { | |
428 char *filename; | |
429 const char *locale; | |
430 | |
431 if (channel) | |
432 return; | |
433 | |
434 locale = setlocale(LC_ALL, ""); | |
435 | |
436 setup_io(); | |
437 | |
18199
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
438 #ifdef NO_WIDECHAR |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
439 ascii_only = TRUE; |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
440 #else |
15818 | 441 if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) |
442 ascii_only = FALSE; | |
443 else | |
444 ascii_only = TRUE; | |
18199
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
445 #endif |
15818 | 446 |
447 initscr(); | |
448 typeahead(-1); | |
449 noecho(); | |
450 curs_set(0); | |
451 | |
452 gnt_init_keys(); | |
453 gnt_init_styles(); | |
454 | |
455 filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); | |
456 gnt_style_read_configure_file(filename); | |
457 g_free(filename); | |
458 | |
459 gnt_init_colors(); | |
460 | |
461 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
462 refresh(); | |
463 | |
464 #ifdef ALL_MOUSE_EVENTS | |
465 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) | |
466 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); | |
467 #endif | |
468 | |
469 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
470 werase(stdscr); | |
471 wrefresh(stdscr); | |
472 | |
473 #ifdef SIGWINCH | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
474 org_winch_handler = signal(SIGWINCH, sighandler); |
15818 | 475 #endif |
476 signal(SIGCHLD, sighandler); | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
477 signal(SIGINT, sighandler); |
15818 | 478 signal(SIGPIPE, SIG_IGN); |
479 | |
480 g_type_init(); | |
481 | |
482 init_wm(); | |
483 | |
484 clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); | |
485 } | |
486 | |
487 void gnt_main() | |
488 { | |
489 wm->loop = g_main_loop_new(NULL, FALSE); | |
490 g_main_loop_run(wm->loop); | |
491 } | |
492 | |
493 /********************************* | |
494 * Stuff for 'window management' * | |
495 *********************************/ | |
496 | |
18070 | 497 void gnt_window_present(GntWidget *window) { |
498 gnt_wm_raise_window(wm, window); | |
499 } | |
500 | |
15818 | 501 void gnt_screen_occupy(GntWidget *widget) |
502 { | |
503 gnt_wm_new_window(wm, widget); | |
504 } | |
505 | |
506 void gnt_screen_release(GntWidget *widget) | |
507 { | |
508 gnt_wm_window_close(wm, widget); | |
509 } | |
510 | |
511 void gnt_screen_update(GntWidget *widget) | |
512 { | |
513 gnt_wm_update_window(wm, widget); | |
514 } | |
515 | |
516 gboolean gnt_widget_has_focus(GntWidget *widget) | |
517 { | |
518 GntWidget *w; | |
519 if (!widget) | |
520 return FALSE; | |
521 | |
522 if (GNT_IS_MENU(widget)) | |
523 return TRUE; | |
524 | |
525 w = widget; | |
526 | |
527 while (widget->parent) | |
528 widget = widget->parent; | |
529 | |
530 if (widget == wm->_list.window) | |
531 return TRUE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
532 if (wm->cws->ordered && wm->cws->ordered->data == widget) { |
15818 | 533 if (GNT_IS_BOX(widget) && |
534 (GNT_BOX(widget)->active == w || widget == w)) | |
535 return TRUE; | |
536 } | |
537 return FALSE; | |
538 } | |
539 | |
540 void gnt_widget_set_urgent(GntWidget *widget) | |
541 { | |
542 while (widget->parent) | |
543 widget = widget->parent; | |
544 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
545 if (wm->cws->ordered && wm->cws->ordered->data == widget) |
15818 | 546 return; |
547 | |
548 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); | |
549 | |
550 gnt_wm_update_window(wm, widget); | |
551 } | |
552 | |
553 void gnt_quit() | |
554 { | |
555 g_hash_table_destroy(wm->nodes); /* XXX: */ | |
556 update_panels(); | |
557 doupdate(); | |
558 gnt_uninit_colors(); | |
559 gnt_uninit_styles(); | |
560 endwin(); | |
561 } | |
562 | |
563 gboolean gnt_ascii_only() | |
564 { | |
565 return ascii_only; | |
566 } | |
567 | |
568 void gnt_screen_resize_widget(GntWidget *widget, int width, int height) | |
569 { | |
570 gnt_wm_resize_window(wm, widget, width, height); | |
571 } | |
572 | |
573 void gnt_screen_move_widget(GntWidget *widget, int x, int y) | |
574 { | |
575 gnt_wm_move_window(wm, widget, x, y); | |
576 } | |
577 | |
578 void gnt_screen_rename_widget(GntWidget *widget, const char *text) | |
579 { | |
580 gnt_box_set_title(GNT_BOX(widget), text); | |
581 gnt_widget_draw(widget); | |
582 gnt_wm_update_window(wm, widget); | |
583 } | |
584 | |
585 void gnt_register_action(const char *label, void (*callback)()) | |
586 { | |
587 GntAction *action = g_new0(GntAction, 1); | |
588 action->label = g_strdup(label); | |
589 action->callback = callback; | |
590 | |
591 wm->acts = g_list_append(wm->acts, action); | |
592 } | |
593 | |
594 static void | |
595 reset_menu(GntWidget *widget, gpointer null) | |
596 { | |
597 wm->menu = NULL; | |
598 } | |
599 | |
600 gboolean gnt_screen_menu_show(gpointer newmenu) | |
601 { | |
602 if (wm->menu) { | |
603 /* For now, if a menu is being displayed, then another menu | |
604 * can NOT take over. */ | |
605 return FALSE; | |
606 } | |
607 | |
608 wm->menu = newmenu; | |
609 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); | |
610 gnt_widget_draw(GNT_WIDGET(wm->menu)); | |
611 | |
612 g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); | |
16792
d0f9b2b217cf
Fix context menu unusualness in the buddylist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
613 g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); |
15818 | 614 |
615 return TRUE; | |
616 } | |
617 | |
618 void gnt_set_clipboard_string(gchar *string) | |
619 { | |
620 gnt_clipboard_set_string(clipboard, string); | |
621 } | |
622 | |
623 GntClipboard *gnt_get_clipboard() | |
624 { | |
625 return clipboard; | |
626 } | |
627 gchar *gnt_get_clipboard_string() | |
628 { | |
629 return gnt_clipboard_get_string(clipboard); | |
630 } |