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