Mercurial > pidgin
comparison console/libgnt/gntmain.c @ 15780:567097a973c6
Do some funky stuff with the escape key.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 09 Mar 2007 01:44:18 +0000 |
parents | c9f0d675196a |
children | 682022b8a129 |
comparison
equal
deleted
inserted
replaced
15779:c9f0d675196a | 15780:567097a973c6 |
---|---|
48 | 48 |
49 static gboolean refresh_screen(); | 49 static gboolean refresh_screen(); |
50 | 50 |
51 GntWM *wm; | 51 GntWM *wm; |
52 static GntClipboard *clipboard; | 52 static GntClipboard *clipboard; |
53 | |
54 #define HOLDING_ESCAPE (escape_stuff.timer != 0) | |
55 | |
56 static struct { | |
57 int timer; | |
58 } escape_stuff; | |
59 | |
60 static gboolean | |
61 escape_timeout(gpointer data) | |
62 { | |
63 gnt_wm_process_input(wm, "\033"); | |
64 escape_stuff.timer = 0; | |
65 return FALSE; | |
66 } | |
53 | 67 |
54 /** | 68 /** |
55 * Mouse support: | 69 * Mouse support: |
56 * - bring a window on top if you click on its taskbar | 70 * - bring a window on top if you click on its taskbar |
57 * - click on the top-bar of the active window and drag+drop to move a window | 71 * - click on the top-bar of the active window and drag+drop to move a window |
178 | 192 |
179 static gboolean | 193 static gboolean |
180 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) | 194 io_invoke(GIOChannel *source, GIOCondition cond, gpointer null) |
181 { | 195 { |
182 char keys[256]; | 196 char keys[256]; |
183 int rd = read(STDIN_FILENO, keys, sizeof(keys) - 1); | 197 int rd = read(STDIN_FILENO, keys + HOLDING_ESCAPE, sizeof(keys) - 1 - HOLDING_ESCAPE); |
184 char *k; | 198 char *k; |
185 if (rd < 0) | 199 if (rd < 0) |
186 { | 200 { |
187 int ch = getch(); /* This should return ERR, but let's see what it really returns */ | 201 int ch = getch(); /* This should return ERR, but let's see what it really returns */ |
188 endwin(); | 202 endwin(); |
195 endwin(); | 209 endwin(); |
196 printf("EOF\n"); | 210 printf("EOF\n"); |
197 raise(SIGABRT); | 211 raise(SIGABRT); |
198 } | 212 } |
199 | 213 |
214 rd += HOLDING_ESCAPE; | |
200 keys[rd] = 0; | 215 keys[rd] = 0; |
201 gnt_keys_refine(keys); | |
202 | |
203 if (mouse_enabled && detect_mouse_action(keys)) | 216 if (mouse_enabled && detect_mouse_action(keys)) |
204 return TRUE; | 217 return TRUE; |
205 | 218 |
219 if (HOLDING_ESCAPE) | |
220 keys[0] = '\033'; | |
206 k = keys; | 221 k = keys; |
207 while (rd) { | 222 while (rd) { |
208 char back; | 223 char back; |
209 int p = MAX(1, gnt_keys_find_combination(k)); | 224 int p; |
225 | |
226 if (k[0] == '\033' && rd == 1) { | |
227 if (escape_stuff.timer) { | |
228 gnt_wm_process_input(wm, "\033\033"); | |
229 g_source_remove(escape_stuff.timer); | |
230 escape_stuff.timer = 0; | |
231 break; | |
232 } | |
233 escape_stuff.timer = g_timeout_add(250, escape_timeout, NULL); | |
234 break; | |
235 } | |
236 | |
237 gnt_keys_refine(k); | |
238 p = MAX(1, gnt_keys_find_combination(k)); | |
210 back = k[p]; | 239 back = k[p]; |
211 k[p] = '\0'; | 240 k[p] = '\0'; |
212 gnt_wm_process_input(wm, k); /* XXX: */ | 241 gnt_wm_process_input(wm, k); /* XXX: */ |
213 k[p] = back; | 242 k[p] = back; |
214 rd -= p; | 243 rd -= p; |
221 static void | 250 static void |
222 setup_io() | 251 setup_io() |
223 { | 252 { |
224 int result; | 253 int result; |
225 channel = g_io_channel_unix_new(STDIN_FILENO); | 254 channel = g_io_channel_unix_new(STDIN_FILENO); |
255 g_io_channel_set_close_on_unref(channel, TRUE); | |
226 | 256 |
227 #if 0 | 257 #if 0 |
228 g_io_channel_set_encoding(channel, NULL, NULL); | 258 g_io_channel_set_encoding(channel, NULL, NULL); |
229 g_io_channel_set_buffered(channel, FALSE); | 259 g_io_channel_set_buffered(channel, FALSE); |
230 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); | 260 g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL ); |