Mercurial > pidgin
annotate finch/libgnt/gntmain.c @ 17819:d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
author | Eric Polino <aluink@pidgin.im> |
---|---|
date | Mon, 21 May 2007 14:50:01 +0000 |
parents | 541c5ed54e90 |
children | cfa84fed6ecd |
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 |
17053
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
148 if (widget && gnt_wm_process_click(wm, event, x, y, widget)) |
15817 | 149 return TRUE; |
150 | |
151 if (event == GNT_LEFT_MOUSE_DOWN && widget && widget != wm->_list.window && | |
152 !GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_TRANSIENT)) { | |
153 if (widget != wm->ordered->data) { | |
154 gnt_wm_raise_window(wm, widget); | |
155 } | |
156 if (y == widget->priv.y) { | |
157 offset = x - widget->priv.x; | |
158 remember = widget; | |
159 button = MOUSE_LEFT; | |
160 } | |
161 } else if (event == GNT_MOUSE_UP) { | |
162 if (button == MOUSE_NONE && y == getmaxy(stdscr) - 1) { | |
163 /* Clicked on the taskbar */ | |
164 int n = g_list_length(wm->list); | |
165 if (n) { | |
166 int width = getmaxx(stdscr) / n; | |
167 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "switch-window-n", x/width, NULL); | |
168 } | |
169 } else if (button == MOUSE_LEFT && remember) { | |
170 x -= offset; | |
171 if (x < 0) x = 0; | |
172 if (y < 0) y = 0; | |
173 gnt_screen_move_widget(remember, x, y); | |
174 } | |
175 button = MOUSE_NONE; | |
176 remember = NULL; | |
177 offset = 0; | |
178 } | |
179 | |
17053
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
180 if (widget) |
541c5ed54e90
Fix the commit from earlier today about null-widgets.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
17047
diff
changeset
|
181 gnt_widget_clicked(widget, event, x, y); |
15817 | 182 return TRUE; |
183 } | |
184 | |
185 static gboolean | |
186 io_invoke_error(GIOChannel *source, GIOCondition cond, gpointer data) | |
187 { | |
188 int id = GPOINTER_TO_INT(data); | |
189 g_source_remove(id); | |
190 g_io_channel_unref(source); | |
191 | |
192 channel = NULL; | |
193 setup_io(); | |
194 return TRUE; | |
195 } | |
196 | |
197 static gboolean | |
198 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | |
199 { | |
200 char keys[256]; | |
201 int rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); | |
202 char *k; | |
203 if (rd < 0) | |
204 { | |
205 int ch = getch(); /* This should return ERR, but let's see what it really returns */ | |
206 endwin(); | |
207 printf("ERROR: %s\n", strerror(errno)); | |
208 printf("File descriptor is: %d\n\nGIOChannel is: %p\ngetch() = %d\n", STDIN_FILENO, source, ch); | |
209 raise(SIGABRT); | |
210 } | |
211 else if (rd == 0) | |
212 { | |
213 endwin(); | |
214 printf("EOF\n"); | |
215 raise(SIGABRT); | |
216 } | |
217 | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
218 gnt_wm_set_event_stack(wm, TRUE); |
15817 | 219 rd += HOLDING_ESCAPE; |
220 keys[rd] = 0; | |
221 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
|
222 goto end; |
15817 | 223 |
224 if (HOLDING_ESCAPE) | |
225 keys[0] = '\033'; | |
226 k = keys; | |
17819
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17053
diff
changeset
|
227 if(*k < 0){//alt not sending ESC |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17053
diff
changeset
|
228 *(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:
17053
diff
changeset
|
229 *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:
17053
diff
changeset
|
230 *(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:
17053
diff
changeset
|
231 rd++; |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17053
diff
changeset
|
232 } |
d8b9bea550bc
Added a few lines to gnt_main::io_invoke to deal with ALT not sending ESC.
Eric Polino <aluink@pidgin.im>
parents:
17053
diff
changeset
|
233 // fprintf(stderr,"io_invoke:%d %d %d %d\n",rd, *k, *(k+1), *(k+2)); |
15817 | 234 while (rd) { |
235 char back; | |
236 int p; | |
237 | |
238 if (k[0] == '\033' && rd == 1) { | |
239 if (escape_stuff.timer) { | |
240 gnt_wm_process_input(wm, "\033\033"); | |
241 g_source_remove(escape_stuff.timer); | |
242 escape_stuff.timer = 0; | |
243 break; | |
244 } | |
245 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
246 break; | |
247 } | |
248 | |
249 gnt_keys_refine(k); | |
250 p = MAX(1, gnt_keys_find_combination(k)); | |
251 back = k[p]; | |
252 k[p] = '\0'; | |
253 gnt_wm_process_input(wm, k); /* XXX: */ | |
254 k[p] = back; | |
255 rd -= p; | |
256 k += p; | |
257 } | |
16281
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
258 end: |
82b6fdd899a9
Dialogs opened resulting from a mouse-click should fain focus.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15817
diff
changeset
|
259 gnt_wm_set_event_stack(wm, FALSE); |
15817 | 260 return TRUE; |
261 } | |
262 | |
263 static void | |
264 setup_io() | |
265 { | |
266 int result; | |
267 channel = g_io_channel_unix_new(STDIN_FILENO); | |
268 g_io_channel_set_close_on_unref(channel, TRUE); | |
269 | |
270 #if 0 | |
271 g_io_channel_set_encoding(channel, NULL, NULL); | |
272 g_io_channel_set_buffered(channel, FALSE); | |
273 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | |
274 #endif | |
275 | |
276 result = g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
277 (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_PRI), | |
278 io_invoke, NULL, NULL); | |
279 | |
280 g_io_add_watch_full(channel, G_PRIORITY_HIGH, | |
281 (G_IO_NVAL), | |
282 io_invoke_error, GINT_TO_POINTER(result), NULL); | |
283 | |
284 g_io_channel_unref(channel); /* Apparently this caused crashes for some people. | |
285 But irssi does this, so I am going to assume the | |
286 crashes were caused by some other stuff. */ | |
287 | |
288 g_printerr("gntmain: setting up IO\n"); | |
289 } | |
290 | |
291 static gboolean | |
292 refresh_screen() | |
293 { | |
294 gnt_bindable_perform_action_named(GNT_BINDABLE(wm), "refresh-screen", NULL); | |
295 return FALSE; | |
296 } | |
297 | |
298 /* Xerox */ | |
299 static void | |
300 clean_pid(void) | |
301 { | |
302 int status; | |
303 pid_t pid; | |
304 | |
305 do { | |
306 pid = waitpid(-1, &status, WNOHANG); | |
307 } while (pid != 0 && pid != (pid_t)-1); | |
308 | |
309 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { | |
310 char errmsg[BUFSIZ]; | |
311 g_snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); | |
312 perror(errmsg); | |
313 } | |
314 } | |
315 | |
316 static void | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
317 exit_confirmed(gpointer null) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
318 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
319 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
|
320 } |
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 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
323 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
|
324 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
325 *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
326 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
327 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
328 static void |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
329 ask_before_exit() |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
330 { |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
331 static GntWidget *win = NULL; |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
332 GntWidget *bbox, *button; |
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 if (win) |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
335 goto raise; |
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 win = gnt_vwindow_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 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
|
342 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
343 bbox = gnt_hbox_new(FALSE); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
344 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
|
345 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
346 button = gnt_button_new("Quit"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
347 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
|
348 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
|
349 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
350 button = gnt_button_new("Cancel"); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
351 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
|
352 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
|
353 |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
354 gnt_widget_show(win); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
355 raise: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
356 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
|
357 } |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
358 |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
359 #ifdef SIGWINCH |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
360 static void (*org_winch_handler)(int); |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
361 #endif |
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
362 |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
363 static void |
15817 | 364 sighandler(int sig) |
365 { | |
366 switch (sig) { | |
367 #ifdef SIGWINCH | |
368 case SIGWINCH: | |
369 werase(stdscr); | |
370 wrefresh(stdscr); | |
371 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
|
372 org_winch_handler(sig); |
15817 | 373 signal(SIGWINCH, sighandler); |
374 break; | |
375 #endif | |
376 case SIGCHLD: | |
377 clean_pid(); | |
378 signal(SIGCHLD, sighandler); | |
379 break; | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
380 case SIGINT: |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
381 ask_before_exit(); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
382 signal(SIGINT, sighandler); |
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
383 break; |
15817 | 384 } |
385 } | |
386 | |
387 static void | |
388 init_wm() | |
389 { | |
390 const char *name = gnt_style_get(GNT_STYLE_WM); | |
391 gpointer handle; | |
392 | |
393 if (name && *name) { | |
394 handle = g_module_open(name, G_MODULE_BIND_LAZY); | |
395 if (handle) { | |
396 gboolean (*init)(GntWM **); | |
397 if (g_module_symbol(handle, "gntwm_init", (gpointer)&init)) { | |
398 init(&wm); | |
399 } | |
400 } | |
401 } | |
402 if (wm == NULL) | |
403 wm = g_object_new(GNT_TYPE_WM, NULL); | |
404 } | |
405 | |
406 void gnt_init() | |
407 { | |
408 char *filename; | |
409 const char *locale; | |
410 | |
411 if (channel) | |
412 return; | |
413 | |
414 locale = setlocale(LC_ALL, ""); | |
415 | |
416 setup_io(); | |
417 | |
418 if (locale && (strstr(locale, "UTF") || strstr(locale, "utf"))) | |
419 ascii_only = FALSE; | |
420 else | |
421 ascii_only = TRUE; | |
422 | |
423 initscr(); | |
424 typeahead(-1); | |
425 noecho(); | |
426 curs_set(0); | |
427 | |
428 gnt_init_keys(); | |
429 gnt_init_styles(); | |
430 | |
431 filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL); | |
432 gnt_style_read_configure_file(filename); | |
433 g_free(filename); | |
434 | |
435 gnt_init_colors(); | |
436 | |
437 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
438 refresh(); | |
439 | |
440 #ifdef ALL_MOUSE_EVENTS | |
441 if ((mouse_enabled = gnt_style_get_bool(GNT_STYLE_MOUSE, FALSE))) | |
442 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL); | |
443 #endif | |
444 | |
445 wbkgdset(stdscr, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); | |
446 werase(stdscr); | |
447 wrefresh(stdscr); | |
448 | |
449 #ifdef SIGWINCH | |
17047
a19b8d71f868
Do not process clicks on no widget.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16888
diff
changeset
|
450 org_winch_handler = signal(SIGWINCH, sighandler); |
15817 | 451 #endif |
452 signal(SIGCHLD, sighandler); | |
16888
d2904afe89e2
Ask before exiting when ctrl+c is pressed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16781
diff
changeset
|
453 signal(SIGINT, sighandler); |
15817 | 454 signal(SIGPIPE, SIG_IGN); |
455 | |
456 g_type_init(); | |
457 | |
458 init_wm(); | |
459 | |
460 clipboard = g_object_new(GNT_TYPE_CLIPBOARD, NULL); | |
461 } | |
462 | |
463 void gnt_main() | |
464 { | |
465 wm->loop = g_main_loop_new(NULL, FALSE); | |
466 g_main_loop_run(wm->loop); | |
467 } | |
468 | |
469 /********************************* | |
470 * Stuff for 'window management' * | |
471 *********************************/ | |
472 | |
473 void gnt_screen_occupy(GntWidget *widget) | |
474 { | |
475 gnt_wm_new_window(wm, widget); | |
476 } | |
477 | |
478 void gnt_screen_release(GntWidget *widget) | |
479 { | |
480 gnt_wm_window_close(wm, widget); | |
481 } | |
482 | |
483 void gnt_screen_update(GntWidget *widget) | |
484 { | |
485 gnt_wm_update_window(wm, widget); | |
486 } | |
487 | |
488 gboolean gnt_widget_has_focus(GntWidget *widget) | |
489 { | |
490 GntWidget *w; | |
491 if (!widget) | |
492 return FALSE; | |
493 | |
494 if (GNT_IS_MENU(widget)) | |
495 return TRUE; | |
496 | |
497 w = widget; | |
498 | |
499 while (widget->parent) | |
500 widget = widget->parent; | |
501 | |
502 if (widget == wm->_list.window) | |
503 return TRUE; | |
504 if (wm->ordered && wm->ordered->data == widget) { | |
505 if (GNT_IS_BOX(widget) && | |
506 (GNT_BOX(widget)->active == w || widget == w)) | |
507 return TRUE; | |
508 } | |
509 return FALSE; | |
510 } | |
511 | |
512 void gnt_widget_set_urgent(GntWidget *widget) | |
513 { | |
514 while (widget->parent) | |
515 widget = widget->parent; | |
516 | |
517 if (wm->ordered && wm->ordered->data == widget) | |
518 return; | |
519 | |
520 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_URGENT); | |
521 | |
522 gnt_wm_update_window(wm, widget); | |
523 } | |
524 | |
525 void gnt_quit() | |
526 { | |
527 g_hash_table_destroy(wm->nodes); /* XXX: */ | |
528 update_panels(); | |
529 doupdate(); | |
530 gnt_uninit_colors(); | |
531 gnt_uninit_styles(); | |
532 endwin(); | |
533 } | |
534 | |
535 gboolean gnt_ascii_only() | |
536 { | |
537 return ascii_only; | |
538 } | |
539 | |
540 void gnt_screen_resize_widget(GntWidget *widget, int width, int height) | |
541 { | |
542 gnt_wm_resize_window(wm, widget, width, height); | |
543 } | |
544 | |
545 void gnt_screen_move_widget(GntWidget *widget, int x, int y) | |
546 { | |
547 gnt_wm_move_window(wm, widget, x, y); | |
548 } | |
549 | |
550 void gnt_screen_rename_widget(GntWidget *widget, const char *text) | |
551 { | |
552 gnt_box_set_title(GNT_BOX(widget), text); | |
553 gnt_widget_draw(widget); | |
554 gnt_wm_update_window(wm, widget); | |
555 } | |
556 | |
557 void gnt_register_action(const char *label, void (*callback)()) | |
558 { | |
559 GntAction *action = g_new0(GntAction, 1); | |
560 action->label = g_strdup(label); | |
561 action->callback = callback; | |
562 | |
563 wm->acts = g_list_append(wm->acts, action); | |
564 } | |
565 | |
566 static void | |
567 reset_menu(GntWidget *widget, gpointer null) | |
568 { | |
569 wm->menu = NULL; | |
570 } | |
571 | |
572 gboolean gnt_screen_menu_show(gpointer newmenu) | |
573 { | |
574 if (wm->menu) { | |
575 /* For now, if a menu is being displayed, then another menu | |
576 * can NOT take over. */ | |
577 return FALSE; | |
578 } | |
579 | |
580 wm->menu = newmenu; | |
581 GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); | |
582 gnt_widget_draw(GNT_WIDGET(wm->menu)); | |
583 | |
584 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
|
585 g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); |
15817 | 586 |
587 return TRUE; | |
588 } | |
589 | |
590 void gnt_set_clipboard_string(gchar *string) | |
591 { | |
592 gnt_clipboard_set_string(clipboard, string); | |
593 } | |
594 | |
595 GntClipboard *gnt_get_clipboard() | |
596 { | |
597 return clipboard; | |
598 } | |
599 gchar *gnt_get_clipboard_string() | |
600 { | |
601 return gnt_clipboard_get_string(clipboard); | |
602 } |