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