Mercurial > pidgin.yaz
annotate finch/libgnt/gntmain.c @ 28659:c42d5c23a9e8
jabber: Don't crash when adding a buddy without a node (no '@'). Closes #10261.
Also add some assertions to jabber_chat_find so this doesn't cause a
crash in the future.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Thu, 24 Sep 2009 16:58:31 +0000 |
parents | de2ac0952487 |
children | a18f421696dc |
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 |
24892
ea28a7b9113c
Compilation fixes for OpenBSD from the OpenBSD ports tree. Closes #8009.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
24503
diff
changeset
|
24 #if (defined(__APPLE__) || defined(__unix__)) && !defined(__FreeBSD__) && !defined(__OpenBSD__) |
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 | |
24503
e2e57d3c0578
Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22696
diff
changeset
|
35 #include "gntinternal.h" |
e2e57d3c0578
Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22696
diff
changeset
|
36 #undef GNT_LOG_DOMAIN |
e2e57d3c0578
Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22696
diff
changeset
|
37 #define GNT_LOG_DOMAIN "Main" |
e2e57d3c0578
Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22696
diff
changeset
|
38 |
15818 | 39 #include "gnt.h" |
40 #include "gntbox.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
41 #include "gntbutton.h" |
15818 | 42 #include "gntcolors.h" |
43 #include "gntclipboard.h" | |
44 #include "gntkeys.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
45 #include "gntlabel.h" |
15818 | 46 #include "gntmenu.h" |
47 #include "gntstyle.h" | |
48 #include "gnttree.h" | |
49 #include "gntutils.h" | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
50 #include "gntwindow.h" |
15818 | 51 #include "gntwm.h" |
52 | |
53 #include <panel.h> | |
54 | |
55 #include <stdio.h> | |
56 #include <stdlib.h> | |
57 #include <locale.h> | |
58 #include <unistd.h> | |
59 #include <signal.h> | |
60 #include <string.h> | |
61 #include <ctype.h> | |
62 #include <errno.h> | |
63 | |
64 /** | |
65 * Notes: Interesting functions to look at: | |
66 * scr_dump, scr_init, scr_restore: for workspaces | |
67 * | |
68 * Need to wattrset for colors to use with PDCurses. | |
69 */ | |
70 | |
71 static GIOChannel *channel = NULL; | |
28497
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
72 static guint channel_read_callback = 0; |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
73 static guint channel_error_callback = 0; |
15818 | 74 |
75 static gboolean ascii_only; | |
76 static gboolean mouse_enabled; | |
77 | |
78 static void setup_io(void); | |
79 | |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21720
diff
changeset
|
80 static gboolean refresh_screen(void); |
15818 | 81 |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17528
diff
changeset
|
82 static GntWM *wm; |
15818 | 83 static GntClipboard *clipboard; |
84 | |
85 #define HOLDING_ESCAPE (escape_stuff.timer != 0) | |
86 | |
87 static struct { | |
88 int timer; | |
89 } escape_stuff; | |
90 | |
91 static gboolean | |
92 escape_timeout(gpointer data) | |
93 { | |
94 gnt_wm_process_input(wm, "\033"); | |
95 escape_stuff.timer = 0; | |
96 return FALSE; | |
97 } | |
98 | |
99 /** | |
100 * Mouse support: | |
101 * - bring a window on top if you click on its taskbar | |
102 * - click on the top-bar of the active window and drag+drop to move a window | |
103 * - click on a window to bring it to focus | |
104 * - allow scrolling in tree/textview on wheel-scroll event | |
105 * - click to activate button or select a row in tree | |
106 * wishlist: | |
107 * - have a little [X] on the windows, and clicking it will close that window. | |
108 */ | |
109 static gboolean | |
110 detect_mouse_action(const char *buffer) | |
111 { | |
112 int x, y; | |
113 static enum { | |
114 MOUSE_NONE, | |
115 MOUSE_LEFT, | |
116 MOUSE_RIGHT, | |
117 MOUSE_MIDDLE | |
118 } button = MOUSE_NONE; | |
119 static GntWidget *remember = NULL; | |
120 static int offset = 0; | |
121 GntMouseEvent event; | |
122 GntWidget *widget = NULL; | |
123 PANEL *p = NULL; | |
124 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
125 if (!wm->cws->ordered || buffer[0] != 27) |
15818 | 126 return FALSE; |
127 | |
128 buffer++; | |
129 if (strlen(buffer) < 5) | |
130 return FALSE; | |
131 | |
132 x = buffer[3]; | |
133 y = buffer[4]; | |
134 if (x < 0) x += 256; | |
135 if (y < 0) y += 256; | |
136 x -= 33; | |
137 y -= 33; | |
138 | |
139 while ((p = panel_below(p)) != NULL) { | |
140 const GntNode *node = panel_userptr(p); | |
141 GntWidget *wid; | |
142 if (!node) | |
143 continue; | |
144 wid = node->me; | |
145 if (x >= wid->priv.x && x < wid->priv.x + wid->priv.width) { | |
146 if (y >= wid->priv.y && y < wid->priv.y + wid->priv.height) { | |
147 widget = wid; | |
148 break; | |
149 } | |
150 } | |
151 } | |
152 | |
153 if (strncmp(buffer, "[M ", 3) == 0) { | |
154 /* left button down */ | |
155 /* Bring the window you clicked on to front */ | |
156 /* If you click on the topbar, then you can drag to move the window */ | |
157 event = GNT_LEFT_MOUSE_DOWN; | |
158 } else if (strncmp(buffer, "[M\"", 3) == 0) { | |
159 /* right button down */ | |
160 event = GNT_RIGHT_MOUSE_DOWN; | |
161 } else if (strncmp(buffer, "[M!", 3) == 0) { | |
162 /* middle button down */ | |
163 event = GNT_MIDDLE_MOUSE_DOWN; | |
164 } else if (strncmp(buffer, "[M`", 3) == 0) { | |
165 /* wheel up*/ | |
166 event = GNT_MOUSE_SCROLL_UP; | |
167 } else if (strncmp(buffer, "[Ma", 3) == 0) { | |
168 /* wheel down */ | |
169 event = GNT_MOUSE_SCROLL_DOWN; | |
170 } else if (strncmp(buffer, "[M#", 3) == 0) { | |
171 /* button up */ | |
172 event = GNT_MOUSE_UP; | |
173 } else | |
174 return FALSE; | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
175 |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
176 if (widget && gnt_wm_process_click(wm, event, x, y, widget)) |
15818 | 177 return TRUE; |
178 | |
179 if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window && | |
180 !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
|
181 if (widget != wm->cws->ordered->data) { |
15818 | 182 gnt_wm_raise_window(wm, widget); |
183 } | |
184 if (y == widget->priv.y) { | |
185 offset = x - widget->priv.x; | |
186 remember = widget; | |
187 button = MOUSE_LEFT; | |
188 } | |
189 } else if (event == GNT_MOUSE_UP) { | |
190 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { | |
191 /* Clicked on the taskbar */ | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
192 int n = g_list_length(wm->cws->list); |
15818 | 193 if (n) { |
194 int width = getmaxx(stdscr) / n; | |
195 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL); | |
196 } | |
197 } else if (button == MOUSE_LEFT && remember) { | |
198 x -= offset; | |
199 if (x < 0) x = 0; | |
200 if (y < 0) y = 0; | |
201 gnt_screen_move_widget(remember, x, y); | |
202 } | |
203 button = MOUSE_NONE; | |
204 remember = NULL; | |
205 offset = 0; | |
206 } | |
207 | |
17064
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
208 if (widget) |
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17058
diff
changeset
|
209 gnt_widget_clicked(widget, event, x, y); |
15818 | 210 return TRUE; |
211 } | |
212 | |
213 static gboolean | |
214 io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) | |
215 { | |
216 int id = GPOINTER_TO_INT(data); | |
217 g_source_remove(id); | |
218 g_io_channel_unref(source); | |
219 | |
220 channel = NULL; | |
221 setup_io(); | |
222 return TRUE; | |
223 } | |
224 | |
225 static gboolean | |
226 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | |
227 { | |
228 char keys[256]; | |
22296
6d3f8042f21f
Fix the "Finch doesn't work" bug. More specifically, it turned out to be
Stu Tomlinson <stu@nosnilmot.com>
parents:
22011
diff
changeset
|
229 gssize rd; |
15818 | 230 char *k; |
20309
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
231 char *cvrt = NULL; |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
232 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
233 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
|
234 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
235 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
236 rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); |
15818 | 237 if (rd < 0) |
238 { | |
239 int ch = getch(); /* This should return ERR, but let's see what it really returns */ | |
240 endwin(); | |
241 printf("ERROR: %s\n", strerror(errno)); | |
242 printf("File descriptor is: %d\n\nGIOChannel is: %p\ngetch() = %d\n", STDIN_FILENO, source, ch); | |
243 raise(SIGABRT); | |
244 } | |
245 else if (rd == 0) | |
246 { | |
247 endwin(); | |
248 printf("EOF\n"); | |
249 raise(SIGABRT); | |
250 } | |
251 | |
252 rd += HOLDING_ESCAPE; | |
22696
8d74a9e409f1
Patch from Dylan Simon <dylan@dylex.net> to fix handling escape key
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22296
diff
changeset
|
253 if (HOLDING_ESCAPE) { |
15818 | 254 keys[0] = '\033'; |
22696
8d74a9e409f1
Patch from Dylan Simon <dylan@dylex.net> to fix handling escape key
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22296
diff
changeset
|
255 g_source_remove(escape_stuff.timer); |
8d74a9e409f1
Patch from Dylan Simon <dylan@dylex.net> to fix handling escape key
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22296
diff
changeset
|
256 escape_stuff.timer = 0; |
8d74a9e409f1
Patch from Dylan Simon <dylan@dylex.net> to fix handling escape key
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22296
diff
changeset
|
257 } |
20309
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
258 keys[rd] = 0; |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
259 gnt_wm_set_event_stack(wm, TRUE); |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
260 |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
261 cvrt = g_locale_to_utf8(keys, rd, (gsize*)&rd, NULL, NULL); |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
262 k = cvrt ? cvrt : keys; |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
263 if (mouse_enabled && detect_mouse_action(k)) |
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
264 goto end; |
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 |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
266 #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
|
267 /* 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
|
268 * 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
|
269 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
|
270 *(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
|
271 *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
|
272 *(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
|
273 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
|
274 } |
19176
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
275 #endif |
33201366bcd4
Fix some white-space and other similar issues. Preparing for a merge.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
19171
diff
changeset
|
276 |
15818 | 277 while (rd) { |
278 char back; | |
279 int p; | |
280 | |
281 if (k[0] == '\033' && rd == 1) { | |
282 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
283 break; | |
284 } | |
285 | |
286 gnt_keys_refine(k); | |
287 p = MAX(1, gnt_keys_find_combination(k)); | |
288 back = k[p]; | |
289 k[p] = '\0'; | |
290 gnt_wm_process_input(wm, k); /* XXX: */ | |
291 k[p] = back; | |
292 rd -= p; | |
293 k += p; | |
294 } | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15818
diff
changeset
|
295 end: |
21283
406aa3be6b32
Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21253
diff
changeset
|
296 if (wm) |
406aa3be6b32
Minor adjustments to prevent a crash, correct a data type and fix drawing.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21253
diff
changeset
|
297 gnt_wm_set_event_stack(wm, FALSE); |
20309
d256249b22ea
applied changes from 4bbc209c8076ef89135700af844ec6bb04602c0a
Luke Schierer <lschiere@pidgin.im>
parents:
20225
diff
changeset
|
298 g_free(cvrt); |
15818 | 299 return TRUE; |
300 } | |
301 | |
302 static void | |
303 setup_io() | |
304 { | |
305 int result; | |
306 channel = g_io_channel_unix_new(STDIN_FILENO); | |
307 g_io_channel_set_close_on_unref(channel, TRUE); | |
308 | |
309 #if 0 | |
310 g_io_channel_set_encoding(channel, NULL, NULL); | |
311 g_io_channel_set_buffered(channel, FALSE); | |
312 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | |
313 #endif | |
314 | |
18425
84d318eadc62
The input was causing some weird issues. This fixes it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18421
diff
changeset
|
315 channel_read_callback = result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, |
15818 | 316 (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), |
317 io_invoke, NULL, NULL); | |
28497
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
318 |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
319 channel_error_callback = g_io_add_watch_full(channel, G_PRIORITY_HIGH, |
15818 | 320 (G_IO_NVAL), |
321 io_invoke_error, GINT_TO_POINTER(result), NULL); | |
28497
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
322 |
15818 | 323 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. |
324 But irssi does this, so I am going to assume the | |
325 crashes were caused by some other stuff. */ | |
326 | |
24503
e2e57d3c0578
Use glib log functions to show error messages.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
22696
diff
changeset
|
327 gnt_warning("setting up IO (%d)", channel_read_callback); |
15818 | 328 } |
329 | |
330 static gboolean | |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21720
diff
changeset
|
331 refresh_screen(void) |
15818 | 332 { |
333 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); | |
334 return FALSE; | |
335 } | |
336 | |
337 /* Xerox */ | |
338 static void | |
339 clean_pid(void) | |
340 { | |
341 int status; | |
342 pid_t pid; | |
343 | |
344 do { | |
345 pid = waitpid(-1, &status, WNOHANG); | |
346 } while (pid != 0 && pid != (pid_t)-1); | |
347 | |
348 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
349 char errmsg[BUFSIZ]; | |
350 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
351 perror(errmsg); | |
352 } | |
353 } | |
354 | |
355 static void | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
356 exit_confirmed(gpointer null) |
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 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
|
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 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
|
363 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
364 *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
365 } |
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 static void |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21720
diff
changeset
|
368 ask_before_exit(void) |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
369 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
370 static GntWidget *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
371 GntWidget *bbox, *button; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
372 |
18439
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
373 if (wm->menu) { |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
374 do { |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
375 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
|
376 if (wm->menu) |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
377 wm->menu = wm->menu->parentmenu; |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
378 } while (wm->menu); |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
379 } |
ec80e921818c
Hide the menu when ctrl-c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18425
diff
changeset
|
380 |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
381 if (win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
382 goto raise; |
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 win = gnt_vwindow_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), 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
|
386 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
|
387 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
|
388 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
|
389 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
390 bbox = gnt_hbox_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
391 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
|
392 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
393 button = gnt_button_new("Quit"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
394 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
|
395 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
|
396 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
397 button = gnt_button_new("Cancel"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
398 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
|
399 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
|
400 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
401 gnt_widget_show(win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
402 raise: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
403 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
|
404 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
405 |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
406 #ifdef SIGWINCH |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
407 static void (*org_winch_handler)(int); |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
408 #endif |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
409 |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
410 static void |
15818 | 411 sighandler(int sig) |
412 { | |
413 switch (sig) { | |
414 #ifdef SIGWINCH | |
415 case SIGWINCH: | |
17251
8d3c28521112
I think this fixes #532.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17064
diff
changeset
|
416 erase(); |
22011
76e0463db3aa
Squash some compiler warnings, some from my -Wstrict-prototypes fixing.
Richard Laager <rlaager@wiktel.com>
parents:
22007
diff
changeset
|
417 g_idle_add((GSourceFunc)refresh_screen, NULL); |
20225
3c415481a943
applied changes from 388507622896337fe56945f851e3aabee3c0427f
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
418 if (org_winch_handler) |
3c415481a943
applied changes from 388507622896337fe56945f851e3aabee3c0427f
Richard Laager <rlaager@wiktel.com>
parents:
19680
diff
changeset
|
419 org_winch_handler(sig); |
15818 | 420 signal(SIGWINCH, sighandler); |
421 break; | |
422 #endif | |
423 case SIGCHLD: | |
424 clean_pid(); | |
425 signal(SIGCHLD, sighandler); | |
426 break; | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
427 case SIGINT: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
428 ask_before_exit(); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
429 signal(SIGINT, sighandler); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
430 break; |
15818 | 431 } |
432 } | |
433 | |
434 static void | |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21720
diff
changeset
|
435 init_wm(void) |
15818 | 436 { |
437 const char *name = gnt_style_get(GNT_STYLE_WM); | |
438 gpointer handle; | |
439 | |
440 if (name && *name) { | |
441 handle = g_module_open(name, G_MODULE_BIND_LAZY); | |
442 if (handle) { | |
443 gboolean (*init)(GntWM **); | |
444 if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { | |
445 init(&wm); | |
446 } | |
447 } | |
448 } | |
449 if (wm == NULL) | |
450 wm = g_object_new(GNT_TYPE_WM, NULL); | |
451 } | |
452 | |
453 void gnt_init() | |
454 { | |
455 char *filename; | |
456 const char *locale; | |
457 | |
458 if (channel) | |
459 return; | |
460 | |
461 locale = setlocale(LC_ALL, ""); | |
462 | |
463 setup_io(); | |
464 | |
18199
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
465 #ifdef NO_WIDECHAR |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
466 ascii_only = TRUE; |
1bb3b07a6879
Detect wide character non-support at compile time, if possible.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18070
diff
changeset
|
467 #else |
15818 | 468 if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) |
469 ascii_only = FALSE; | |
470 else | |
471 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
|
472 #endif |
15818 | 473 |
474 initscr(); | |
475 typeahead(-1); | |
476 noecho(); | |
477 curs_set(0); | |
478 | |
479 gnt_init_keys(); | |
480 gnt_init_styles(); | |
481 | |
482 filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); | |
483 gnt_style_read_configure_file(filename); | |
484 g_free(filename); | |
485 | |
486 gnt_init_colors(); | |
487 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20309
diff
changeset
|
488 wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 489 refresh(); |
490 | |
491 #ifdef ALL_MOUSE_EVENTS | |
492 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) | |
493 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); | |
494 #endif | |
495 | |
21250
9187d331aebe
Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20309
diff
changeset
|
496 wbkgdset(stdscr, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); |
15818 | 497 werase(stdscr); |
498 wrefresh(stdscr); | |
499 | |
500 #ifdef SIGWINCH | |
17058
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16899
diff
changeset
|
501 org_winch_handler = signal(SIGWINCH, sighandler); |
15818 | 502 #endif |
503 signal(SIGCHLD, sighandler); | |
16899
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16792
diff
changeset
|
504 signal(SIGINT, sighandler); |
15818 | 505 signal(SIGPIPE, SIG_IGN); |
506 | |
507 g_type_init(); | |
508 | |
509 init_wm(); | |
510 | |
511 clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); | |
512 } | |
513 | |
514 void gnt_main() | |
515 { | |
516 wm->loop = g_main_loop_new(NULL, FALSE); | |
517 g_main_loop_run(wm->loop); | |
518 } | |
519 | |
520 /********************************* | |
521 * Stuff for 'window management' * | |
522 *********************************/ | |
523 | |
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
|
524 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
|
525 { |
310bad6dafe4
Allow raising window only from an event-stack, otherwise set the urgent flag.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18199
diff
changeset
|
526 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
|
527 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
|
528 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
|
529 gnt_widget_set_urgent(window); |
18070 | 530 } |
531 | |
15818 | 532 void gnt_screen_occupy(GntWidget *widget) |
533 { | |
534 gnt_wm_new_window(wm, widget); | |
535 } | |
536 | |
537 void gnt_screen_release(GntWidget *widget) | |
538 { | |
18716
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
539 if (wm) |
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
540 gnt_wm_window_close(wm, widget); |
15818 | 541 } |
542 | |
543 void gnt_screen_update(GntWidget *widget) | |
544 { | |
545 gnt_wm_update_window(wm, widget); | |
546 } | |
547 | |
548 gboolean gnt_widget_has_focus(GntWidget *widget) | |
549 { | |
550 GntWidget *w; | |
551 if (!widget) | |
552 return FALSE; | |
553 | |
554 if (GNT_IS_MENU(widget)) | |
555 return TRUE; | |
556 | |
557 w = widget; | |
558 | |
559 while (widget->parent) | |
560 widget = widget->parent; | |
561 | |
562 if (widget == wm->_list.window) | |
563 return TRUE; | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
564 if (wm->cws->ordered && wm->cws->ordered->data == widget) { |
15818 | 565 if (GNT_IS_BOX(widget) && |
566 (GNT_BOX(widget)->active == w || widget == w)) | |
567 return TRUE; | |
568 } | |
569 return FALSE; | |
570 } | |
571 | |
572 void gnt_widget_set_urgent(GntWidget *widget) | |
573 { | |
574 while (widget->parent) | |
575 widget = widget->parent; | |
576 | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
16281
diff
changeset
|
577 if (wm->cws->ordered && wm->cws->ordered->data == widget) |
15818 | 578 return; |
579 | |
580 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); | |
581 | |
582 gnt_wm_update_window(wm, widget); | |
583 } | |
584 | |
585 void gnt_quit() | |
586 { | |
28497
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
587 /* Prevent io_invoke() from being called after wm is destroyed */ |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
588 g_source_remove(channel_error_callback); |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
589 g_source_remove(channel_read_callback); |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
590 |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
591 channel_error_callback = 0; |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
592 channel_read_callback = 0; |
de2ac0952487
Remove IO watches at shutdown in gntmain.c Closes #9872.
desowin@gmail.com
parents:
24892
diff
changeset
|
593 |
18716
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
594 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
|
595 wm = NULL; |
0873698f8cce
This fixes a few weird crashes in pygnt.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18526
diff
changeset
|
596 |
15818 | 597 update_panels(); |
598 doupdate(); | |
599 gnt_uninit_colors(); | |
600 gnt_uninit_styles(); | |
601 endwin(); | |
602 } | |
603 | |
604 gboolean gnt_ascii_only() | |
605 { | |
606 return ascii_only; | |
607 } | |
608 | |
609 void gnt_screen_resize_widget(GntWidget *widget, int width, int height) | |
610 { | |
611 gnt_wm_resize_window(wm, widget, width, height); | |
612 } | |
613 | |
614 void gnt_screen_move_widget(GntWidget *widget, int x, int y) | |
615 { | |
616 gnt_wm_move_window(wm, widget, x, y); | |
617 } | |
618 | |
619 void gnt_screen_rename_widget(GntWidget *widget, const char *text) | |
620 { | |
621 gnt_box_set_title(GNT_BOX(widget), text); | |
622 gnt_widget_draw(widget); | |
623 gnt_wm_update_window(wm, widget); | |
624 } | |
625 | |
22007
c38d72677c8a
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents:
21720
diff
changeset
|
626 void gnt_register_action(const char *label, void (*callback)(void)) |
15818 | 627 { |
628 GntAction *action = g_new0(GntAction, 1); | |
629 action->label = g_strdup(label); | |
630 action->callback = callback; | |
631 | |
632 wm->acts = g_list_append(wm->acts, action); | |
633 } | |
634 | |
635 static void | |
636 reset_menu(GntWidget *widget, gpointer null) | |
637 { | |
638 wm->menu = NULL; | |
639 } | |
640 | |
641 gboolean gnt_screen_menu_show(gpointer newmenu) | |
642 { | |
643 if (wm->menu) { | |
644 /* For now, if a menu is being displayed, then another menu | |
645 * can NOT take over. */ | |
646 return FALSE; | |
647 } | |
648 | |
649 wm->menu = newmenu; | |
650 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); | |
651 gnt_widget_draw(GNT_WIDGET(wm->menu)); | |
652 | |
653 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
|
654 g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); |
15818 | 655 |
656 return TRUE; | |
657 } | |
658 | |
21161
e119edfc0fb0
applied changes from 172a59b41412c4630834d66f2e7ec3be970cc36b
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
20309
diff
changeset
|
659 void gnt_set_clipboard_string(const gchar *string) |
15818 | 660 { |
661 gnt_clipboard_set_string(clipboard, string); | |
662 } | |
663 | |
664 GntClipboard *gnt_get_clipboard() | |
665 { | |
666 return clipboard; | |
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 |
15818 | 669 gchar *gnt_get_clipboard_string() |
670 { | |
671 return gnt_clipboard_get_string(clipboard); | |
672 } | |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
673 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
674 #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
|
675 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
|
676 { |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
677 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
|
678 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
|
679 } ChildProcess; |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
680 |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
681 static void |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
682 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
|
683 { |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
684 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
|
685 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
|
686 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
|
687 } |
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
688 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
|
689 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
|
690 wm->mode = GNT_KP_MODE_NORMAL; |
21720
ea56d9386081
Restore the screen properly after the child process ends.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21668
diff
changeset
|
691 endwin(); |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
692 setup_io(); |
21720
ea56d9386081
Restore the screen properly after the child process ends.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
21668
diff
changeset
|
693 refresh(); |
18421
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
694 refresh_screen(); |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
695 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
696 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
697 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 { |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
702 #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
|
703 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
|
704 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
|
705 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
706 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
|
707 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
|
708 (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
|
709 &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
|
710 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
711 |
18526
09db6fec9dce
Allow having a callback after the child process terminates. Use the callback
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18439
diff
changeset
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
719 return TRUE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
720 #else |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
721 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
722 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
723 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
724 |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
725 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
|
726 { |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
727 #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
|
728 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
|
729 #else |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
730 return FALSE; |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
731 #endif |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
732 } |
e16d097c5739
Allow executing another application (eg. PAGER) that will use the same
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18344
diff
changeset
|
733 |