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