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