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