462
|
1 /* The event_stream interface for X11 with gtk, and/or tty frames.
|
|
2 Copyright (C) 1991-5, 1997 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
788
|
4 Copyright (C) 1996, 2001, 2002 Ben Wing.
|
462
|
5 Copyright (C) 2000 William Perry.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* This file is heavily based upon event-Xt.c */
|
|
25
|
|
26 /* Synched up with: Not in FSF. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "console-gtk.h"
|
|
32
|
|
33 #include "blocktype.h"
|
|
34 #include "buffer.h"
|
|
35 #include "commands.h"
|
|
36 #include "console.h"
|
|
37 #include "console-tty.h"
|
|
38 #include "events.h"
|
|
39 #include "frame.h"
|
|
40 #include "objects-gtk.h"
|
|
41 #include "process.h"
|
|
42 #include "redisplay.h"
|
|
43 #include "elhash.h"
|
|
44
|
|
45 #include "gtk-xemacs.h"
|
|
46
|
|
47 #include "systime.h"
|
|
48 #include "sysproc.h" /* for MAXDESC */
|
|
49
|
|
50 #include "lstream.h"
|
|
51 #include "file-coding.h"
|
|
52
|
|
53 #include <gdk/gdkkeysyms.h>
|
|
54
|
|
55 #ifdef HAVE_DRAGNDROP
|
|
56 #include "dragdrop.h"
|
|
57 #endif
|
|
58
|
|
59 #if defined (HAVE_OFFIX_DND)
|
|
60 #include "offix.h"
|
|
61 #endif
|
|
62
|
778
|
63 #include <gdk/gdkx.h>
|
462
|
64
|
778
|
65 #include "event-gtk.h"
|
462
|
66
|
|
67 static struct event_stream *gtk_event_stream;
|
|
68
|
|
69 /* Do we accept events sent by other clients? */
|
|
70 int gtk_allow_sendevents;
|
|
71
|
|
72 static int process_events_occurred;
|
|
73 static int tty_events_occurred;
|
|
74
|
|
75 /* Mask of bits indicating the descriptors that we wait for input on */
|
|
76 extern SELECT_TYPE input_wait_mask, process_only_mask, tty_only_mask;
|
|
77
|
|
78 static Lisp_Object gtk_keysym_to_emacs_keysym ();
|
|
79 void debug_process_finalization (struct Lisp_Process *p);
|
|
80 gboolean emacs_gtk_event_handler (GtkWidget *wid /* unused */,
|
|
81 GdkEvent *event,
|
|
82 gpointer closure /* unused */);
|
|
83
|
|
84 static int last_quit_check_signal_tick_count;
|
|
85
|
|
86 Lisp_Object Qkey_mapping;
|
|
87 Lisp_Object Qsans_modifiers;
|
|
88
|
|
89 static void enqueue_gtk_dispatch_event (Lisp_Object event);
|
|
90
|
|
91 #define IS_MODIFIER_KEY(keysym) \
|
|
92 ((((keysym) >= GDK_Shift_L) && ((keysym) <= GDK_Hyper_R)) \
|
|
93 || ((keysym) == GDK_Mode_switch) \
|
|
94 || ((keysym) == GDK_Num_Lock))
|
|
95
|
|
96
|
|
97
|
|
98 /************************************************************************/
|
|
99 /* magic-event handling */
|
|
100 /************************************************************************/
|
|
101 static void
|
|
102 handle_focus_event_1 (struct frame *f, int in_p)
|
|
103 {
|
|
104 /* We don't want to handle the focus change now, because we might
|
|
105 be in an accept-process-output, sleep-for, or sit-for. So
|
|
106 we enqueue it.
|
|
107
|
|
108 Actually, we half handle it: we handle it as far as changing the
|
|
109 box cursor for redisplay, but we don't call any hooks or do any
|
|
110 select-frame stuff until after the sit-for.
|
|
111 */
|
|
112
|
|
113 if (in_p)
|
|
114 {
|
|
115 GTK_WIDGET_SET_FLAGS (FRAME_GTK_TEXT_WIDGET (f), GTK_HAS_FOCUS);
|
|
116 }
|
|
117 else
|
|
118 {
|
|
119 GTK_WIDGET_UNSET_FLAGS (FRAME_GTK_TEXT_WIDGET (f), GTK_HAS_FOCUS);
|
|
120 }
|
|
121 gtk_widget_grab_focus (FRAME_GTK_TEXT_WIDGET (f));
|
|
122 gtk_widget_draw_focus (FRAME_GTK_TEXT_WIDGET (f));
|
|
123
|
|
124 {
|
|
125 Lisp_Object frm;
|
|
126 Lisp_Object conser;
|
|
127 struct gcpro gcpro1;
|
|
128
|
|
129 XSETFRAME (frm, f);
|
|
130 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
131 GCPRO1 (conser);
|
|
132
|
|
133 emacs_handle_focus_change_preliminary (conser);
|
|
134 enqueue_magic_eval_event (emacs_handle_focus_change_final,
|
|
135 conser);
|
|
136 UNGCPRO;
|
|
137 }
|
|
138 }
|
|
139
|
|
140 /* both GDK_MAP and GDK_VISIBILITY_NOTIFY can cause this
|
|
141 JV is_visible has the same semantics as f->visible*/
|
|
142 static void
|
|
143 change_frame_visibility (struct frame *f, int is_visible)
|
|
144 {
|
|
145 Lisp_Object frame;
|
|
146
|
|
147 XSETFRAME (frame, f);
|
|
148
|
|
149 if (!FRAME_VISIBLE_P (f) && is_visible)
|
|
150 {
|
|
151 FRAME_VISIBLE_P (f) = is_visible;
|
|
152 /* This improves the double flicker when uniconifying a frame
|
|
153 some. A lot of it is not showing a buffer which has changed
|
|
154 while the frame was iconified. To fix it further requires
|
|
155 the good 'ol double redisplay structure. */
|
|
156 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
157 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
158 }
|
|
159 else if (FRAME_VISIBLE_P (f) && !is_visible)
|
|
160 {
|
|
161 FRAME_VISIBLE_P (f) = 0;
|
|
162 va_run_hook_with_args (Qunmap_frame_hook, 1, frame);
|
|
163 }
|
|
164 else if (FRAME_VISIBLE_P (f) * is_visible < 0)
|
|
165 {
|
|
166 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f);
|
|
167 if (FRAME_REPAINT_P (f))
|
|
168 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
169 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
170 }
|
|
171 }
|
|
172
|
|
173 static void
|
|
174 handle_map_event (struct frame *f, GdkEvent *event)
|
|
175 {
|
|
176 Lisp_Object frame;
|
|
177
|
|
178 XSETFRAME (frame, f);
|
|
179 if (event->any.type == GDK_MAP)
|
|
180 {
|
|
181 FRAME_GTK_TOTALLY_VISIBLE_P (f) = 1;
|
|
182 change_frame_visibility (f, 1);
|
|
183 }
|
|
184 else
|
|
185 {
|
|
186 FRAME_GTK_TOTALLY_VISIBLE_P (f) = 0;
|
|
187 change_frame_visibility (f, 0);
|
|
188 /* Calling Fframe_iconified_p is the only way we have to
|
|
189 correctly update FRAME_ICONIFIED_P */
|
|
190 Fframe_iconified_p (frame);
|
|
191 }
|
|
192 }
|
|
193
|
|
194 static void
|
|
195 handle_client_message (struct frame *f, GdkEvent *event)
|
|
196 {
|
|
197 Lisp_Object frame;
|
|
198
|
|
199 XSETFRAME (frame, f);
|
|
200
|
|
201 /* The event-Xt code used to handle WM_DELETE_WINDOW here, but we
|
|
202 handle that directly in frame-gtk.c */
|
|
203
|
|
204 if (event->client.message_type == gdk_atom_intern ("WM_PROTOCOLS", 0) &&
|
|
205 (GdkAtom) event->client.data.l[0] == gdk_atom_intern ("WM_TAKE_FOCUS", 0))
|
|
206 {
|
|
207 handle_focus_event_1 (f, 1);
|
|
208 }
|
|
209 }
|
|
210
|
|
211 static void
|
788
|
212 emacs_gtk_format_magic_event (Lisp_Event *emacs_event, Lisp_Object pstream)
|
|
213 {
|
|
214 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
|
|
215 if (CONSOLE_GTK_P (XCONSOLE (console)))
|
|
216 write_c_string (gtk_event_name (event->event.magic.underlying_gdk_event.
|
|
217 type));
|
|
218 }
|
|
219
|
|
220 static int
|
|
221 emacs_gtk_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
|
|
222 {
|
|
223 if (CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) &&
|
|
224 CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
|
225 return (!memcmp (&e1->event.magic.underlying_gdk_event,
|
|
226 &e2->event.magic.underlying_gdk_event,
|
|
227 sizeof (GdkEvent)));
|
|
228 if (CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) ||
|
|
229 CONSOLE_GTK_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
|
230 return 0;
|
|
231 return 1;
|
|
232 }
|
|
233
|
|
234 static Hashcode
|
|
235 emacs_gtk_hash_magic_event (Lisp_Event *e)
|
|
236 {
|
|
237 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
|
|
238 if (CONSOLE_GTK_P (XCONSOLE (console)))
|
|
239 return memory_hash (&e->event.magic.underlying_gdk_event,
|
|
240 sizeof (GdkEvent));
|
|
241 return 0;
|
|
242 }
|
|
243
|
|
244 static void
|
462
|
245 emacs_gtk_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
246 {
|
|
247 /* This function can GC */
|
|
248 GdkEvent *event = &emacs_event->event.magic.underlying_gdk_event;
|
|
249 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
250
|
|
251 if (!FRAME_LIVE_P (f))
|
|
252 return;
|
|
253
|
|
254 switch (event->any.type)
|
|
255 {
|
|
256 case GDK_CLIENT_EVENT:
|
|
257 handle_client_message (f, event);
|
|
258 break;
|
|
259
|
|
260 case GDK_FOCUS_CHANGE:
|
|
261 handle_focus_event_1 (f, event->focus_change.in);
|
|
262 break;
|
|
263
|
|
264 case GDK_MAP:
|
|
265 case GDK_UNMAP:
|
|
266 handle_map_event (f, event);
|
|
267 break;
|
|
268
|
|
269 case GDK_ENTER_NOTIFY:
|
|
270 if (event->crossing.detail != GDK_NOTIFY_INFERIOR)
|
|
271 {
|
|
272 Lisp_Object frame;
|
|
273
|
|
274 XSETFRAME (frame, f);
|
|
275 /* FRAME_X_MOUSE_P (f) = 1; */
|
|
276 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame);
|
|
277 }
|
|
278 break;
|
|
279
|
|
280 case GDK_LEAVE_NOTIFY:
|
|
281 if (event->crossing.detail != GDK_NOTIFY_INFERIOR)
|
|
282 {
|
|
283 Lisp_Object frame;
|
|
284
|
|
285 XSETFRAME (frame, f);
|
|
286 /* FRAME_X_MOUSE_P (f) = 0; */
|
|
287 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame);
|
|
288 }
|
|
289 break;
|
|
290
|
|
291 case GDK_VISIBILITY_NOTIFY: /* window visiblity has changed */
|
|
292 if (event->visibility.window == GET_GTK_WIDGET_WINDOW (FRAME_GTK_SHELL_WIDGET (f)))
|
|
293 {
|
|
294 FRAME_GTK_TOTALLY_VISIBLE_P (f) =
|
|
295 (event->visibility.state == GDK_VISIBILITY_UNOBSCURED);
|
|
296 /* Note that the fvwm pager only sends VisibilityNotify when
|
|
297 changing pages. Is this all we need to do ? JV */
|
|
298 /* Nope. We must at least trigger a redisplay here.
|
|
299 Since this case seems similar to MapNotify, I've
|
|
300 factored out some code to change_frame_visibility().
|
|
301 This triggers the necessary redisplay and runs
|
|
302 (un)map-frame-hook. - dkindred@cs.cmu.edu */
|
|
303 /* Changed it again to support the tristate visibility flag */
|
|
304 change_frame_visibility (f, (event->visibility.state
|
|
305 != GDK_VISIBILITY_FULLY_OBSCURED) ? 1 : -1);
|
|
306 }
|
|
307 break;
|
|
308
|
|
309 default:
|
|
310 break;
|
|
311 }
|
|
312 }
|
|
313
|
|
314 /************************************************************************/
|
|
315 /* Gtk to Emacs event conversion */
|
|
316 /************************************************************************/
|
|
317
|
|
318 static int
|
|
319 keysym_obeys_caps_lock_p (guint sym, struct device *d)
|
|
320 {
|
|
321 struct gtk_device *gd = DEVICE_GTK_DATA (d);
|
|
322 /* Eeeeevil hack. Don't apply Caps_Lock to things that aren't alphabetic
|
|
323 characters, where "alphabetic" means something more than simply A-Z.
|
|
324 That is, if Caps_Lock is down, typing ESC doesn't produce Shift-ESC.
|
|
325 But if shift-lock is down, then it does. */
|
|
326 if (gd->lock_interpretation == GDK_Shift_Lock)
|
|
327 return 1;
|
|
328
|
|
329 return
|
|
330 ((sym >= GDK_A) && (sym <= GDK_Z)) ||
|
|
331 ((sym >= GDK_a) && (sym <= GDK_z)) ||
|
|
332 ((sym >= GDK_Agrave) && (sym <= GDK_Odiaeresis)) ||
|
|
333 ((sym >= GDK_agrave) && (sym <= GDK_odiaeresis)) ||
|
|
334 ((sym >= GDK_Ooblique) && (sym <= GDK_Thorn)) ||
|
|
335 ((sym >= GDK_oslash) && (sym <= GDK_thorn));
|
|
336 }
|
|
337
|
|
338 static void
|
|
339 set_last_server_timestamp (struct device *d, GdkEvent *gdk_event)
|
|
340 {
|
|
341 guint32 t;
|
|
342 switch (gdk_event->type)
|
|
343 {
|
|
344 case GDK_KEY_PRESS:
|
|
345 case GDK_KEY_RELEASE: t = gdk_event->key.time; break;
|
|
346 case GDK_BUTTON_PRESS:
|
|
347 case GDK_2BUTTON_PRESS:
|
|
348 case GDK_3BUTTON_PRESS:
|
|
349 case GDK_BUTTON_RELEASE: t = gdk_event->button.time; break;
|
|
350 case GDK_ENTER_NOTIFY:
|
|
351 case GDK_LEAVE_NOTIFY: t = gdk_event->crossing.time; break;
|
|
352 case GDK_MOTION_NOTIFY: t = gdk_event->motion.time; break;
|
|
353 case GDK_PROPERTY_NOTIFY: t = gdk_event->property.time; break;
|
|
354 case GDK_SELECTION_CLEAR:
|
|
355 case GDK_SELECTION_REQUEST:
|
|
356 case GDK_SELECTION_NOTIFY: t = gdk_event->selection.time; break;
|
|
357 default: return;
|
|
358 }
|
|
359 DEVICE_GTK_LAST_SERVER_TIMESTAMP (d) = t;
|
|
360 }
|
|
361
|
|
362 static Lisp_Object
|
|
363 gtk_keysym_to_emacs_keysym (guint keysym, int simple_p)
|
|
364 {
|
|
365 char *name;
|
|
366 if (keysym >= GDK_exclam && keysym <= GDK_asciitilde)
|
|
367 /* We must assume that the X keysym numbers for the ASCII graphic
|
|
368 characters are the same as their ASCII codes. */
|
|
369 return make_char (keysym);
|
|
370
|
|
371 switch (keysym)
|
|
372 {
|
|
373 /* These would be handled correctly by the default case, but by
|
|
374 special-casing them here we don't garbage a string or call
|
|
375 intern(). */
|
|
376 case GDK_BackSpace: return QKbackspace;
|
|
377 case GDK_Tab: return QKtab;
|
|
378 case GDK_Linefeed: return QKlinefeed;
|
|
379 case GDK_Return: return QKreturn;
|
|
380 case GDK_Escape: return QKescape;
|
|
381 case GDK_space: return QKspace;
|
|
382 case GDK_Delete: return QKdelete;
|
|
383 case 0: return Qnil;
|
|
384 default:
|
|
385 if (simple_p) return Qnil;
|
|
386 /* !!#### not Mule-ized */
|
|
387 name = gdk_keyval_name (keysym);
|
|
388 if (!name || !name[0])
|
|
389 /* This happens if there is a mismatch between the Xlib of
|
|
390 XEmacs and the Xlib of the X server...
|
|
391
|
|
392 Let's hard-code in some knowledge of common keysyms introduced
|
|
393 in recent X11 releases. Snarfed from X11/keysymdef.h
|
|
394
|
|
395 Probably we should add some stuff here for X11R6. */
|
|
396 switch (keysym)
|
|
397 {
|
|
398 case 0xFF95: return KEYSYM ("kp-home");
|
|
399 case 0xFF96: return KEYSYM ("kp-left");
|
|
400 case 0xFF97: return KEYSYM ("kp-up");
|
|
401 case 0xFF98: return KEYSYM ("kp-right");
|
|
402 case 0xFF99: return KEYSYM ("kp-down");
|
|
403 case 0xFF9A: return KEYSYM ("kp-prior");
|
|
404 case 0xFF9B: return KEYSYM ("kp-next");
|
|
405 case 0xFF9C: return KEYSYM ("kp-end");
|
|
406 case 0xFF9D: return KEYSYM ("kp-begin");
|
|
407 case 0xFF9E: return KEYSYM ("kp-insert");
|
|
408 case 0xFF9F: return KEYSYM ("kp-delete");
|
|
409
|
|
410 case 0x1005FF10: return KEYSYM ("SunF36"); /* labeled F11 */
|
|
411 case 0x1005FF11: return KEYSYM ("SunF37"); /* labeled F12 */
|
|
412 default:
|
|
413 {
|
|
414 char buf [64];
|
|
415 sprintf (buf, "unknown-keysym-0x%X", (int) keysym);
|
|
416 return KEYSYM (buf);
|
|
417 }
|
|
418 }
|
|
419 /* If it's got a one-character name, that's good enough. */
|
|
420 if (!name[1])
|
|
421 return make_char (name[0]);
|
|
422
|
|
423 /* If it's in the "Keyboard" character set, downcase it.
|
|
424 The case of those keysyms is too totally random for us to
|
|
425 force anyone to remember them.
|
|
426 The case of the other character sets is significant, however.
|
|
427 */
|
|
428 if ((((unsigned int) keysym) & (~0x1FF)) == ((unsigned int) 0xFE00))
|
|
429 {
|
|
430 char buf [255];
|
|
431 char *s1, *s2;
|
|
432 for (s1 = name, s2 = buf; *s1; s1++, s2++) {
|
|
433 if (*s1 == '_') {
|
|
434 *s2 = '-';
|
|
435 } else {
|
|
436 *s2 = tolower (* (unsigned char *) s1);
|
|
437 }
|
|
438 }
|
|
439 *s2 = 0;
|
|
440 return KEYSYM (buf);
|
|
441 }
|
|
442 return KEYSYM (name);
|
|
443 }
|
|
444 }
|
|
445
|
|
446 static Lisp_Object
|
|
447 gtk_to_emacs_keysym (struct device *d, GdkEventKey *event, int simple_p)
|
|
448 /* simple_p means don't try too hard (ASCII only) */
|
|
449 {
|
|
450 if (event->length != 1)
|
771
|
451 {
|
462
|
452 /* Generate multiple emacs events */
|
|
453 Emchar ch;
|
|
454 Lisp_Object instream, fb_instream;
|
|
455 Lstream *istr;
|
|
456 struct gcpro gcpro1, gcpro2;
|
|
457
|
|
458 fb_instream =
|
771
|
459 make_fixed_buffer_input_stream ((unsigned char *) event->string, event->length);
|
462
|
460
|
771
|
461 /* #### Use get_coding_system_for_text_file
|
|
462 (Vcomposed_input_coding_system, 0) */
|
462
|
463 instream =
|
771
|
464 make_coding_input_stream (XLSTREAM (fb_instream),
|
|
465 Qundecided, CODING_DECODE);
|
462
|
466
|
|
467 istr = XLSTREAM (instream);
|
|
468
|
|
469 GCPRO2 (instream, fb_instream);
|
|
470 while ((ch = Lstream_get_emchar (istr)) != EOF)
|
771
|
471 {
|
462
|
472 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
473 struct Lisp_Event *ev = XEVENT (emacs_event);
|
|
474 ev->channel = DEVICE_CONSOLE (d);
|
|
475 ev->event_type = key_press_event;
|
|
476 ev->timestamp = event->time;
|
|
477 ev->event.key.modifiers = 0;
|
|
478 ev->event.key.keysym = make_char (ch);
|
|
479 enqueue_gtk_dispatch_event (emacs_event);
|
771
|
480 }
|
462
|
481 Lstream_close (istr);
|
|
482 UNGCPRO;
|
|
483 Lstream_delete (istr);
|
|
484 Lstream_delete (XLSTREAM (fb_instream));
|
|
485 if (IS_MODIFIER_KEY (event->keyval) || (event->keyval == GDK_Mode_switch))
|
771
|
486 return (Qnil);
|
462
|
487 return (gtk_keysym_to_emacs_keysym (event->keyval, simple_p));
|
771
|
488 }
|
462
|
489 else
|
771
|
490 {
|
462
|
491 if (IS_MODIFIER_KEY (event->keyval) || (event->keyval == GDK_Mode_switch))
|
771
|
492 return (Qnil);
|
462
|
493 return (gtk_keysym_to_emacs_keysym (event->keyval, simple_p));
|
771
|
494 }
|
462
|
495 }
|
|
496
|
|
497
|
|
498 /************************************************************************/
|
|
499 /* timeout events */
|
|
500 /************************************************************************/
|
|
501
|
|
502 static int timeout_id_tick;
|
|
503
|
|
504 struct GTK_timeout {
|
|
505 int id;
|
|
506 guint timeout_id;
|
|
507 struct GTK_timeout *next;
|
|
508 } *pending_timeouts, *completed_timeouts;
|
|
509
|
|
510 struct GTK_timeout_blocktype
|
|
511 {
|
|
512 Blocktype_declare (struct GTK_timeout);
|
|
513 } *the_GTK_timeout_blocktype;
|
|
514
|
|
515 /* called by the gtk main loop */
|
|
516 static gint
|
|
517 gtk_timeout_callback (gpointer closure)
|
|
518 {
|
|
519 struct GTK_timeout *timeout = (struct GTK_timeout *) closure;
|
|
520 struct GTK_timeout *t2 = pending_timeouts;
|
|
521
|
|
522 /* Remove this one from the list of pending timeouts */
|
|
523 if (t2 == timeout)
|
|
524 pending_timeouts = pending_timeouts->next;
|
|
525 else
|
|
526 {
|
|
527 while (t2->next && t2->next != timeout) t2 = t2->next;
|
|
528 assert (t2->next);
|
|
529 t2->next = t2->next->next;
|
|
530 }
|
|
531 /* Add this one to the list of completed timeouts */
|
|
532 timeout->next = completed_timeouts;
|
|
533 completed_timeouts = timeout;
|
|
534 return(FALSE);
|
|
535 }
|
|
536
|
|
537 static int
|
|
538 emacs_gtk_add_timeout (EMACS_TIME thyme)
|
|
539 {
|
|
540 struct GTK_timeout *timeout = Blocktype_alloc (the_GTK_timeout_blocktype);
|
|
541 EMACS_TIME current_time;
|
|
542 int milliseconds;
|
|
543
|
|
544 timeout->id = timeout_id_tick++;
|
|
545 timeout->next = pending_timeouts;
|
|
546 pending_timeouts = timeout;
|
|
547 EMACS_GET_TIME (current_time);
|
|
548 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
549 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
550 EMACS_USECS (thyme) / 1000;
|
|
551 if (milliseconds < 1)
|
|
552 milliseconds = 1;
|
|
553 timeout->timeout_id = gtk_timeout_add (milliseconds,
|
|
554 gtk_timeout_callback,
|
|
555 (gpointer) timeout);
|
|
556 return timeout->id;
|
|
557 }
|
|
558
|
|
559 static void
|
|
560 emacs_gtk_remove_timeout (int id)
|
|
561 {
|
|
562 struct GTK_timeout *timeout, *t2;
|
|
563
|
|
564 timeout = NULL;
|
|
565
|
|
566 /* Find the timeout on the list of pending ones, if it's still there. */
|
|
567 if (pending_timeouts)
|
|
568 {
|
|
569 if (id == pending_timeouts->id)
|
|
570 {
|
|
571 timeout = pending_timeouts;
|
|
572 pending_timeouts = pending_timeouts->next;
|
|
573 }
|
|
574 else
|
|
575 {
|
|
576 t2 = pending_timeouts;
|
|
577 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
578 if ( t2->next) /*found it */
|
|
579 {
|
|
580 timeout = t2->next;
|
|
581 t2->next = t2->next->next;
|
|
582 }
|
|
583 }
|
|
584 /* if it was pending, we have removed it from the list */
|
|
585 if (timeout)
|
|
586 gtk_timeout_remove (timeout->timeout_id);
|
|
587 }
|
|
588
|
|
589 /* It could be that the call back was already called but we didn't convert
|
|
590 into an Emacs event yet */
|
|
591 if (!timeout && completed_timeouts)
|
|
592 {
|
|
593 /* Code duplication! */
|
|
594 if (id == completed_timeouts->id)
|
|
595 {
|
|
596 timeout = completed_timeouts;
|
|
597 completed_timeouts = completed_timeouts->next;
|
|
598 }
|
|
599 else
|
|
600 {
|
|
601 t2 = completed_timeouts;
|
|
602 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
603 if ( t2->next) /*found it */
|
|
604 {
|
|
605 timeout = t2->next;
|
|
606 t2->next = t2->next->next;
|
|
607 }
|
|
608 }
|
|
609 }
|
|
610
|
|
611 /* If we found the thing on the lists of timeouts,
|
|
612 and removed it, deallocate
|
|
613 */
|
|
614 if (timeout)
|
|
615 Blocktype_free (the_GTK_timeout_blocktype, timeout);
|
|
616 }
|
|
617
|
|
618 static void
|
|
619 gtk_timeout_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
620 {
|
|
621 struct GTK_timeout *timeout = completed_timeouts;
|
|
622 assert (timeout);
|
|
623 completed_timeouts = completed_timeouts->next;
|
|
624 emacs_event->event_type = timeout_event;
|
|
625 /* timeout events have nil as channel */
|
|
626 emacs_event->timestamp = 0; /* #### wrong!! */
|
|
627 emacs_event->event.timeout.interval_id = timeout->id;
|
|
628 Blocktype_free (the_GTK_timeout_blocktype, timeout);
|
|
629 }
|
|
630
|
|
631
|
|
632 /************************************************************************/
|
|
633 /* process and tty events */
|
|
634 /************************************************************************/
|
|
635
|
|
636 struct what_is_ready_closure
|
|
637 {
|
|
638 int fd;
|
|
639 Lisp_Object what;
|
|
640 gint id;
|
|
641 };
|
|
642
|
|
643 static Lisp_Object *filedesc_with_input;
|
|
644 static struct what_is_ready_closure **filedesc_to_what_closure;
|
|
645
|
|
646 static void
|
|
647 init_what_input_once (void)
|
|
648 {
|
|
649 int i;
|
|
650
|
|
651 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC);
|
|
652 filedesc_to_what_closure =
|
|
653 xnew_array (struct what_is_ready_closure *, MAXDESC);
|
|
654
|
|
655 for (i = 0; i < MAXDESC; i++)
|
|
656 {
|
|
657 filedesc_to_what_closure[i] = 0;
|
|
658 filedesc_with_input[i] = Qnil;
|
|
659 }
|
|
660
|
|
661 process_events_occurred = 0;
|
|
662 tty_events_occurred = 0;
|
|
663 }
|
|
664
|
|
665 static void
|
|
666 mark_what_as_being_ready (struct what_is_ready_closure *closure)
|
|
667 {
|
|
668 if (NILP (filedesc_with_input[closure->fd]))
|
|
669 {
|
|
670 SELECT_TYPE temp_mask;
|
|
671 FD_ZERO (&temp_mask);
|
|
672 FD_SET (closure->fd, &temp_mask);
|
|
673 /* Check to make sure there's *really* input available.
|
|
674 Sometimes things seem to get confused and this gets called
|
|
675 for the tty fd when there's really only input available
|
|
676 on some process's fd. (It will subsequently get called
|
|
677 for that process's fd, so returning without setting any
|
|
678 flags will take care of it.) To see the problem, uncomment
|
|
679 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS
|
|
680 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log'
|
|
681 and press return repeatedly. (Seen under AIX & Linux.)
|
|
682 -dkindred@cs.cmu.edu */
|
|
683 if (!poll_fds_for_input (temp_mask))
|
|
684 {
|
|
685 #if 0
|
|
686 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n",
|
|
687 closure->fd);
|
|
688 #endif
|
|
689 return;
|
|
690 }
|
|
691 filedesc_with_input[closure->fd] = closure->what;
|
|
692 if (PROCESSP (closure->what))
|
|
693 {
|
|
694 /* Don't increment this if the current process is already marked
|
|
695 * as having input. */
|
|
696 process_events_occurred++;
|
|
697 }
|
|
698 else
|
|
699 {
|
|
700 tty_events_occurred++;
|
|
701 }
|
|
702 }
|
|
703 }
|
|
704
|
|
705 static void
|
|
706 gtk_what_callback (gpointer closure, gint source, GdkInputCondition why)
|
|
707 {
|
|
708 /* If closure is 0, then we got a fake event from a signal handler.
|
|
709 The only purpose of this is to make XtAppProcessEvent() stop
|
|
710 blocking. */
|
|
711 if (closure)
|
|
712 mark_what_as_being_ready ((struct what_is_ready_closure *) closure);
|
|
713 else
|
|
714 {
|
|
715 fake_event_occurred++;
|
|
716 drain_signal_event_pipe ();
|
|
717 }
|
|
718 }
|
|
719
|
|
720 static void
|
|
721 select_filedesc (int fd, Lisp_Object what)
|
|
722 {
|
|
723 struct what_is_ready_closure *closure;
|
|
724
|
|
725 /* If somebody is trying to select something that's already selected
|
|
726 for, then something went wrong. The generic routines ought to
|
|
727 detect this and error before here. */
|
|
728 assert (!filedesc_to_what_closure[fd]);
|
|
729
|
|
730 closure = xnew (struct what_is_ready_closure);
|
|
731 closure->fd = fd;
|
|
732 closure->what = what;
|
|
733 closure->id = gdk_input_add (fd, GDK_INPUT_READ,
|
|
734 (GdkInputFunction) gtk_what_callback, closure);
|
|
735 filedesc_to_what_closure[fd] = closure;
|
|
736 }
|
|
737
|
|
738 static void
|
|
739 unselect_filedesc (int fd)
|
|
740 {
|
|
741 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd];
|
|
742
|
|
743 assert (closure);
|
|
744 if (!NILP (filedesc_with_input[fd]))
|
|
745 {
|
|
746 /* We are unselecting this process before we have drained the rest of
|
|
747 the input from it, probably from status_notify() in the command loop.
|
|
748 This can happen like so:
|
|
749
|
|
750 - We are waiting in XtAppNextEvent()
|
|
751 - Process generates output
|
|
752 - Process is marked as being ready
|
|
753 - Process dies, SIGCHLD gets generated before we return (!?)
|
|
754 It could happen I guess.
|
|
755 - sigchld_handler() marks process as dead
|
|
756 - Somehow we end up getting a new KeyPress event on the queue
|
|
757 at the same time (I'm really so sure how that happens but I'm
|
|
758 not sure it can't either so let's assume it can...).
|
|
759 - Key events have priority so we return that instead of the proc.
|
|
760 - Before dispatching the lisp key event we call status_notify()
|
|
761 - Which deselects the process that SIGCHLD marked as dead.
|
|
762
|
|
763 Thus we never remove it from _with_input and turn it into a lisp
|
|
764 event, so we need to do it here. But this does not mean that we're
|
|
765 throwing away the last block of output - status_notify() has already
|
|
766 taken care of running the proc filter or whatever.
|
|
767 */
|
|
768 filedesc_with_input[fd] = Qnil;
|
|
769 if (PROCESSP (closure->what))
|
|
770 {
|
|
771 assert (process_events_occurred > 0);
|
|
772 process_events_occurred--;
|
|
773 }
|
|
774 else
|
|
775 {
|
|
776 assert (tty_events_occurred > 0);
|
|
777 tty_events_occurred--;
|
|
778 }
|
|
779 }
|
|
780 gdk_input_remove (closure->id);
|
|
781 xfree (closure);
|
|
782 filedesc_to_what_closure[fd] = 0;
|
|
783 }
|
|
784
|
|
785 static void
|
|
786 emacs_gtk_select_process (struct Lisp_Process *p)
|
|
787 {
|
|
788 Lisp_Object process;
|
|
789 int infd = event_stream_unixoid_select_process (p);
|
|
790
|
|
791 XSETPROCESS (process, p);
|
|
792 select_filedesc (infd, process);
|
|
793 }
|
|
794
|
|
795 static void
|
|
796 emacs_gtk_unselect_process (struct Lisp_Process *p)
|
|
797 {
|
|
798 int infd = event_stream_unixoid_unselect_process (p);
|
|
799
|
|
800 unselect_filedesc (infd);
|
|
801 }
|
|
802
|
|
803 static USID
|
|
804 emacs_gtk_create_stream_pair (void* inhandle, void* outhandle,
|
|
805 Lisp_Object* instream, Lisp_Object* outstream, int flags)
|
|
806 {
|
|
807 USID u = event_stream_unixoid_create_stream_pair
|
|
808 (inhandle, outhandle, instream, outstream, flags);
|
|
809 if (u != USID_ERROR)
|
|
810 u = USID_DONTHASH;
|
|
811 return u;
|
|
812 }
|
|
813
|
|
814 static USID
|
|
815 emacs_gtk_delete_stream_pair (Lisp_Object instream, Lisp_Object outstream)
|
|
816 {
|
|
817 event_stream_unixoid_delete_stream_pair (instream, outstream);
|
|
818 return USID_DONTHASH;
|
|
819 }
|
|
820
|
|
821 /* This is called from GC when a process object is about to be freed.
|
|
822 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
823 */
|
|
824 void
|
|
825 debug_process_finalization (struct Lisp_Process *p)
|
|
826 {
|
|
827 #if 0 /* #### */
|
|
828 int i;
|
|
829 Lisp_Object instr, outstr;
|
|
830
|
|
831 get_process_streams (p, &instr, &outstr);
|
|
832 /* if it still has fds, then it hasn't been killed yet. */
|
|
833 assert (NILP(instr));
|
|
834 assert (NILP(outstr));
|
|
835 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
836 for (i = 0; i < MAXDESC; i++)
|
|
837 {
|
|
838 Lisp_Object process = filedesc_fds_with_input [i];
|
|
839 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
840 }
|
|
841 #endif
|
|
842 }
|
|
843
|
|
844 static void
|
|
845 gtk_process_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
846 {
|
|
847 int i;
|
|
848 Lisp_Object process;
|
|
849
|
|
850 assert (process_events_occurred > 0);
|
|
851 for (i = 0; i < MAXDESC; i++)
|
|
852 {
|
|
853 process = filedesc_with_input[i];
|
|
854 if (PROCESSP (process))
|
|
855 break;
|
|
856 }
|
|
857 assert (i < MAXDESC);
|
|
858 filedesc_with_input[i] = Qnil;
|
|
859 process_events_occurred--;
|
|
860 /* process events have nil as channel */
|
|
861 emacs_event->event_type = process_event;
|
|
862 emacs_event->timestamp = 0; /* #### */
|
|
863 emacs_event->event.process.process = process;
|
|
864 }
|
|
865
|
|
866 static void
|
|
867 emacs_gtk_select_console (struct console *con)
|
|
868 {
|
|
869 Lisp_Object console;
|
|
870 int infd;
|
|
871
|
|
872 if (CONSOLE_GTK_P (con))
|
|
873 return; /* Gtk consoles are automatically selected for when we initialize them */
|
|
874 infd = event_stream_unixoid_select_console (con);
|
|
875 XSETCONSOLE (console, con);
|
|
876 select_filedesc (infd, console);
|
|
877 }
|
|
878
|
|
879 static void
|
|
880 emacs_gtk_unselect_console (struct console *con)
|
|
881 {
|
|
882 Lisp_Object console;
|
|
883 int infd;
|
|
884
|
|
885 if (CONSOLE_GTK_P (con))
|
|
886 return; /* X consoles are automatically selected for when we initialize them */
|
|
887 infd = event_stream_unixoid_unselect_console (con);
|
|
888 XSETCONSOLE (console, con);
|
|
889 unselect_filedesc (infd);
|
|
890 }
|
|
891
|
|
892 /* read an event from a tty, if one is available. Returns non-zero
|
|
893 if an event was available. Note that when this function is
|
|
894 called, there should always be a tty marked as ready for input.
|
|
895 However, the input condition might actually be EOF, so there
|
|
896 may not really be any input available. (In this case,
|
|
897 read_event_from_tty_or_stream_desc() will arrange for the TTY device
|
|
898 to be deleted.) */
|
|
899
|
|
900 static int
|
|
901 gtk_tty_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
902 {
|
|
903 int i;
|
|
904
|
|
905 assert (tty_events_occurred > 0);
|
|
906 for (i = 0; i < MAXDESC; i++)
|
|
907 {
|
|
908 Lisp_Object console = filedesc_with_input[i];
|
|
909 if (CONSOLEP (console))
|
|
910 {
|
|
911 assert (tty_events_occurred > 0);
|
|
912 tty_events_occurred--;
|
|
913 filedesc_with_input[i] = Qnil;
|
771
|
914 if (read_event_from_tty_or_stream_desc (emacs_event,
|
|
915 XCONSOLE (console)))
|
462
|
916 return 1;
|
|
917 }
|
|
918 }
|
|
919
|
|
920 return 0;
|
|
921 }
|
|
922
|
|
923
|
|
924 /************************************************************************/
|
|
925 /* Drag 'n Drop handling */
|
|
926 /************************************************************************/
|
|
927 #ifdef HAVE_DRAGNDROP
|
|
928 #define TARGET_URI_LIST 0x00
|
|
929 #define TARGET_TEXT_PLAIN 0x01
|
|
930 #define TARGET_FILE_NAME 0x02
|
|
931 #define TARGET_NETSCAPE 0x03
|
|
932
|
|
933 static GdkAtom preferred_targets[10];
|
|
934
|
|
935 void
|
|
936 dragndrop_data_received (GtkWidget *widget,
|
|
937 GdkDragContext *context,
|
|
938 gint x,
|
|
939 gint y,
|
|
940 GtkSelectionData *data,
|
|
941 guint info,
|
|
942 guint time)
|
|
943 {
|
|
944 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
945 struct device *d = gtk_any_window_to_device (widget->window);
|
|
946 struct frame *f = gtk_any_widget_or_parent_to_frame (d, widget);
|
|
947 struct Lisp_Event *ev = XEVENT (event);
|
|
948 Lisp_Object l_type = Qnil, l_data = Qnil;
|
|
949 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
950 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
951
|
|
952 GCPRO4 (l_type, l_data, l_dndlist, l_item);
|
|
953
|
|
954 ev->event_type = misc_user_event;
|
|
955 ev->timestamp = time;
|
|
956
|
|
957 XSETFRAME (ev->channel, f);
|
|
958
|
|
959 ev->event.misc.x = x;
|
|
960 ev->event.misc.y = y;
|
|
961
|
|
962 if (data->type == preferred_targets[TARGET_URI_LIST])
|
|
963 {
|
|
964 /* newline-separated list of URLs */
|
|
965 int start, end;
|
|
966 const char *string_data = (char *) data->data;
|
|
967
|
|
968 l_type = Qdragdrop_URL;
|
|
969
|
|
970 for (start = 0, end = 0; string_data && string_data[end]; end++)
|
|
971 {
|
|
972 if ((string_data[end] == '\r') && (string_data[end+1] == '\n'))
|
|
973 {
|
|
974 l_item = make_string (&string_data[start], end - start);
|
|
975 l_dndlist = Fcons (l_item, l_dndlist);
|
|
976 ++end;
|
|
977 start = ++end;
|
|
978 }
|
|
979 }
|
|
980 }
|
|
981 else if (data->type == preferred_targets[TARGET_TEXT_PLAIN])
|
|
982 {
|
|
983 /* Arbitrary string */
|
|
984 l_type = Qdragdrop_MIME;
|
|
985 l_dndlist = list1 (list3 (list1 (build_string ("text/plain")),
|
|
986 build_string ("8_bit"),
|
|
987 make_ext_string (data->data,
|
|
988 strlen ((char *)data->data),
|
|
989 Qctext)));
|
|
990 }
|
|
991 else if (data->type == preferred_targets[TARGET_FILE_NAME])
|
|
992 {
|
|
993 /* Random filename */
|
|
994 char *hurl = dnd_url_hexify_string (data->data, "file:");
|
|
995
|
665
|
996 l_dndlist = list1 (make_string ((Intbyte *)hurl, strlen (hurl)));
|
462
|
997 l_type = Qdragdrop_URL;
|
|
998
|
|
999 xfree (hurl);
|
|
1000 }
|
|
1001 else if (data->type == preferred_targets[TARGET_NETSCAPE])
|
|
1002 {
|
|
1003 /* Single URL */
|
|
1004 l_dndlist = list1 (make_string ((Extbyte *)data->data,
|
|
1005 strlen ((char *)data->data)));
|
|
1006 l_type = Qdragdrop_URL;
|
|
1007 }
|
|
1008 else
|
|
1009 {
|
|
1010 /* Unknown type - what to do?
|
|
1011 We just pass it up to lisp - we already have a mime type.
|
|
1012 */
|
|
1013 l_type = Qdragdrop_MIME;
|
|
1014 l_dndlist = list1 (list3 (list1 (build_string (gdk_atom_name (data->type))),
|
|
1015 build_string ("8bit"),
|
|
1016 make_ext_string ((Extbyte *) data->data,
|
|
1017 data->length, Qbinary)));
|
|
1018 }
|
|
1019
|
|
1020 ev->event.misc.function = Qdragdrop_drop_dispatch;
|
|
1021 ev->event.misc.object = Fcons (l_type, l_dndlist);
|
|
1022
|
|
1023 UNGCPRO;
|
|
1024
|
|
1025 gtk_drag_finish (context, TRUE, FALSE, time);
|
|
1026 enqueue_gtk_dispatch_event (event);
|
|
1027 }
|
|
1028
|
|
1029 gboolean
|
|
1030 dragndrop_dropped (GtkWidget *widget,
|
|
1031 GdkDragContext *drag_context,
|
|
1032 gint x,
|
|
1033 gint y,
|
|
1034 guint time,
|
|
1035 gpointer user_data)
|
|
1036 {
|
|
1037 /* Netscape drops things like:
|
|
1038 STRING
|
|
1039 _SGI_ICON
|
|
1040 _SGI_ICON_TYPE
|
|
1041 SGI_FILE
|
|
1042 FILE_NAME
|
|
1043 _NETSCAPE_URL
|
|
1044
|
|
1045 gmc drops things like
|
|
1046 application/x-mc-desktop-icon
|
|
1047 text/uri-list
|
|
1048 text/plain
|
|
1049 _NETSCAPE_URL
|
|
1050
|
|
1051 We prefer:
|
|
1052 text/uri-list
|
|
1053 text/plain
|
|
1054 FILE_NAME
|
|
1055 _NETSCAPE_URL
|
|
1056 first one
|
|
1057 */
|
|
1058 GdkAtom found = 0;
|
|
1059 GList *list = drag_context->targets;
|
|
1060
|
|
1061 int i;
|
|
1062
|
|
1063 if (!preferred_targets[0])
|
|
1064 {
|
|
1065 preferred_targets[TARGET_URI_LIST] = gdk_atom_intern ("text/uri-list", FALSE);
|
|
1066 preferred_targets[TARGET_TEXT_PLAIN] = gdk_atom_intern ("text/plain", FALSE);
|
|
1067 preferred_targets[TARGET_FILE_NAME] = gdk_atom_intern ("FILE_NAME", FALSE);
|
|
1068 preferred_targets[TARGET_NETSCAPE] = gdk_atom_intern ("_NETSCAPE_URL", FALSE);
|
|
1069 }
|
|
1070
|
|
1071 #if 0
|
|
1072 stderr_out ("Drop info available in the following formats: \n");
|
|
1073 while (list)
|
|
1074 {
|
|
1075 stderr_out ("\t%s\n", gdk_atom_name ((GdkAtom)list->data));
|
|
1076 list = list->next;
|
|
1077 }
|
|
1078 list = drag_context->targets;
|
|
1079 #endif
|
|
1080
|
|
1081 while (list && !found)
|
|
1082 {
|
|
1083 for (i = 0; preferred_targets[i] && !found; i++)
|
|
1084 {
|
|
1085 if ((GdkAtom) list->data == preferred_targets[i])
|
|
1086 {
|
|
1087 found = (GdkAtom) list->data;
|
|
1088 }
|
|
1089 }
|
|
1090 list = list->next;
|
|
1091 }
|
|
1092
|
|
1093 if (!found)
|
|
1094 {
|
|
1095 found = (GdkAtom) drag_context->targets->data;
|
|
1096 }
|
|
1097
|
|
1098 gtk_drag_get_data (GTK_WIDGET (user_data), drag_context, found, time);
|
|
1099 return (TRUE);
|
|
1100 }
|
|
1101 #endif /* HAVE_DRAGNDROP */
|
|
1102
|
|
1103
|
|
1104 /************************************************************************/
|
|
1105 /* get the next event from gtk */
|
|
1106 /************************************************************************/
|
|
1107
|
|
1108 static Lisp_Object dispatch_event_queue, dispatch_event_queue_tail;
|
|
1109
|
|
1110 static void
|
|
1111 enqueue_gtk_dispatch_event (Lisp_Object event)
|
|
1112 {
|
|
1113 enqueue_event (event, &dispatch_event_queue, &dispatch_event_queue_tail);
|
|
1114 }
|
|
1115
|
|
1116 static Lisp_Object
|
|
1117 dequeue_gtk_dispatch_event (void)
|
|
1118 {
|
|
1119 return dequeue_event (&dispatch_event_queue, &dispatch_event_queue_tail);
|
|
1120 }
|
|
1121
|
|
1122 /* This business exists because menu events "happen" when
|
|
1123 menubar_selection_callback() is called from somewhere deep
|
|
1124 within XtAppProcessEvent in emacs_Xt_next_event(). The
|
|
1125 callback needs to terminate the modal loop in that function
|
|
1126 or else it will continue waiting until another event is
|
|
1127 received.
|
|
1128
|
|
1129 Same business applies to scrollbar events. */
|
|
1130
|
|
1131 void
|
|
1132 signal_special_gtk_user_event (Lisp_Object channel, Lisp_Object function,
|
|
1133 Lisp_Object object)
|
|
1134 {
|
|
1135 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
1136
|
|
1137 XEVENT (event)->event_type = misc_user_event;
|
|
1138 XEVENT (event)->channel = channel;
|
|
1139 XEVENT (event)->event.eval.function = function;
|
|
1140 XEVENT (event)->event.eval.object = object;
|
|
1141
|
|
1142 enqueue_gtk_dispatch_event (event);
|
|
1143 }
|
|
1144
|
|
1145 static void
|
|
1146 emacs_gtk_next_event (struct Lisp_Event *emacs_event)
|
|
1147 {
|
|
1148 we_didnt_get_an_event:
|
|
1149
|
|
1150 while (NILP (dispatch_event_queue) &&
|
|
1151 !completed_timeouts &&
|
|
1152 !fake_event_occurred &&
|
|
1153 !process_events_occurred &&
|
|
1154 !tty_events_occurred)
|
|
1155 {
|
|
1156 gtk_main_iteration();
|
|
1157 }
|
|
1158
|
|
1159 if (!NILP (dispatch_event_queue))
|
|
1160 {
|
|
1161 Lisp_Object event, event2;
|
|
1162 XSETEVENT (event2, emacs_event);
|
|
1163 event = dequeue_gtk_dispatch_event ();
|
|
1164 Fcopy_event (event, event2);
|
|
1165 Fdeallocate_event (event);
|
|
1166 }
|
|
1167 else if (tty_events_occurred)
|
|
1168 {
|
|
1169 if (!gtk_tty_to_emacs_event (emacs_event))
|
|
1170 goto we_didnt_get_an_event;
|
|
1171 }
|
|
1172 else if (completed_timeouts)
|
|
1173 gtk_timeout_to_emacs_event (emacs_event);
|
|
1174 else if (fake_event_occurred)
|
|
1175 {
|
|
1176 /* A dummy event, so that a cycle of the command loop will occur. */
|
|
1177 fake_event_occurred = 0;
|
|
1178 /* eval events have nil as channel */
|
|
1179 emacs_event->event_type = eval_event;
|
|
1180 emacs_event->event.eval.function = Qidentity;
|
|
1181 emacs_event->event.eval.object = Qnil;
|
|
1182 }
|
|
1183 else /* if (process_events_occurred) */
|
|
1184 gtk_process_to_emacs_event (emacs_event);
|
|
1185 }
|
|
1186
|
|
1187 int
|
|
1188 gtk_event_to_emacs_event (struct frame *frame, GdkEvent *gdk_event, struct Lisp_Event *emacs_event)
|
|
1189 {
|
|
1190 struct device *d = NULL;
|
|
1191 struct gtk_device *gd = NULL;
|
|
1192 gboolean accept_any_window = FALSE;
|
|
1193
|
|
1194 if (!frame)
|
|
1195 {
|
|
1196 frame = XFRAME (Fselected_frame (Vdefault_gtk_device));
|
|
1197 accept_any_window = TRUE;
|
|
1198 }
|
|
1199
|
|
1200 d = XDEVICE (FRAME_DEVICE (frame));
|
|
1201 gd = DEVICE_GTK_DATA (d);
|
|
1202
|
|
1203 set_last_server_timestamp (d, gdk_event);
|
|
1204
|
|
1205 switch (gdk_event->type)
|
|
1206 {
|
|
1207 /* XEmacs handles double and triple clicking on its own, and if
|
|
1208 we capture these events, it royally confuses the code in
|
|
1209 ../lisp/mouse.el */
|
|
1210 case GDK_2BUTTON_PRESS:
|
|
1211 case GDK_3BUTTON_PRESS:
|
|
1212 return (0);
|
|
1213
|
|
1214 case GDK_BUTTON_PRESS:
|
|
1215 case GDK_BUTTON_RELEASE:
|
|
1216 /* We need to ignore button events outside our main window or
|
|
1217 things get ugly. The standard scrollbars in Gtk try to be
|
|
1218 nice and pass the button press events up to the parent
|
|
1219 widget. This causes us no end of grief though. Effects
|
|
1220 range from setting point to the wrong place to selecting
|
|
1221 new windows. */
|
|
1222 {
|
|
1223 GdkWindow *w = gdk_window_at_pointer (NULL, NULL);
|
|
1224
|
|
1225 /* If you press mouse button and drag it around, and release
|
|
1226 it outside the window, you will get a NULL GdkWindow at
|
|
1227 pointer. We need to forward these events on to XEmacs so
|
|
1228 that the mouse selection voodoo works.
|
|
1229 */
|
|
1230 if (w && (w != gdk_window_lookup (GDK_ROOT_WINDOW ())))
|
|
1231 {
|
|
1232 GdkEvent ev;
|
|
1233 GtkWidget *wid = NULL;
|
|
1234
|
|
1235 ev.any.window = w;
|
|
1236 wid = gtk_get_event_widget (&ev);
|
|
1237
|
|
1238 if (!GTK_IS_XEMACS (wid) && !accept_any_window)
|
|
1239 {
|
|
1240 return (0);
|
|
1241 }
|
|
1242 }
|
|
1243 if (!accept_any_window)
|
|
1244 gtk_widget_grab_focus (FRAME_GTK_TEXT_WIDGET (frame));
|
|
1245 }
|
|
1246 /* Fall through */
|
|
1247 case GDK_KEY_PRESS:
|
|
1248 {
|
|
1249 unsigned int modifiers = 0;
|
|
1250 int shift_p, lock_p;
|
|
1251 gboolean key_event_p = (gdk_event->type == GDK_KEY_PRESS);
|
|
1252 unsigned int *state =
|
|
1253 key_event_p ? &gdk_event->key.state : &gdk_event->button.state;
|
|
1254
|
|
1255 /* If this is a synthetic KeyPress or Button event, and the user
|
|
1256 has expressed a disinterest in this security hole, then drop
|
|
1257 it on the floor. */
|
|
1258 /* #### BILL!!! Should this be a generic check for ANY synthetic
|
|
1259 event? */
|
|
1260 if ((gdk_event->any.send_event) && !gtk_allow_sendevents)
|
|
1261 return 0;
|
|
1262
|
|
1263 DEVICE_GTK_MOUSE_TIMESTAMP (d) =
|
|
1264 DEVICE_GTK_GLOBAL_MOUSE_TIMESTAMP (d) =
|
|
1265 key_event_p ? gdk_event->key.time : gdk_event->button.time;
|
|
1266
|
|
1267 if (*state & GDK_CONTROL_MASK) modifiers |= XEMACS_MOD_CONTROL;
|
|
1268 if (*state & gd->MetaMask) modifiers |= XEMACS_MOD_META;
|
|
1269 if (*state & gd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
|
|
1270 if (*state & gd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
|
|
1271 if (*state & gd->AltMask) modifiers |= XEMACS_MOD_ALT;
|
|
1272
|
589
|
1273 {
|
|
1274 int numero_de_botao = -1;
|
|
1275
|
|
1276 if (!key_event_p)
|
|
1277 numero_de_botao = gdk_event->button.button;
|
|
1278
|
|
1279 /* the button gets noted either in the button or the modifiers
|
|
1280 field, but not both. */
|
|
1281 if (numero_de_botao != 1 && (*state & GDK_BUTTON1_MASK))
|
|
1282 modifiers |= XEMACS_MOD_BUTTON1;
|
|
1283 if (numero_de_botao != 2 && (*state & GDK_BUTTON2_MASK))
|
|
1284 modifiers |= XEMACS_MOD_BUTTON2;
|
|
1285 if (numero_de_botao != 3 && (*state & GDK_BUTTON3_MASK))
|
|
1286 modifiers |= XEMACS_MOD_BUTTON3;
|
|
1287 if (numero_de_botao != 4 && (*state & GDK_BUTTON4_MASK))
|
|
1288 modifiers |= XEMACS_MOD_BUTTON4;
|
|
1289 if (numero_de_botao != 5 && (*state & GDK_BUTTON5_MASK))
|
|
1290 modifiers |= XEMACS_MOD_BUTTON5;
|
|
1291 }
|
|
1292
|
462
|
1293 /* Ignore the Caps_Lock key if:
|
|
1294 - any other modifiers are down, so that Caps_Lock doesn't
|
|
1295 turn C-x into C-X, which would suck.
|
|
1296 - the event was a mouse event. */
|
|
1297 if (modifiers || ! key_event_p)
|
|
1298 *state &= (~GDK_LOCK_MASK);
|
|
1299
|
|
1300 shift_p = *state & GDK_SHIFT_MASK;
|
|
1301 lock_p = *state & GDK_LOCK_MASK;
|
|
1302
|
|
1303 if (shift_p || lock_p)
|
|
1304 modifiers |= XEMACS_MOD_SHIFT;
|
|
1305
|
|
1306 if (key_event_p)
|
|
1307 {
|
|
1308 GdkEventKey *key_event = &gdk_event->key;
|
|
1309 Lisp_Object keysym;
|
|
1310
|
|
1311 /* This used to compute the frame from the given X window and
|
|
1312 store it here, but we really don't care about the frame. */
|
|
1313 emacs_event->channel = DEVICE_CONSOLE (d);
|
|
1314
|
|
1315 /* Keysym mucking has already been done inside the
|
|
1316 GdkEventKey parsing */
|
|
1317 keysym = gtk_to_emacs_keysym (d, key_event, 0);
|
|
1318
|
|
1319 /* If the emacs keysym is nil, then that means that the X
|
|
1320 keysym was either a Modifier or NoSymbol, which
|
|
1321 probably means that we're in the midst of reading a
|
|
1322 Multi_key sequence, or a "dead" key prefix, or XIM
|
|
1323 input. Ignore it. */
|
|
1324 if (NILP (keysym))
|
|
1325 return 0;
|
|
1326
|
|
1327 /* More Caps_Lock garbage: Caps_Lock should *only* add the
|
|
1328 shift modifier to two-case keys (that is, A-Z and
|
|
1329 related characters). So at this point (after looking up
|
|
1330 the keysym) if the keysym isn't a dual-case alphabetic,
|
|
1331 and if the caps lock key was down but the shift key
|
|
1332 wasn't, then turn off the shift modifier. Gag barf */
|
|
1333 /* #### type lossage: assuming equivalence of emacs and
|
|
1334 X keysyms */
|
|
1335 /* !!#### maybe fix for Mule */
|
|
1336 if (lock_p && !shift_p &&
|
|
1337 ! (CHAR_OR_CHAR_INTP (keysym)
|
|
1338 && keysym_obeys_caps_lock_p
|
|
1339 ((guint) XCHAR_OR_CHAR_INT (keysym), d)))
|
|
1340 modifiers &= (~XEMACS_MOD_SHIFT);
|
|
1341
|
|
1342 /* If this key contains two distinct keysyms, that is,
|
|
1343 "shift" generates a different keysym than the
|
|
1344 non-shifted key, then don't apply the shift modifier
|
|
1345 bit: it's implicit. Otherwise, if there would be no
|
|
1346 other way to tell the difference between the shifted
|
|
1347 and unshifted version of this key, apply the shift bit.
|
|
1348 Non-graphics, like Backspace and F1 get the shift bit
|
|
1349 in the modifiers slot. Neither the characters "a",
|
|
1350 "A", "2", nor "@" normally have the shift bit set.
|
|
1351 However, "F1" normally does. */
|
|
1352 if (modifiers & XEMACS_MOD_SHIFT)
|
|
1353 {
|
|
1354 if (CHAR_OR_CHAR_INTP (keysym))
|
|
1355 {
|
|
1356 modifiers &= ~XEMACS_MOD_SHIFT;
|
|
1357 }
|
|
1358 }
|
|
1359
|
|
1360 emacs_event->event_type = key_press_event;
|
|
1361 emacs_event->timestamp = key_event->time;
|
|
1362 emacs_event->event.key.modifiers = modifiers;
|
|
1363 emacs_event->event.key.keysym = keysym;
|
|
1364 }
|
|
1365 else /* Mouse press/release event */
|
|
1366 {
|
|
1367 GdkEventButton *button_event = &gdk_event->button;
|
|
1368 XSETFRAME (emacs_event->channel, frame);
|
|
1369
|
|
1370 emacs_event->event_type = (button_event->type == GDK_BUTTON_RELEASE) ?
|
|
1371 button_release_event : button_press_event;
|
|
1372
|
|
1373 emacs_event->event.button.modifiers = modifiers;
|
|
1374 emacs_event->timestamp = button_event->time;
|
|
1375 emacs_event->event.button.button = button_event->button;
|
|
1376 emacs_event->event.button.x = button_event->x;
|
|
1377 emacs_event->event.button.y = button_event->y;
|
|
1378 }
|
|
1379 }
|
|
1380 break;
|
|
1381 case GDK_KEY_RELEASE:
|
|
1382 return 0;
|
|
1383 break;
|
|
1384 case GDK_MOTION_NOTIFY:
|
|
1385 {
|
|
1386 GdkEventMotion *ev = &gdk_event->motion;
|
|
1387 unsigned int modifiers = 0;
|
|
1388 gint x,y;
|
|
1389 GdkModifierType mask;
|
|
1390
|
|
1391 /* We use MOTION_HINT_MASK, so we will get only one motion
|
|
1392 event until the next time we call gdk_window_get_pointer or
|
|
1393 the user clicks the mouse. So call gdk_window_get_pointer
|
|
1394 now (meaning that the event will be in sync with the server
|
|
1395 just before Fnext_event() returns). If the mouse is still
|
|
1396 in motion, then the server will immediately generate
|
|
1397 exactly one more motion event, which will be on the queue
|
|
1398 waiting for us next time around. */
|
|
1399 gdk_window_get_pointer (ev->window, &x, &y, &mask);
|
|
1400
|
|
1401 DEVICE_GTK_MOUSE_TIMESTAMP (d) = ev->time;
|
|
1402
|
|
1403 XSETFRAME (emacs_event->channel, frame);
|
|
1404 emacs_event->event_type = pointer_motion_event;
|
|
1405 emacs_event->timestamp = ev->time;
|
|
1406 emacs_event->event.motion.x = x;
|
|
1407 emacs_event->event.motion.y = y;
|
|
1408 if (mask & GDK_SHIFT_MASK) modifiers |= XEMACS_MOD_SHIFT;
|
|
1409 if (mask & GDK_CONTROL_MASK) modifiers |= XEMACS_MOD_CONTROL;
|
|
1410 if (mask & gd->MetaMask) modifiers |= XEMACS_MOD_META;
|
|
1411 if (mask & gd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
|
|
1412 if (mask & gd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
|
|
1413 if (mask & gd->AltMask) modifiers |= XEMACS_MOD_ALT;
|
589
|
1414 if (mask & GDK_BUTTON1_MASK) modifiers |= XEMACS_MOD_BUTTON1;
|
|
1415 if (mask & GDK_BUTTON2_MASK) modifiers |= XEMACS_MOD_BUTTON2;
|
|
1416 if (mask & GDK_BUTTON3_MASK) modifiers |= XEMACS_MOD_BUTTON3;
|
|
1417 if (mask & GDK_BUTTON4_MASK) modifiers |= XEMACS_MOD_BUTTON4;
|
|
1418 if (mask & GDK_BUTTON5_MASK) modifiers |= XEMACS_MOD_BUTTON5;
|
|
1419
|
462
|
1420 /* Currently ignores Shift_Lock but probably shouldn't
|
|
1421 (but it definitely should ignore Caps_Lock). */
|
|
1422 emacs_event->event.motion.modifiers = modifiers;
|
|
1423 }
|
|
1424 break;
|
|
1425
|
|
1426 default: /* it's a magic event */
|
|
1427 return (0);
|
|
1428 break;
|
|
1429 }
|
|
1430 return 1;
|
|
1431 }
|
|
1432
|
|
1433 static const char *event_name (GdkEvent *);
|
|
1434
|
|
1435 static gboolean
|
|
1436 generic_event_handler (GtkWidget *widget, GdkEvent *event)
|
|
1437 {
|
|
1438 Lisp_Object emacs_event = Qnil;
|
|
1439 if (!GTK_IS_XEMACS (widget))
|
|
1440 {
|
|
1441 stderr_out ("Got a %s event for a non-XEmacs widget\n",event_name (event));
|
|
1442 return (FALSE);
|
|
1443 }
|
|
1444
|
|
1445 emacs_event = Fmake_event (Qnil, Qnil);
|
|
1446
|
|
1447 if (gtk_event_to_emacs_event (GTK_XEMACS_FRAME (widget), event, XEVENT (emacs_event)))
|
|
1448 {
|
|
1449 enqueue_gtk_dispatch_event (emacs_event);
|
|
1450 return (TRUE);
|
|
1451 }
|
|
1452 else
|
|
1453 {
|
|
1454 Fdeallocate_event (emacs_event);
|
|
1455 }
|
|
1456 return (FALSE);
|
|
1457 }
|
|
1458
|
|
1459 gint emacs_gtk_key_event_handler(GtkWidget *widget, GdkEventKey *event)
|
|
1460 {
|
|
1461 return (generic_event_handler (widget, (GdkEvent *) event));
|
|
1462 }
|
|
1463
|
|
1464 gint emacs_gtk_button_event_handler(GtkWidget *widget, GdkEventButton *event)
|
|
1465 {
|
|
1466 return (generic_event_handler (widget, (GdkEvent *) event));
|
|
1467 }
|
|
1468
|
|
1469 gint emacs_gtk_motion_event_handler (GtkWidget *widget, GdkEventMotion *event)
|
|
1470 {
|
|
1471 return (generic_event_handler (widget, (GdkEvent *) event));
|
|
1472 }
|
|
1473
|
|
1474 gboolean
|
|
1475 emacs_shell_event_handler (GtkWidget *wid /* unused */,
|
|
1476 GdkEvent *event,
|
|
1477 gpointer closure)
|
|
1478 {
|
|
1479 struct frame *frame = (struct frame *) closure;
|
|
1480 Lisp_Object lisp_event = Fmake_event (Qnil, Qnil);
|
|
1481 struct Lisp_Event *emacs_event = XEVENT (lisp_event);
|
|
1482 GdkEvent *gdk_event_copy = &emacs_event->event.magic.underlying_gdk_event;
|
|
1483 struct device *d = XDEVICE (FRAME_DEVICE (frame));
|
|
1484 gboolean ignore_p = FALSE;
|
|
1485
|
|
1486 set_last_server_timestamp (d, event);
|
|
1487
|
|
1488 #define FROB(event_member) gdk_event_copy->event_member = event->event_member
|
|
1489
|
|
1490 switch (event->type)
|
|
1491 {
|
|
1492 case GDK_SELECTION_REQUEST:
|
|
1493 case GDK_SELECTION_CLEAR:
|
|
1494 case GDK_SELECTION_NOTIFY: FROB(selection); break;
|
|
1495 case GDK_PROPERTY_NOTIFY: FROB(property); break;
|
|
1496 case GDK_CLIENT_EVENT: FROB(client); break;
|
|
1497 case GDK_MAP:
|
|
1498 case GDK_UNMAP: FROB(any); break;
|
|
1499 case GDK_CONFIGURE: FROB(configure); break;
|
|
1500 case GDK_ENTER_NOTIFY:
|
|
1501 case GDK_LEAVE_NOTIFY: FROB(crossing); break;
|
|
1502 case GDK_FOCUS_CHANGE: FROB(focus_change); break;
|
|
1503 case GDK_VISIBILITY_NOTIFY: FROB(visibility); break;
|
|
1504 default:
|
|
1505 ignore_p = TRUE;
|
|
1506 /* Hrmm... do we really want to swallow all the other events as magic? */
|
|
1507 *gdk_event_copy = *event;
|
|
1508 break;
|
|
1509 }
|
|
1510 #undef FROB
|
|
1511
|
|
1512 emacs_event->event_type = magic_event;
|
|
1513 XSETFRAME (emacs_event->channel, frame);
|
|
1514
|
|
1515 if (ignore_p)
|
|
1516 {
|
|
1517 stderr_out ("Ignoring event... (%s)\n", event_name (event));
|
|
1518 Fdeallocate_event (lisp_event);
|
|
1519 return (FALSE);
|
|
1520 }
|
|
1521 else
|
|
1522 {
|
|
1523 enqueue_gtk_dispatch_event (lisp_event);
|
|
1524 return (TRUE);
|
|
1525 }
|
|
1526 }
|
|
1527
|
|
1528
|
|
1529 /************************************************************************/
|
|
1530 /* input pending / C-g checking */
|
|
1531 /************************************************************************/
|
|
1532 static void
|
|
1533 gtk_check_for_quit_char (struct device *d);
|
|
1534
|
|
1535 static void
|
|
1536 check_for_tty_quit_char (struct device *d)
|
|
1537 {
|
|
1538 SELECT_TYPE temp_mask;
|
|
1539 int infd = DEVICE_INFD (d);
|
|
1540 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
1541 Emchar quit_char = CONSOLE_QUIT_CHAR (con);
|
|
1542
|
|
1543 FD_ZERO (&temp_mask);
|
|
1544 FD_SET (infd, &temp_mask);
|
|
1545
|
|
1546 while (1)
|
|
1547 {
|
|
1548 Lisp_Object event;
|
|
1549 Emchar the_char;
|
|
1550
|
|
1551 if (!poll_fds_for_input (temp_mask))
|
|
1552 return;
|
|
1553
|
|
1554 event = Fmake_event (Qnil, Qnil);
|
771
|
1555 if (!read_event_from_tty_or_stream_desc (XEVENT (event), con))
|
462
|
1556 /* EOF, or something ... */
|
|
1557 return;
|
|
1558 /* #### bogus. quit-char should be allowed to be any sort
|
|
1559 of event. */
|
|
1560 the_char = event_to_character (XEVENT (event), 1, 0, 0);
|
|
1561 if (the_char >= 0 && the_char == quit_char)
|
|
1562 {
|
|
1563 Vquit_flag = Qt;
|
|
1564 /* do not queue the C-g. See above. */
|
|
1565 return;
|
|
1566 }
|
|
1567
|
|
1568 /* queue the read event to be read for real later. */
|
|
1569 enqueue_gtk_dispatch_event (event);
|
|
1570 }
|
|
1571 }
|
|
1572
|
|
1573 static void
|
|
1574 emacs_gtk_quit_p (void)
|
|
1575 {
|
|
1576 Lisp_Object devcons, concons;
|
|
1577
|
|
1578 CONSOLE_LOOP (concons)
|
|
1579 {
|
|
1580 struct console *con = XCONSOLE (XCAR (concons));
|
|
1581 if (!con->input_enabled)
|
|
1582 continue;
|
|
1583
|
|
1584 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
1585 {
|
|
1586 struct device *d;
|
|
1587 d = XDEVICE (XCAR (devcons));
|
|
1588
|
|
1589 if (DEVICE_GTK_P (d))
|
|
1590 /* emacs may be exiting */
|
|
1591 gtk_check_for_quit_char (d);
|
|
1592 else if (DEVICE_TTY_P (d))
|
|
1593 check_for_tty_quit_char (d);
|
|
1594 }
|
|
1595 }
|
|
1596 }
|
|
1597
|
|
1598 #include <gdk/gdkx.h>
|
|
1599
|
|
1600 static void
|
|
1601 drain_gtk_queue (void)
|
|
1602
|
|
1603 {
|
|
1604 /* We can't just spin through here and wait for GTKs idea of the
|
|
1605 event queue to get empty, or the queue never gets drained. The
|
|
1606 situation is as follows. A process event gets signalled, we put
|
|
1607 it on the queue, then we go into Fnext_event(), which calls
|
|
1608 drain_gtk_queue(). But gtk_events_pending() will always return
|
|
1609 TRUE if there are file-descriptor (aka our process) events
|
|
1610 pending. Using GDK_events_pending() only shows us windowing
|
|
1611 system events.
|
|
1612 */
|
|
1613 if (GDK_DISPLAY ())
|
|
1614 while (gdk_events_pending ())
|
|
1615 gtk_main_iteration ();
|
|
1616 }
|
|
1617
|
|
1618 static int
|
|
1619 emacs_gtk_event_pending_p (int user_p)
|
|
1620 {
|
|
1621 Lisp_Object event;
|
|
1622 int tick_count_val;
|
|
1623
|
|
1624 /* If `user_p' is false, then this function returns whether there are any
|
|
1625 X, timeout, or fd events pending (that is, whether emacs_gtk_next_event()
|
|
1626 would return immediately without blocking).
|
|
1627
|
|
1628 if `user_p' is true, then this function returns whether there are any
|
|
1629 *user generated* events available (that is, whether there are keyboard
|
|
1630 or mouse-click events ready to be read). This also implies that
|
|
1631 emacs_Xt_next_event() would not block.
|
|
1632
|
|
1633 In a non-SIGIO world, this also checks whether the user has typed ^G,
|
|
1634 since this is a convenient place to do so. We don't need to do this
|
|
1635 in a SIGIO world, since input causes an interrupt.
|
|
1636 */
|
|
1637
|
|
1638 /* This function used to simply check whether there were any X
|
|
1639 events (or if user_p was 1, it iterated over all the pending
|
|
1640 X events using XCheckIfEvent(), looking for keystrokes and
|
|
1641 button events). That worked in the old cheesoid event loop,
|
|
1642 which didn't go through XtAppDispatchEvent(), but it doesn't
|
|
1643 work any more -- X events may not result in anything. For
|
|
1644 example, a button press in a blank part of the menubar appears
|
|
1645 as an X event but will not result in any Emacs events (a
|
|
1646 button press that activates the menubar results in an Emacs
|
|
1647 event through the stop_next_event mechanism).
|
|
1648
|
|
1649 The only accurate way of determining whether these X events
|
|
1650 translate into Emacs events is to go ahead and dispatch them
|
|
1651 until there's something on the dispatch queue. */
|
|
1652
|
|
1653 /* See if there are any user events already on the queue. */
|
|
1654 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
1655 if (!user_p || command_event_p (event))
|
|
1656 return 1;
|
|
1657
|
|
1658 /* See if there's any TTY input available.
|
|
1659 */
|
|
1660 if (poll_fds_for_input (tty_only_mask))
|
|
1661 return 1;
|
|
1662
|
|
1663 if (!user_p)
|
|
1664 {
|
|
1665 /* If not user_p and there are any timer or file-desc events
|
|
1666 pending, we know there will be an event so we're through. */
|
|
1667 /* XtInputMask pending_value; */
|
|
1668
|
|
1669 /* Note that formerly we just checked the value of XtAppPending()
|
|
1670 to determine if there was file-desc input. This doesn't
|
|
1671 work any more with the signal_event_pipe; XtAppPending()
|
|
1672 will says "yes" in this case but there isn't really any
|
|
1673 input. Another way of fixing this problem is for the
|
|
1674 signal_event_pipe to generate actual input in the form
|
|
1675 of an identity eval event or something. (#### maybe this
|
|
1676 actually happens?) */
|
|
1677
|
|
1678 if (poll_fds_for_input (process_only_mask))
|
|
1679 return 1;
|
|
1680
|
|
1681 /* #### Is there any way to do this in Gtk? I don't think there
|
|
1682 is a 'peek' for events */
|
|
1683 #if 0
|
|
1684 pending_value = XtAppPending (Xt_app_con);
|
|
1685
|
|
1686 if (pending_value & XtIMTimer)
|
|
1687 return 1;
|
|
1688 #endif
|
|
1689 }
|
|
1690
|
|
1691 /* XtAppPending() can be super-slow, esp. over a network connection.
|
|
1692 Quantify results have indicated that in some cases the
|
|
1693 call to detect_input_pending() completely dominates the
|
|
1694 running time of redisplay(). Fortunately, in a SIGIO world
|
|
1695 we can more quickly determine whether there are any X events:
|
|
1696 if an event has happened since the last time we checked, then
|
|
1697 a SIGIO will have happened. On a machine with broken SIGIO,
|
|
1698 we'll still be in an OK state -- the sigio_happened flag
|
|
1699 will get set at least once a second, so we'll be no more than
|
|
1700 one second behind reality. (In general it's OK if we
|
|
1701 erroneously report no input pending when input is actually
|
|
1702 pending() -- preemption is just a bit less efficient, that's
|
|
1703 all. It's bad bad bad if you err the other way -- you've
|
|
1704 promised that `next-event' won't block but it actually will,
|
|
1705 and some action might get delayed until the next time you
|
|
1706 hit a key.)
|
|
1707 */
|
|
1708
|
|
1709 /* quit_check_signal_tick_count is volatile so try to avoid race conditions
|
|
1710 by using a temporary variable */
|
|
1711 tick_count_val = quit_check_signal_tick_count;
|
|
1712 if (last_quit_check_signal_tick_count != tick_count_val)
|
|
1713 {
|
|
1714 last_quit_check_signal_tick_count = tick_count_val;
|
|
1715
|
|
1716 /* We need to drain the entire queue now -- if we only
|
|
1717 drain part of it, we may later on end up with events
|
|
1718 actually pending but detect_input_pending() returning
|
|
1719 false because there wasn't another SIGIO. */
|
|
1720
|
|
1721 drain_gtk_queue ();
|
|
1722
|
|
1723 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
1724 if (!user_p || command_event_p (event))
|
|
1725 return 1;
|
|
1726 }
|
|
1727
|
|
1728 return 0;
|
|
1729 }
|
|
1730
|
|
1731
|
|
1732 /************************************************************************/
|
|
1733 /* initialization */
|
|
1734 /************************************************************************/
|
|
1735
|
|
1736 void
|
|
1737 syms_of_event_gtk (void)
|
|
1738 {
|
563
|
1739 DEFSYMBOL (Qkey_mapping);
|
|
1740 DEFSYMBOL (Qsans_modifiers);
|
462
|
1741 }
|
|
1742
|
|
1743 void reinit_vars_of_event_gtk (void)
|
|
1744 {
|
|
1745 gtk_event_stream = xnew (struct event_stream);
|
|
1746 gtk_event_stream->event_pending_p = emacs_gtk_event_pending_p;
|
|
1747 gtk_event_stream->next_event_cb = emacs_gtk_next_event;
|
|
1748 gtk_event_stream->handle_magic_event_cb= emacs_gtk_handle_magic_event;
|
788
|
1749 gtk_event_stream->format_magic_event_cb= emacs_gtk_format_magic_event;
|
|
1750 gtk_event_stream->compare_magic_event_cb= emacs_gtk_compare_magic_event;
|
|
1751 gtk_event_stream->hash_magic_event_cb = emacs_gtk_hash_magic_event;
|
462
|
1752 gtk_event_stream->add_timeout_cb = emacs_gtk_add_timeout;
|
|
1753 gtk_event_stream->remove_timeout_cb = emacs_gtk_remove_timeout;
|
|
1754 gtk_event_stream->select_console_cb = emacs_gtk_select_console;
|
|
1755 gtk_event_stream->unselect_console_cb = emacs_gtk_unselect_console;
|
|
1756 gtk_event_stream->select_process_cb = emacs_gtk_select_process;
|
|
1757 gtk_event_stream->unselect_process_cb = emacs_gtk_unselect_process;
|
|
1758 gtk_event_stream->quit_p_cb = emacs_gtk_quit_p;
|
|
1759 gtk_event_stream->create_stream_pair_cb= emacs_gtk_create_stream_pair;
|
|
1760 gtk_event_stream->delete_stream_pair_cb= emacs_gtk_delete_stream_pair;
|
|
1761
|
|
1762 the_GTK_timeout_blocktype = Blocktype_new (struct GTK_timeout_blocktype);
|
|
1763
|
|
1764 /* this function only makes safe calls */
|
|
1765 init_what_input_once ();
|
|
1766 }
|
|
1767
|
|
1768 void
|
|
1769 vars_of_event_gtk (void)
|
|
1770 {
|
|
1771 reinit_vars_of_event_gtk ();
|
|
1772
|
|
1773 dispatch_event_queue = Qnil;
|
|
1774 staticpro (&dispatch_event_queue);
|
|
1775 dispatch_event_queue_tail = Qnil;
|
464
|
1776 staticpro (&dispatch_event_queue_tail);
|
462
|
1777
|
|
1778 DEFVAR_BOOL ("gtk-allow-sendevents", >k_allow_sendevents /*
|
|
1779 *Non-nil means to allow synthetic events. Nil means they are ignored.
|
|
1780 Beware: allowing emacs to process SendEvents opens a big security hole.
|
|
1781 */ );
|
|
1782 gtk_allow_sendevents = 0;
|
|
1783
|
|
1784 last_quit_check_signal_tick_count = 0;
|
|
1785 }
|
|
1786
|
|
1787 void
|
|
1788 init_event_gtk_late (void) /* called when already initialized */
|
|
1789 {
|
|
1790 timeout_id_tick = 1;
|
|
1791 pending_timeouts = 0;
|
|
1792 completed_timeouts = 0;
|
|
1793
|
|
1794 event_stream = gtk_event_stream;
|
|
1795
|
|
1796 #if 0
|
|
1797 /* Shut GDK the hell up */
|
|
1798 gdk_error_trap_push ();
|
|
1799 #endif
|
|
1800
|
|
1801 gdk_input_add (signal_event_pipe[0], GDK_INPUT_READ,
|
|
1802 (GdkInputFunction) gtk_what_callback, NULL);
|
|
1803 }
|
|
1804
|
|
1805 /* Bogus utility routines */
|
|
1806 static const char *event_name (GdkEvent *ev)
|
|
1807 {
|
|
1808 return (gtk_event_name (ev->any.type));
|
|
1809 }
|
|
1810
|
|
1811 /* This is down at the bottom of the file so I can avoid polluting the
|
|
1812 generic code with this X specific CRAP! */
|
|
1813
|
|
1814 #include <gdk/gdkx.h>
|
|
1815 #include <X11/keysym.h>
|
|
1816 /* #### BILL!!! Fix this please! */
|
|
1817
|
|
1818
|
|
1819 /************************************************************************/
|
|
1820 /* keymap handling */
|
|
1821 /************************************************************************/
|
|
1822
|
|
1823 /* X bogusly doesn't define the interpretations of any bits besides
|
|
1824 ModControl, ModShift, and ModLock; so the Interclient Communication
|
|
1825 Conventions Manual says that we have to bend over backwards to figure
|
|
1826 out what the other modifier bits mean. According to ICCCM:
|
|
1827
|
|
1828 - Any keycode which is assigned ModControl is a "control" key.
|
|
1829
|
|
1830 - Any modifier bit which is assigned to a keycode which generates Meta_L
|
|
1831 or Meta_R is the modifier bit meaning "meta". Likewise for Super, Hyper,
|
|
1832 etc.
|
|
1833
|
|
1834 - Any keypress event which contains ModControl in its state should be
|
|
1835 interpreted as a "control" character.
|
|
1836
|
|
1837 - Any keypress event which contains a modifier bit in its state which is
|
|
1838 generated by a keycode whose corresponding keysym is Meta_L or Meta_R
|
|
1839 should be interpreted as a "meta" character. Likewise for Super, Hyper,
|
|
1840 etc.
|
|
1841
|
|
1842 - It is illegal for a keysym to be associated with more than one modifier
|
|
1843 bit.
|
|
1844
|
|
1845 This means that the only thing that emacs can reasonably interpret as a
|
|
1846 "meta" key is a key whose keysym is Meta_L or Meta_R, and which generates
|
|
1847 one of the modifier bits Mod1-Mod5.
|
|
1848
|
|
1849 Unfortunately, many keyboards don't have Meta keys in their default
|
|
1850 configuration. So, if there are no Meta keys, but there are "Alt" keys,
|
|
1851 emacs will interpret Alt as Meta. If there are both Meta and Alt keys,
|
|
1852 then the Meta keys mean "Meta", and the Alt keys mean "Alt" (it used to
|
|
1853 mean "Symbol," but that just confused the hell out of way too many people).
|
|
1854
|
|
1855 This works with the default configurations of the 19 keyboard-types I've
|
|
1856 checked.
|
|
1857
|
|
1858 Emacs detects keyboard configurations which violate the above rules, and
|
|
1859 prints an error message on the standard-error-output. (Perhaps it should
|
|
1860 use a pop-up-window instead.)
|
|
1861 */
|
|
1862
|
|
1863 static void
|
|
1864 gtk_reset_key_mapping (struct device *d)
|
|
1865 {
|
|
1866 Display *display = GDK_DISPLAY ();
|
|
1867 struct gtk_device *xd = DEVICE_GTK_DATA (d);
|
|
1868 XModifierKeymap *map = (XModifierKeymap *) xd->x_keysym_map;
|
|
1869 KeySym *keysym, *keysym_end;
|
|
1870 Lisp_Object hashtable;
|
|
1871 int key_code_count, keysyms_per_code;
|
|
1872
|
|
1873 if (map)
|
|
1874 XFree ((char *) map);
|
|
1875 XDisplayKeycodes (display,
|
|
1876 &xd->x_keysym_map_min_code,
|
|
1877 &xd->x_keysym_map_max_code);
|
|
1878 key_code_count = xd->x_keysym_map_max_code - xd->x_keysym_map_min_code + 1;
|
|
1879 map = (XModifierKeymap *)
|
|
1880 XGetKeyboardMapping (display, xd->x_keysym_map_min_code, key_code_count,
|
|
1881 &xd->x_keysym_map_keysyms_per_code);
|
|
1882
|
|
1883 xd->x_keysym_map = (void *)map;
|
|
1884 hashtable = xd->x_keysym_map_hashtable;
|
|
1885 if (HASH_TABLEP (hashtable))
|
|
1886 {
|
|
1887 Fclrhash (hashtable);
|
|
1888 }
|
|
1889 else
|
|
1890 {
|
|
1891 xd->x_keysym_map_hashtable = hashtable =
|
|
1892 make_lisp_hash_table (128, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
|
|
1893 }
|
|
1894
|
|
1895 for (keysym = (KeySym *) map,
|
|
1896 keysyms_per_code = xd->x_keysym_map_keysyms_per_code,
|
|
1897 keysym_end = keysym + (key_code_count * keysyms_per_code);
|
|
1898 keysym < keysym_end;
|
|
1899 keysym += keysyms_per_code)
|
|
1900 {
|
|
1901 int j;
|
|
1902
|
|
1903 if (keysym[0] == NoSymbol)
|
|
1904 continue;
|
|
1905
|
|
1906 {
|
771
|
1907 Extbyte *name = XKeysymToString (keysym[0]);
|
462
|
1908 Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[0], 0);
|
|
1909 if (name)
|
|
1910 {
|
771
|
1911 Fputhash (build_ext_string (name, Qnative), Qsans_modifiers,
|
|
1912 hashtable);
|
462
|
1913 Fputhash (sym, Qsans_modifiers, hashtable);
|
|
1914 }
|
|
1915 }
|
|
1916
|
|
1917 for (j = 1; j < keysyms_per_code; j++)
|
|
1918 {
|
|
1919 if (keysym[j] != keysym[0] &&
|
|
1920 keysym[j] != NoSymbol)
|
|
1921 {
|
771
|
1922 Extbyte *name = XKeysymToString (keysym[j]);
|
462
|
1923 Lisp_Object sym = gtk_keysym_to_emacs_keysym (keysym[j], 0);
|
|
1924 if (name && NILP (Fgethash (sym, hashtable, Qnil)))
|
|
1925 {
|
771
|
1926 Fputhash (build_ext_string (name, Qnative), Qt, hashtable);
|
462
|
1927 Fputhash (sym, Qt, hashtable);
|
|
1928 }
|
|
1929 }
|
|
1930 }
|
|
1931 }
|
|
1932 }
|
|
1933
|
|
1934 static const char *
|
|
1935 index_to_name (int indice)
|
|
1936 {
|
|
1937 switch (indice)
|
|
1938 {
|
|
1939 case ShiftMapIndex: return "ModShift";
|
|
1940 case LockMapIndex: return "ModLock";
|
|
1941 case ControlMapIndex: return "ModControl";
|
|
1942 case Mod1MapIndex: return "Mod1";
|
|
1943 case Mod2MapIndex: return "Mod2";
|
|
1944 case Mod3MapIndex: return "Mod3";
|
|
1945 case Mod4MapIndex: return "Mod4";
|
|
1946 case Mod5MapIndex: return "Mod5";
|
|
1947 default: return "???";
|
|
1948 }
|
|
1949 }
|
|
1950
|
|
1951 /* Boy, I really wish C had local functions... */
|
|
1952 struct c_doesnt_have_closures /* #### not yet used */
|
|
1953 {
|
|
1954 int warned_about_overlapping_modifiers;
|
|
1955 int warned_about_predefined_modifiers;
|
|
1956 int warned_about_duplicate_modifiers;
|
|
1957 int meta_bit;
|
|
1958 int hyper_bit;
|
|
1959 int super_bit;
|
|
1960 int alt_bit;
|
|
1961 int mode_bit;
|
|
1962 };
|
|
1963
|
|
1964 static void
|
|
1965 gtk_reset_modifier_mapping (struct device *d)
|
|
1966 {
|
|
1967 Display *display = GDK_DISPLAY ();
|
|
1968 struct gtk_device *xd = DEVICE_GTK_DATA (d);
|
|
1969 int modifier_index, modifier_key, column, mkpm;
|
|
1970 int warned_about_overlapping_modifiers = 0;
|
|
1971 /* int warned_about_predefined_modifiers = 0; */
|
|
1972 /* int warned_about_duplicate_modifiers = 0; */
|
|
1973 int meta_bit = 0;
|
|
1974 int hyper_bit = 0;
|
|
1975 int super_bit = 0;
|
|
1976 int alt_bit = 0;
|
|
1977 int mode_bit = 0;
|
|
1978 XModifierKeymap *map = (XModifierKeymap *) xd->x_modifier_keymap;
|
|
1979
|
|
1980 xd->lock_interpretation = 0;
|
|
1981
|
|
1982 if (map)
|
|
1983 XFreeModifiermap (map);
|
|
1984
|
|
1985 gtk_reset_key_mapping (d);
|
|
1986
|
|
1987 xd->x_modifier_keymap = map = XGetModifierMapping (display);
|
|
1988
|
|
1989 /* Boy, I really wish C had local functions...
|
|
1990 */
|
|
1991
|
|
1992 /* The call to warn_when_safe must be on the same line as the string or
|
|
1993 make-msgfile won't pick it up properly (the newline doesn't confuse
|
|
1994 it, but the backslash does). */
|
|
1995
|
|
1996 #define store_modifier(name,old) \
|
|
1997 old = modifier_index;
|
|
1998
|
|
1999 mkpm = map->max_keypermod;
|
|
2000 for (modifier_index = 0; modifier_index < 8; modifier_index++)
|
|
2001 for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
|
|
2002 KeySym last_sym = 0;
|
|
2003 for (column = 0; column < 4; column += 2) {
|
|
2004 KeyCode code = map->modifiermap[modifier_index * mkpm
|
|
2005 + modifier_key];
|
|
2006 KeySym sym = (code ? XKeycodeToKeysym (display, code, column) : 0);
|
|
2007 if (sym == last_sym) continue;
|
|
2008 last_sym = sym;
|
|
2009 switch (sym) {
|
|
2010 case XK_Mode_switch:store_modifier ("Mode_switch", mode_bit); break;
|
|
2011 case XK_Meta_L: store_modifier ("Meta_L", meta_bit); break;
|
|
2012 case XK_Meta_R: store_modifier ("Meta_R", meta_bit); break;
|
|
2013 case XK_Super_L: store_modifier ("Super_L", super_bit); break;
|
|
2014 case XK_Super_R: store_modifier ("Super_R", super_bit); break;
|
|
2015 case XK_Hyper_L: store_modifier ("Hyper_L", hyper_bit); break;
|
|
2016 case XK_Hyper_R: store_modifier ("Hyper_R", hyper_bit); break;
|
|
2017 case XK_Alt_L: store_modifier ("Alt_L", alt_bit); break;
|
|
2018 case XK_Alt_R: store_modifier ("Alt_R", alt_bit); break;
|
|
2019 #if 0
|
|
2020 case XK_Control_L: check_modifier ("Control_L", ControlMask); break;
|
|
2021 case XK_Control_R: check_modifier ("Control_R", ControlMask); break;
|
|
2022 case XK_Shift_L: check_modifier ("Shift_L", ShiftMask); break;
|
|
2023 case XK_Shift_R: check_modifier ("Shift_R", ShiftMask); break;
|
|
2024 #endif
|
|
2025 case XK_Shift_Lock: /* check_modifier ("Shift_Lock", LockMask); */
|
|
2026 xd->lock_interpretation = XK_Shift_Lock; break;
|
|
2027 case XK_Caps_Lock: /* check_modifier ("Caps_Lock", LockMask); */
|
|
2028 xd->lock_interpretation = XK_Caps_Lock; break;
|
|
2029
|
|
2030 /* It probably doesn't make any sense for a modifier bit to be
|
|
2031 assigned to a key that is not one of the above, but OpenWindows
|
|
2032 assigns modifier bits to a couple of random function keys for
|
|
2033 no reason that I can discern, so printing a warning here would
|
|
2034 be annoying. */
|
|
2035 }
|
|
2036 }
|
|
2037 }
|
|
2038 #undef store_modifier
|
|
2039 #undef check_modifier
|
|
2040 #undef modwarn
|
|
2041 #undef modbarf
|
|
2042
|
|
2043 /* If there was no Meta key, then try using the Alt key instead.
|
|
2044 If there is both a Meta key and an Alt key, then the Alt key
|
|
2045 is not disturbed and remains an Alt key. */
|
|
2046 if (! meta_bit && alt_bit)
|
|
2047 meta_bit = alt_bit, alt_bit = 0;
|
|
2048
|
|
2049 /* mode_bit overrides everything, since it's processed down inside of
|
|
2050 XLookupString() instead of by us. If Meta and Mode_switch both
|
|
2051 generate the same modifier bit (which is an error), then we don't
|
|
2052 interpret that bit as Meta, because we can't make XLookupString()
|
|
2053 not interpret it as Mode_switch; and interpreting it as both would
|
|
2054 be totally wrong. */
|
|
2055 if (mode_bit)
|
|
2056 {
|
|
2057 const char *warn = 0;
|
|
2058 if (mode_bit == meta_bit) warn = "Meta", meta_bit = 0;
|
|
2059 else if (mode_bit == hyper_bit) warn = "Hyper", hyper_bit = 0;
|
|
2060 else if (mode_bit == super_bit) warn = "Super", super_bit = 0;
|
|
2061 else if (mode_bit == alt_bit) warn = "Alt", alt_bit = 0;
|
|
2062 if (warn)
|
|
2063 {
|
|
2064 warn_when_safe
|
|
2065 (Qkey_mapping, Qwarning,
|
|
2066 "XEmacs: %s is being used for both Mode_switch and %s.",
|
|
2067 index_to_name (mode_bit), warn),
|
|
2068 warned_about_overlapping_modifiers = 1;
|
|
2069 }
|
|
2070 }
|
|
2071 #undef index_to_name
|
|
2072
|
|
2073 xd->MetaMask = (meta_bit ? (1 << meta_bit) : 0);
|
|
2074 xd->HyperMask = (hyper_bit ? (1 << hyper_bit) : 0);
|
|
2075 xd->SuperMask = (super_bit ? (1 << super_bit) : 0);
|
|
2076 xd->AltMask = (alt_bit ? (1 << alt_bit) : 0);
|
|
2077 xd->ModeMask = (mode_bit ? (1 << mode_bit) : 0); /* unused */
|
|
2078
|
|
2079 }
|
|
2080
|
|
2081 void
|
|
2082 gtk_init_modifier_mapping (struct device *d)
|
|
2083 {
|
|
2084 struct gtk_device *gd = DEVICE_GTK_DATA (d);
|
|
2085 gd->x_keysym_map_hashtable = Qnil;
|
|
2086 gd->x_keysym_map = NULL;
|
|
2087 gd->x_modifier_keymap = NULL;
|
|
2088 gtk_reset_modifier_mapping (d);
|
|
2089 }
|
|
2090
|
|
2091 #if 0
|
|
2092 static int
|
|
2093 gtk_key_is_modifier_p (KeyCode keycode, struct device *d)
|
|
2094 {
|
|
2095 struct gtk_device *xd = DEVICE_GTK_DATA (d);
|
|
2096 KeySym *syms;
|
|
2097 KeySym *map = (KeySym *) xd->x_keysym_map;
|
|
2098 int i;
|
|
2099
|
|
2100 if (keycode < xd->x_keysym_map_min_code ||
|
|
2101 keycode > xd->x_keysym_map_max_code)
|
|
2102 return 0;
|
|
2103
|
|
2104 syms = &map [(keycode - xd->x_keysym_map_min_code) *
|
|
2105 xd->x_keysym_map_keysyms_per_code];
|
|
2106 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
|
|
2107 if (IsModifierKey (syms [i]) ||
|
|
2108 syms [i] == XK_Mode_switch) /* why doesn't IsModifierKey count this? */
|
|
2109 return 1;
|
|
2110 return 0;
|
|
2111 }
|
|
2112 #endif
|
|
2113
|
|
2114 struct _quit_predicate_closure {
|
|
2115 struct device *device;
|
|
2116 Bool *critical;
|
|
2117 };
|
|
2118
|
|
2119 static Bool
|
|
2120 quit_char_predicate (Display *display, XEvent *event, XPointer data)
|
|
2121 {
|
|
2122 struct _quit_predicate_closure *cl = (struct _quit_predicate_closure *) data;
|
|
2123 struct device *d = cl->device;
|
|
2124 struct frame *f = NULL;
|
|
2125 struct gtk_device *gd = DEVICE_GTK_DATA (d);
|
|
2126 char c, quit_char;
|
|
2127 Bool *critical = cl->critical;
|
|
2128 Lisp_Object keysym;
|
|
2129 GdkWindow *window = gdk_window_lookup (event->xany.window);
|
|
2130 guint32 keycode = 0;
|
|
2131 GdkEventKey gdk_event;
|
|
2132
|
|
2133 if (window)
|
|
2134 f = gtk_any_window_to_frame (d, window);
|
|
2135
|
|
2136 if (critical)
|
|
2137 *critical = False;
|
|
2138
|
|
2139 if ((event->type != KeyPress) ||
|
|
2140 (! window) ||
|
|
2141 (! f) ||
|
|
2142 (event->xkey.state
|
|
2143 & (gd->MetaMask | gd->HyperMask | gd->SuperMask | gd->AltMask)))
|
|
2144 {
|
|
2145 return 0;
|
|
2146 }
|
|
2147
|
|
2148 {
|
|
2149 char dummy[256];
|
|
2150 XLookupString (&(event->xkey), dummy, 200, (KeySym *)&keycode, 0);
|
|
2151 }
|
|
2152
|
|
2153 memset (&gdk_event, 0, sizeof (gdk_event));
|
|
2154 gdk_event.type = GDK_KEY_PRESS;
|
|
2155 gdk_event.window = window;
|
|
2156 gdk_event.keyval = keycode;
|
|
2157 gdk_event.state = event->xkey.state;
|
|
2158
|
|
2159 /* This duplicates some code that exists elsewhere, but it's relatively
|
|
2160 fast and doesn't cons. */
|
|
2161 keysym = gtk_to_emacs_keysym (d, &gdk_event, 1);
|
|
2162 if (NILP (keysym)) return 0;
|
|
2163 if (CHAR_OR_CHAR_INTP (keysym))
|
|
2164 c = XCHAR_OR_CHAR_INT (keysym);
|
|
2165 /* Highly doubtful that these are the quit character, but... */
|
|
2166 else if (EQ (keysym, QKbackspace)) c = '\b';
|
|
2167 else if (EQ (keysym, QKtab)) c = '\t';
|
|
2168 else if (EQ (keysym, QKlinefeed)) c = '\n';
|
|
2169 else if (EQ (keysym, QKreturn)) c = '\r';
|
|
2170 else if (EQ (keysym, QKescape)) c = 27;
|
|
2171 else if (EQ (keysym, QKspace)) c = ' ';
|
|
2172 else if (EQ (keysym, QKdelete)) c = 127;
|
|
2173 else return 0;
|
|
2174
|
|
2175 if (event->xkey.state & gd->MetaMask) c |= 0x80;
|
|
2176 if ((event->xkey.state & ControlMask) && !(c >= 'A' && c <= 'Z'))
|
|
2177 c &= 0x1F; /* unshifted control characters */
|
|
2178 quit_char = CONSOLE_QUIT_CHAR (XCONSOLE (DEVICE_CONSOLE (d)));
|
|
2179
|
|
2180 if (c == quit_char)
|
|
2181 return True;
|
|
2182 /* If we've got Control-Shift-G instead of Control-G, that means
|
|
2183 we have a critical_quit. Caps_Lock is its own modifier, so it
|
|
2184 won't cause ^G to act differently than before. */
|
|
2185 if (event->xkey.state & ControlMask) c &= 0x1F;
|
|
2186 if (c == quit_char)
|
|
2187 {
|
|
2188 if (critical) *critical = True;
|
|
2189 return True;
|
|
2190 }
|
|
2191 return False;
|
|
2192 }
|
|
2193
|
|
2194 static void
|
|
2195 gtk_check_for_quit_char (struct device *d)
|
|
2196 {
|
|
2197 XEvent event;
|
|
2198 int queued;
|
|
2199 Bool critical_quit = False;
|
|
2200 struct _quit_predicate_closure closure;
|
|
2201
|
|
2202 XEventsQueued (GDK_DISPLAY (), QueuedAfterReading);
|
|
2203
|
|
2204 closure.device = d;
|
|
2205 closure.critical = &critical_quit;
|
|
2206
|
|
2207 queued = XCheckIfEvent (GDK_DISPLAY (), &event, quit_char_predicate, (char *) &closure);
|
|
2208
|
|
2209 if (queued)
|
|
2210 {
|
|
2211 Vquit_flag = (critical_quit ? Qcritical : Qt);
|
|
2212 }
|
|
2213 }
|