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