428
|
1 /* The event_stream interface for X11 with Xt, 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.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 #include <config.h>
|
|
26 #include "lisp.h"
|
|
27
|
|
28 #include "blocktype.h"
|
771
|
29 #include "charset.h"
|
428
|
30 #include "console.h"
|
872
|
31 #include "device-impl.h"
|
800
|
32 #include "elhash.h"
|
428
|
33 #include "events.h"
|
800
|
34 #include "file-coding.h"
|
872
|
35 #include "frame-impl.h"
|
800
|
36 #include "glyphs.h"
|
|
37 #include "lstream.h"
|
428
|
38 #include "process.h"
|
|
39 #include "redisplay.h"
|
800
|
40 #include "window.h"
|
|
41
|
|
42 #include "console-tty.h"
|
|
43
|
872
|
44 #include "console-x-impl.h"
|
800
|
45 #include "objects-x.h"
|
|
46 #include "../lwlib/lwlib.h"
|
|
47 #include "EmacsFrame.h"
|
|
48
|
|
49 #include "sysproc.h" /* for MAXDESC */
|
428
|
50 #include "systime.h"
|
|
51
|
|
52 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
53 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
54 a core widget directly. We could
|
|
55 use XtGetValues(), but ... */
|
|
56 #include <X11/ShellP.h>
|
|
57
|
800
|
58 #if defined (HAVE_XIM) && defined (XIM_MOTIF)
|
1315
|
59 #include "xmotif.h"
|
428
|
60 #endif
|
|
61
|
|
62 #ifdef HAVE_DRAGNDROP
|
|
63 #include "dragdrop.h"
|
|
64 #endif
|
|
65
|
|
66 #if defined (HAVE_OFFIX_DND)
|
|
67 #include "offix.h"
|
|
68 #endif
|
|
69
|
1292
|
70 #ifdef WIN32_ANY
|
|
71 extern int mswindows_is_blocking;
|
|
72 #endif
|
|
73
|
2828
|
74 /* For Russian C-x processing. */
|
3171
|
75 Lisp_Object Vx_us_keymap_description;
|
|
76 Fixnum Vx_us_keymap_first_keycode;
|
2699
|
77
|
1094
|
78 /* used in glyphs-x.c */
|
|
79 void enqueue_focus_event (Widget wants_it, Lisp_Object frame, int in_p);
|
428
|
80 static void handle_focus_event_1 (struct frame *f, int in_p);
|
863
|
81 static void handle_focus_event_2 (Window w, struct frame *f, int in_p);
|
428
|
82
|
|
83 static struct event_stream *Xt_event_stream;
|
|
84
|
|
85 /* With the new event model, all events go through XtDispatchEvent()
|
|
86 and are picked up by an event handler that is added to each frame
|
|
87 widget. (This is how it's supposed to be.) In the old method,
|
|
88 Emacs sucks out events directly from XtNextEvent() and only
|
|
89 dispatches the events that it doesn't need to deal with. This
|
|
90 old way has lots of corresponding junk that is no longer
|
|
91 necessary: lwlib extensions, synthetic XAnyEvents, unnecessary
|
|
92 magic events, etc. */
|
|
93
|
|
94 /* The one and only one application context that Emacs uses. */
|
|
95 XtAppContext Xt_app_con;
|
|
96
|
|
97 /* Do we accept events sent by other clients? */
|
|
98 int x_allow_sendevents;
|
|
99
|
|
100 #ifdef DEBUG_XEMACS
|
458
|
101 Fixnum debug_x_events;
|
428
|
102 #endif
|
|
103
|
|
104 static int process_events_occurred;
|
|
105 static int tty_events_occurred;
|
450
|
106 static Widget widget_with_focus;
|
428
|
107
|
|
108 /* Mask of bits indicating the descriptors that we wait for input on */
|
1268
|
109 extern SELECT_TYPE input_wait_mask, non_fake_input_wait_mask;
|
|
110 extern SELECT_TYPE process_only_mask, tty_only_mask;
|
428
|
111
|
442
|
112 static const String x_fallback_resources[] =
|
428
|
113 {
|
|
114 /* This file is automatically generated from the app-defaults file
|
|
115 in ../etc/Emacs.ad. These resources are consulted only if no
|
|
116 app-defaults file is found at all.
|
|
117 */
|
|
118 #include <Emacs.ad.h>
|
|
119 0
|
|
120 };
|
|
121
|
|
122 static Lisp_Object x_keysym_to_emacs_keysym (KeySym keysym, int simple_p);
|
|
123 void emacs_Xt_mapping_action (Widget w, XEvent *event);
|
440
|
124 void debug_process_finalization (Lisp_Process *p);
|
428
|
125 void emacs_Xt_event_handler (Widget wid, XtPointer closure, XEvent *event,
|
|
126 Boolean *continue_to_dispatch);
|
|
127
|
|
128 static int last_quit_check_signal_tick_count;
|
|
129
|
|
130 Lisp_Object Qsans_modifiers;
|
|
131
|
1268
|
132 #define THIS_IS_X
|
|
133 #include "event-xlike-inc.c"
|
|
134
|
428
|
135
|
|
136 /************************************************************************/
|
|
137 /* keymap handling */
|
|
138 /************************************************************************/
|
|
139
|
2828
|
140 /* See comment near character_to_event(). */
|
440
|
141 static void
|
2828
|
142 maybe_define_x_key_as_self_inserting_character (KeySym keysym,
|
|
143 Lisp_Object symbol)
|
440
|
144 {
|
|
145 Lisp_Object character = x_keysym_to_character (keysym);
|
|
146
|
|
147 if (CHARP (character))
|
|
148 {
|
|
149 extern Lisp_Object Vcurrent_global_map;
|
2828
|
150 extern Lisp_Object Qcharacter_of_keysym;
|
971
|
151 if (NILP (Flookup_key (Vcurrent_global_map, symbol, Qnil)))
|
|
152 {
|
2828
|
153 Fput (symbol, Qcharacter_of_keysym, character);
|
971
|
154 Fdefine_key (Vcurrent_global_map, symbol, Qself_insert_command);
|
|
155 }
|
440
|
156 }
|
|
157 }
|
|
158
|
2828
|
159 void
|
440
|
160 x_has_keysym (KeySym keysym, Lisp_Object hash_table, int with_modifiers)
|
|
161 {
|
|
162 KeySym upper_lower[2];
|
|
163 int j;
|
|
164
|
|
165 if (keysym < 0x80) /* Optimize for ASCII keysyms */
|
|
166 return;
|
442
|
167
|
|
168 /* If you execute:
|
|
169 xmodmap -e 'keysym NN = scaron'
|
440
|
170 and then press (Shift scaron), X11 will return the different
|
442
|
171 keysym `Scaron', but `xmodmap -pke' might not even mention `Scaron'.
|
|
172 So we "register" both `scaron' and `Scaron'. */
|
|
173 #ifdef HAVE_XCONVERTCASE
|
440
|
174 XConvertCase (keysym, &upper_lower[0], &upper_lower[1]);
|
442
|
175 #else
|
|
176 upper_lower[0] = upper_lower[1] = keysym;
|
|
177 #endif
|
440
|
178
|
|
179 for (j = 0; j < (upper_lower[0] == upper_lower[1] ? 1 : 2); j++)
|
|
180 {
|
2828
|
181 Extbyte *name;
|
440
|
182 keysym = upper_lower[j];
|
|
183
|
|
184 name = XKeysymToString (keysym);
|
|
185 if (name)
|
|
186 {
|
|
187 /* X guarantees NAME to be in the Host Portable Character Encoding */
|
|
188 Lisp_Object sym = x_keysym_to_emacs_keysym (keysym, 0);
|
|
189 Lisp_Object new_value = with_modifiers ? Qt : Qsans_modifiers;
|
|
190 Lisp_Object old_value = Fgethash (sym, hash_table, Qnil);
|
|
191
|
|
192 if (! EQ (old_value, new_value)
|
|
193 && ! (EQ (old_value, Qsans_modifiers) &&
|
|
194 EQ (new_value, Qt)))
|
|
195 {
|
|
196 maybe_define_x_key_as_self_inserting_character (keysym, sym);
|
2828
|
197 Fputhash (build_ext_string (name, Qbinary), new_value,
|
|
198 hash_table);
|
440
|
199 Fputhash (sym, new_value, hash_table);
|
|
200 }
|
|
201 }
|
|
202 }
|
|
203 }
|
|
204
|
428
|
205 static void
|
|
206 x_reset_key_mapping (struct device *d)
|
|
207 {
|
|
208 Display *display = DEVICE_X_DISPLAY (d);
|
|
209 struct x_device *xd = DEVICE_X_DATA (d);
|
|
210 KeySym *keysym, *keysym_end;
|
|
211 Lisp_Object hash_table;
|
|
212 int key_code_count, keysyms_per_code;
|
|
213
|
|
214 if (xd->x_keysym_map)
|
|
215 XFree ((char *) xd->x_keysym_map);
|
|
216 XDisplayKeycodes (display,
|
|
217 &xd->x_keysym_map_min_code,
|
|
218 &xd->x_keysym_map_max_code);
|
|
219 key_code_count = xd->x_keysym_map_max_code - xd->x_keysym_map_min_code + 1;
|
|
220 xd->x_keysym_map =
|
|
221 XGetKeyboardMapping (display, xd->x_keysym_map_min_code, key_code_count,
|
|
222 &xd->x_keysym_map_keysyms_per_code);
|
|
223
|
|
224 hash_table = xd->x_keysym_map_hash_table;
|
|
225 if (HASH_TABLEP (hash_table))
|
|
226 Fclrhash (hash_table);
|
|
227 else
|
|
228 xd->x_keysym_map_hash_table = hash_table =
|
|
229 make_lisp_hash_table (128, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
|
|
230
|
|
231 for (keysym = xd->x_keysym_map,
|
|
232 keysyms_per_code = xd->x_keysym_map_keysyms_per_code,
|
|
233 keysym_end = keysym + (key_code_count * keysyms_per_code);
|
|
234 keysym < keysym_end;
|
|
235 keysym += keysyms_per_code)
|
|
236 {
|
|
237 int j;
|
|
238
|
|
239 if (keysym[0] == NoSymbol)
|
|
240 continue;
|
|
241
|
440
|
242 x_has_keysym (keysym[0], hash_table, 0);
|
428
|
243
|
|
244 for (j = 1; j < keysyms_per_code; j++)
|
|
245 {
|
|
246 if (keysym[j] != keysym[0] &&
|
|
247 keysym[j] != NoSymbol)
|
440
|
248 x_has_keysym (keysym[j], hash_table, 1);
|
428
|
249 }
|
|
250 }
|
|
251 }
|
|
252
|
2828
|
253 static const Ascbyte *
|
428
|
254 index_to_name (int indice)
|
|
255 {
|
|
256 switch (indice)
|
|
257 {
|
|
258 case ShiftMapIndex: return "ModShift";
|
|
259 case LockMapIndex: return "ModLock";
|
|
260 case ControlMapIndex: return "ModControl";
|
|
261 case Mod1MapIndex: return "Mod1";
|
|
262 case Mod2MapIndex: return "Mod2";
|
|
263 case Mod3MapIndex: return "Mod3";
|
|
264 case Mod4MapIndex: return "Mod4";
|
|
265 case Mod5MapIndex: return "Mod5";
|
|
266 default: return "???";
|
|
267 }
|
|
268 }
|
|
269
|
2828
|
270 /* X bogusly doesn't define the interpretations of any bits besides
|
|
271 ModControl, ModShift, and ModLock; so the Interclient Communication
|
|
272 Conventions Manual says that we have to bend over backwards to figure
|
|
273 out what the other modifier bits mean. According to ICCCM:
|
|
274
|
|
275 - Any keycode which is assigned ModControl is a "control" key.
|
|
276
|
|
277 - Any modifier bit which is assigned to a keycode which generates Meta_L
|
|
278 or Meta_R is the modifier bit meaning "meta". Likewise for Super, Hyper,
|
|
279 etc.
|
|
280
|
|
281 - Any keypress event which contains ModControl in its state should be
|
|
282 interpreted as a "control" character.
|
|
283
|
|
284 - Any keypress event which contains a modifier bit in its state which is
|
|
285 generated by a keycode whose corresponding keysym is Meta_L or Meta_R
|
|
286 should be interpreted as a "meta" character. Likewise for Super, Hyper,
|
|
287 etc.
|
|
288
|
|
289 - It is illegal for a keysym to be associated with more than one modifier
|
|
290 bit.
|
|
291
|
|
292 This means that the only thing that emacs can reasonably interpret as a
|
|
293 "meta" key is a key whose keysym is Meta_L or Meta_R, and which generates
|
|
294 one of the modifier bits Mod1-Mod5.
|
|
295
|
|
296 Unfortunately, many keyboards don't have Meta keys in their default
|
|
297 configuration. So, if there are no Meta keys, but there are "Alt" keys,
|
|
298 emacs will interpret Alt as Meta. If there are both Meta and Alt keys,
|
|
299 then the Meta keys mean "Meta", and the Alt keys mean "Alt" (it used to
|
|
300 mean "Symbol," but that just confused the hell out of way too many people).
|
|
301
|
|
302 This works with the default configurations of the 19 keyboard-types I've
|
|
303 checked.
|
|
304
|
|
305 Emacs detects keyboard configurations which violate the above rules, and
|
|
306 gives a warning. */
|
428
|
307
|
|
308 static void
|
|
309 x_reset_modifier_mapping (struct device *d)
|
|
310 {
|
|
311 Display *display = DEVICE_X_DISPLAY (d);
|
|
312 struct x_device *xd = DEVICE_X_DATA (d);
|
|
313 int modifier_index, modifier_key, column, mkpm;
|
|
314 int warned_about_overlapping_modifiers = 0;
|
|
315 int warned_about_predefined_modifiers = 0;
|
|
316 int warned_about_duplicate_modifiers = 0;
|
|
317 int meta_bit = 0;
|
|
318 int hyper_bit = 0;
|
|
319 int super_bit = 0;
|
|
320 int alt_bit = 0;
|
|
321 int mode_bit = 0;
|
|
322
|
|
323 xd->lock_interpretation = 0;
|
|
324
|
|
325 if (xd->x_modifier_keymap)
|
3949
|
326 {
|
|
327 XFreeModifiermap (xd->x_modifier_keymap);
|
|
328 /* Set it to NULL in case we receive two MappingModifier events in a
|
|
329 row, and the second is processed during some CHECK_QUITs within
|
|
330 x_reset_key_mapping. If that happens, XFreeModifierMap will be
|
|
331 called twice on the same map, and we crash. */
|
|
332 xd->x_modifier_keymap = NULL;
|
|
333 }
|
428
|
334
|
|
335 x_reset_key_mapping (d);
|
|
336
|
|
337 xd->x_modifier_keymap = XGetModifierMapping (display);
|
|
338
|
|
339 /* Boy, I really wish C had local functions...
|
|
340 */
|
|
341
|
|
342 /* The call to warn_when_safe must be on the same line as the string or
|
|
343 make-msgfile won't pick it up properly (the newline doesn't confuse
|
|
344 it, but the backslash does). */
|
|
345
|
|
346 #define modwarn(name,old,other) \
|
|
347 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is generated by %s.", \
|
|
348 name, code, index_to_name (old), other), \
|
|
349 warned_about_overlapping_modifiers = 1
|
|
350
|
|
351 #define modbarf(name,other) \
|
|
352 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \
|
|
353 name, code, other), \
|
|
354 warned_about_predefined_modifiers = 1
|
|
355
|
|
356 #define check_modifier(name,mask) \
|
|
357 if ((1<<modifier_index) != mask) \
|
|
358 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \
|
|
359 name, code, index_to_name (modifier_index)), \
|
|
360 warned_about_predefined_modifiers = 1
|
|
361
|
|
362 #define store_modifier(name,old) \
|
|
363 if (old && old != modifier_index) \
|
|
364 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates both %s and %s, which is nonsensical.",\
|
|
365 name, code, index_to_name (old), \
|
|
366 index_to_name (modifier_index)), \
|
|
367 warned_about_duplicate_modifiers = 1; \
|
|
368 if (modifier_index == ShiftMapIndex) modbarf (name,"ModShift"); \
|
|
369 else if (modifier_index == LockMapIndex) modbarf (name,"ModLock"); \
|
|
370 else if (modifier_index == ControlMapIndex) modbarf (name,"ModControl"); \
|
|
371 else if (sym == XK_Mode_switch) \
|
|
372 mode_bit = modifier_index; /* Mode_switch is special, see below... */ \
|
|
373 else if (modifier_index == meta_bit && old != meta_bit) \
|
|
374 modwarn (name, meta_bit, "Meta"); \
|
|
375 else if (modifier_index == super_bit && old != super_bit) \
|
|
376 modwarn (name, super_bit, "Super"); \
|
|
377 else if (modifier_index == hyper_bit && old != hyper_bit) \
|
|
378 modwarn (name, hyper_bit, "Hyper"); \
|
|
379 else if (modifier_index == alt_bit && old != alt_bit) \
|
|
380 modwarn (name, alt_bit, "Alt"); \
|
|
381 else \
|
|
382 old = modifier_index;
|
|
383
|
|
384 mkpm = xd->x_modifier_keymap->max_keypermod;
|
|
385 for (modifier_index = 0; modifier_index < 8; modifier_index++)
|
|
386 for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
|
|
387 KeySym last_sym = 0;
|
|
388 for (column = 0; column < 4; column += 2) {
|
|
389 KeyCode code = xd->x_modifier_keymap->modifiermap[modifier_index * mkpm
|
|
390 + modifier_key];
|
|
391 KeySym sym = (code ? XKeycodeToKeysym (display, code, column) : 0);
|
|
392 if (sym == last_sym) continue;
|
|
393 last_sym = sym;
|
|
394 switch (sym) {
|
|
395 case XK_Mode_switch:store_modifier ("Mode_switch", mode_bit); break;
|
|
396 case XK_Meta_L: store_modifier ("Meta_L", meta_bit); break;
|
|
397 case XK_Meta_R: store_modifier ("Meta_R", meta_bit); break;
|
|
398 case XK_Super_L: store_modifier ("Super_L", super_bit); break;
|
|
399 case XK_Super_R: store_modifier ("Super_R", super_bit); break;
|
|
400 case XK_Hyper_L: store_modifier ("Hyper_L", hyper_bit); break;
|
|
401 case XK_Hyper_R: store_modifier ("Hyper_R", hyper_bit); break;
|
|
402 case XK_Alt_L: store_modifier ("Alt_L", alt_bit); break;
|
|
403 case XK_Alt_R: store_modifier ("Alt_R", alt_bit); break;
|
|
404 case XK_Control_L: check_modifier ("Control_L", ControlMask); break;
|
|
405 case XK_Control_R: check_modifier ("Control_R", ControlMask); break;
|
|
406 case XK_Shift_L: check_modifier ("Shift_L", ShiftMask); break;
|
|
407 case XK_Shift_R: check_modifier ("Shift_R", ShiftMask); break;
|
|
408 case XK_Shift_Lock: check_modifier ("Shift_Lock", LockMask);
|
|
409 xd->lock_interpretation = XK_Shift_Lock; break;
|
|
410 case XK_Caps_Lock: check_modifier ("Caps_Lock", LockMask);
|
|
411 xd->lock_interpretation = XK_Caps_Lock; break;
|
|
412
|
|
413 /* It probably doesn't make any sense for a modifier bit to be
|
|
414 assigned to a key that is not one of the above, but OpenWindows
|
|
415 assigns modifier bits to a couple of random function keys for
|
|
416 no reason that I can discern, so printing a warning here would
|
|
417 be annoying. */
|
|
418 }
|
|
419 }
|
|
420 }
|
|
421 #undef store_modifier
|
|
422 #undef check_modifier
|
|
423 #undef modwarn
|
|
424 #undef modbarf
|
|
425
|
|
426 /* If there was no Meta key, then try using the Alt key instead.
|
|
427 If there is both a Meta key and an Alt key, then the Alt key
|
|
428 is not disturbed and remains an Alt key. */
|
|
429 if (! meta_bit && alt_bit)
|
|
430 meta_bit = alt_bit, alt_bit = 0;
|
|
431
|
|
432 /* mode_bit overrides everything, since it's processed down inside of
|
|
433 XLookupString() instead of by us. If Meta and Mode_switch both
|
|
434 generate the same modifier bit (which is an error), then we don't
|
|
435 interpret that bit as Meta, because we can't make XLookupString()
|
|
436 not interpret it as Mode_switch; and interpreting it as both would
|
|
437 be totally wrong. */
|
|
438 if (mode_bit)
|
|
439 {
|
2828
|
440 const Ascbyte *warn = 0;
|
428
|
441 if (mode_bit == meta_bit) warn = "Meta", meta_bit = 0;
|
|
442 else if (mode_bit == hyper_bit) warn = "Hyper", hyper_bit = 0;
|
|
443 else if (mode_bit == super_bit) warn = "Super", super_bit = 0;
|
|
444 else if (mode_bit == alt_bit) warn = "Alt", alt_bit = 0;
|
|
445 if (warn)
|
|
446 {
|
|
447 warn_when_safe
|
|
448 (Qkey_mapping, Qwarning,
|
|
449 "XEmacs: %s is being used for both Mode_switch and %s.",
|
|
450 index_to_name (mode_bit), warn),
|
|
451 warned_about_overlapping_modifiers = 1;
|
|
452 }
|
|
453 }
|
|
454 #undef index_to_name
|
|
455
|
|
456 xd->MetaMask = (meta_bit ? (1 << meta_bit) : 0);
|
|
457 xd->HyperMask = (hyper_bit ? (1 << hyper_bit) : 0);
|
|
458 xd->SuperMask = (super_bit ? (1 << super_bit) : 0);
|
|
459 xd->AltMask = (alt_bit ? (1 << alt_bit) : 0);
|
|
460 xd->ModeMask = (mode_bit ? (1 << mode_bit) : 0); /* unused */
|
|
461
|
|
462
|
|
463 if (warned_about_overlapping_modifiers)
|
|
464 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
465 " Two distinct modifier keys (such as Meta and Hyper) cannot generate\n"
|
|
466 " the same modifier bit, because Emacs won't be able to tell which\n"
|
|
467 " modifier was actually held down when some other key is pressed. It\n"
|
|
468 " won't be able to tell Meta-x and Hyper-x apart, for example. Change\n"
|
|
469 " one of these keys to use some other modifier bit. If you intend for\n"
|
|
470 " these keys to have the same behavior, then change them to have the\n"
|
|
471 " same keysym as well as the same modifier bit.");
|
|
472
|
|
473 if (warned_about_predefined_modifiers)
|
|
474 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
475 " The semantics of the modifier bits ModShift, ModLock, and ModControl\n"
|
|
476 " are predefined. It does not make sense to assign ModControl to any\n"
|
|
477 " keysym other than Control_L or Control_R, or to assign any modifier\n"
|
|
478 " bits to the \"control\" keysyms other than ModControl. You can't\n"
|
|
479 " turn a \"control\" key into a \"meta\" key (or vice versa) by simply\n"
|
|
480 " assigning the key a different modifier bit. You must also make that\n"
|
|
481 " key generate an appropriate keysym (Control_L, Meta_L, etc).");
|
|
482
|
|
483 /* No need to say anything more for warned_about_duplicate_modifiers. */
|
|
484
|
|
485 if (warned_about_overlapping_modifiers || warned_about_predefined_modifiers)
|
|
486 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
487 " The meanings of the modifier bits Mod1 through Mod5 are determined\n"
|
|
488 " by the keysyms used to control those bits. Mod1 does NOT always\n"
|
|
489 " mean Meta, although some non-ICCCM-compliant programs assume that.");
|
|
490 }
|
|
491
|
|
492 void
|
|
493 x_init_modifier_mapping (struct device *d)
|
|
494 {
|
|
495 struct x_device *xd = DEVICE_X_DATA (d);
|
|
496 xd->x_keysym_map_hash_table = Qnil;
|
|
497 xd->x_keysym_map = NULL;
|
|
498 xd->x_modifier_keymap = NULL;
|
|
499 x_reset_modifier_mapping (d);
|
|
500 }
|
|
501
|
|
502 static int
|
|
503 x_key_is_modifier_p (KeyCode keycode, struct device *d)
|
|
504 {
|
|
505 struct x_device *xd = DEVICE_X_DATA (d);
|
|
506 KeySym *syms;
|
|
507 int i;
|
|
508
|
|
509 if (keycode < xd->x_keysym_map_min_code ||
|
|
510 keycode > xd->x_keysym_map_max_code)
|
|
511 return 0;
|
|
512
|
|
513 syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) *
|
|
514 xd->x_keysym_map_keysyms_per_code];
|
|
515 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
|
|
516 if (IsModifierKey (syms [i]) ||
|
|
517 syms [i] == XK_Mode_switch) /* why doesn't IsModifierKey count this? */
|
|
518 return 1;
|
|
519 return 0;
|
|
520 }
|
|
521
|
|
522 /* key-handling code is always ugly. It just ends up working out
|
|
523 that way.
|
|
524
|
|
525 Here are some pointers:
|
|
526
|
|
527 -- DOWN_MASK indicates which modifiers should be treated as "down"
|
|
528 when the corresponding upstroke happens. It gets reset for
|
|
529 a particular modifier when that modifier goes up, and reset
|
|
530 for all modifiers when a non-modifier key is pressed. Example:
|
|
531
|
|
532 I press Control-A-Shift and then release Control-A-Shift.
|
|
533 I want the Shift key to be sticky but not the Control key.
|
|
534
|
|
535 -- LAST_DOWNKEY and RELEASE_TIME are used to keep track of
|
|
536 auto-repeat -- see below.
|
|
537
|
|
538 -- If a modifier key is sticky, I can unstick it by pressing
|
|
539 the modifier key again. */
|
|
540
|
|
541 static void
|
|
542 x_handle_sticky_modifiers (XEvent *ev, struct device *d)
|
|
543 {
|
|
544 struct x_device *xd;
|
|
545 KeyCode keycode;
|
|
546 int type;
|
|
547
|
|
548 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */
|
|
549 return;
|
|
550
|
|
551 xd = DEVICE_X_DATA (d);
|
|
552 keycode = ev->xkey.keycode;
|
|
553 type = ev->type;
|
|
554
|
|
555 if (keycode < xd->x_keysym_map_min_code ||
|
|
556 keycode > xd->x_keysym_map_max_code)
|
|
557 return;
|
|
558
|
|
559 if (! ((type == KeyPress || type == KeyRelease) &&
|
|
560 x_key_is_modifier_p (keycode, d)))
|
|
561 { /* Not a modifier key */
|
|
562 Bool key_event_p = (type == KeyPress || type == KeyRelease);
|
|
563
|
444
|
564 if (type == ButtonPress
|
|
565 || (type == KeyPress
|
|
566 && ((xd->last_downkey
|
|
567 && ((keycode != xd->last_downkey
|
|
568 || ev->xkey.time != xd->release_time)))
|
|
569 || (INTP (Vmodifier_keys_sticky_time)
|
|
570 && ev->xkey.time
|
|
571 > (xd->modifier_release_time
|
|
572 + XINT (Vmodifier_keys_sticky_time))))))
|
428
|
573 {
|
|
574 xd->need_to_add_mask = 0;
|
|
575 xd->last_downkey = 0;
|
|
576 }
|
444
|
577 else if (type == KeyPress && !xd->last_downkey)
|
|
578 xd->last_downkey = keycode;
|
|
579
|
428
|
580 if (type == KeyPress)
|
|
581 xd->release_time = 0;
|
|
582 if (type == KeyPress || type == ButtonPress)
|
444
|
583 {
|
|
584 xd->down_mask = 0;
|
|
585 xd->modifier_release_time = 0;
|
|
586 }
|
428
|
587
|
|
588 if (key_event_p)
|
|
589 ev->xkey.state |= xd->need_to_add_mask;
|
|
590 else
|
|
591 ev->xbutton.state |= xd->need_to_add_mask;
|
|
592
|
|
593 if (type == KeyRelease && keycode == xd->last_downkey)
|
|
594 /* If I hold press-and-release the Control key and then press
|
|
595 and hold down the right arrow, I want it to auto-repeat
|
|
596 Control-Right. On the other hand, if I do the same but
|
|
597 manually press the Right arrow a bunch of times, I want
|
|
598 to see one Control-Right and then a bunch of Rights.
|
|
599 This means that we need to distinguish between an
|
|
600 auto-repeated key and a key pressed and released a bunch
|
|
601 of times.
|
|
602
|
|
603 Naturally, the designers of the X spec didn't see fit
|
|
604 to provide an obvious way to distinguish these cases.
|
|
605 So we assume that if the release and the next press
|
|
606 occur at the same time, the key was actually auto-
|
|
607 repeated. Under Open-Windows, at least, this works. */
|
444
|
608 xd->modifier_release_time = xd->release_time
|
|
609 = key_event_p ? ev->xkey.time : ev->xbutton.time;
|
428
|
610 }
|
|
611 else /* Modifier key pressed */
|
|
612 {
|
|
613 int i;
|
|
614 KeySym *syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) *
|
|
615 xd->x_keysym_map_keysyms_per_code];
|
|
616
|
|
617 /* If a non-modifier key was pressed in the middle of a bunch
|
|
618 of modifiers, then it unsticks all the modifiers that were
|
|
619 previously pressed. We cannot unstick the modifiers until
|
|
620 now because we want to check for auto-repeat of the
|
|
621 non-modifier key. */
|
|
622
|
|
623 if (xd->last_downkey)
|
|
624 {
|
|
625 xd->last_downkey = 0;
|
|
626 xd->need_to_add_mask = 0;
|
|
627 }
|
|
628
|
444
|
629 if (xd->modifier_release_time
|
|
630 && INTP (Vmodifier_keys_sticky_time)
|
|
631 && (ev->xkey.time
|
|
632 > xd->modifier_release_time + XINT (Vmodifier_keys_sticky_time)))
|
|
633 {
|
|
634 xd->need_to_add_mask = 0;
|
|
635 xd->down_mask = 0;
|
|
636 }
|
|
637
|
428
|
638 #define FROB(mask) \
|
|
639 do { \
|
|
640 if (type == KeyPress) \
|
|
641 { \
|
|
642 /* If modifier key is already sticky, \
|
|
643 then unstick it. Note that we do \
|
|
644 not test down_mask to deal with the \
|
|
645 unlikely but possible case that the \
|
|
646 modifier key auto-repeats. */ \
|
|
647 if (xd->need_to_add_mask & mask) \
|
|
648 { \
|
|
649 xd->need_to_add_mask &= ~mask; \
|
|
650 xd->down_mask &= ~mask; \
|
|
651 } \
|
|
652 else \
|
|
653 xd->down_mask |= mask; \
|
|
654 } \
|
|
655 else \
|
|
656 { \
|
|
657 if (xd->down_mask & mask) \
|
|
658 { \
|
|
659 xd->down_mask &= ~mask; \
|
|
660 xd->need_to_add_mask |= mask; \
|
|
661 } \
|
|
662 } \
|
444
|
663 xd->modifier_release_time = ev->xkey.time; \
|
428
|
664 } while (0)
|
|
665
|
|
666 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
|
|
667 switch (syms[i])
|
|
668 {
|
|
669 case XK_Control_L: case XK_Control_R: FROB (ControlMask); break;
|
|
670 case XK_Shift_L: case XK_Shift_R: FROB (ShiftMask); break;
|
|
671 case XK_Meta_L: case XK_Meta_R: FROB (xd->MetaMask); break;
|
|
672 case XK_Super_L: case XK_Super_R: FROB (xd->SuperMask); break;
|
|
673 case XK_Hyper_L: case XK_Hyper_R: FROB (xd->HyperMask); break;
|
|
674 case XK_Alt_L: case XK_Alt_R: FROB (xd->AltMask); break;
|
|
675 }
|
|
676 }
|
|
677 #undef FROB
|
|
678 }
|
|
679
|
|
680 static void
|
|
681 clear_sticky_modifiers (struct device *d)
|
|
682 {
|
|
683 struct x_device *xd = DEVICE_X_DATA (d);
|
|
684
|
|
685 xd->need_to_add_mask = 0;
|
|
686 xd->last_downkey = 0;
|
|
687 xd->release_time = 0;
|
|
688 xd->down_mask = 0;
|
|
689 }
|
|
690
|
|
691 static int
|
|
692 keysym_obeys_caps_lock_p (KeySym sym, struct device *d)
|
|
693 {
|
|
694 struct x_device *xd = DEVICE_X_DATA (d);
|
|
695 /* Eeeeevil hack. Don't apply Caps_Lock to things that aren't alphabetic
|
|
696 characters, where "alphabetic" means something more than simply A-Z.
|
|
697 That is, if Caps_Lock is down, typing ESC doesn't produce Shift-ESC.
|
|
698 But if shift-lock is down, then it does. */
|
|
699 if (xd->lock_interpretation == XK_Shift_Lock)
|
|
700 return 1;
|
|
701
|
|
702 return
|
|
703 ((sym >= XK_A) && (sym <= XK_Z)) ||
|
|
704 ((sym >= XK_a) && (sym <= XK_z)) ||
|
|
705 ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis)) ||
|
|
706 ((sym >= XK_agrave) && (sym <= XK_odiaeresis)) ||
|
|
707 ((sym >= XK_Ooblique) && (sym <= XK_Thorn)) ||
|
|
708 ((sym >= XK_oslash) && (sym <= XK_thorn));
|
|
709 }
|
|
710
|
|
711 /* called from EmacsFrame.c (actually from Xt itself) when a
|
|
712 MappingNotify event is received. In its infinite wisdom, Xt
|
|
713 decided that Xt event handlers never get MappingNotify events.
|
|
714 O'Reilly Xt Programming Manual 9.1.2 says:
|
|
715
|
|
716 MappingNotify is automatically handled by Xt, so it isn't passed
|
|
717 to event handlers and you don't need to worry about it.
|
|
718
|
|
719 Of course, we DO worry about it, so we need a special translation. */
|
|
720 void
|
2286
|
721 emacs_Xt_mapping_action (Widget UNUSED (w), XEvent *event)
|
428
|
722 {
|
|
723 struct device *d = get_device_from_display (event->xany.display);
|
|
724
|
|
725 if (DEVICE_X_BEING_DELETED (d))
|
|
726 return;
|
|
727 #if 0
|
|
728 /* nyet. Now this is handled by Xt. */
|
|
729 XRefreshKeyboardMapping (&event->xmapping);
|
|
730 #endif
|
|
731 /* xmodmap generates about a billion MappingKeyboard events, followed
|
|
732 by a single MappingModifier event, so it might be worthwhile to
|
|
733 take extra MappingKeyboard events out of the queue before requesting
|
|
734 the current keymap from the server. */
|
|
735 switch (event->xmapping.request)
|
|
736 {
|
|
737 case MappingKeyboard: x_reset_key_mapping (d); break;
|
|
738 case MappingModifier: x_reset_modifier_mapping (d); break;
|
|
739 case MappingPointer: /* Do something here? */ break;
|
2500
|
740 default: ABORT();
|
428
|
741 }
|
|
742 }
|
|
743
|
|
744
|
|
745 /************************************************************************/
|
|
746 /* X to Emacs event conversion */
|
|
747 /************************************************************************/
|
|
748
|
|
749 static Lisp_Object
|
|
750 x_keysym_to_emacs_keysym (KeySym keysym, int simple_p)
|
|
751 {
|
2828
|
752 Extbyte *name;
|
|
753 DECLARE_EISTRING(einame);
|
|
754
|
428
|
755 if (keysym >= XK_exclam && keysym <= XK_asciitilde)
|
|
756 /* We must assume that the X keysym numbers for the ASCII graphic
|
|
757 characters are the same as their ASCII codes. */
|
|
758 return make_char (keysym);
|
|
759
|
|
760 switch (keysym)
|
|
761 {
|
|
762 /* These would be handled correctly by the default case, but by
|
|
763 special-casing them here we don't garbage a string or call
|
|
764 intern(). */
|
|
765 case XK_BackSpace: return QKbackspace;
|
|
766 case XK_Tab: return QKtab;
|
|
767 case XK_Linefeed: return QKlinefeed;
|
|
768 case XK_Return: return QKreturn;
|
|
769 case XK_Escape: return QKescape;
|
|
770 case XK_space: return QKspace;
|
|
771 case XK_Delete: return QKdelete;
|
|
772 case 0: return Qnil;
|
|
773 default:
|
|
774 if (simple_p) return Qnil;
|
|
775 name = XKeysymToString (keysym);
|
|
776 if (!name || !name[0])
|
|
777 /* This happens if there is a mismatch between the Xlib of
|
|
778 XEmacs and the Xlib of the X server...
|
|
779
|
|
780 Let's hard-code in some knowledge of common keysyms introduced
|
|
781 in recent X11 releases. Snarfed from X11/keysymdef.h
|
|
782
|
|
783 Probably we should add some stuff here for X11R6. */
|
|
784 switch (keysym)
|
|
785 {
|
|
786 case 0xFF95: return KEYSYM ("kp-home");
|
|
787 case 0xFF96: return KEYSYM ("kp-left");
|
|
788 case 0xFF97: return KEYSYM ("kp-up");
|
|
789 case 0xFF98: return KEYSYM ("kp-right");
|
|
790 case 0xFF99: return KEYSYM ("kp-down");
|
|
791 case 0xFF9A: return KEYSYM ("kp-prior");
|
|
792 case 0xFF9B: return KEYSYM ("kp-next");
|
|
793 case 0xFF9C: return KEYSYM ("kp-end");
|
|
794 case 0xFF9D: return KEYSYM ("kp-begin");
|
|
795 case 0xFF9E: return KEYSYM ("kp-insert");
|
|
796 case 0xFF9F: return KEYSYM ("kp-delete");
|
|
797
|
|
798 case 0x1005FF10: return KEYSYM ("SunF36"); /* labeled F11 */
|
|
799 case 0x1005FF11: return KEYSYM ("SunF37"); /* labeled F12 */
|
|
800 default:
|
|
801 {
|
2828
|
802 Ascbyte buf [64];
|
428
|
803 sprintf (buf, "unknown-keysym-0x%X", (int) keysym);
|
|
804 return KEYSYM (buf);
|
|
805 }
|
|
806 }
|
2828
|
807
|
428
|
808 /* If it's got a one-character name, that's good enough. */
|
|
809 if (!name[1])
|
2828
|
810 return make_char ((Ichar)name[0]);
|
|
811
|
|
812 /* In theory the Host Portable Character Set is just ASCII, but
|
|
813 trusting X11 implementors to get that right is likely to lead to
|
|
814 tears. */
|
|
815 eicpy_ext(einame, name, Qbinary);
|
428
|
816
|
|
817 /* If it's in the "Keyboard" character set, downcase it.
|
|
818 The case of those keysyms is too totally random for us to
|
|
819 force anyone to remember them.
|
2828
|
820 The case of the other character sets is significant, however. */
|
428
|
821 if ((((unsigned int) keysym) & (~0x1FF)) == ((unsigned int) 0xFE00))
|
|
822 {
|
2828
|
823 Ibyte *iname;
|
|
824 eilwr(einame);
|
|
825
|
|
826 for (iname = eidata(einame); *iname != '\0';)
|
|
827 {
|
|
828 if (*iname == '_')
|
|
829 {
|
|
830 *iname = '-';
|
|
831 }
|
|
832 INC_IBYTEPTR(iname);
|
428
|
833 }
|
|
834 }
|
2837
|
835 return KEYSYM ((const CIbyte *) eidata (einame));
|
428
|
836 }
|
|
837 }
|
|
838
|
|
839 static Lisp_Object
|
|
840 x_to_emacs_keysym (XKeyPressedEvent *event, int simple_p)
|
|
841 /* simple_p means don't try too hard (ASCII only) */
|
|
842 {
|
|
843 KeySym keysym = 0;
|
|
844
|
|
845 #ifdef HAVE_XIM
|
3072
|
846 int len = 0;
|
442
|
847 /* Some implementations of XmbLookupString don't return
|
|
848 XBufferOverflow correctly, so increase the size of the xim input
|
|
849 buffer from 64 to the more reasonable size 513, as Emacs has done.
|
|
850 From Kenichi Handa. */
|
|
851 char buffer[513];
|
428
|
852 char *bufptr = buffer;
|
|
853 int bufsiz = sizeof (buffer);
|
|
854 Status status;
|
|
855 #ifdef XIM_XLIB
|
|
856 XIC xic = FRAME_X_XIC (x_any_window_to_frame
|
|
857 (get_device_from_display (event->display),
|
|
858 event->window));
|
|
859 #endif /* XIM_XLIB */
|
|
860 #endif /* HAVE_XIM */
|
|
861
|
|
862 /* We use XLookupString if we're not using XIM, or are using
|
|
863 XIM_XLIB but input context creation failed. */
|
|
864 #if ! (defined (HAVE_XIM) && defined (XIM_MOTIF))
|
|
865 #if defined (HAVE_XIM) && defined (XIM_XLIB)
|
|
866 if (!xic)
|
|
867 #endif /* XIM_XLIB */
|
|
868 {
|
|
869 /* Apparently it's necessary to specify a dummy here (rather
|
|
870 than passing in 0) to avoid crashes on German IRIX */
|
|
871 char dummy[256];
|
|
872 XLookupString (event, dummy, 200, &keysym, 0);
|
|
873 return (IsModifierKey (keysym) || keysym == XK_Mode_switch )
|
|
874 ? Qnil : x_keysym_to_emacs_keysym (keysym, simple_p);
|
|
875 }
|
|
876 #endif /* ! XIM_MOTIF */
|
|
877
|
|
878 #ifdef HAVE_XIM
|
|
879 Lookup_String: /* Come-From XBufferOverflow */
|
|
880 #ifdef XIM_MOTIF
|
|
881 len = XmImMbLookupString (XtWindowToWidget (event->display, event->window),
|
|
882 event, bufptr, bufsiz, &keysym, &status);
|
|
883 #else /* XIM_XLIB */
|
|
884 if (xic)
|
|
885 len = XmbLookupString (xic, event, bufptr, bufsiz, &keysym, &status);
|
1494
|
886 #endif /* XIM_MOTIF */
|
428
|
887
|
|
888 #ifdef DEBUG_XEMACS
|
442
|
889 if (debug_x_events > 0)
|
428
|
890 {
|
|
891 stderr_out (" status=");
|
|
892 #define print_status_when(S) if (status == S) stderr_out (#S)
|
|
893 print_status_when (XLookupKeySym);
|
|
894 print_status_when (XLookupBoth);
|
|
895 print_status_when (XLookupChars);
|
|
896 print_status_when (XLookupNone);
|
|
897 print_status_when (XBufferOverflow);
|
|
898
|
|
899 if (status == XLookupKeySym || status == XLookupBoth)
|
|
900 stderr_out (" keysym=%s", XKeysymToString (keysym));
|
|
901 if (status == XLookupChars || status == XLookupBoth)
|
|
902 {
|
3072
|
903 if (len > 1)
|
428
|
904 {
|
|
905 int j;
|
|
906 stderr_out (" chars=\"");
|
|
907 for (j=0; j<len; j++)
|
3142
|
908 {
|
|
909 if (040 <= bufptr[j] && bufptr[j] >= 0177)
|
|
910 {
|
|
911 stderr_out ("%c", bufptr[j]);
|
|
912 }
|
|
913 else
|
|
914 {
|
|
915 stderr_out ("\\%o", (unsigned)(bufptr[j]));
|
|
916 }
|
|
917 }
|
428
|
918 stderr_out ("\"");
|
|
919 }
|
|
920 else if (bufptr[0] <= 32 || bufptr[0] >= 127)
|
|
921 stderr_out (" char=0x%x", bufptr[0]);
|
|
922 else
|
|
923 stderr_out (" char=%c", bufptr[0]);
|
|
924 }
|
|
925 stderr_out ("\n");
|
|
926 }
|
|
927 #endif /* DEBUG_XEMACS */
|
|
928
|
|
929 switch (status)
|
|
930 {
|
|
931 case XLookupKeySym:
|
|
932 case XLookupBoth:
|
|
933 return (IsModifierKey (keysym) || keysym == XK_Mode_switch )
|
|
934 ? Qnil : x_keysym_to_emacs_keysym (keysym, simple_p);
|
|
935
|
|
936 case XLookupChars:
|
|
937 {
|
|
938 /* Generate multiple emacs events */
|
|
939 struct device *d = get_device_from_display (event->display);
|
867
|
940 Ichar ch;
|
428
|
941 Lisp_Object instream, fb_instream;
|
|
942 Lstream *istr;
|
|
943 struct gcpro gcpro1, gcpro2;
|
|
944
|
440
|
945 fb_instream = make_fixed_buffer_input_stream (bufptr, len);
|
|
946
|
3142
|
947 /* [[ Use get_coding_system_for_text_file
|
|
948 (Vcomposed_input_coding_system, 0) ]]
|
|
949
|
|
950 Nope. If it is possible for the X libraries to have multiple IM
|
|
951 connections on different DISPLAYs active at once, this should be
|
|
952 a console-specific variable (like a TTY's coding system) but I've
|
|
953 seen no evidence that that is possible. Aidan Kehoe,
|
|
954 2005-12-17. */
|
|
955
|
428
|
956 instream =
|
771
|
957 make_coding_input_stream
|
3142
|
958 (XLSTREAM (fb_instream), Qkeyboard, CODING_DECODE, 0);
|
428
|
959
|
|
960 istr = XLSTREAM (instream);
|
|
961
|
|
962 GCPRO2 (instream, fb_instream);
|
867
|
963 while ((ch = Lstream_get_ichar (istr)) != EOF)
|
428
|
964 {
|
|
965 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
440
|
966 Lisp_Event *ev = XEVENT (emacs_event);
|
428
|
967 ev->channel = DEVICE_CONSOLE (d);
|
960
|
968 ev->timestamp = event->time;
|
|
969 XSET_EVENT_TYPE (emacs_event, key_press_event);
|
1204
|
970 XSET_EVENT_KEY_MODIFIERS (emacs_event, 0);
|
|
971 XSET_EVENT_KEY_KEYSYM (emacs_event, make_char (ch));
|
|
972 enqueue_dispatch_event (emacs_event);
|
428
|
973 }
|
|
974 Lstream_close (istr);
|
|
975 UNGCPRO;
|
|
976 Lstream_delete (istr);
|
|
977 Lstream_delete (XLSTREAM (fb_instream));
|
|
978 return Qnil;
|
|
979 }
|
|
980 case XLookupNone: return Qnil;
|
|
981 case XBufferOverflow:
|
2367
|
982 /* !!#### needs work */
|
851
|
983 bufptr = (char *) ALLOCA (len+1);
|
428
|
984 bufsiz = len+1;
|
|
985 goto Lookup_String;
|
|
986 }
|
801
|
987 return Qnil; /* not (usually) reached */
|
428
|
988 #endif /* HAVE_XIM */
|
|
989 }
|
|
990
|
|
991 static void
|
|
992 set_last_server_timestamp (struct device *d, XEvent *x_event)
|
|
993 {
|
|
994 Time t;
|
|
995 switch (x_event->type)
|
|
996 {
|
|
997 case KeyPress:
|
|
998 case KeyRelease: t = x_event->xkey.time; break;
|
|
999 case ButtonPress:
|
|
1000 case ButtonRelease: t = x_event->xbutton.time; break;
|
|
1001 case EnterNotify:
|
|
1002 case LeaveNotify: t = x_event->xcrossing.time; break;
|
|
1003 case MotionNotify: t = x_event->xmotion.time; break;
|
|
1004 case PropertyNotify: t = x_event->xproperty.time; break;
|
|
1005 case SelectionClear: t = x_event->xselectionclear.time; break;
|
|
1006 case SelectionRequest: t = x_event->xselectionrequest.time; break;
|
|
1007 case SelectionNotify: t = x_event->xselection.time; break;
|
|
1008 default: return;
|
|
1009 }
|
|
1010 DEVICE_X_LAST_SERVER_TIMESTAMP (d) = t;
|
|
1011 }
|
|
1012
|
|
1013 static int
|
440
|
1014 x_event_to_emacs_event (XEvent *x_event, Lisp_Event *emacs_event)
|
428
|
1015 {
|
|
1016 Display *display = x_event->xany.display;
|
|
1017 struct device *d = get_device_from_display (display);
|
|
1018 struct x_device *xd = DEVICE_X_DATA (d);
|
|
1019
|
|
1020 if (DEVICE_X_BEING_DELETED (d))
|
2828
|
1021 {
|
|
1022 /* [[ Uh, is this 0 correct? ]]
|
|
1023
|
|
1024 Yup--it means emacs_Xt_event_handler, the only place that calls
|
|
1025 this, doesn't queue the emacs_event dispatch, instead immediately
|
|
1026 deallocating it. */
|
|
1027 return 0;
|
|
1028 }
|
428
|
1029
|
|
1030 set_last_server_timestamp (d, x_event);
|
|
1031
|
|
1032 switch (x_event->type)
|
|
1033 {
|
|
1034 case KeyRelease:
|
934
|
1035 {
|
|
1036 x_handle_sticky_modifiers (x_event, d);
|
|
1037 return 0;
|
|
1038 }
|
428
|
1039 case KeyPress:
|
|
1040 case ButtonPress:
|
|
1041 case ButtonRelease:
|
|
1042 {
|
442
|
1043 int modifiers = 0;
|
428
|
1044 int shift_p, lock_p;
|
|
1045 Bool key_event_p = (x_event->type == KeyPress);
|
|
1046 unsigned int *state =
|
|
1047 key_event_p ? &x_event->xkey.state : &x_event->xbutton.state;
|
|
1048
|
|
1049 /* If this is a synthetic KeyPress or Button event, and the user
|
|
1050 has expressed a disinterest in this security hole, then drop
|
|
1051 it on the floor. */
|
|
1052 if ((key_event_p
|
|
1053 ? x_event->xkey.send_event
|
|
1054 : x_event->xbutton.send_event)
|
|
1055 #ifdef EXTERNAL_WIDGET
|
|
1056 /* ben: events get sent to an ExternalShell using XSendEvent.
|
|
1057 This is not a perfect solution. */
|
|
1058 && !FRAME_X_EXTERNAL_WINDOW_P
|
|
1059 (x_any_window_to_frame (d, x_event->xany.window))
|
|
1060 #endif
|
|
1061 && !x_allow_sendevents)
|
|
1062 return 0;
|
|
1063
|
|
1064 DEVICE_X_MOUSE_TIMESTAMP (d) =
|
|
1065 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d) =
|
|
1066 key_event_p ? x_event->xkey.time : x_event->xbutton.time;
|
|
1067
|
|
1068 x_handle_sticky_modifiers (x_event, d);
|
|
1069
|
442
|
1070 if (*state & ControlMask) modifiers |= XEMACS_MOD_CONTROL;
|
|
1071 if (*state & xd->MetaMask) modifiers |= XEMACS_MOD_META;
|
|
1072 if (*state & xd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
|
|
1073 if (*state & xd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
|
|
1074 if (*state & xd->AltMask) modifiers |= XEMACS_MOD_ALT;
|
|
1075 {
|
|
1076 int numero_de_botao = -1;
|
|
1077
|
|
1078 if (!key_event_p)
|
|
1079 numero_de_botao = x_event->xbutton.button;
|
|
1080
|
|
1081 /* the button gets noted either in the button or the modifiers
|
|
1082 field, but not both. */
|
|
1083 if (numero_de_botao != 1 && (*state & Button1Mask))
|
|
1084 modifiers |= XEMACS_MOD_BUTTON1;
|
|
1085 if (numero_de_botao != 2 && (*state & Button2Mask))
|
|
1086 modifiers |= XEMACS_MOD_BUTTON2;
|
|
1087 if (numero_de_botao != 3 && (*state & Button3Mask))
|
|
1088 modifiers |= XEMACS_MOD_BUTTON3;
|
|
1089 if (numero_de_botao != 4 && (*state & Button4Mask))
|
|
1090 modifiers |= XEMACS_MOD_BUTTON4;
|
|
1091 if (numero_de_botao != 5 && (*state & Button5Mask))
|
|
1092 modifiers |= XEMACS_MOD_BUTTON5;
|
|
1093 }
|
428
|
1094
|
|
1095 /* Ignore the Caps_Lock key if:
|
|
1096 - any other modifiers are down, so that Caps_Lock doesn't
|
|
1097 turn C-x into C-X, which would suck.
|
|
1098 - the event was a mouse event. */
|
|
1099 if (modifiers || ! key_event_p)
|
|
1100 *state &= (~LockMask);
|
|
1101
|
|
1102 shift_p = *state & ShiftMask;
|
|
1103 lock_p = *state & LockMask;
|
|
1104
|
|
1105 if (shift_p || lock_p)
|
442
|
1106 modifiers |= XEMACS_MOD_SHIFT;
|
428
|
1107
|
|
1108 if (key_event_p)
|
|
1109 {
|
|
1110 Lisp_Object keysym;
|
|
1111 XKeyEvent *ev = &x_event->xkey;
|
|
1112 /* This used to compute the frame from the given X window and
|
|
1113 store it here, but we really don't care about the frame. */
|
934
|
1114 SET_EVENT_CHANNEL (emacs_event, DEVICE_CONSOLE (d));
|
428
|
1115 keysym = x_to_emacs_keysym (&x_event->xkey, 0);
|
|
1116
|
|
1117 /* If the emacs keysym is nil, then that means that the X
|
|
1118 keysym was either a Modifier or NoSymbol, which
|
|
1119 probably means that we're in the midst of reading a
|
|
1120 Multi_key sequence, or a "dead" key prefix, or XIM
|
|
1121 input. Ignore it. */
|
|
1122 if (NILP (keysym))
|
|
1123 return 0;
|
|
1124
|
3171
|
1125 /* If we have the map from keycodes to the US layout for our
|
|
1126 keyboard available, store the US layout interpretation of
|
|
1127 that key in the event structure, in case a binding lookup
|
|
1128 fails and we want to fall back to the US layout binding.
|
|
1129
|
|
1130 This _might_ be possible within an XKB framework, changing
|
|
1131 the keyboard to a US XKB layout for a moment at startup,
|
|
1132 storing the correspondance, and changing it back. But that
|
|
1133 won't work on non-XKB servers, it makes our already slow
|
|
1134 startup slower, and it's not clear that it's really any
|
|
1135 easier or more maintainable than storing a correspondence in
|
|
1136 Lisp. */
|
|
1137
|
|
1138 if (!NILP(Vx_us_keymap_description) &&
|
|
1139 VECTORP(Vx_us_keymap_description) &&
|
|
1140 ev->keycode >= (unsigned)Vx_us_keymap_first_keycode &&
|
|
1141 ev->keycode
|
|
1142 < (unsigned)XVECTOR_LENGTH(Vx_us_keymap_description))
|
|
1143 {
|
|
1144 Lisp_Object entr = XVECTOR_DATA(Vx_us_keymap_description)
|
|
1145 [ev->keycode - Vx_us_keymap_first_keycode];
|
|
1146 Ichar alternate = '\0';
|
|
1147
|
|
1148 if (!NILP (entr))
|
|
1149 {
|
|
1150 if (CHARP(entr))
|
|
1151 {
|
|
1152 alternate = XCHAR(entr);
|
|
1153 }
|
|
1154 else if (VECTORP(entr))
|
|
1155 {
|
|
1156 if (modifiers & XEMACS_MOD_SHIFT
|
|
1157 && XVECTOR_LENGTH(Vx_us_keymap_description) > 1)
|
|
1158 {
|
|
1159 entr = XVECTOR_DATA(entr)[1];
|
|
1160 if (CHARP(entr))
|
|
1161 {
|
|
1162 alternate = XCHAR(entr);
|
|
1163 }
|
|
1164 }
|
|
1165 else if (XVECTOR_LENGTH(Vx_us_keymap_description)
|
|
1166 > 0)
|
|
1167 {
|
|
1168 entr = XVECTOR_DATA(entr)[0];
|
|
1169 if (CHARP(entr))
|
|
1170 {
|
|
1171 alternate = XCHAR(entr);
|
|
1172 }
|
|
1173 }
|
|
1174 }
|
|
1175 if ('\0' != alternate)
|
|
1176 {
|
|
1177 SET_EVENT_KEY_ALT_KEYCHARS(emacs_event, KEYCHAR_QWERTY,
|
|
1178 alternate);
|
|
1179 }
|
|
1180 }
|
|
1181 }
|
|
1182
|
428
|
1183 /* More Caps_Lock garbage: Caps_Lock should *only* add the
|
|
1184 shift modifier to two-case keys (that is, A-Z and
|
|
1185 related characters). So at this point (after looking up
|
|
1186 the keysym) if the keysym isn't a dual-case alphabetic,
|
|
1187 and if the caps lock key was down but the shift key
|
|
1188 wasn't, then turn off the shift modifier. Gag barf */
|
2828
|
1189
|
428
|
1190 /* #### type lossage: assuming equivalence of emacs and
|
2828
|
1191 X keysyms
|
|
1192
|
|
1193 The right thing to do here is to have pass a third, pointer,
|
|
1194 argument to x_to_emacs_keysym, where it should store the
|
|
1195 intermediate KeySym it used to calculate the string XEmacs
|
|
1196 keysym. Then we can call keysym_obeys_caps_lock_p with
|
|
1197 exactly the right argument. */
|
3171
|
1198
|
2828
|
1199 /* !!#### maybe fix for Mule
|
|
1200
|
|
1201 Hard, in the absence of a full case infrastructure for
|
|
1202 Mule characters. When
|
|
1203 (downcase (make-char 'cyrillic-iso8859-5 73))
|
|
1204 works, we should revisit it. */
|
|
1205
|
428
|
1206 if (lock_p && !shift_p &&
|
|
1207 ! (CHAR_OR_CHAR_INTP (keysym)
|
|
1208 && keysym_obeys_caps_lock_p
|
|
1209 ((KeySym) XCHAR_OR_CHAR_INT (keysym), d)))
|
442
|
1210 modifiers &= (~XEMACS_MOD_SHIFT);
|
428
|
1211
|
|
1212 /* If this key contains two distinct keysyms, that is,
|
|
1213 "shift" generates a different keysym than the
|
|
1214 non-shifted key, then don't apply the shift modifier
|
|
1215 bit: it's implicit. Otherwise, if there would be no
|
|
1216 other way to tell the difference between the shifted
|
|
1217 and unshifted version of this key, apply the shift bit.
|
|
1218 Non-graphics, like Backspace and F1 get the shift bit
|
|
1219 in the modifiers slot. Neither the characters "a",
|
|
1220 "A", "2", nor "@" normally have the shift bit set.
|
|
1221 However, "F1" normally does. */
|
3171
|
1222
|
442
|
1223 if (modifiers & XEMACS_MOD_SHIFT)
|
428
|
1224 {
|
|
1225 int Mode_switch_p = *state & xd->ModeMask;
|
|
1226 KeySym bot = XLookupKeysym (ev, Mode_switch_p ? 2 : 0);
|
|
1227 KeySym top = XLookupKeysym (ev, Mode_switch_p ? 3 : 1);
|
|
1228 if (top && bot && top != bot)
|
442
|
1229 modifiers &= ~XEMACS_MOD_SHIFT;
|
428
|
1230 }
|
934
|
1231 set_event_type (emacs_event, key_press_event);
|
|
1232 SET_EVENT_TIMESTAMP (emacs_event, ev->time);
|
1204
|
1233 SET_EVENT_KEY_MODIFIERS (emacs_event, modifiers);
|
|
1234 SET_EVENT_KEY_KEYSYM (emacs_event, keysym);
|
428
|
1235 }
|
|
1236 else /* Mouse press/release event */
|
|
1237 {
|
|
1238 XButtonEvent *ev = &x_event->xbutton;
|
|
1239 struct frame *frame = x_window_to_frame (d, ev->window);
|
|
1240
|
|
1241 if (! frame)
|
|
1242 return 0; /* not for us */
|
934
|
1243 set_event_type (emacs_event, (x_event->type == ButtonPress) ?
|
|
1244 button_press_event : button_release_event);
|
1204
|
1245 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame));
|
|
1246
|
|
1247 SET_EVENT_BUTTON_MODIFIERS (emacs_event, modifiers);
|
934
|
1248 SET_EVENT_TIMESTAMP (emacs_event, ev->time);
|
1204
|
1249 SET_EVENT_BUTTON_BUTTON (emacs_event, ev->button);
|
|
1250 SET_EVENT_BUTTON_X (emacs_event, ev->x);
|
|
1251 SET_EVENT_BUTTON_Y (emacs_event, ev->y);
|
428
|
1252 /* because we don't seem to get a FocusIn event for button clicks
|
|
1253 when a widget-glyph is selected we will assume that we want the
|
|
1254 focus if a button gets pressed. */
|
|
1255 if (x_event->type == ButtonPress)
|
|
1256 handle_focus_event_1 (frame, 1);
|
|
1257 }
|
|
1258 }
|
|
1259 break;
|
|
1260
|
|
1261 case MotionNotify:
|
|
1262 {
|
|
1263 XMotionEvent *ev = &x_event->xmotion;
|
|
1264 struct frame *frame = x_window_to_frame (d, ev->window);
|
442
|
1265 int modifiers = 0;
|
428
|
1266 XMotionEvent event2;
|
|
1267
|
|
1268 if (! frame)
|
|
1269 return 0; /* not for us */
|
|
1270
|
|
1271 /* We use MotionHintMask, so we will get only one motion event
|
|
1272 until the next time we call XQueryPointer or the user
|
|
1273 clicks the mouse. So call XQueryPointer now (meaning that
|
|
1274 the event will be in sync with the server just before
|
|
1275 Fnext_event() returns). If the mouse is still in motion,
|
|
1276 then the server will immediately generate exactly one more
|
|
1277 motion event, which will be on the queue waiting for us
|
|
1278 next time around. */
|
|
1279 event2 = *ev;
|
|
1280 if (XQueryPointer (event2.display, event2.window,
|
|
1281 &event2.root, &event2.subwindow,
|
|
1282 &event2.x_root, &event2.y_root,
|
|
1283 &event2.x, &event2.y,
|
|
1284 &event2.state))
|
|
1285 ev = &event2; /* only one structure copy */
|
|
1286
|
|
1287 DEVICE_X_MOUSE_TIMESTAMP (d) = ev->time;
|
1204
|
1288 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame));
|
934
|
1289 set_event_type (emacs_event, pointer_motion_event);
|
|
1290 SET_EVENT_TIMESTAMP (emacs_event, ev->time);
|
1204
|
1291 SET_EVENT_MOTION_X (emacs_event, ev->x);
|
|
1292 SET_EVENT_MOTION_Y (emacs_event, ev->y);
|
442
|
1293 if (ev->state & ShiftMask) modifiers |= XEMACS_MOD_SHIFT;
|
|
1294 if (ev->state & ControlMask) modifiers |= XEMACS_MOD_CONTROL;
|
|
1295 if (ev->state & xd->MetaMask) modifiers |= XEMACS_MOD_META;
|
|
1296 if (ev->state & xd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
|
|
1297 if (ev->state & xd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
|
|
1298 if (ev->state & xd->AltMask) modifiers |= XEMACS_MOD_ALT;
|
|
1299 if (ev->state & Button1Mask) modifiers |= XEMACS_MOD_BUTTON1;
|
|
1300 if (ev->state & Button2Mask) modifiers |= XEMACS_MOD_BUTTON2;
|
|
1301 if (ev->state & Button3Mask) modifiers |= XEMACS_MOD_BUTTON3;
|
|
1302 if (ev->state & Button4Mask) modifiers |= XEMACS_MOD_BUTTON4;
|
|
1303 if (ev->state & Button5Mask) modifiers |= XEMACS_MOD_BUTTON5;
|
428
|
1304 /* Currently ignores Shift_Lock but probably shouldn't
|
|
1305 (but it definitely should ignore Caps_Lock). */
|
1204
|
1306 SET_EVENT_MOTION_MODIFIERS (emacs_event, modifiers);
|
428
|
1307 }
|
|
1308 break;
|
|
1309
|
|
1310 case ClientMessage:
|
|
1311 {
|
|
1312 /* Patch bogus TAKE_FOCUS messages from MWM; CurrentTime is
|
|
1313 passed as the timestamp of the TAKE_FOCUS, which the ICCCM
|
|
1314 explicitly prohibits. */
|
|
1315 XClientMessageEvent *ev = &x_event->xclient;
|
|
1316 #ifdef HAVE_OFFIX_DND
|
2367
|
1317 if (DndIsDropMessage (x_event))
|
428
|
1318 {
|
442
|
1319 unsigned int state;
|
|
1320 int modifiers = 0;
|
647
|
1321 int button = 0;
|
428
|
1322 struct frame *frame = x_any_window_to_frame (d, ev->window);
|
|
1323 Extbyte *data;
|
|
1324 unsigned long size, dtype;
|
|
1325 Lisp_Object l_type = Qnil, l_data = Qnil;
|
|
1326 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
1327 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1328
|
|
1329 if (! frame)
|
|
1330 return 0; /* not for us */
|
446
|
1331
|
|
1332 GCPRO4 (l_type, l_data, l_dndlist, l_item);
|
934
|
1333 set_event_type (emacs_event, misc_user_event);
|
1204
|
1334 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame));
|
2367
|
1335 SET_EVENT_TIMESTAMP (emacs_event,
|
|
1336 DEVICE_X_LAST_SERVER_TIMESTAMP (d));
|
1204
|
1337 state=DndDragButtons (x_event);
|
428
|
1338
|
442
|
1339 if (state & ShiftMask) modifiers |= XEMACS_MOD_SHIFT;
|
|
1340 if (state & ControlMask) modifiers |= XEMACS_MOD_CONTROL;
|
|
1341 if (state & xd->MetaMask) modifiers |= XEMACS_MOD_META;
|
|
1342 if (state & xd->SuperMask) modifiers |= XEMACS_MOD_SUPER;
|
|
1343 if (state & xd->HyperMask) modifiers |= XEMACS_MOD_HYPER;
|
|
1344 if (state & xd->AltMask) modifiers |= XEMACS_MOD_ALT;
|
|
1345 if (state & Button1Mask) modifiers |= XEMACS_MOD_BUTTON1;
|
|
1346 if (state & Button2Mask) modifiers |= XEMACS_MOD_BUTTON2;
|
|
1347 if (state & Button3Mask) modifiers |= XEMACS_MOD_BUTTON3;
|
|
1348 if (state & Button4Mask) modifiers |= XEMACS_MOD_BUTTON4;
|
|
1349 if (state & Button5Mask) modifiers |= XEMACS_MOD_BUTTON5;
|
428
|
1350
|
|
1351 if (state & Button5Mask) button = Button5;
|
|
1352 if (state & Button4Mask) button = Button4;
|
|
1353 if (state & Button3Mask) button = Button3;
|
|
1354 if (state & Button2Mask) button = Button2;
|
|
1355 if (state & Button1Mask) button = Button1;
|
|
1356
|
1204
|
1357 SET_EVENT_MISC_USER_MODIFIERS (emacs_event, modifiers);
|
|
1358 SET_EVENT_MISC_USER_BUTTON (emacs_event, button);
|
|
1359
|
|
1360 DndDropCoordinates (FRAME_X_TEXT_WIDGET (frame), x_event,
|
|
1361 &(EVENT_MISC_USER_X (emacs_event)),
|
|
1362 &(EVENT_MISC_USER_Y (emacs_event)));
|
2367
|
1363 DndGetData (x_event, &data, &size);
|
|
1364
|
|
1365 dtype = DndDataType (x_event);
|
428
|
1366 switch (dtype)
|
|
1367 {
|
|
1368 case DndFiles: /* null terminated strings, end null */
|
|
1369 {
|
|
1370 int len;
|
2367
|
1371 Ibyte *hurl = NULL;
|
428
|
1372
|
|
1373 while (*data)
|
|
1374 {
|
2367
|
1375 Ibyte *dataint;
|
|
1376 len = strlen (data);
|
|
1377 EXTERNAL_TO_C_STRING (data, dataint, Qfile_name);
|
2956
|
1378 hurl = dnd_url_hexify_string (dataint,
|
|
1379 (const Ibyte *) "file:");
|
2367
|
1380 l_item = build_intstring (hurl);
|
428
|
1381 l_dndlist = Fcons (l_item, l_dndlist);
|
|
1382 data += len + 1;
|
2367
|
1383 xfree (hurl, Ibyte *);
|
428
|
1384 }
|
|
1385 l_type = Qdragdrop_URL;
|
|
1386 }
|
|
1387 break;
|
|
1388 case DndText:
|
|
1389 l_type = Qdragdrop_MIME;
|
2367
|
1390 l_dndlist = list1 (list3 (list1 (build_string ("text/plain")),
|
|
1391 build_string ("8bit"),
|
|
1392 build_ext_string (data,
|
|
1393 Qctext)));
|
428
|
1394 break;
|
|
1395 case DndMIME:
|
|
1396 /* we have to parse this in some way to extract
|
|
1397 content-type and params (in the tm way) and
|
|
1398 content encoding.
|
|
1399 OR: if data is string, let tm do the job
|
|
1400 if data is list[2], give the first two
|
|
1401 to tm...
|
|
1402 */
|
|
1403 l_type = Qdragdrop_MIME;
|
2367
|
1404 l_dndlist = list1 (build_ext_string (data, Qbinary));
|
428
|
1405 break;
|
|
1406 case DndFile:
|
|
1407 case DndDir:
|
|
1408 case DndLink:
|
|
1409 case DndExe:
|
|
1410 {
|
2367
|
1411 Ibyte *dataint, *hurl;
|
|
1412 EXTERNAL_TO_C_STRING (data, dataint, Qfile_name);
|
|
1413 hurl = dnd_url_hexify_string (dataint, "file:");
|
|
1414 l_dndlist = list1 (build_intstring (hurl));
|
|
1415 xfree (hurl, Ibyte *);
|
428
|
1416 }
|
|
1417 break;
|
|
1418 case DndURL:
|
|
1419 /* as it is a real URL it should already be escaped
|
|
1420 and escaping again will break them (cause % is unsave) */
|
2367
|
1421 l_dndlist = list1 (build_ext_string (data,
|
|
1422 Qfile_name));
|
428
|
1423 l_type = Qdragdrop_URL;
|
|
1424 break;
|
|
1425 default: /* Unknown, RawData and any other type */
|
2367
|
1426 l_dndlist = list1 (list3 (list1 (build_string
|
|
1427 ("application/octet-stream")),
|
|
1428 build_string ("8bit"),
|
|
1429 make_ext_string (data, size,
|
|
1430 Qbinary)));
|
428
|
1431 l_type = Qdragdrop_MIME;
|
|
1432 break;
|
|
1433 }
|
|
1434
|
2367
|
1435 SET_EVENT_MISC_USER_FUNCTION (emacs_event,
|
|
1436 Qdragdrop_drop_dispatch);
|
|
1437 SET_EVENT_MISC_USER_OBJECT (emacs_event,
|
|
1438 Fcons (l_type, l_dndlist));
|
428
|
1439
|
|
1440 UNGCPRO;
|
|
1441
|
|
1442 break;
|
|
1443 }
|
|
1444 #endif /* HAVE_OFFIX_DND */
|
|
1445 if (ev->message_type == DEVICE_XATOM_WM_PROTOCOLS (d)
|
|
1446 && (Atom) (ev->data.l[0]) == DEVICE_XATOM_WM_TAKE_FOCUS (d)
|
|
1447 && (Atom) (ev->data.l[1]) == 0)
|
|
1448 {
|
|
1449 ev->data.l[1] = DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
1450 }
|
|
1451 }
|
|
1452 /* fall through */
|
|
1453
|
|
1454 default: /* it's a magic event */
|
|
1455 {
|
|
1456 struct frame *frame;
|
|
1457 Window w;
|
934
|
1458 XEvent *x_event_copy;
|
|
1459 SET_EVENT_TYPE (emacs_event, magic_event);
|
1204
|
1460 x_event_copy = &EVENT_MAGIC_X_EVENT (emacs_event);
|
428
|
1461
|
|
1462 #define FROB(event_member, window_member) \
|
|
1463 x_event_copy->event_member = x_event->event_member; \
|
|
1464 w = x_event->event_member.window_member
|
|
1465
|
|
1466 switch (x_event->type)
|
|
1467 {
|
|
1468 case SelectionRequest: FROB(xselectionrequest, owner); break;
|
|
1469 case SelectionClear: FROB(xselectionclear, window); break;
|
|
1470 case SelectionNotify: FROB(xselection, requestor); break;
|
|
1471 case PropertyNotify: FROB(xproperty, window); break;
|
|
1472 case ClientMessage: FROB(xclient, window); break;
|
|
1473 case ConfigureNotify: FROB(xconfigure, window); break;
|
|
1474 case Expose:
|
|
1475 case GraphicsExpose: FROB(xexpose, window); break;
|
|
1476 case MapNotify:
|
|
1477 case UnmapNotify: FROB(xmap, window); break;
|
|
1478 case EnterNotify:
|
|
1479 case LeaveNotify: FROB(xcrossing, window); break;
|
|
1480 case FocusIn:
|
|
1481 case FocusOut: FROB(xfocus, window); break;
|
|
1482 case VisibilityNotify: FROB(xvisibility, window); break;
|
442
|
1483 case CreateNotify: FROB(xcreatewindow, window); break;
|
428
|
1484 default:
|
|
1485 w = x_event->xany.window;
|
|
1486 *x_event_copy = *x_event;
|
|
1487 break;
|
|
1488 }
|
|
1489 #undef FROB
|
|
1490 frame = x_any_window_to_frame (d, w);
|
|
1491
|
|
1492 if (!frame)
|
|
1493 return 0;
|
|
1494
|
1204
|
1495 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame));
|
|
1496 SET_EVENT_MAGIC_X_EVENT (emacs_event, *x_event_copy);
|
428
|
1497 break;
|
|
1498 }
|
|
1499 }
|
|
1500 return 1;
|
|
1501 }
|
|
1502
|
|
1503
|
|
1504
|
|
1505 /************************************************************************/
|
|
1506 /* magic-event handling */
|
|
1507 /************************************************************************/
|
|
1508
|
|
1509 static void
|
|
1510 handle_focus_event_1 (struct frame *f, int in_p)
|
|
1511 {
|
863
|
1512 handle_focus_event_2 (XtWindow (FRAME_X_TEXT_WIDGET (f)), f, in_p);
|
|
1513 }
|
|
1514
|
|
1515 static void
|
|
1516 handle_focus_event_2 (Window win, struct frame *f, int in_p)
|
|
1517 {
|
|
1518 /* Although this treats focus differently for all widgets (including
|
|
1519 the frame) it seems to work ok. */
|
|
1520 Widget needs_it = XtWindowToWidget (FRAME_X_DISPLAY (f), win);
|
|
1521
|
428
|
1522 #if XtSpecificationRelease > 5
|
450
|
1523 widget_with_focus = XtGetKeyboardFocusWidget (FRAME_X_TEXT_WIDGET (f));
|
428
|
1524 #endif
|
|
1525 #ifdef HAVE_XIM
|
|
1526 XIM_focus_event (f, in_p);
|
|
1527 #endif /* HAVE_XIM */
|
450
|
1528
|
428
|
1529 /* On focus change, clear all memory of sticky modifiers
|
|
1530 to avoid non-intuitive behavior. */
|
|
1531 clear_sticky_modifiers (XDEVICE (FRAME_DEVICE (f)));
|
|
1532
|
|
1533 /* We don't want to handle the focus change now, because we might
|
|
1534 be in an accept-process-output, sleep-for, or sit-for. So
|
|
1535 we enqueue it.
|
|
1536
|
|
1537 Actually, we half handle it: we handle it as far as changing the
|
|
1538 box cursor for redisplay, but we don't call any hooks or do any
|
|
1539 select-frame stuff until after the sit-for.
|
|
1540
|
|
1541 Unfortunately native widgets break the model because they grab
|
|
1542 the keyboard focus and nothing sets it back again. I cannot find
|
|
1543 any reasonable way to do this elsewhere so we assert here that
|
|
1544 the keyboard focus is on the emacs text widget. Menus and dialogs
|
|
1545 do this in their selection callback, but we don't want that since
|
|
1546 a button having focus is legitimate. An edit field having focus
|
|
1547 is mandatory. Weirdly you get a FocusOut event when you click in
|
442
|
1548 a widget-glyph but you don't get a corresponding FocusIn when you
|
428
|
1549 click in the frame. Why is this? */
|
438
|
1550 if (in_p
|
|
1551 #if XtSpecificationRelease > 5
|
863
|
1552 && needs_it != widget_with_focus
|
428
|
1553 #endif
|
|
1554 )
|
|
1555 {
|
863
|
1556 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), needs_it);
|
428
|
1557 }
|
450
|
1558
|
863
|
1559 /* If we are focusing on a native widget then record and exit. */
|
|
1560 if (needs_it != FRAME_X_TEXT_WIDGET (f)) {
|
|
1561 widget_with_focus = needs_it;
|
|
1562 return;
|
|
1563 }
|
|
1564
|
450
|
1565 /* We have the focus now. See comment in
|
|
1566 emacs_Xt_handle_widget_losing_focus (). */
|
|
1567 if (in_p)
|
|
1568 widget_with_focus = NULL;
|
|
1569
|
428
|
1570 /* do the generic event-stream stuff. */
|
|
1571 {
|
|
1572 Lisp_Object frm;
|
|
1573 Lisp_Object conser;
|
|
1574 struct gcpro gcpro1;
|
|
1575
|
793
|
1576 frm = wrap_frame (f);
|
428
|
1577 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
1578 GCPRO1 (conser);
|
|
1579 emacs_handle_focus_change_preliminary (conser);
|
|
1580 enqueue_magic_eval_event (emacs_handle_focus_change_final,
|
|
1581 conser);
|
|
1582 UNGCPRO;
|
|
1583 }
|
|
1584 }
|
|
1585
|
863
|
1586 /* Create a synthetic X focus event. */
|
1111
|
1587 void emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame,
|
|
1588 int in_p);
|
863
|
1589 void
|
1111
|
1590 emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame, int in_p)
|
863
|
1591 {
|
|
1592 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1593 Lisp_Event *ev = XEVENT (emacs_event);
|
960
|
1594 XEvent *x_event;
|
|
1595
|
|
1596 XSET_EVENT_TYPE (emacs_event, magic_event);
|
1204
|
1597 x_event = &EVENT_MAGIC_X_EVENT (ev);
|
863
|
1598
|
|
1599 x_event->type = in_p ? FocusIn : FocusOut;
|
|
1600 x_event->xfocus.window = XtWindow (wants_it);
|
|
1601
|
960
|
1602 SET_EVENT_CHANNEL (ev, frame);
|
1204
|
1603
|
|
1604 enqueue_dispatch_event (emacs_event);
|
863
|
1605 }
|
|
1606
|
450
|
1607 /* The idea here is that when a widget glyph gets unmapped we don't
|
|
1608 want the focus to stay with it if it has focus - because it may
|
863
|
1609 well just get deleted next and then we have lost the focus until the
|
450
|
1610 user does something. So handle_focus_event_1 records the widget
|
|
1611 with keyboard focus when FocusOut is processed, and then, when a
|
|
1612 widget gets unmapped, it calls this function to restore focus if
|
|
1613 appropriate. */
|
853
|
1614 void emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget);
|
450
|
1615 void
|
853
|
1616 emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget)
|
450
|
1617 {
|
|
1618 if (losing_widget == widget_with_focus)
|
|
1619 {
|
|
1620 handle_focus_event_1 (f, 1);
|
|
1621 }
|
|
1622 }
|
|
1623
|
428
|
1624 /* This is called from the external-widget code */
|
|
1625
|
|
1626 void emacs_Xt_handle_focus_event (XEvent *event);
|
|
1627 void
|
|
1628 emacs_Xt_handle_focus_event (XEvent *event)
|
|
1629 {
|
|
1630 struct device *d = get_device_from_display (event->xany.display);
|
|
1631 struct frame *f;
|
|
1632
|
|
1633 if (DEVICE_X_BEING_DELETED (d))
|
|
1634 return;
|
|
1635
|
|
1636 /*
|
|
1637 * It's curious that we're using x_any_window_to_frame() instead
|
|
1638 * of x_window_to_frame(). I don't know what the impact of this is.
|
|
1639 */
|
|
1640 f = x_any_window_to_frame (d, event->xfocus.window);
|
|
1641 if (!f)
|
|
1642 /* focus events are sometimes generated just before
|
|
1643 a frame is destroyed. */
|
|
1644 return;
|
|
1645 handle_focus_event_1 (f, event->type == FocusIn);
|
|
1646 }
|
|
1647
|
|
1648 /* both MapNotify and VisibilityNotify can cause this
|
|
1649 JV is_visible has the same semantics as f->visible*/
|
|
1650 static void
|
|
1651 change_frame_visibility (struct frame *f, int is_visible)
|
|
1652 {
|
793
|
1653 Lisp_Object frame = wrap_frame (f);
|
|
1654
|
428
|
1655
|
|
1656 if (!FRAME_VISIBLE_P (f) && is_visible)
|
|
1657 {
|
|
1658 FRAME_VISIBLE_P (f) = is_visible;
|
872
|
1659 /* [[ This improves the double flicker when uniconifying a frame
|
428
|
1660 some. A lot of it is not showing a buffer which has changed
|
|
1661 while the frame was iconified. To fix it further requires
|
872
|
1662 the good 'ol double redisplay structure. ]] -- comment is
|
|
1663 invalid, obviously predates 19.12, when the double redisplay
|
|
1664 structure (i.e. current + desired) was put back in. --ben */
|
428
|
1665 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1666 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1667 }
|
|
1668 else if (FRAME_VISIBLE_P (f) && !is_visible)
|
|
1669 {
|
|
1670 FRAME_VISIBLE_P (f) = 0;
|
|
1671 va_run_hook_with_args (Qunmap_frame_hook, 1, frame);
|
|
1672 }
|
|
1673 else if (FRAME_VISIBLE_P (f) * is_visible < 0)
|
|
1674 {
|
|
1675 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f);
|
|
1676 if (FRAME_REPAINT_P(f))
|
|
1677 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1678 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1679 }
|
|
1680 }
|
|
1681
|
|
1682 static void
|
593
|
1683 update_frame_iconify_status (struct frame *f)
|
|
1684 {
|
|
1685 f->iconified = (x_frame_window_state (f) == IconicState);
|
|
1686 }
|
|
1687
|
|
1688 static void
|
428
|
1689 handle_map_event (struct frame *f, XEvent *event)
|
|
1690 {
|
593
|
1691
|
|
1692 /* It seems that, given the multiplicity of window managers and X
|
|
1693 implementations, plus the fact that X was designed without
|
|
1694 window managers or icons in mind and this was then grafted on
|
|
1695 with about the skill of a drunk freshman med student attempting
|
|
1696 surgery with a rusty razor blade, we cannot treat any off
|
|
1697 MapNotify/UnmapNotify/VisibilityNotify as more than vague hints
|
|
1698 as to the actual situation.
|
|
1699
|
|
1700 So we should just query the actual status. Unfortunately, things
|
|
1701 are worse because (a) there aren't obvious ways to query some
|
|
1702 of these values (e.g. "totally visible"), and (b) there may be
|
|
1703 race conditions (see below).
|
|
1704
|
638
|
1705 However, according to the ICCCM, there's a specific way to
|
593
|
1706 ask the window manager whether the state is (a) visible,
|
|
1707 (b) iconic, (c) withdrawn. It must be one of these three.
|
|
1708 We already use this call to check for the iconified state.
|
|
1709 I'd suggest we do the same for visible (i.e. NormalState),
|
|
1710 and scrap most of the nasty code below.
|
|
1711
|
|
1712 --ben
|
|
1713 */
|
|
1714
|
|
1715 update_frame_iconify_status (f);
|
|
1716
|
|
1717 /* #### Ben suggests rewriting the code below using
|
|
1718 x_frame_window_state (f). */
|
|
1719
|
428
|
1720 if (event->type == MapNotify)
|
|
1721 {
|
|
1722 XWindowAttributes xwa;
|
|
1723
|
|
1724 /* Bleagh!!!!!! Apparently some window managers (e.g. MWM)
|
|
1725 send synthetic MapNotify events when a window is first
|
|
1726 created, EVEN IF IT'S CREATED ICONIFIED OR INVISIBLE.
|
|
1727 Or something like that. We initially tried a different
|
|
1728 solution below, but that ran into a different window-
|
|
1729 manager bug.
|
|
1730
|
|
1731 It seems that the only reliable way is to treat a
|
|
1732 MapNotify event as a "hint" that the window might or
|
|
1733 might not be visible, and check explicitly. */
|
|
1734
|
|
1735 XGetWindowAttributes (event->xany.display, event->xmap.window,
|
|
1736 &xwa);
|
|
1737 if (xwa.map_state != IsViewable)
|
593
|
1738 return;
|
428
|
1739
|
|
1740 FRAME_X_TOTALLY_VISIBLE_P (f) = 1;
|
|
1741 #if 0
|
|
1742 /* Bleagh again!!!! We initially tried the following hack
|
|
1743 around the MWM problem, but it turns out that TWM
|
|
1744 has a race condition when you un-iconify, where it maps
|
|
1745 the window and then tells the server that the window
|
|
1746 is un-iconified. Usually, XEmacs wakes up between
|
|
1747 those two occurrences, and thus thinks that un-iconified
|
|
1748 windows are still iconified.
|
|
1749
|
|
1750 Ah, the joys of X. */
|
|
1751
|
|
1752 /* By Emacs definition, a frame that is iconified is not
|
|
1753 visible. Marking a frame as visible will automatically cause
|
|
1754 frame-iconified-p to return nil, regardless of whether the
|
|
1755 frame is actually iconified. Therefore, we have to ignore
|
|
1756 MapNotify events on iconified frames. (It's not obvious
|
|
1757 to me why these are being sent, but it happens at startup
|
|
1758 with frames that are initially iconified; perhaps they are
|
|
1759 synthetic MapNotify events coming from the window manager.)
|
|
1760 Note that `frame-iconified-p' queries the server
|
|
1761 to determine whether the frame is currently iconified,
|
|
1762 rather than consulting some internal (and likely
|
|
1763 inaccurate) state flag. Therefore, ignoring the MapNotify
|
|
1764 is correct. */
|
793
|
1765 if (!FRAME_VISIBLE_P (f) && NILP (Fframe_iconified_p (wrap_frame (f))))
|
428
|
1766 #endif /* 0 */
|
|
1767 change_frame_visibility (f, 1);
|
|
1768 }
|
|
1769 else
|
|
1770 {
|
|
1771 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
1772 change_frame_visibility (f, 0);
|
|
1773 }
|
|
1774 }
|
|
1775
|
|
1776 static void
|
|
1777 handle_client_message (struct frame *f, XEvent *event)
|
|
1778 {
|
|
1779 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
793
|
1780 Lisp_Object frame = wrap_frame (f);
|
428
|
1781
|
|
1782 if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1783 (Atom) (event->xclient.data.l[0]) == DEVICE_XATOM_WM_DELETE_WINDOW (d))
|
|
1784 {
|
|
1785 /* WM_DELETE_WINDOW is a misc-user event, but other ClientMessages,
|
|
1786 such as WM_TAKE_FOCUS, are eval events. That's because delete-window
|
|
1787 was probably executed with a mouse click, while the others could
|
|
1788 have been sent as a result of mouse motion or some other implicit
|
|
1789 action. (Call this a "heuristic"...) The reason for caring about
|
|
1790 this is so that clicking on the close-box will make emacs prompt
|
|
1791 using a dialog box instead of the minibuffer if there are unsaved
|
|
1792 buffers.
|
|
1793 */
|
|
1794 enqueue_misc_user_event (frame, Qeval,
|
|
1795 list3 (Qdelete_frame, frame, Qt));
|
|
1796 }
|
|
1797 else if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1798 (Atom) event->xclient.data.l[0] == DEVICE_XATOM_WM_TAKE_FOCUS (d))
|
|
1799 {
|
|
1800 handle_focus_event_1 (f, 1);
|
|
1801 #if 0
|
|
1802 /* If there is a dialog box up, focus on it.
|
|
1803
|
|
1804 #### Actually, we're raising it too, which is wrong. We should
|
|
1805 #### just focus on it, but lwlib doesn't currently give us an
|
|
1806 #### easy way to do that. This should be fixed.
|
|
1807 */
|
|
1808 unsigned long take_focus_timestamp = event->xclient.data.l[1];
|
|
1809 Widget widget = lw_raise_all_pop_up_widgets ();
|
|
1810 if (widget)
|
|
1811 {
|
|
1812 /* kludge: raise_all returns bottommost widget, but we really
|
|
1813 want the topmost. So just raise it for now. */
|
|
1814 XMapRaised (XtDisplay (widget), XtWindow (widget));
|
|
1815 /* Grab the focus with the timestamp of the TAKE_FOCUS. */
|
|
1816 XSetInputFocus (XtDisplay (widget), XtWindow (widget),
|
|
1817 RevertToParent, take_focus_timestamp);
|
|
1818 }
|
|
1819 #endif
|
|
1820 }
|
|
1821 }
|
|
1822
|
448
|
1823 /* #### I'm struggling to understand how the X event loop really works.
|
|
1824 Here is the problem:
|
|
1825
|
|
1826 When widgets get mapped / changed etc the actual display updates
|
|
1827 are done asynchronously via X events being processed - this
|
|
1828 normally happens when XtAppProcessEvent() gets called. However, if
|
|
1829 we are executing lisp code or even doing redisplay we won't
|
|
1830 necessarily process X events for a very long time. This has the
|
|
1831 effect of widgets only getting updated when XEmacs only goes into
|
|
1832 idle, or some other event causes processing of the X event queue.
|
|
1833
|
|
1834 XtAppProcessEvent can get called from the following places:
|
|
1835
|
|
1836 emacs_Xt_next_event () - this is normal event processing, almost
|
|
1837 any non-X event will take precedence and this means that we
|
|
1838 cannot rely on it to do the right thing at the right time for
|
|
1839 widget display.
|
|
1840
|
1204
|
1841 emacs_Xt_drain_queue () - this happens when SIGIO gets tripped,
|
|
1842 processing the event queue allows C-g to be checked for. It gets
|
|
1843 called from emacs_Xt_event_pending_p (). #### Update this comment.
|
448
|
1844
|
|
1845 In order to solve this I have tried introducing a list primitive -
|
|
1846 dispatch-non-command-events - which forces processing of X events
|
|
1847 related to display. Unfortunately this has a number of problems,
|
|
1848 one is that it is possible for event_stream_event_pending_p to
|
|
1849 block for ever if there isn't actually an event. I guess this can
|
|
1850 happen if we drop the synthetic event for reason. It also relies on
|
|
1851 SIGIO processing which makes things rather fragile.
|
|
1852
|
|
1853 People have seen behaviour whereby XEmacs blocks until you move the
|
|
1854 mouse. This seems to indicate that dispatch-non-command-events is
|
|
1855 blocking. It may be that in a SIGIO world forcing SIGIO processing
|
|
1856 does the wrong thing.
|
|
1857 */
|
428
|
1858 static void
|
853
|
1859 emacs_Xt_force_event_pending (struct frame *f)
|
442
|
1860 {
|
|
1861 XEvent event;
|
|
1862
|
853
|
1863 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (FRAME_DEVICE (f)));
|
442
|
1864 event.xclient.type = ClientMessage;
|
|
1865 event.xclient.display = dpy;
|
|
1866 event.xclient.message_type = XInternAtom (dpy, "BumpQueue", False);
|
|
1867 event.xclient.format = 32;
|
|
1868 event.xclient.window = 0;
|
|
1869
|
|
1870 /* Send the drop message */
|
|
1871 XSendEvent(dpy, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
1872 True, NoEventMask, &event);
|
448
|
1873 /* We rely on SIGIO and friends to realise we have generated an
|
|
1874 event. */
|
442
|
1875 }
|
|
1876
|
|
1877 static void
|
788
|
1878 emacs_Xt_format_magic_event (Lisp_Event *event, Lisp_Object pstream)
|
|
1879 {
|
|
1880 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
|
|
1881 if (CONSOLE_X_P (XCONSOLE (console)))
|
826
|
1882 write_c_string
|
1204
|
1883 (pstream, x_event_name ((EVENT_MAGIC_X_EVENT (event)).type));
|
788
|
1884 }
|
|
1885
|
|
1886 static int
|
|
1887 emacs_Xt_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
|
|
1888 {
|
|
1889 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) &&
|
|
1890 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
1204
|
1891 return ((EVENT_MAGIC_X_EVENT (e1)).xany.serial ==
|
|
1892 (EVENT_MAGIC_X_EVENT (e2)).xany.serial);
|
788
|
1893 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) ||
|
|
1894 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
|
1895 return 0;
|
|
1896 return 1;
|
|
1897 }
|
|
1898
|
|
1899 static Hashcode
|
|
1900 emacs_Xt_hash_magic_event (Lisp_Event *e)
|
|
1901 {
|
|
1902 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
|
|
1903 if (CONSOLE_X_P (XCONSOLE (console)))
|
1204
|
1904 return (EVENT_MAGIC_X_EVENT (e)).xany.serial;
|
788
|
1905 return 0;
|
|
1906 }
|
|
1907
|
|
1908 static void
|
440
|
1909 emacs_Xt_handle_magic_event (Lisp_Event *emacs_event)
|
428
|
1910 {
|
|
1911 /* This function can GC */
|
1204
|
1912 XEvent *event = &EVENT_MAGIC_X_EVENT (emacs_event);
|
428
|
1913 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
1914
|
|
1915 if (!FRAME_LIVE_P (f) || DEVICE_X_BEING_DELETED (XDEVICE (FRAME_DEVICE (f))))
|
|
1916 return;
|
|
1917
|
|
1918 switch (event->type)
|
|
1919 {
|
|
1920 case SelectionRequest:
|
|
1921 x_handle_selection_request (&event->xselectionrequest);
|
|
1922 break;
|
934
|
1923
|
428
|
1924 case SelectionClear:
|
|
1925 x_handle_selection_clear (&event->xselectionclear);
|
|
1926 break;
|
934
|
1927
|
428
|
1928 case SelectionNotify:
|
|
1929 x_handle_selection_notify (&event->xselection);
|
|
1930 break;
|
934
|
1931
|
428
|
1932 case PropertyNotify:
|
|
1933 x_handle_property_notify (&event->xproperty);
|
|
1934 break;
|
934
|
1935
|
428
|
1936 case Expose:
|
|
1937 if (!check_for_ignored_expose (f, event->xexpose.x, event->xexpose.y,
|
1318
|
1938 event->xexpose.width,
|
|
1939 event->xexpose.height)
|
428
|
1940 &&
|
|
1941 !find_matching_subwindow (f, event->xexpose.x, event->xexpose.y,
|
|
1942 event->xexpose.width, event->xexpose.height))
|
1318
|
1943 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1944 event->xexpose.width,
|
|
1945 event->xexpose.height);
|
428
|
1946 break;
|
|
1947
|
|
1948 case GraphicsExpose: /* This occurs when an XCopyArea's source area was
|
|
1949 obscured or not available. */
|
1318
|
1950 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1951 event->xexpose.width,
|
|
1952 event->xexpose.height);
|
428
|
1953 break;
|
|
1954
|
|
1955 case MapNotify:
|
|
1956 case UnmapNotify:
|
|
1957 handle_map_event (f, event);
|
|
1958 break;
|
|
1959
|
|
1960 case EnterNotify:
|
|
1961 if (event->xcrossing.detail != NotifyInferior)
|
|
1962 {
|
793
|
1963 Lisp_Object frame = wrap_frame (f);
|
|
1964
|
428
|
1965 /* FRAME_X_MOUSE_P (f) = 1; */
|
|
1966 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame);
|
|
1967 }
|
|
1968 break;
|
|
1969
|
|
1970 case LeaveNotify:
|
|
1971 if (event->xcrossing.detail != NotifyInferior)
|
|
1972 {
|
793
|
1973 Lisp_Object frame = wrap_frame (f);
|
|
1974
|
428
|
1975 /* FRAME_X_MOUSE_P (f) = 0; */
|
|
1976 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame);
|
|
1977 }
|
|
1978 break;
|
|
1979
|
|
1980 case FocusIn:
|
|
1981 case FocusOut:
|
|
1982
|
|
1983 #ifdef EXTERNAL_WIDGET
|
|
1984 /* External widget lossage: Ben said:
|
|
1985 YUCK. The only way to make focus changes work properly is to
|
|
1986 completely ignore all FocusIn/FocusOut events and depend only
|
|
1987 on notifications from the ExternalClient widget. */
|
|
1988 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1989 break;
|
|
1990 #endif
|
863
|
1991 handle_focus_event_2 (event->xfocus.window, f, event->type == FocusIn);
|
428
|
1992 break;
|
|
1993
|
|
1994 case ClientMessage:
|
|
1995 handle_client_message (f, event);
|
|
1996 break;
|
|
1997
|
|
1998 case VisibilityNotify: /* window visibility has changed */
|
|
1999 if (event->xvisibility.window == XtWindow (FRAME_X_SHELL_WIDGET (f)))
|
|
2000 {
|
593
|
2001 /* See comment in handle_map_event */
|
|
2002 update_frame_iconify_status (f);
|
|
2003
|
|
2004 /* #### Ben suggests rewriting the code below using
|
|
2005 x_frame_window_state (f). */
|
428
|
2006 FRAME_X_TOTALLY_VISIBLE_P (f) =
|
|
2007 (event->xvisibility.state == VisibilityUnobscured);
|
|
2008 /* Note that the fvwm pager only sends VisibilityNotify when
|
|
2009 changing pages. Is this all we need to do ? JV */
|
|
2010 /* Nope. We must at least trigger a redisplay here.
|
|
2011 Since this case seems similar to MapNotify, I've
|
|
2012 factored out some code to change_frame_visibility().
|
|
2013 This triggers the necessary redisplay and runs
|
|
2014 (un)map-frame-hook. - dkindred@cs.cmu.edu */
|
|
2015 /* Changed it again to support the tristate visibility flag */
|
|
2016 change_frame_visibility (f, (event->xvisibility.state
|
|
2017 != VisibilityFullyObscured) ? 1 : -1);
|
|
2018 }
|
|
2019 break;
|
|
2020
|
|
2021 case ConfigureNotify:
|
|
2022 #ifdef HAVE_XIM
|
|
2023 XIM_SetGeometry (f);
|
|
2024 #endif
|
|
2025 break;
|
|
2026
|
442
|
2027 case CreateNotify:
|
|
2028 break;
|
|
2029
|
428
|
2030 default:
|
|
2031 break;
|
|
2032 }
|
|
2033 }
|
|
2034
|
|
2035
|
|
2036 /************************************************************************/
|
|
2037 /* timeout events */
|
|
2038 /************************************************************************/
|
|
2039
|
|
2040 static int timeout_id_tick;
|
|
2041
|
|
2042 /* Xt interval id's might not fit into an int (they're pointers, as it
|
|
2043 happens), so we need to provide a conversion list. */
|
|
2044
|
|
2045 static struct Xt_timeout
|
|
2046 {
|
|
2047 int id;
|
|
2048 XtIntervalId interval_id;
|
|
2049 struct Xt_timeout *next;
|
|
2050 } *pending_timeouts, *completed_timeouts;
|
|
2051
|
|
2052 static struct Xt_timeout_blocktype
|
|
2053 {
|
|
2054 Blocktype_declare (struct Xt_timeout);
|
|
2055 } *the_Xt_timeout_blocktype;
|
|
2056
|
|
2057 /* called by XtAppNextEvent() */
|
|
2058 static void
|
2286
|
2059 Xt_timeout_callback (XtPointer closure, XtIntervalId *UNUSED (id))
|
428
|
2060 {
|
|
2061 struct Xt_timeout *timeout = (struct Xt_timeout *) closure;
|
|
2062 struct Xt_timeout *t2 = pending_timeouts;
|
|
2063 /* Remove this one from the list of pending timeouts */
|
|
2064 if (t2 == timeout)
|
|
2065 pending_timeouts = pending_timeouts->next;
|
|
2066 else
|
|
2067 {
|
|
2068 while (t2->next && t2->next != timeout) t2 = t2->next;
|
|
2069 assert (t2->next);
|
|
2070 t2->next = t2->next->next;
|
|
2071 }
|
|
2072 /* Add this one to the list of completed timeouts */
|
|
2073 timeout->next = completed_timeouts;
|
|
2074 completed_timeouts = timeout;
|
|
2075 }
|
|
2076
|
|
2077 static int
|
|
2078 emacs_Xt_add_timeout (EMACS_TIME thyme)
|
|
2079 {
|
|
2080 struct Xt_timeout *timeout = Blocktype_alloc (the_Xt_timeout_blocktype);
|
|
2081 EMACS_TIME current_time;
|
|
2082 int milliseconds;
|
|
2083
|
|
2084 timeout->id = timeout_id_tick++;
|
|
2085 timeout->next = pending_timeouts;
|
|
2086 pending_timeouts = timeout;
|
|
2087 EMACS_GET_TIME (current_time);
|
|
2088 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
2089 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
2090 EMACS_USECS (thyme) / 1000;
|
|
2091 if (milliseconds < 1)
|
|
2092 milliseconds = 1;
|
|
2093 timeout->interval_id = XtAppAddTimeOut (Xt_app_con, milliseconds,
|
|
2094 Xt_timeout_callback,
|
|
2095 (XtPointer) timeout);
|
|
2096 return timeout->id;
|
|
2097 }
|
|
2098
|
|
2099 static void
|
|
2100 emacs_Xt_remove_timeout (int id)
|
|
2101 {
|
|
2102 struct Xt_timeout *timeout, *t2;
|
|
2103
|
|
2104 timeout = NULL;
|
|
2105
|
|
2106 /* Find the timeout on the list of pending ones, if it's still there. */
|
|
2107 if (pending_timeouts)
|
|
2108 {
|
|
2109 if (id == pending_timeouts->id)
|
|
2110 {
|
|
2111 timeout = pending_timeouts;
|
|
2112 pending_timeouts = pending_timeouts->next;
|
|
2113 }
|
|
2114 else
|
|
2115 {
|
|
2116 t2 = pending_timeouts;
|
|
2117 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
2118 if ( t2->next) /*found it */
|
|
2119 {
|
|
2120 timeout = t2->next;
|
|
2121 t2->next = t2->next->next;
|
|
2122 }
|
|
2123 }
|
|
2124 /* if it was pending, we have removed it from the list */
|
|
2125 if (timeout)
|
|
2126 XtRemoveTimeOut (timeout->interval_id);
|
|
2127 }
|
|
2128
|
|
2129 /* It could be that the Xt call back was already called but we didn't convert
|
|
2130 into an Emacs event yet */
|
|
2131 if (!timeout && completed_timeouts)
|
|
2132 {
|
|
2133 /* Code duplication! */
|
|
2134 if (id == completed_timeouts->id)
|
|
2135 {
|
|
2136 timeout = completed_timeouts;
|
|
2137 completed_timeouts = completed_timeouts->next;
|
|
2138 }
|
|
2139 else
|
|
2140 {
|
|
2141 t2 = completed_timeouts;
|
|
2142 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
2143 if ( t2->next) /*found it */
|
|
2144 {
|
|
2145 timeout = t2->next;
|
|
2146 t2->next = t2->next->next;
|
|
2147 }
|
|
2148 }
|
|
2149 }
|
|
2150
|
|
2151 /* If we found the thing on the lists of timeouts,
|
|
2152 and removed it, deallocate
|
|
2153 */
|
|
2154 if (timeout)
|
|
2155 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
2156 }
|
|
2157
|
|
2158 static void
|
440
|
2159 Xt_timeout_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2160 {
|
|
2161 struct Xt_timeout *timeout = completed_timeouts;
|
|
2162 assert (timeout);
|
|
2163 completed_timeouts = completed_timeouts->next;
|
934
|
2164 /* timeout events have nil as channel */
|
1204
|
2165 set_event_type (emacs_event, timeout_event);
|
934
|
2166 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### wrong!! */
|
1204
|
2167 SET_EVENT_TIMEOUT_INTERVAL_ID (emacs_event, timeout->id);
|
|
2168 SET_EVENT_TIMEOUT_FUNCTION (emacs_event, Qnil);
|
|
2169 SET_EVENT_TIMEOUT_OBJECT (emacs_event, Qnil);
|
428
|
2170 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
2171 }
|
|
2172
|
|
2173
|
|
2174 /************************************************************************/
|
|
2175 /* process and tty events */
|
|
2176 /************************************************************************/
|
|
2177
|
|
2178 struct what_is_ready_closure
|
|
2179 {
|
|
2180 int fd;
|
|
2181 Lisp_Object what;
|
|
2182 XtInputId id;
|
|
2183 };
|
|
2184
|
|
2185 static Lisp_Object *filedesc_with_input;
|
|
2186 static struct what_is_ready_closure **filedesc_to_what_closure;
|
|
2187
|
|
2188 static void
|
|
2189 init_what_input_once (void)
|
|
2190 {
|
|
2191 int i;
|
|
2192
|
|
2193 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC);
|
|
2194 filedesc_to_what_closure =
|
|
2195 xnew_array (struct what_is_ready_closure *, MAXDESC);
|
|
2196
|
|
2197 for (i = 0; i < MAXDESC; i++)
|
|
2198 {
|
|
2199 filedesc_to_what_closure[i] = 0;
|
|
2200 filedesc_with_input[i] = Qnil;
|
|
2201 }
|
|
2202
|
|
2203 process_events_occurred = 0;
|
|
2204 tty_events_occurred = 0;
|
|
2205 }
|
|
2206
|
|
2207 static void
|
|
2208 mark_what_as_being_ready (struct what_is_ready_closure *closure)
|
|
2209 {
|
|
2210 if (NILP (filedesc_with_input[closure->fd]))
|
|
2211 {
|
|
2212 SELECT_TYPE temp_mask;
|
|
2213 FD_ZERO (&temp_mask);
|
|
2214 FD_SET (closure->fd, &temp_mask);
|
|
2215 /* Check to make sure there's *really* input available.
|
|
2216 Sometimes things seem to get confused and this gets called
|
|
2217 for the tty fd when there's really only input available
|
|
2218 on some process's fd. (It will subsequently get called
|
|
2219 for that process's fd, so returning without setting any
|
|
2220 flags will take care of it.) To see the problem, uncomment
|
|
2221 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS
|
|
2222 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log'
|
|
2223 and press return repeatedly. (Seen under AIX & Linux.)
|
|
2224 -dkindred@cs.cmu.edu */
|
|
2225 if (!poll_fds_for_input (temp_mask))
|
|
2226 {
|
|
2227 #if 0
|
|
2228 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n",
|
|
2229 closure->fd);
|
|
2230 #endif
|
|
2231 return;
|
|
2232 }
|
|
2233 filedesc_with_input[closure->fd] = closure->what;
|
|
2234 if (PROCESSP (closure->what))
|
|
2235 /* Don't increment this if the current process is already marked
|
|
2236 * as having input. */
|
|
2237 process_events_occurred++;
|
|
2238 else
|
|
2239 tty_events_occurred++;
|
|
2240 }
|
|
2241 }
|
|
2242
|
|
2243 static void
|
2286
|
2244 Xt_what_callback (void *closure, int *UNUSED (source), XtInputId *UNUSED (id))
|
428
|
2245 {
|
|
2246 /* If closure is 0, then we got a fake event from a signal handler.
|
|
2247 The only purpose of this is to make XtAppProcessEvent() stop
|
|
2248 blocking. */
|
|
2249 if (closure)
|
|
2250 mark_what_as_being_ready ((struct what_is_ready_closure *) closure);
|
|
2251 else
|
|
2252 {
|
|
2253 fake_event_occurred++;
|
|
2254 drain_signal_event_pipe ();
|
|
2255 }
|
|
2256 }
|
|
2257
|
|
2258 static void
|
|
2259 select_filedesc (int fd, Lisp_Object what)
|
|
2260 {
|
|
2261 struct what_is_ready_closure *closure;
|
|
2262
|
|
2263 /* If somebody is trying to select something that's already selected
|
|
2264 for, then something went wrong. The generic routines ought to
|
|
2265 detect this and error before here. */
|
|
2266 assert (!filedesc_to_what_closure[fd]);
|
|
2267
|
|
2268 closure = xnew (struct what_is_ready_closure);
|
|
2269 closure->fd = fd;
|
|
2270 closure->what = what;
|
|
2271 closure->id =
|
|
2272 XtAppAddInput (Xt_app_con, fd,
|
|
2273 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
2274 Xt_what_callback, closure);
|
|
2275 filedesc_to_what_closure[fd] = closure;
|
|
2276 }
|
|
2277
|
|
2278 static void
|
|
2279 unselect_filedesc (int fd)
|
|
2280 {
|
|
2281 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd];
|
|
2282
|
|
2283 assert (closure);
|
|
2284 if (!NILP (filedesc_with_input[fd]))
|
|
2285 {
|
|
2286 /* We are unselecting this process before we have drained the rest of
|
|
2287 the input from it, probably from status_notify() in the command loop.
|
|
2288 This can happen like so:
|
|
2289
|
|
2290 - We are waiting in XtAppNextEvent()
|
|
2291 - Process generates output
|
|
2292 - Process is marked as being ready
|
|
2293 - Process dies, SIGCHLD gets generated before we return (!?)
|
|
2294 It could happen I guess.
|
|
2295 - sigchld_handler() marks process as dead
|
|
2296 - Somehow we end up getting a new KeyPress event on the queue
|
|
2297 at the same time (I'm really so sure how that happens but I'm
|
|
2298 not sure it can't either so let's assume it can...).
|
|
2299 - Key events have priority so we return that instead of the proc.
|
|
2300 - Before dispatching the lisp key event we call status_notify()
|
|
2301 - Which deselects the process that SIGCHLD marked as dead.
|
|
2302
|
|
2303 Thus we never remove it from _with_input and turn it into a lisp
|
|
2304 event, so we need to do it here. But this does not mean that we're
|
|
2305 throwing away the last block of output - status_notify() has already
|
|
2306 taken care of running the proc filter or whatever.
|
|
2307 */
|
|
2308 filedesc_with_input[fd] = Qnil;
|
|
2309 if (PROCESSP (closure->what))
|
|
2310 {
|
|
2311 assert (process_events_occurred > 0);
|
|
2312 process_events_occurred--;
|
|
2313 }
|
|
2314 else
|
|
2315 {
|
|
2316 assert (tty_events_occurred > 0);
|
|
2317 tty_events_occurred--;
|
|
2318 }
|
|
2319 }
|
|
2320 XtRemoveInput (closure->id);
|
1726
|
2321 xfree (closure, struct what_is_ready_closure *);
|
428
|
2322 filedesc_to_what_closure[fd] = 0;
|
|
2323 }
|
|
2324
|
|
2325 static void
|
853
|
2326 emacs_Xt_select_process (Lisp_Process *process, int doin, int doerr)
|
428
|
2327 {
|
853
|
2328 Lisp_Object proc;
|
|
2329 int infd, errfd;
|
|
2330
|
|
2331 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd);
|
|
2332
|
|
2333 proc = wrap_process (process);
|
|
2334 if (doin)
|
|
2335 select_filedesc (infd, proc);
|
|
2336 if (doerr)
|
|
2337 select_filedesc (errfd, proc);
|
|
2338 }
|
|
2339
|
|
2340 static void
|
|
2341 emacs_Xt_unselect_process (Lisp_Process *process, int doin, int doerr)
|
|
2342 {
|
|
2343 int infd, errfd;
|
|
2344
|
|
2345 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd);
|
|
2346
|
|
2347 if (doin)
|
|
2348 unselect_filedesc (infd);
|
|
2349 if (doerr)
|
|
2350 unselect_filedesc (errfd);
|
428
|
2351 }
|
|
2352
|
|
2353 static void
|
853
|
2354 emacs_Xt_create_io_streams (void *inhandle, void *outhandle,
|
|
2355 void *errhandle, Lisp_Object *instream,
|
|
2356 Lisp_Object *outstream,
|
|
2357 Lisp_Object *errstream,
|
|
2358 USID *in_usid,
|
|
2359 USID *err_usid,
|
|
2360 int flags)
|
428
|
2361 {
|
853
|
2362 event_stream_unixoid_create_io_streams
|
|
2363 (inhandle, outhandle, errhandle, instream, outstream,
|
|
2364 errstream, in_usid, err_usid, flags);
|
|
2365 if (*in_usid != USID_ERROR)
|
|
2366 *in_usid = USID_DONTHASH;
|
|
2367 if (*err_usid != USID_ERROR)
|
|
2368 *err_usid = USID_DONTHASH;
|
428
|
2369 }
|
|
2370
|
853
|
2371 static void
|
|
2372 emacs_Xt_delete_io_streams (Lisp_Object instream,
|
|
2373 Lisp_Object outstream,
|
|
2374 Lisp_Object errstream,
|
|
2375 USID *in_usid,
|
|
2376 USID *err_usid)
|
428
|
2377 {
|
853
|
2378 event_stream_unixoid_delete_io_streams
|
|
2379 (instream, outstream, errstream, in_usid, err_usid);
|
|
2380 *in_usid = USID_DONTHASH;
|
|
2381 *err_usid = USID_DONTHASH;
|
428
|
2382 }
|
|
2383
|
|
2384 /* This is called from GC when a process object is about to be freed.
|
|
2385 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
2386 */
|
|
2387 void
|
2286
|
2388 debug_process_finalization (Lisp_Process *UNUSED (p))
|
428
|
2389 {
|
|
2390 #if 0 /* #### */
|
|
2391 int i;
|
853
|
2392 Lisp_Object instr, outstr, errstr;
|
|
2393
|
|
2394 get_process_streams (p, &instr, &outstr, &errstr);
|
428
|
2395 /* if it still has fds, then it hasn't been killed yet. */
|
|
2396 assert (NILP(instr));
|
|
2397 assert (NILP(outstr));
|
853
|
2398 assert (NILP(errstr));
|
428
|
2399 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
2400 for (i = 0; i < MAXDESC; i++)
|
|
2401 {
|
|
2402 Lisp_Object process = filedesc_fds_with_input [i];
|
|
2403 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
2404 }
|
|
2405 #endif
|
|
2406 }
|
|
2407
|
|
2408 static void
|
440
|
2409 Xt_process_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2410 {
|
|
2411 int i;
|
|
2412
|
|
2413 assert (process_events_occurred > 0);
|
438
|
2414
|
428
|
2415 for (i = 0; i < MAXDESC; i++)
|
|
2416 {
|
438
|
2417 Lisp_Object process = filedesc_with_input[i];
|
428
|
2418 if (PROCESSP (process))
|
438
|
2419 {
|
|
2420 filedesc_with_input[i] = Qnil;
|
|
2421 process_events_occurred--;
|
|
2422 /* process events have nil as channel */
|
934
|
2423 set_event_type (emacs_event, process_event);
|
|
2424 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### */
|
1204
|
2425 SET_EVENT_PROCESS_PROCESS (emacs_event, process);
|
438
|
2426 return;
|
|
2427 }
|
428
|
2428 }
|
2500
|
2429 ABORT ();
|
428
|
2430 }
|
|
2431
|
|
2432 static void
|
|
2433 emacs_Xt_select_console (struct console *con)
|
|
2434 {
|
|
2435 Lisp_Object console;
|
|
2436 int infd;
|
|
2437
|
|
2438 if (CONSOLE_X_P (con))
|
|
2439 return; /* X consoles are automatically selected for when we
|
|
2440 initialize them in Xt */
|
|
2441 infd = event_stream_unixoid_select_console (con);
|
793
|
2442 console = wrap_console (con);
|
428
|
2443 select_filedesc (infd, console);
|
|
2444 }
|
|
2445
|
|
2446 static void
|
|
2447 emacs_Xt_unselect_console (struct console *con)
|
|
2448 {
|
|
2449 int infd;
|
|
2450
|
|
2451 if (CONSOLE_X_P (con))
|
|
2452 return; /* X consoles are automatically selected for when we
|
|
2453 initialize them in Xt */
|
|
2454 infd = event_stream_unixoid_unselect_console (con);
|
|
2455 unselect_filedesc (infd);
|
|
2456 }
|
|
2457
|
|
2458 /* read an event from a tty, if one is available. Returns non-zero
|
|
2459 if an event was available. Note that when this function is
|
|
2460 called, there should always be a tty marked as ready for input.
|
|
2461 However, the input condition might actually be EOF, so there
|
|
2462 may not really be any input available. (In this case,
|
|
2463 read_event_from_tty_or_stream_desc() will arrange for the TTY device
|
|
2464 to be deleted.) */
|
|
2465
|
|
2466 static int
|
440
|
2467 Xt_tty_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2468 {
|
|
2469 int i;
|
|
2470
|
|
2471 assert (tty_events_occurred > 0);
|
|
2472 for (i = 0; i < MAXDESC; i++)
|
|
2473 {
|
|
2474 Lisp_Object console = filedesc_with_input[i];
|
|
2475 if (CONSOLEP (console))
|
|
2476 {
|
|
2477 assert (tty_events_occurred > 0);
|
|
2478 tty_events_occurred--;
|
|
2479 filedesc_with_input[i] = Qnil;
|
771
|
2480 if (read_event_from_tty_or_stream_desc (emacs_event,
|
|
2481 XCONSOLE (console)))
|
428
|
2482 return 1;
|
|
2483 }
|
|
2484 }
|
|
2485
|
|
2486 return 0;
|
|
2487 }
|
|
2488
|
|
2489
|
|
2490 /************************************************************************/
|
|
2491 /* debugging functions to decipher an event */
|
|
2492 /************************************************************************/
|
|
2493
|
|
2494 #ifdef DEBUG_XEMACS
|
|
2495 #include "xintrinsicp.h" /* only describe_event() needs this */
|
|
2496 #include <X11/Xproto.h> /* only describe_event() needs this */
|
|
2497
|
|
2498 static void
|
788
|
2499 describe_event_window (Window window, Display *display, Lisp_Object pstream)
|
428
|
2500 {
|
|
2501 struct frame *f;
|
|
2502 Widget w;
|
788
|
2503 write_fmt_string (pstream, " window: 0x%lx", (unsigned long) window);
|
428
|
2504 w = XtWindowToWidget (display, window);
|
|
2505 if (w)
|
788
|
2506 write_fmt_string (pstream, " %s",
|
|
2507 w->core.widget_class->core_class.class_name);
|
428
|
2508 f = x_any_window_to_frame (get_device_from_display (display), window);
|
|
2509 if (f)
|
788
|
2510 write_fmt_string_lisp (pstream, " \"%s\"", 1, f->name);
|
|
2511 write_fmt_string (pstream, "\n");
|
428
|
2512 }
|
|
2513
|
442
|
2514 static const char *
|
428
|
2515 XEvent_mode_to_string (int mode)
|
|
2516 {
|
|
2517 switch (mode)
|
|
2518 {
|
|
2519 case NotifyNormal: return "Normal";
|
|
2520 case NotifyGrab: return "Grab";
|
|
2521 case NotifyUngrab: return "Ungrab";
|
|
2522 case NotifyWhileGrabbed: return "WhileGrabbed";
|
|
2523 default: return "???";
|
|
2524 }
|
|
2525 }
|
|
2526
|
442
|
2527 static const char *
|
428
|
2528 XEvent_detail_to_string (int detail)
|
|
2529 {
|
|
2530 switch (detail)
|
|
2531 {
|
|
2532 case NotifyAncestor: return "Ancestor";
|
|
2533 case NotifyInferior: return "Inferior";
|
|
2534 case NotifyNonlinear: return "Nonlinear";
|
|
2535 case NotifyNonlinearVirtual: return "NonlinearVirtual";
|
|
2536 case NotifyPointer: return "Pointer";
|
|
2537 case NotifyPointerRoot: return "PointerRoot";
|
|
2538 case NotifyDetailNone: return "DetailNone";
|
|
2539 default: return "???";
|
|
2540 }
|
|
2541 }
|
|
2542
|
442
|
2543 static const char *
|
428
|
2544 XEvent_visibility_to_string (int state)
|
|
2545 {
|
|
2546 switch (state)
|
|
2547 {
|
|
2548 case VisibilityFullyObscured: return "FullyObscured";
|
|
2549 case VisibilityPartiallyObscured: return "PartiallyObscured";
|
|
2550 case VisibilityUnobscured: return "Unobscured";
|
|
2551 default: return "???";
|
|
2552 }
|
|
2553 }
|
|
2554
|
|
2555 static void
|
788
|
2556 describe_event (XEvent *event, Lisp_Object pstream)
|
428
|
2557 {
|
|
2558 char buf[100];
|
|
2559 struct device *d = get_device_from_display (event->xany.display);
|
|
2560
|
|
2561 sprintf (buf, "%s%s", x_event_name (event->type),
|
|
2562 event->xany.send_event ? " (send)" : "");
|
788
|
2563 write_fmt_string (pstream, "%-30s", buf);
|
428
|
2564 switch (event->type)
|
|
2565 {
|
|
2566 case FocusIn:
|
|
2567 case FocusOut:
|
|
2568 {
|
|
2569 XFocusChangeEvent *ev = &event->xfocus;
|
788
|
2570 describe_event_window (ev->window, ev->display, pstream);
|
|
2571 write_fmt_string (pstream, " mode: %s\n",
|
|
2572 XEvent_mode_to_string (ev->mode));
|
|
2573 write_fmt_string (pstream, " detail: %s\n",
|
|
2574 XEvent_detail_to_string (ev->detail));
|
428
|
2575 break;
|
|
2576 }
|
|
2577
|
|
2578 case KeyPress:
|
|
2579 {
|
|
2580 XKeyEvent *ev = &event->xkey;
|
|
2581 unsigned int state = ev->state;
|
|
2582
|
788
|
2583 describe_event_window (ev->window, ev->display, pstream);
|
|
2584 write_fmt_string (pstream, " subwindow: %ld\n", ev->subwindow);
|
|
2585 write_fmt_string (pstream, " state: ");
|
428
|
2586 /* Complete list of modifier key masks */
|
788
|
2587 if (state & ShiftMask) write_fmt_string (pstream, "Shift ");
|
|
2588 if (state & LockMask) write_fmt_string (pstream, "Lock ");
|
|
2589 if (state & ControlMask) write_fmt_string (pstream, "Control ");
|
|
2590 if (state & Mod1Mask) write_fmt_string (pstream, "Mod1 ");
|
|
2591 if (state & Mod2Mask) write_fmt_string (pstream, "Mod2 ");
|
|
2592 if (state & Mod3Mask) write_fmt_string (pstream, "Mod3 ");
|
|
2593 if (state & Mod4Mask) write_fmt_string (pstream, "Mod4 ");
|
|
2594 if (state & Mod5Mask) write_fmt_string (pstream, "Mod5 ");
|
428
|
2595
|
|
2596 if (! state)
|
788
|
2597 write_fmt_string (pstream, "vanilla\n");
|
428
|
2598 else
|
788
|
2599 write_fmt_string (pstream, "\n");
|
428
|
2600 if (x_key_is_modifier_p (ev->keycode, d))
|
788
|
2601 write_fmt_string (pstream, " Modifier key");
|
|
2602 write_fmt_string (pstream, " keycode: 0x%x\n", ev->keycode);
|
428
|
2603 }
|
|
2604 break;
|
|
2605
|
|
2606 case Expose:
|
442
|
2607 if (debug_x_events > 1)
|
428
|
2608 {
|
|
2609 XExposeEvent *ev = &event->xexpose;
|
788
|
2610 describe_event_window (ev->window, ev->display, pstream);
|
|
2611 write_fmt_string (pstream,
|
|
2612 " region: x=%d y=%d width=%d height=%d\n",
|
428
|
2613 ev->x, ev->y, ev->width, ev->height);
|
788
|
2614 write_fmt_string (pstream, " count: %d\n", ev->count);
|
428
|
2615 }
|
|
2616 else
|
788
|
2617 write_fmt_string (pstream, "\n");
|
428
|
2618 break;
|
|
2619
|
|
2620 case GraphicsExpose:
|
442
|
2621 if (debug_x_events > 1)
|
428
|
2622 {
|
|
2623 XGraphicsExposeEvent *ev = &event->xgraphicsexpose;
|
788
|
2624 describe_event_window (ev->drawable, ev->display, pstream);
|
|
2625 write_fmt_string (pstream, " major: %s\n",
|
428
|
2626 (ev ->major_code == X_CopyArea ? "CopyArea" :
|
|
2627 (ev->major_code == X_CopyPlane ? "CopyPlane" : "?")));
|
788
|
2628 write_fmt_string (pstream,
|
|
2629 " region: x=%d y=%d width=%d height=%d\n",
|
428
|
2630 ev->x, ev->y, ev->width, ev->height);
|
788
|
2631 write_fmt_string (pstream, " count: %d\n", ev->count);
|
428
|
2632 }
|
|
2633 else
|
788
|
2634 write_fmt_string (pstream, "\n");
|
428
|
2635 break;
|
|
2636
|
|
2637 case EnterNotify:
|
|
2638 case LeaveNotify:
|
442
|
2639 if (debug_x_events > 1)
|
428
|
2640 {
|
|
2641 XCrossingEvent *ev = &event->xcrossing;
|
788
|
2642 describe_event_window (ev->window, ev->display, pstream);
|
428
|
2643 #if 0
|
788
|
2644 write_fmt_string (pstream, " subwindow: 0x%x\n", ev->subwindow);
|
|
2645 write_fmt_string (pstream, " pos: %d %d\n", ev->x, ev->y);
|
|
2646 write_fmt_string (pstream, " root pos: %d %d\n", ev->x_root,
|
|
2647 ev->y_root);
|
428
|
2648 #endif
|
788
|
2649 write_fmt_string (pstream, " mode: %s\n",
|
|
2650 XEvent_mode_to_string(ev->mode));
|
|
2651 write_fmt_string (pstream, " detail: %s\n",
|
|
2652 XEvent_detail_to_string(ev->detail));
|
|
2653 write_fmt_string (pstream, " focus: %d\n", ev->focus);
|
428
|
2654 #if 0
|
788
|
2655 write_fmt_string (pstream, " state: 0x%x\n", ev->state);
|
428
|
2656 #endif
|
|
2657 }
|
|
2658 else
|
788
|
2659 write_fmt_string (pstream, "\n");
|
428
|
2660 break;
|
|
2661
|
|
2662 case ConfigureNotify:
|
442
|
2663 if (debug_x_events > 1)
|
428
|
2664 {
|
|
2665 XConfigureEvent *ev = &event->xconfigure;
|
788
|
2666 describe_event_window (ev->window, ev->display, pstream);
|
|
2667 write_fmt_string (pstream, " above: 0x%lx\n", ev->above);
|
|
2668 write_fmt_string (pstream, " size: %d %d %d %d\n", ev->x, ev->y,
|
428
|
2669 ev->width, ev->height);
|
788
|
2670 write_fmt_string (pstream, " redirect: %d\n",
|
|
2671 ev->override_redirect);
|
428
|
2672 }
|
|
2673 else
|
788
|
2674 write_fmt_string (pstream, "\n");
|
428
|
2675 break;
|
|
2676
|
|
2677 case VisibilityNotify:
|
442
|
2678 if (debug_x_events > 1)
|
428
|
2679 {
|
|
2680 XVisibilityEvent *ev = &event->xvisibility;
|
788
|
2681 describe_event_window (ev->window, ev->display, pstream);
|
|
2682 write_fmt_string (pstream, " state: %s\n",
|
|
2683 XEvent_visibility_to_string (ev->state));
|
428
|
2684 }
|
|
2685 else
|
788
|
2686 write_fmt_string (pstream, "\n");
|
428
|
2687 break;
|
|
2688
|
|
2689 case ClientMessage:
|
|
2690 {
|
|
2691 XClientMessageEvent *ev = &event->xclient;
|
|
2692 char *name = XGetAtomName (ev->display, ev->message_type);
|
788
|
2693 write_fmt_string (pstream, "%s", name);
|
|
2694 if (!strcmp (name, "WM_PROTOCOLS"))
|
|
2695 {
|
|
2696 char *protname = XGetAtomName (ev->display, ev->data.l[0]);
|
|
2697 write_fmt_string (pstream, "(%s)", protname);
|
|
2698 XFree (protname);
|
|
2699 }
|
428
|
2700 XFree (name);
|
788
|
2701 write_fmt_string (pstream, "\n");
|
428
|
2702 break;
|
|
2703 }
|
|
2704
|
|
2705 default:
|
788
|
2706 write_fmt_string (pstream, "\n");
|
428
|
2707 break;
|
|
2708 }
|
|
2709
|
|
2710 fflush (stdout);
|
|
2711 }
|
|
2712
|
|
2713 #endif /* include describe_event definition */
|
|
2714
|
|
2715
|
|
2716 /************************************************************************/
|
|
2717 /* get the next event from Xt */
|
|
2718 /************************************************************************/
|
|
2719
|
|
2720 /* This business exists because menu events "happen" when
|
|
2721 menubar_selection_callback() is called from somewhere deep
|
|
2722 within XtAppProcessEvent in emacs_Xt_next_event(). The
|
|
2723 callback needs to terminate the modal loop in that function
|
|
2724 or else it will continue waiting until another event is
|
|
2725 received.
|
|
2726
|
|
2727 Same business applies to scrollbar events. */
|
|
2728
|
|
2729 void
|
|
2730 signal_special_Xt_user_event (Lisp_Object channel, Lisp_Object function,
|
|
2731 Lisp_Object object)
|
|
2732 {
|
|
2733 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
2734
|
934
|
2735 XSET_EVENT_TYPE (event, misc_user_event);
|
|
2736 XSET_EVENT_CHANNEL (event, channel);
|
1204
|
2737 XSET_EVENT_MISC_USER_FUNCTION (event, function);
|
|
2738 XSET_EVENT_MISC_USER_OBJECT (event, object);
|
|
2739 enqueue_dispatch_event (event);
|
428
|
2740 }
|
|
2741
|
|
2742 static void
|
440
|
2743 emacs_Xt_next_event (Lisp_Event *emacs_event)
|
428
|
2744 {
|
|
2745 we_didnt_get_an_event:
|
|
2746
|
|
2747 while (NILP (dispatch_event_queue) &&
|
|
2748 !completed_timeouts &&
|
|
2749 !fake_event_occurred &&
|
|
2750 !process_events_occurred &&
|
|
2751 !tty_events_occurred)
|
|
2752 {
|
1268
|
2753 if (in_modal_loop)
|
|
2754 {
|
|
2755 /* in_modal_loop gets set when we are in the process of
|
|
2756 dispatching an event (more specifically, when we are inside of
|
|
2757 a menu callback -- if we get here, it means we called a filter
|
|
2758 and the filter did something that tried to fetch an event,
|
|
2759 e.g. sit-for). In such a case, we cannot safely dispatch any
|
|
2760 more events. This is because those dispatching those events
|
|
2761 could cause lwlib to be entered reentranty, specifically if
|
|
2762 they are menu events. lwlib is not designed for this and will
|
|
2763 crash. We used to see this crash constantly as a result of
|
|
2764 QUIT checking, but QUIT will not now function in a modal loop.
|
|
2765 However, we can't just not process any events at all, because
|
|
2766 that will make sit-for etc. hang. So we go ahead and process
|
|
2767 the non-X kinds of events. */
|
1292
|
2768 #ifdef WIN32_ANY
|
|
2769 mswindows_is_blocking = 1;
|
|
2770 #endif
|
|
2771 XtAppProcessEvent (Xt_app_con, XtIMTimer | XtIMAlternateInput);
|
|
2772 #ifdef WIN32_ANY
|
|
2773 mswindows_is_blocking = 0;
|
|
2774 #endif
|
1268
|
2775 }
|
428
|
2776 else
|
|
2777 {
|
1268
|
2778 /* Stupid logic in XtAppProcessEvent() dictates that, if process
|
|
2779 events and X events are both available, the process event gets
|
|
2780 taken first. This will cause an infinite loop if we're being
|
|
2781 called from Fdiscard_input().
|
|
2782 */
|
|
2783
|
|
2784 if (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2785 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2786 else
|
428
|
2787 {
|
1268
|
2788 Lisp_Object devcons, concons;
|
|
2789
|
|
2790 /* We're about to block. Xt has a bug in it (big surprise,
|
|
2791 there) in that it blocks using select() and doesn't
|
|
2792 flush the Xlib output buffers (XNextEvent() does this
|
|
2793 automatically before blocking). So it's necessary
|
|
2794 for us to do this ourselves. If we don't do it, then
|
|
2795 display output may not be seen until the next time
|
|
2796 an X event is received. (This happens esp. with
|
|
2797 subprocess output that gets sent to a visible buffer.)
|
|
2798
|
|
2799 #### The above comment may not have any validity. */
|
|
2800
|
|
2801 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
2802 {
|
|
2803 struct device *d;
|
|
2804 d = XDEVICE (XCAR (devcons));
|
|
2805
|
|
2806 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2807 /* emacs may be exiting */
|
|
2808 XFlush (DEVICE_X_DISPLAY (d));
|
|
2809 }
|
1292
|
2810 #ifdef WIN32_ANY
|
|
2811 mswindows_is_blocking = 1;
|
|
2812 #endif
|
1268
|
2813 XtAppProcessEvent (Xt_app_con, XtIMAll);
|
1292
|
2814 #ifdef WIN32_ANY
|
|
2815 mswindows_is_blocking = 0;
|
|
2816 #endif
|
428
|
2817 }
|
|
2818 }
|
|
2819 }
|
|
2820
|
|
2821 if (!NILP (dispatch_event_queue))
|
|
2822 {
|
|
2823 Lisp_Object event, event2;
|
793
|
2824 event2 = wrap_event (emacs_event);
|
1204
|
2825 event = dequeue_dispatch_event ();
|
428
|
2826 Fcopy_event (event, event2);
|
|
2827 Fdeallocate_event (event);
|
|
2828 }
|
|
2829 else if (tty_events_occurred)
|
|
2830 {
|
|
2831 if (!Xt_tty_to_emacs_event (emacs_event))
|
|
2832 goto we_didnt_get_an_event;
|
|
2833 }
|
|
2834 else if (completed_timeouts)
|
|
2835 Xt_timeout_to_emacs_event (emacs_event);
|
|
2836 else if (fake_event_occurred)
|
|
2837 {
|
|
2838 /* A dummy event, so that a cycle of the command loop will occur. */
|
|
2839 fake_event_occurred = 0;
|
|
2840 /* eval events have nil as channel */
|
934
|
2841 set_event_type (emacs_event, eval_event);
|
1204
|
2842 SET_EVENT_EVAL_FUNCTION (emacs_event, Qidentity);
|
|
2843 SET_EVENT_EVAL_OBJECT (emacs_event, Qnil);
|
428
|
2844 }
|
|
2845 else /* if (process_events_occurred) */
|
|
2846 Xt_process_to_emacs_event (emacs_event);
|
|
2847
|
|
2848 /* No need to call XFilterEvent; Xt does it for us */
|
|
2849 }
|
|
2850
|
|
2851 void
|
2286
|
2852 emacs_Xt_event_handler (Widget UNUSED (wid),
|
|
2853 XtPointer UNUSED (closure),
|
428
|
2854 XEvent *event,
|
2286
|
2855 Boolean *UNUSED (continue_to_dispatch))
|
428
|
2856 {
|
|
2857 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
2858
|
|
2859 #ifdef DEBUG_XEMACS
|
442
|
2860 if (debug_x_events > 0)
|
788
|
2861 describe_event (event, Qexternal_debugging_output);
|
428
|
2862 #endif /* DEBUG_XEMACS */
|
|
2863 if (x_event_to_emacs_event (event, XEVENT (emacs_event)))
|
1204
|
2864 enqueue_dispatch_event (emacs_event);
|
428
|
2865 else
|
|
2866 Fdeallocate_event (emacs_event);
|
|
2867 }
|
|
2868
|
|
2869
|
|
2870 /************************************************************************/
|
1204
|
2871 /* input pending */
|
428
|
2872 /************************************************************************/
|
|
2873
|
|
2874 static void
|
1204
|
2875 emacs_Xt_drain_queue (void)
|
428
|
2876 {
|
|
2877 Lisp_Object devcons, concons;
|
1268
|
2878 if (!in_modal_loop)
|
428
|
2879 {
|
1268
|
2880 CONSOLE_LOOP (concons)
|
428
|
2881 {
|
1268
|
2882 struct console *con = XCONSOLE (XCAR (concons));
|
|
2883 if (!con->input_enabled)
|
|
2884 continue;
|
|
2885
|
|
2886 CONSOLE_DEVICE_LOOP (devcons, con)
|
1204
|
2887 {
|
1268
|
2888 struct device *d;
|
|
2889 Display *display;
|
|
2890 d = XDEVICE (XCAR (devcons));
|
|
2891 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2892 {
|
|
2893 display = DEVICE_X_DISPLAY (d);
|
|
2894 while (XEventsQueued (display, QueuedAfterReading))
|
|
2895 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2896 }
|
1204
|
2897 }
|
428
|
2898 }
|
1268
|
2899 /*
|
|
2900 while (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2901 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2902 */
|
428
|
2903 }
|
1268
|
2904
|
|
2905 #ifdef HAVE_TTY
|
1204
|
2906 drain_tty_devices ();
|
428
|
2907 #endif
|
|
2908 }
|
|
2909
|
1204
|
2910 int
|
|
2911 check_if_pending_expose_event (struct device *dev)
|
|
2912 {
|
|
2913 Display *d = DEVICE_X_DISPLAY (dev);
|
|
2914 Lisp_Object event;
|
|
2915
|
|
2916 emacs_Xt_drain_queue ();
|
|
2917
|
|
2918 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
2919 if (XEVENT_TYPE (event) == magic_event)
|
|
2920 {
|
|
2921 XEvent *xev = &XEVENT_MAGIC_X_EVENT (event);
|
|
2922 if (xev->type == Expose &&
|
|
2923 xev->xexpose.display == d)
|
|
2924 return 1;
|
|
2925 }
|
|
2926
|
|
2927 return 0;
|
|
2928 }
|
|
2929
|
442
|
2930 static int
|
|
2931 emacs_Xt_current_event_timestamp (struct console *c)
|
|
2932 {
|
|
2933 /* semi-yuck. */
|
|
2934 Lisp_Object devs = CONSOLE_DEVICE_LIST (c);
|
|
2935
|
|
2936 if (NILP (devs))
|
|
2937 return 0;
|
|
2938 else
|
|
2939 {
|
|
2940 struct device *d = XDEVICE (XCAR (devs));
|
|
2941 return DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
2942 }
|
|
2943 }
|
|
2944
|
428
|
2945
|
|
2946 /************************************************************************/
|
|
2947 /* replacement for standard string-to-pixel converter */
|
|
2948 /************************************************************************/
|
|
2949
|
|
2950 /* This was constructed by ripping off the standard string-to-pixel
|
|
2951 converter from Converters.c in the Xt source code and modifying
|
|
2952 appropriately. */
|
|
2953
|
|
2954 #if 0
|
|
2955
|
|
2956 /* This is exported by the Xt library (at least by mine). If this
|
|
2957 isn't the case somewhere, rename this appropriately and remove
|
|
2958 the '#if 0'. Note, however, that I got "unknown structure"
|
|
2959 errors when I tried this. */
|
|
2960 XtConvertArgRec Const colorConvertArgs[] = {
|
440
|
2961 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
|
|
2962 sizeof (Screen *) },
|
|
2963 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
|
|
2964 sizeof (Colormap) }
|
428
|
2965 };
|
|
2966
|
|
2967 #endif
|
|
2968
|
|
2969 #define done(type, value) \
|
|
2970 if (toVal->addr != NULL) { \
|
|
2971 if (toVal->size < sizeof(type)) { \
|
|
2972 toVal->size = sizeof(type); \
|
|
2973 return False; \
|
|
2974 } \
|
|
2975 *(type*)(toVal->addr) = (value); \
|
|
2976 } else { \
|
|
2977 static type static_val; \
|
|
2978 static_val = (value); \
|
|
2979 toVal->addr = (XPointer)&static_val; \
|
|
2980 } \
|
|
2981 toVal->size = sizeof(type); \
|
|
2982 return True /* Caller supplies `;' */
|
|
2983
|
|
2984 /* JH: We use this because I think there's a possibility this
|
|
2985 is called before the device is properly set up, in which case
|
|
2986 I don't want to abort. */
|
|
2987 extern struct device *get_device_from_display_1 (Display *dpy);
|
|
2988
|
|
2989 static
|
|
2990 Boolean EmacsXtCvtStringToPixel (
|
|
2991 Display *dpy,
|
|
2992 XrmValuePtr args,
|
|
2993 Cardinal *num_args,
|
|
2994 XrmValuePtr fromVal,
|
|
2995 XrmValuePtr toVal,
|
|
2996 XtPointer *closure_ret)
|
|
2997 {
|
|
2998 String str = (String)fromVal->addr;
|
|
2999 XColor screenColor;
|
|
3000 XColor exactColor;
|
|
3001 Screen *screen;
|
|
3002 Colormap colormap;
|
|
3003 Visual *visual;
|
|
3004 struct device *d;
|
|
3005 Status status;
|
|
3006 String params[1];
|
|
3007 Cardinal num_params = 1;
|
|
3008 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy);
|
|
3009
|
|
3010 if (*num_args != 2) {
|
|
3011 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToPixel",
|
|
3012 "XtToolkitError",
|
|
3013 "String to pixel conversion needs screen and colormap arguments",
|
|
3014 (String *)NULL, (Cardinal *)NULL);
|
|
3015 return False;
|
|
3016 }
|
|
3017
|
|
3018 screen = *((Screen **) args[0].addr);
|
|
3019 colormap = *((Colormap *) args[1].addr);
|
|
3020
|
|
3021 /* The original uses the private function CompareISOLatin1().
|
|
3022 Use XmuCompareISOLatin1() if you want, but I don't think it
|
|
3023 makes any difference here. */
|
|
3024 if (strcmp(str, XtDefaultBackground) == 0) {
|
|
3025 *closure_ret = False;
|
|
3026 /* This refers to the display's "*reverseVideo" resource.
|
|
3027 These display resources aren't documented anywhere that
|
|
3028 I can find, so I'm going to ignore this. */
|
|
3029 /* if (pd->rv) done(Pixel, BlackPixelOfScreen(screen)) else */
|
|
3030 done(Pixel, WhitePixelOfScreen(screen));
|
|
3031 }
|
|
3032 if (strcmp(str, XtDefaultForeground) == 0) {
|
|
3033 *closure_ret = False;
|
|
3034 /* if (pd->rv) done(Pixel, WhitePixelOfScreen(screen)) else */
|
|
3035 done(Pixel, BlackPixelOfScreen(screen));
|
|
3036 }
|
|
3037
|
|
3038 /* Originally called XAllocNamedColor() here. */
|
|
3039 if ((d = get_device_from_display_1(dpy))) {
|
|
3040 visual = DEVICE_X_VISUAL(d);
|
|
3041 if (colormap != DEVICE_X_COLORMAP(d)) {
|
442
|
3042 XtAppWarningMsg(the_app_con, "weirdColormap", "cvtStringToPixel",
|
428
|
3043 "XtToolkitWarning",
|
442
|
3044 "The colormap passed to cvtStringToPixel doesn't match the one registered to the device.\n",
|
428
|
3045 NULL, 0);
|
|
3046 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor);
|
|
3047 } else {
|
|
3048 status = XParseColor (dpy, colormap, (char*)str, &screenColor);
|
|
3049 if (status) {
|
3094
|
3050 status = x_allocate_nearest_color (dpy, colormap, visual, &screenColor);
|
428
|
3051 }
|
|
3052 }
|
|
3053 } else {
|
|
3054 /* We haven't set up this device totally yet, so just punt */
|
|
3055 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor);
|
|
3056 }
|
|
3057 if (status == 0) {
|
|
3058 params[0] = str;
|
|
3059 /* Server returns a specific error code but Xlib discards it. Ugh */
|
|
3060 if (XLookupColor(DisplayOfScreen(screen), colormap, (char*) str,
|
|
3061 &exactColor, &screenColor)) {
|
|
3062 XtAppWarningMsg(the_app_con, "noColormap", "cvtStringToPixel",
|
|
3063 "XtToolkitError",
|
|
3064 "Cannot allocate colormap entry for \"%s\"",
|
|
3065 params, &num_params);
|
|
3066
|
|
3067 } else {
|
|
3068 XtAppWarningMsg(the_app_con, "badValue", "cvtStringToPixel",
|
|
3069 "XtToolkitError",
|
|
3070 "Color name \"%s\" is not defined", params, &num_params);
|
|
3071 }
|
|
3072
|
|
3073 *closure_ret = False;
|
|
3074 return False;
|
|
3075 } else {
|
|
3076 *closure_ret = (char*)True;
|
|
3077 done(Pixel, screenColor.pixel);
|
|
3078 }
|
|
3079 }
|
|
3080
|
|
3081 /* ARGSUSED */
|
|
3082 static void EmacsFreePixel (
|
|
3083 XtAppContext app,
|
|
3084 XrmValuePtr toVal,
|
|
3085 XtPointer closure,
|
|
3086 XrmValuePtr args,
|
|
3087 Cardinal *num_args)
|
|
3088 {
|
|
3089 if (*num_args != 2) {
|
|
3090 XtAppWarningMsg(app, "wrongParameters","freePixel","XtToolkitError",
|
|
3091 "Freeing a pixel requires screen and colormap arguments",
|
|
3092 (String *)NULL, (Cardinal *)NULL);
|
|
3093 return;
|
|
3094 }
|
|
3095
|
|
3096 if (closure) {
|
|
3097 Screen *screen = *((Screen **) args[0].addr);
|
|
3098 Colormap colormap = *((Colormap *) args[1].addr);
|
|
3099 XFreeColors(DisplayOfScreen(screen), colormap,
|
|
3100 (unsigned long*)toVal->addr, 1, (unsigned long)0);
|
|
3101 }
|
|
3102 }
|
|
3103
|
|
3104
|
|
3105 /************************************************************************/
|
442
|
3106 /* handle focus changes for native widgets */
|
|
3107 /************************************************************************/
|
|
3108 static void
|
|
3109 emacs_Xt_event_widget_focus_in (Widget w,
|
|
3110 XEvent *event,
|
2286
|
3111 String *UNUSED (params),
|
|
3112 Cardinal *UNUSED (num_params))
|
442
|
3113 {
|
853
|
3114 struct frame *f =
|
442
|
3115 x_any_widget_or_parent_to_frame (get_device_from_display (event->xany.display), w);
|
|
3116
|
|
3117 XtSetKeyboardFocus (FRAME_X_SHELL_WIDGET (f), w);
|
|
3118 }
|
|
3119
|
|
3120 static void
|
2286
|
3121 emacs_Xt_event_widget_focus_out (Widget UNUSED (w),
|
|
3122 XEvent *UNUSED (event),
|
|
3123 String *UNUSED (params),
|
|
3124 Cardinal *UNUSED (num_params))
|
442
|
3125 {
|
|
3126 }
|
|
3127
|
|
3128 static XtActionsRec widgetActionsList[] =
|
|
3129 {
|
|
3130 {"widget-focus-in", emacs_Xt_event_widget_focus_in },
|
|
3131 {"widget-focus-out", emacs_Xt_event_widget_focus_out },
|
|
3132 };
|
|
3133
|
|
3134 static void
|
|
3135 emacs_Xt_event_add_widget_actions (XtAppContext ctx)
|
|
3136 {
|
|
3137 XtAppAddActions (ctx, widgetActionsList, 2);
|
|
3138 }
|
|
3139
|
|
3140
|
|
3141 /************************************************************************/
|
428
|
3142 /* initialization */
|
|
3143 /************************************************************************/
|
|
3144
|
|
3145 void
|
|
3146 syms_of_event_Xt (void)
|
|
3147 {
|
563
|
3148 DEFSYMBOL (Qsans_modifiers);
|
|
3149 DEFSYMBOL (Qself_insert_command);
|
428
|
3150 }
|
|
3151
|
|
3152 void
|
|
3153 reinit_vars_of_event_Xt (void)
|
|
3154 {
|
1204
|
3155 Xt_event_stream = xnew_and_zero (struct event_stream);
|
428
|
3156 Xt_event_stream->event_pending_p = emacs_Xt_event_pending_p;
|
1204
|
3157 Xt_event_stream->force_event_pending_cb= emacs_Xt_force_event_pending;
|
428
|
3158 Xt_event_stream->next_event_cb = emacs_Xt_next_event;
|
|
3159 Xt_event_stream->handle_magic_event_cb = emacs_Xt_handle_magic_event;
|
788
|
3160 Xt_event_stream->format_magic_event_cb = emacs_Xt_format_magic_event;
|
|
3161 Xt_event_stream->compare_magic_event_cb= emacs_Xt_compare_magic_event;
|
|
3162 Xt_event_stream->hash_magic_event_cb = emacs_Xt_hash_magic_event;
|
428
|
3163 Xt_event_stream->add_timeout_cb = emacs_Xt_add_timeout;
|
|
3164 Xt_event_stream->remove_timeout_cb = emacs_Xt_remove_timeout;
|
|
3165 Xt_event_stream->select_console_cb = emacs_Xt_select_console;
|
|
3166 Xt_event_stream->unselect_console_cb = emacs_Xt_unselect_console;
|
|
3167 Xt_event_stream->select_process_cb = emacs_Xt_select_process;
|
|
3168 Xt_event_stream->unselect_process_cb = emacs_Xt_unselect_process;
|
1204
|
3169 Xt_event_stream->drain_queue_cb = emacs_Xt_drain_queue;
|
853
|
3170 Xt_event_stream->create_io_streams_cb = emacs_Xt_create_io_streams;
|
|
3171 Xt_event_stream->delete_io_streams_cb = emacs_Xt_delete_io_streams;
|
442
|
3172 Xt_event_stream->current_event_timestamp_cb =
|
|
3173 emacs_Xt_current_event_timestamp;
|
428
|
3174
|
|
3175 the_Xt_timeout_blocktype = Blocktype_new (struct Xt_timeout_blocktype);
|
|
3176
|
|
3177 last_quit_check_signal_tick_count = 0;
|
|
3178
|
|
3179 /* this function only makes safe calls */
|
|
3180 init_what_input_once ();
|
|
3181 }
|
|
3182
|
|
3183 void
|
|
3184 vars_of_event_Xt (void)
|
|
3185 {
|
|
3186 DEFVAR_BOOL ("x-allow-sendevents", &x_allow_sendevents /*
|
|
3187 *Non-nil means to allow synthetic events. Nil means they are ignored.
|
|
3188 Beware: allowing emacs to process SendEvents opens a big security hole.
|
|
3189 */ );
|
|
3190 x_allow_sendevents = 0;
|
|
3191
|
|
3192 #ifdef DEBUG_XEMACS
|
442
|
3193 DEFVAR_INT ("debug-x-events", &debug_x_events /*
|
428
|
3194 If non-zero, display debug information about X events that XEmacs sees.
|
|
3195 Information is displayed on stderr. Currently defined values are:
|
|
3196
|
|
3197 1 == non-verbose output
|
|
3198 2 == verbose output
|
|
3199 */ );
|
442
|
3200 debug_x_events = 0;
|
428
|
3201 #endif
|
3171
|
3202 DEFVAR_LISP ("x-us-keymap-description", &Vx_us_keymap_description /*
|
|
3203 X11-specific vector describing the current keyboard hardware, and how to map
|
|
3204 from its keycodes to those alphanumeric and punctuation characters that
|
|
3205 would be produced by it if a US layout were configured in software.
|
|
3206
|
|
3207 We use this to make possible the usage of standard key bindings on keyboards
|
|
3208 where the keys that those bindings assume are not available; for example, on
|
|
3209 a Russian keyboard, one can type C-Cyrillic_che C-Cyrillic_a and have XEmacs
|
|
3210 use the binding for C-x C-f, rather than give an error message that
|
|
3211 C-Cyrillic_che C-Cyrillic_a is not bound.
|
|
3212
|
|
3213 Entries are either nil, which means the corresponding key code does not map
|
|
3214 to a non-function key in the US layout, a single character, meaning it maps to
|
|
3215 that character, or a vector of two characters, the first indicating the
|
|
3216 unshifted mapping, the second the shifted mapping for the US layout.
|
|
3217
|
|
3218 `x-us-keymap-first-keycode' tells XEmacs the keycode of the first entry in
|
|
3219 this vector.
|
|
3220 */ );
|
|
3221 Vx_us_keymap_description = Qnil;
|
|
3222
|
|
3223 DEFVAR_INT ("x-us-keymap-first-keycode", &Vx_us_keymap_first_keycode /*
|
|
3224 The X11 keycode that the first entry in `x-us-keymap-description'
|
|
3225 corresponds to. See the documentation for that variable.
|
|
3226
|
|
3227 The X11 documentation for XDisplayKeycodes says this can never be less than
|
|
3228 8, but XEmacs doesn't enforce any limitation on what you set it to.
|
|
3229 */ );
|
|
3230 Vx_us_keymap_first_keycode = 0;
|
428
|
3231 }
|
|
3232
|
|
3233 /* This mess is a hack that patches the shell widget to treat visual inheritance
|
|
3234 the same as colormap and depth inheritance */
|
|
3235
|
|
3236 static XtInitProc orig_shell_init_proc;
|
|
3237
|
2956
|
3238 static void ShellVisualPatch(Widget wanted, Widget new_,
|
428
|
3239 ArgList args, Cardinal *num_args)
|
|
3240 {
|
|
3241 Widget p;
|
2956
|
3242 ShellWidget w = (ShellWidget) new_;
|
428
|
3243
|
|
3244 /* first, call the original setup */
|
2956
|
3245 (*orig_shell_init_proc)(wanted, new_, args, num_args);
|
428
|
3246
|
|
3247 /* if the visual isn't explicitly set, grab it from the nearest shell ancestor */
|
|
3248 if (w->shell.visual == CopyFromParent) {
|
|
3249 p = XtParent(w);
|
|
3250 while (p && !XtIsShell(p)) p = XtParent(p);
|
|
3251 if (p) w->shell.visual = ((ShellWidget)p)->shell.visual;
|
|
3252 }
|
|
3253 }
|
|
3254
|
|
3255 void
|
|
3256 init_event_Xt_late (void) /* called when already initialized */
|
|
3257 {
|
|
3258 timeout_id_tick = 1;
|
|
3259 pending_timeouts = 0;
|
|
3260 completed_timeouts = 0;
|
|
3261
|
|
3262 event_stream = Xt_event_stream;
|
|
3263
|
|
3264 XtToolkitInitialize ();
|
|
3265 Xt_app_con = XtCreateApplicationContext ();
|
|
3266 XtAppSetFallbackResources (Xt_app_con, (String *) x_fallback_resources);
|
|
3267
|
442
|
3268 /* In select-x.c */
|
428
|
3269 x_selection_timeout = (XtAppGetSelectionTimeout (Xt_app_con) / 1000);
|
|
3270 XSetErrorHandler (x_error_handler);
|
|
3271 XSetIOErrorHandler (x_IO_error_handler);
|
|
3272
|
442
|
3273 #ifndef WIN32_NATIVE
|
428
|
3274 XtAppAddInput (Xt_app_con, signal_event_pipe[0],
|
|
3275 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
3276 Xt_what_callback, 0);
|
|
3277 #endif
|
|
3278
|
|
3279 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRPixel,
|
|
3280 EmacsXtCvtStringToPixel,
|
|
3281 (XtConvertArgList) colorConvertArgs,
|
|
3282 2, XtCacheByDisplay, EmacsFreePixel);
|
|
3283
|
|
3284 #ifdef XIM_XLIB
|
|
3285 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRXimStyles,
|
|
3286 EmacsXtCvtStringToXIMStyles,
|
|
3287 NULL, 0,
|
|
3288 XtCacheByDisplay, EmacsFreeXIMStyles);
|
|
3289 #endif /* XIM_XLIB */
|
442
|
3290 /* Add extra actions to native widgets to handle focus and friends. */
|
|
3291 emacs_Xt_event_add_widget_actions (Xt_app_con);
|
428
|
3292
|
|
3293 /* insert the visual inheritance patch/hack described above */
|
|
3294 orig_shell_init_proc = shellClassRec.core_class.initialize;
|
|
3295 shellClassRec.core_class.initialize = ShellVisualPatch;
|
|
3296
|
|
3297 }
|