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