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