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