Mercurial > pidgin.yaz
annotate finch/libgnt/gntmain.c @ 20649:964014aee978
merge of '025faf23aaac403798451974c320c4de6df470d5'
and '5c5edb6508adac74635924c3b6fa2676a92323e3'
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 22 Sep 2007 03:21:11 +0000 |
parents | 7d072354544a |
children | d256249b22ea |
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 |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19179
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
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; | |
18425
84d318eadc62
The input was causing some weird issues. This fixes it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
68 static int channel_read_callback; |
15818 | 69 |
70 static gboolean ascii_only; | |
71 static gboolean mouse_enabled; | |
72 | |
73 static void setup_io(void); | |
74 | |
75 static gboolean refresh_screen(); | |
76 | |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
77 static GntWM *wm; |
15818 | 78 static GntClipboard *clipboard; |
79 | |
80 #define HOLDING_ESCAPE (escape_stuff.timer != 0) | |
81 | |
82 static struct { | |
83 int timer; | |
84 } escape_stuff; | |
85 | |
86 static gboolean | |
87 escape_timeout(gpointer data) | |
88 { | |
89 gnt_wm_process_input(wm, "\033"); | |
90 escape_stuff.timer = 0; | |
91 return FALSE; | |
92 } | |
93 | |
94 /** | |
95 * Mouse support: | |
96 * - bring a window on top if you click on its taskbar | |
97 * - click on the top-bar of the active window and drag+drop to move a window | |
98 * - click on a window to bring it to focus | |
99 * - allow scrolling in tree/textview on wheel-scroll event | |
100 * - click to activate button or select a row in tree | |
101 * wishlist: | |
102 * - have a little [X] on the windows, and clicking it will close that window. | |
103 */ | |
104 static gboolean | |
105 detect_mouse_action(const char *buffer) | |
106 { | |
107 int x, y; | |
108 static enum { | |
109 MOUSE_NONE, | |
110 MOUSE_LEFT, | |
111 MOUSE_RIGHT, | |
112 MOUSE_MIDDLE | |
113 } button = MOUSE_NONE; | |
114 static GntWidget *remember = NULL; | |
115 static int offset = 0; | |
116 GntMouseEvent event; | |
117 GntWidget *widget = NULL; | |
118 PANEL *p = NULL; | |
119 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
120 if (!wm->cws->ordered || buffer[0] != 27) |
15818 | 121 return FALSE; |
122 | |
123 buffer++; | |
124 if (strlen(buffer) < 5) | |
125 return FALSE; | |
126 | |
127 x = buffer[3]; | |
128 y = buffer[4]; | |
129 if (x < 0) x += 256; | |
130 if (y < 0) y += 256; | |
131 x -= 33; | |
132 y -= 33; | |
133 | |
134 while ((p = panel_below(p)) != NULL) { | |
135 const GntNode *node = panel_userptr(p); | |
136 GntWidget *wid; | |
137 if (!node) | |
138 continue; | |
139 wid = node->me; | |
140 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { | |
141 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { | |
142 widget = wid; | |
143 break; | |
144 } | |
145 } | |
146 } | |
147 | |
148 if (strncmp(buffer, "[M ", 3) == 0) { | |
149 /* left button down */ | |
150 /* Bring the window you clicked on to front */ | |
151 /* If you click on the topbar, then you can drag to move the window */ | |
152 event = GNT_LEFT_MOUSE_DOWN; | |
153 } else if (strncmp(buffer, "[M\"", 3) == 0) { | |
154 /* right button down */ | |
155 event = GNT_RIGHT_MOUSE_DOWN; | |
156 } else if (strncmp(buffer, "[M!", 3) == 0) { | |
157 /* middle button down */ | |
158 event = GNT_MIDDLE_MOUSE_DOWN; | |
159 } else if (strncmp(buffer, "[M`", 3) == 0) { | |
160 /* wheel up*/ | |
161 event = GNT_MOUSE_SCROLL_UP; | |
162 } else if (strncmp(buffer, "[Ma", 3) == 0) { | |
163 /* wheel down */ | |
164 event = GNT_MOUSE_SCROLL_DOWN; | |
165 } else if (strncmp(buffer, "[M#", 3) == 0) { | |
166 /* button up */ | |
167 event = GNT_MOUSE_UP; | |
168 } else | |
169 return FALSE; | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
170 |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
171 if (widget && gnt_wm_process_click(wm, event, x, y, widget)) |
15818 | 172 return TRUE; |
173 | |
174 if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window && | |
175 !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
|
176 if (widget != wm->cws->ordered->data) { |
15818 | 177 gnt_wm_raise_window(wm, widget); |
178 } | |
179 if (y == widget->priv.y) { | |
180 offset = x - widget->priv.x; | |
181 remember = widget; | |
182 button = MOUSE_LEFT; | |
183 } | |
184 } else if (event == GNT_MOUSE_UP) { | |
185 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { | |
186 /* Clicked on the taskbar */ | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
187 int n = g_list_length(wm->cws->list); |
15818 | 188 if (n) { |
189 int width = getmaxx(stdscr) / n; | |
190 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL); | |
191 } | |
192 } else if (button == MOUSE_LEFT && remember) { | |
193 x -= offset; | |
194 if (x < 0) x = 0; | |
195 if (y < 0) y = 0; | |
196 gnt_screen_move_widget(remember, x, y); | |
197 } | |
198 button = MOUSE_NONE; | |
199 remember = NULL; | |
200 offset = 0; | |
201 } | |
202 | |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
203 if (widget) |
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
204 gnt_widget_clicked(widget, event, x, y); |
15818 | 205 return TRUE; |
206 } | |
207 | |
208 static gboolean | |
209 io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) | |
210 { | |
211 int id = GPOINTER_TO_INT(data); | |
212 g_source_remove(id); | |
213 g_io_channel_unref(source); | |
214 | |
215 channel = NULL; | |
216 setup_io(); | |
217 return TRUE; | |
218 } | |
219 | |
220 static gboolean | |
221 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | |
222 { | |
223 char keys[256]; | |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
224 int rd; |
15818 | 225 char *k; |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
226 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
227 if (wm->mode == GNT_KP_MODE_WAIT_ON_CHILD) |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
228 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
229 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
230 rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); |
15818 | 231 if (rd < 0) |
232 { | |
233 int ch = getch(); /* This should return ERR, but let's see what it really returns */ | |
234 endwin(); | |
235 printf("ERROR: %s\n", strerror(errno)); | |
236 printf("File descriptor is: %d\n\nGIOChannel is: %p\ngetch() = %d\n", STDIN_FILENO, source, ch); | |
237 raise(SIGABRT); | |
238 } | |
239 else if (rd == 0) | |
240 { | |
241 endwin(); | |
242 printf("EOF\n"); | |
243 raise(SIGABRT); | |
244 } | |
245 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
246 gnt_wm_set_event_stack(wm, TRUE); |
15818 | 247 rd += HOLDING_ESCAPE; |
248 keys[rd] = 0; | |
249 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
|
250 goto end; |
15818 | 251 |
252 if (HOLDING_ESCAPE) | |
253 keys[0] = '\033'; | |
254 k = keys; | |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
255 |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
256 #if 0 |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
257 /* I am not sure what's happening here. If this actually does something, |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
258 * then this needs to go in gnt_keys_refine. */ |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
259 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
|
260 *(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
|
261 *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
|
262 *(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
|
263 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
|
264 } |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
265 #endif |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
266 |
15818 | 267 while (rd) { |
268 char back; | |
269 int p; | |
270 | |
271 if (k[0] == '\033' && rd == 1) { | |
272 if (escape_stuff.timer) { | |
273 gnt_wm_process_input(wm, "\033\033"); | |
274 g_source_remove(escape_stuff.timer); | |
275 escape_stuff.timer = 0; | |
276 break; | |
277 } | |
278 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
279 break; | |
280 } | |
281 | |
282 gnt_keys_refine(k); | |
283 p = MAX(1, gnt_keys_find_combination(k)); | |
284 back = k[p]; | |
285 k[p] = '\0'; | |
286 gnt_wm_process_input(wm, k); /* XXX: */ | |
287 k[p] = back; | |
288 rd -= p; | |
289 k += p; | |
290 } | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
291 end: |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
292 gnt_wm_set_event_stack(wm, FALSE); |
15818 | 293 return TRUE; |
294 } | |
295 | |
296 static void | |
297 setup_io() | |
298 { | |
299 int result; | |
300 channel = g_io_channel_unix_new(STDIN_FILENO); | |
301 g_io_channel_set_close_on_unref(channel, TRUE); | |
302 | |
303 #if 0 | |
304 g_io_channel_set_encoding(channel, NULL, NULL); | |
305 g_io_channel_set_buffered(channel, FALSE); | |
306 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | |
307 #endif | |
308 | |
18425
84d318eadc62
The input was causing some weird issues. This fixes it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
309 channel_read_callback = result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, |
15818 | 310 (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), |
311 io_invoke, NULL, NULL); | |
312 | |
313 g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
314 (G_IO_NVAL), | |
315 io_invoke_error, GINT_TO_POINTER(result), NULL); | |
316 | |
317 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. | |
318 But irssi does this, so I am going to assume the | |
319 crashes were caused by some other stuff. */ | |
320 | |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
321 g_printerr("gntmain: setting up IO (%d)\n", channel_read_callback); |
15818 | 322 } |
323 | |
324 static gboolean | |
325 refresh_screen() | |
326 { | |
327 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); | |
328 return FALSE; | |
329 } | |
330 | |
331 /* Xerox */ | |
332 static void | |
333 clean_pid(void) | |
334 { | |
335 int status; | |
336 pid_t pid; | |
337 | |
338 do { | |
339 pid = waitpid(-1, &status, WNOHANG); | |
340 } while (pid != 0 && pid != (pid_t)-1); | |
341 | |
342 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
343 char errmsg[BUFSIZ]; | |
344 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
345 perror(errmsg); | |
346 } | |
347 } | |
348 | |
349 static void | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
350 exit_confirmed(gpointer null) |
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 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
|
353 } |
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 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
356 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
|
357 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
358 *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
359 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
360 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
361 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
362 ask_before_exit() |
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 static GntWidget *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
365 GntWidget *bbox, *button; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
366 |
18439
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
367 if (wm->menu) { |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
368 do { |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
369 gnt_widget_hide(GNT_WIDGET(wm->menu)); |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
370 if (wm->menu) |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
371 wm->menu = wm->menu->parentmenu; |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
372 } while (wm->menu); |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
373 } |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
374 |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
375 if (win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
376 goto raise; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
377 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
378 win = gnt_vwindow_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 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
|
383 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
384 bbox = gnt_hbox_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
385 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
|
386 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
387 button = gnt_button_new("Quit"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
388 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
|
389 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
|
390 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
391 button = gnt_button_new("Cancel"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
392 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
|
393 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
|
394 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
395 gnt_widget_show(win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
396 raise: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
397 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
|
398 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
399 |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
400 #ifdef SIGWINCH |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
401 static void (*org_winch_handler)(int); |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
402 #endif |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
403 |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
404 static void |
15818 | 405 sighandler(int sig) |
406 { | |
407 switch (sig) { | |
408 #ifdef SIGWINCH | |
409 case SIGWINCH: | |
17251
8d3c28521112
I think this fixes #532.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17064
diff
changeset
|
410 erase(); |
15818 | 411 g_idle_add(refresh_screen, NULL); |
20596
7d072354544a
Fix #3249 (Bus error using finch on mac os x). Make sure we don't crash if there's no default SIGWINCH handler.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
412 if (org_winch_handler) |
7d072354544a
Fix #3249 (Bus error using finch on mac os x). Make sure we don't crash if there's no default SIGWINCH handler.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19680
diff
changeset
|
413 org_winch_handler(sig); |
15818 | 414 signal(SIGWINCH, sighandler); |
415 break; | |
416 #endif | |
417 case SIGCHLD: | |
418 clean_pid(); | |
419 signal(SIGCHLD, sighandler); | |
420 break; | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
421 case SIGINT: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
422 ask_before_exit(); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
423 signal(SIGINT, sighandler); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
424 break; |
15818 | 425 } |
426 } | |
427 | |
428 static void | |
429 init_wm() | |
430 { | |
431 const char *name = gnt_style_get(GNT_STYLE_WM); | |
432 gpointer handle; | |
433 | |
434 if (name && *name) { | |
435 handle = g_module_open(name, G_MODULE_BIND_LAZY); | |
436 if (handle) { | |
437 gboolean (*init)(GntWM **); | |
438 if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { | |
439 init(&wm); | |
440 } | |
441 } | |
442 } | |
443 if (wm == NULL) | |
444 wm = g_object_new(GNT_TYPE_WM, NULL); | |
445 } | |
446 | |
447 void gnt_init() | |
448 { | |
449 char *filename; | |
450 const char *locale; | |
451 | |
452 if (channel) | |
453 return; | |
454 | |
455 locale = setlocale(LC_ALL, ""); | |
456 | |
457 setup_io(); | |
458 | |
18199
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
459 #ifdef NO_WIDECHAR |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
460 ascii_only = TRUE; |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
461 #else |
15818 | 462 if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) |
463 ascii_only = FALSE; | |
464 else | |
465 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
|
466 #endif |
15818 | 467 |
468 initscr(); | |
469 typeahead(-1); | |
470 noecho(); | |
471 curs_set(0); | |
472 | |
473 gnt_init_keys(); | |
474 gnt_init_styles(); | |
475 | |
476 filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); | |
477 gnt_style_read_configure_file(filename); | |
478 g_free(filename); | |
479 | |
480 gnt_init_colors(); | |
481 | |
482 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
483 refresh(); | |
484 | |
485 #ifdef ALL_MOUSE_EVENTS | |
486 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) | |
487 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); | |
488 #endif | |
489 | |
490 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
491 werase(stdscr); | |
492 wrefresh(stdscr); | |
493 | |
494 #ifdef SIGWINCH | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
495 org_winch_handler = signal(SIGWINCH, sighandler); |
15818 | 496 #endif |
497 signal(SIGCHLD, sighandler); | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
498 signal(SIGINT, sighandler); |
15818 | 499 signal(SIGPIPE, SIG_IGN); |
500 | |
501 g_type_init(); | |
502 | |
503 init_wm(); | |
504 | |
505 clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); | |
506 } | |
507 | |
508 void gnt_main() | |
509 { | |
510 wm->loop = g_main_loop_new(NULL, FALSE); | |
511 g_main_loop_run(wm->loop); | |
512 } | |
513 | |
514 /********************************* | |
515 * Stuff for 'window management' * | |
516 *********************************/ | |
517 | |
18344
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
518 void gnt_window_present(GntWidget *window) |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
519 { |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
520 if (wm->event_stack) |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
521 gnt_wm_raise_window(wm, window); |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
522 else |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
523 gnt_widget_set_urgent(window); |
18070 | 524 } |
525 | |
15818 | 526 void gnt_screen_occupy(GntWidget *widget) |
527 { | |
528 gnt_wm_new_window(wm, widget); | |
529 } | |
530 | |
531 void gnt_screen_release(GntWidget *widget) | |
532 { | |
18716
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
533 if (wm) |
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
534 gnt_wm_window_close(wm, widget); |
15818 | 535 } |
536 | |
537 void gnt_screen_update(GntWidget *widget) | |
538 { | |
539 gnt_wm_update_window(wm, widget); | |
540 } | |
541 | |
542 gboolean gnt_widget_has_focus(GntWidget *widget) | |
543 { | |
544 GntWidget *w; | |
545 if (!widget) | |
546 return FALSE; | |
547 | |
548 if (GNT_IS_MENU(widget)) | |
549 return TRUE; | |
550 | |
551 w = widget; | |
552 | |
553 while (widget->parent) | |
554 widget = widget->parent; | |
555 | |
556 if (widget == wm->_list.window) | |
557 return TRUE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
558 if (wm->cws->ordered && wm->cws->ordered->data == widget) { |
15818 | 559 if (GNT_IS_BOX(widget) && |
560 (GNT_BOX(widget)->active == w || widget == w)) | |
561 return TRUE; | |
562 } | |
563 return FALSE; | |
564 } | |
565 | |
566 void gnt_widget_set_urgent(GntWidget *widget) | |
567 { | |
568 while (widget->parent) | |
569 widget = widget->parent; | |
570 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
571 if (wm->cws->ordered && wm->cws->ordered->data == widget) |
15818 | 572 return; |
573 | |
574 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); | |
575 | |
576 gnt_wm_update_window(wm, widget); | |
577 } | |
578 | |
579 void gnt_quit() | |
580 { | |
18716
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
581 g_object_unref(G_OBJECT(wm)); |
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
582 wm = NULL; |
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
583 |
15818 | 584 update_panels(); |
585 doupdate(); | |
586 gnt_uninit_colors(); | |
587 gnt_uninit_styles(); | |
588 endwin(); | |
589 } | |
590 | |
591 gboolean gnt_ascii_only() | |
592 { | |
593 return ascii_only; | |
594 } | |
595 | |
596 void gnt_screen_resize_widget(GntWidget *widget, int width, int height) | |
597 { | |
598 gnt_wm_resize_window(wm, widget, width, height); | |
599 } | |
600 | |
601 void gnt_screen_move_widget(GntWidget *widget, int x, int y) | |
602 { | |
603 gnt_wm_move_window(wm, widget, x, y); | |
604 } | |
605 | |
606 void gnt_screen_rename_widget(GntWidget *widget, const char *text) | |
607 { | |
608 gnt_box_set_title(GNT_BOX(widget), text); | |
609 gnt_widget_draw(widget); | |
610 gnt_wm_update_window(wm, widget); | |
611 } | |
612 | |
613 void gnt_register_action(const char *label, void (*callback)()) | |
614 { | |
615 GntAction *action = g_new0(GntAction, 1); | |
616 action->label = g_strdup(label); | |
617 action->callback = callback; | |
618 | |
619 wm->acts = g_list_append(wm->acts, action); | |
620 } | |
621 | |
622 static void | |
623 reset_menu(GntWidget *widget, gpointer null) | |
624 { | |
625 wm->menu = NULL; | |
626 } | |
627 | |
628 gboolean gnt_screen_menu_show(gpointer newmenu) | |
629 { | |
630 if (wm->menu) { | |
631 /* For now, if a menu is being displayed, then another menu | |
632 * can NOT take over. */ | |
633 return FALSE; | |
634 } | |
635 | |
636 wm->menu = newmenu; | |
637 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); | |
638 gnt_widget_draw(GNT_WIDGET(wm->menu)); | |
639 | |
640 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
|
641 g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); |
15818 | 642 |
643 return TRUE; | |
644 } | |
645 | |
646 void gnt_set_clipboard_string(gchar *string) | |
647 { | |
648 gnt_clipboard_set_string(clipboard, string); | |
649 } | |
650 | |
651 GntClipboard *gnt_get_clipboard() | |
652 { | |
653 return clipboard; | |
654 } | |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
655 |
15818 | 656 gchar *gnt_get_clipboard_string() |
657 { | |
658 return gnt_clipboard_get_string(clipboard); | |
659 } | |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
660 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
661 #if GLIB_CHECK_VERSION(2,4,0) |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
662 typedef struct |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
663 { |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
664 void (*callback)(int status, gpointer data); |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
665 gpointer data; |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
666 } ChildProcess; |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
667 |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
668 static void |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
669 reap_child(GPid pid, gint status, gpointer data) |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
670 { |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
671 ChildProcess *cp = data; |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
672 if (cp->callback) { |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
673 cp->callback(status, cp->data); |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
674 } |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
675 g_free(cp); |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
676 clean_pid(); |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
677 wm->mode = GNT_KP_MODE_NORMAL; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
678 clear(); |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
679 setup_io(); |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
680 refresh_screen(); |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
681 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
682 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
683 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
684 gboolean gnt_giveup_console(const char *wd, char **argv, char **envp, |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
685 gint *stin, gint *stout, gint *sterr, |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
686 void (*callback)(int status, gpointer data), gpointer data) |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
687 { |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
688 #if GLIB_CHECK_VERSION(2,4,0) |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
689 GPid pid = 0; |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
690 ChildProcess *cp = NULL; |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
691 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
692 if (!g_spawn_async_with_pipes(wd, argv, envp, |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
693 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
694 (GSpawnChildSetupFunc)endwin, NULL, |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
695 &pid, stin, stout, sterr, NULL)) |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
696 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
697 |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
698 cp = g_new0(ChildProcess, 1); |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
699 cp->callback = callback; |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
700 cp->data = data; |
18425
84d318eadc62
The input was causing some weird issues. This fixes it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
701 g_source_remove(channel_read_callback); |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
702 wm->mode = GNT_KP_MODE_WAIT_ON_CHILD; |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
703 g_child_watch_add(pid, reap_child, cp); |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
704 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
705 return TRUE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
706 #else |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
707 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
708 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
709 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
710 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
711 gboolean gnt_is_refugee() |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
712 { |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
713 #if GLIB_CHECK_VERSION(2,4,0) |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
714 return (wm && wm->mode == GNT_KP_MODE_WAIT_ON_CHILD); |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
715 #else |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
716 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
717 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
718 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
719 |