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