Mercurial > pidgin
annotate finch/libgnt/gntmain.c @ 18193:09eb621782bc
explicit merge of 'f2eb358baf2c72cb37b6b9bcb4c036e44e0bcc2b'
and '2344c84a6e70c374b19936a127462d2f19c0139c'
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Tue, 19 Jun 2007 17:17:57 +0000 |
parents | 2b757aadddc9 |
children | 1bb3b07a6879 ac904659104f |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
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:
17812
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:
17812
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
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:
17812
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:
17812
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:
17812
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:
17812
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
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:
17812
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:
17812
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:
17812
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:
17812
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
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:
17812
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:
17812
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:
17812
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17812
diff
changeset
|
22 |
15817 | 23 #define _GNU_SOURCE |
17812
c0c17a81f5fe
Fix libgnt compilation on BSD and solaris. This references #516.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17745
diff
changeset
|
24 #if defined(__APPLE__) || defined(__unix__) |
15817 | 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" | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
37 #include "gntbutton.h" |
15817 | 38 #include "gntcolors.h" |
39 #include "gntclipboard.h" | |
40 #include "gntkeys.h" | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
41 #include "gntlabel.h" |
15817 | 42 #include "gntmenu.h" |
43 #include "gntstyle.h" | |
44 #include "gnttree.h" | |
45 #include "gntutils.h" | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
46 #include "gntwindow.h" |
15817 | 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:
17812
diff
changeset
|
76 static GntWM *wm; |
15817 | 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 | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
119 if (!wm->cws->ordered || buffer[0] != 27) |
15817 | 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; | |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
169 |
17053
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
170 if (widget && gnt_wm_process_click(wm, event, x, y, widget)) |
15817 | 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)) { | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
175 if (widget != wm->cws->ordered->data) { |
15817 | 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 */ | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
186 int n = g_list_length(wm->cws->list); |
15817 | 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 | |
17053
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
202 if (widget) |
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
203 gnt_widget_clicked(widget, event, x, y); |
15817 | 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:
15817
diff
changeset
|
240 gnt_wm_set_event_stack(wm, TRUE); |
15817 | 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:
15817
diff
changeset
|
244 goto end; |
15817 | 245 |
246 if (HOLDING_ESCAPE) | |
247 keys[0] = '\033'; | |
248 k = keys; | |
249 while (rd) { | |
250 char back; | |
251 int p; | |
252 | |
253 if (k[0] == '\033' && rd == 1) { | |
254 if (escape_stuff.timer) { | |
255 gnt_wm_process_input(wm, "\033\033"); | |
256 g_source_remove(escape_stuff.timer); | |
257 escape_stuff.timer = 0; | |
258 break; | |
259 } | |
260 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
261 break; | |
262 } | |
263 | |
264 gnt_keys_refine(k); | |
265 p = MAX(1, gnt_keys_find_combination(k)); | |
266 back = k[p]; | |
267 k[p] = '\0'; | |
268 gnt_wm_process_input(wm, k); /* XXX: */ | |
269 k[p] = back; | |
270 rd -= p; | |
271 k += p; | |
272 } | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
273 end: |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
274 gnt_wm_set_event_stack(wm, FALSE); |
15817 | 275 return TRUE; |
276 } | |
277 | |
278 static void | |
279 setup_io() | |
280 { | |
281 int result; | |
282 channel = g_io_channel_unix_new(STDIN_FILENO); | |
283 g_io_channel_set_close_on_unref(channel, TRUE); | |
284 | |
285 #if 0 | |
286 g_io_channel_set_encoding(channel, NULL, NULL); | |
287 g_io_channel_set_buffered(channel, FALSE); | |
288 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | |
289 #endif | |
290 | |
291 result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
292 (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), | |
293 io_invoke, NULL, NULL); | |
294 | |
295 g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
296 (G_IO_NVAL), | |
297 io_invoke_error, GINT_TO_POINTER(result), NULL); | |
298 | |
299 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. | |
300 But irssi does this, so I am going to assume the | |
301 crashes were caused by some other stuff. */ | |
302 | |
303 g_printerr("gntmain: setting up IO\n"); | |
304 } | |
305 | |
306 static gboolean | |
307 refresh_screen() | |
308 { | |
309 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); | |
310 return FALSE; | |
311 } | |
312 | |
313 /* Xerox */ | |
314 static void | |
315 clean_pid(void) | |
316 { | |
317 int status; | |
318 pid_t pid; | |
319 | |
320 do { | |
321 pid = waitpid(-1, &status, WNOHANG); | |
322 } while (pid != 0 && pid != (pid_t)-1); | |
323 | |
324 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
325 char errmsg[BUFSIZ]; | |
326 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
327 perror(errmsg); | |
328 } | |
329 } | |
330 | |
331 static void | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
332 exit_confirmed(gpointer null) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
333 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
334 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:
16781
diff
changeset
|
335 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
336 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
337 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
338 exit_win_close(GntWidget *w, GntWidget **win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
339 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
340 *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
341 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
342 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
343 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
344 ask_before_exit() |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
345 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
346 static GntWidget *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
347 GntWidget *bbox, *button; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
348 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
349 if (win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
350 goto raise; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
351 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
352 win = gnt_vwindow_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
353 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:
16781
diff
changeset
|
354 gnt_box_set_title(GNT_BOX(win), "Quit?"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
355 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:
16781
diff
changeset
|
356 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:
16781
diff
changeset
|
357 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
358 bbox = gnt_hbox_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
359 gnt_box_add_widget(GNT_BOX(win), bbox); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
360 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
361 button = gnt_button_new("Quit"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
362 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:
16781
diff
changeset
|
363 gnt_box_add_widget(GNT_BOX(bbox), button); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
364 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
365 button = gnt_button_new("Cancel"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
366 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:
16781
diff
changeset
|
367 gnt_box_add_widget(GNT_BOX(bbox), button); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
368 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
369 gnt_widget_show(win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
370 raise: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
371 gnt_wm_raise_window(wm, win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
372 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
373 |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
374 #ifdef SIGWINCH |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
375 static void (*org_winch_handler)(int); |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
376 #endif |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
377 |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
378 static void |
15817 | 379 sighandler(int sig) |
380 { | |
381 switch (sig) { | |
382 #ifdef SIGWINCH | |
383 case SIGWINCH: | |
17745
8d3c28521112
I think this fixes #532.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17053
diff
changeset
|
384 erase(); |
15817 | 385 g_idle_add(refresh_screen, NULL); |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
386 org_winch_handler(sig); |
15817 | 387 signal(SIGWINCH, sighandler); |
388 break; | |
389 #endif | |
390 case SIGCHLD: | |
391 clean_pid(); | |
392 signal(SIGCHLD, sighandler); | |
393 break; | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
394 case SIGINT: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
395 ask_before_exit(); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
396 signal(SIGINT, sighandler); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
397 break; |
15817 | 398 } |
399 } | |
400 | |
401 static void | |
402 init_wm() | |
403 { | |
404 const char *name = gnt_style_get(GNT_STYLE_WM); | |
405 gpointer handle; | |
406 | |
407 if (name && *name) { | |
408 handle = g_module_open(name, G_MODULE_BIND_LAZY); | |
409 if (handle) { | |
410 gboolean (*init)(GntWM **); | |
411 if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { | |
412 init(&wm); | |
413 } | |
414 } | |
415 } | |
416 if (wm == NULL) | |
417 wm = g_object_new(GNT_TYPE_WM, NULL); | |
418 } | |
419 | |
420 void gnt_init() | |
421 { | |
422 char *filename; | |
423 const char *locale; | |
424 | |
425 if (channel) | |
426 return; | |
427 | |
428 locale = setlocale(LC_ALL, ""); | |
429 | |
430 setup_io(); | |
431 | |
432 if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) | |
433 ascii_only = FALSE; | |
434 else | |
435 ascii_only = TRUE; | |
436 | |
437 initscr(); | |
438 typeahead(-1); | |
439 noecho(); | |
440 curs_set(0); | |
441 | |
442 gnt_init_keys(); | |
443 gnt_init_styles(); | |
444 | |
445 filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); | |
446 gnt_style_read_configure_file(filename); | |
447 g_free(filename); | |
448 | |
449 gnt_init_colors(); | |
450 | |
451 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
452 refresh(); | |
453 | |
454 #ifdef ALL_MOUSE_EVENTS | |
455 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) | |
456 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); | |
457 #endif | |
458 | |
459 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
460 werase(stdscr); | |
461 wrefresh(stdscr); | |
462 | |
463 #ifdef SIGWINCH | |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
464 org_winch_handler = signal(SIGWINCH, sighandler); |
15817 | 465 #endif |
466 signal(SIGCHLD, sighandler); | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
467 signal(SIGINT, sighandler); |
15817 | 468 signal(SIGPIPE, SIG_IGN); |
469 | |
470 g_type_init(); | |
471 | |
472 init_wm(); | |
473 | |
474 clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); | |
475 } | |
476 | |
477 void gnt_main() | |
478 { | |
479 wm->loop = g_main_loop_new(NULL, FALSE); | |
480 g_main_loop_run(wm->loop); | |
481 } | |
482 | |
483 /********************************* | |
484 * Stuff for 'window management' * | |
485 *********************************/ | |
486 | |
18070 | 487 void gnt_window_present(GntWidget *window) { |
488 gnt_wm_raise_window(wm, window); | |
489 } | |
490 | |
15817 | 491 void gnt_screen_occupy(GntWidget *widget) |
492 { | |
493 gnt_wm_new_window(wm, widget); | |
494 } | |
495 | |
496 void gnt_screen_release(GntWidget *widget) | |
497 { | |
498 gnt_wm_window_close(wm, widget); | |
499 } | |
500 | |
501 void gnt_screen_update(GntWidget *widget) | |
502 { | |
503 gnt_wm_update_window(wm, widget); | |
504 } | |
505 | |
506 gboolean gnt_widget_has_focus(GntWidget *widget) | |
507 { | |
508 GntWidget *w; | |
509 if (!widget) | |
510 return FALSE; | |
511 | |
512 if (GNT_IS_MENU(widget)) | |
513 return TRUE; | |
514 | |
515 w = widget; | |
516 | |
517 while (widget->parent) | |
518 widget = widget->parent; | |
519 | |
520 if (widget == wm->_list.window) | |
521 return TRUE; | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
522 if (wm->cws->ordered && wm->cws->ordered->data == widget) { |
15817 | 523 if (GNT_IS_BOX(widget) && |
524 (GNT_BOX(widget)->active == w || widget == w)) | |
525 return TRUE; | |
526 } | |
527 return FALSE; | |
528 } | |
529 | |
530 void gnt_widget_set_urgent(GntWidget *widget) | |
531 { | |
532 while (widget->parent) | |
533 widget = widget->parent; | |
534 | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
535 if (wm->cws->ordered && wm->cws->ordered->data == widget) |
15817 | 536 return; |
537 | |
538 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); | |
539 | |
540 gnt_wm_update_window(wm, widget); | |
541 } | |
542 | |
543 void gnt_quit() | |
544 { | |
545 g_hash_table_destroy(wm->nodes); /* XXX: */ | |
546 update_panels(); | |
547 doupdate(); | |
548 gnt_uninit_colors(); | |
549 gnt_uninit_styles(); | |
550 endwin(); | |
551 } | |
552 | |
553 gboolean gnt_ascii_only() | |
554 { | |
555 return ascii_only; | |
556 } | |
557 | |
558 void gnt_screen_resize_widget(GntWidget *widget, int width, int height) | |
559 { | |
560 gnt_wm_resize_window(wm, widget, width, height); | |
561 } | |
562 | |
563 void gnt_screen_move_widget(GntWidget *widget, int x, int y) | |
564 { | |
565 gnt_wm_move_window(wm, widget, x, y); | |
566 } | |
567 | |
568 void gnt_screen_rename_widget(GntWidget *widget, const char *text) | |
569 { | |
570 gnt_box_set_title(GNT_BOX(widget), text); | |
571 gnt_widget_draw(widget); | |
572 gnt_wm_update_window(wm, widget); | |
573 } | |
574 | |
575 void gnt_register_action(const char *label, void (*callback)()) | |
576 { | |
577 GntAction *action = g_new0(GntAction, 1); | |
578 action->label = g_strdup(label); | |
579 action->callback = callback; | |
580 | |
581 wm->acts = g_list_append(wm->acts, action); | |
582 } | |
583 | |
584 static void | |
585 reset_menu(GntWidget *widget, gpointer null) | |
586 { | |
587 wm->menu = NULL; | |
588 } | |
589 | |
590 gboolean gnt_screen_menu_show(gpointer newmenu) | |
591 { | |
592 if (wm->menu) { | |
593 /* For now, if a menu is being displayed, then another menu | |
594 * can NOT take over. */ | |
595 return FALSE; | |
596 } | |
597 | |
598 wm->menu = newmenu; | |
599 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); | |
600 gnt_widget_draw(GNT_WIDGET(wm->menu)); | |
601 | |
602 g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); | |
16781
d0f9b2b217cf
Fix context menu unusualness in the buddylist.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16281
diff
changeset
|
603 g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); |
15817 | 604 |
605 return TRUE; | |
606 } | |
607 | |
608 void gnt_set_clipboard_string(gchar *string) | |
609 { | |
610 gnt_clipboard_set_string(clipboard, string); | |
611 } | |
612 | |
613 GntClipboard *gnt_get_clipboard() | |
614 { | |
615 return clipboard; | |
616 } | |
617 gchar *gnt_get_clipboard_string() | |
618 { | |
619 return gnt_clipboard_get_string(clipboard); | |
620 } |