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