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