0
|
1 /* The event_stream interface for X11 with Xt, and/or tty frames.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1996 Ben Wing.
|
|
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 "console-x.h"
|
157
|
29 #include "../lwlib/lwlib.h"
|
0
|
30 #include "EmacsFrame.h"
|
|
31
|
|
32 #include "blocktype.h"
|
|
33 #include "buffer.h"
|
|
34 #include "commands.h"
|
|
35 #include "console.h"
|
|
36 #include "console-tty.h"
|
|
37 #include "events.h"
|
|
38 #include "frame.h"
|
|
39 #include "objects-x.h"
|
|
40 #include "process.h"
|
|
41 #include "redisplay.h"
|
187
|
42 #include "elhash.h"
|
0
|
43
|
|
44 #include "systime.h"
|
|
45 #include "sysproc.h" /* for MAXDESC */
|
|
46
|
|
47 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
48 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
49 a core widget directly. We could
|
165
|
50 use XtGetValues(), but ... */
|
70
|
51 #ifdef HAVE_XIM
|
|
52 #ifdef XIM_MOTIF
|
|
53 #include <Xm/Xm.h>
|
|
54 #endif
|
|
55 #include "lstream.h"
|
|
56 #include "mule-coding.h"
|
|
57 #endif
|
0
|
58
|
197
|
59 #ifdef HAVE_OFFIX_DND
|
|
60 #include "offix.h"
|
|
61 #endif
|
|
62
|
100
|
63 #ifdef WINDOWSNT
|
|
64 /* Hmm, under unix we want X modifiers, under NT we want X modifiers if
|
|
65 we are running X and Windows modifiers otherwise.
|
|
66 gak. This is a kludge until we support multiple native GUIs!
|
|
67 */
|
|
68 #undef MOD_ALT
|
|
69 #undef MOD_CONTROL
|
|
70 #undef MOD_SHIFT
|
|
71 #endif
|
|
72
|
157
|
73 #include "events-mod.h"
|
100
|
74
|
20
|
75 static void enqueue_Xt_dispatch_event (Lisp_Object event);
|
|
76
|
0
|
77 static struct event_stream *Xt_event_stream;
|
|
78
|
|
79 /* With the new event model, all events go through XtDispatchEvent()
|
|
80 and are picked up by an event handler that is added to each frame
|
|
81 widget. (This is how it's supposed to be.) In the old method,
|
|
82 Emacs sucks out events directly from XtNextEvent() and only
|
|
83 dispatches the events that it doesn't need to deal with. This
|
|
84 old way has lots of corresponding junk that is no longer
|
|
85 necessary: lwlib extensions, synthetic XAnyEvents, unnecessary
|
|
86 magic events, etc. */
|
|
87
|
|
88 /* The one and only one application context that Emacs uses. */
|
|
89 XtAppContext Xt_app_con;
|
|
90
|
|
91 /* Do we accept events sent by other clients? */
|
|
92 int x_allow_sendevents;
|
|
93
|
|
94 int modifier_keys_are_sticky;
|
|
95
|
|
96 #ifdef DEBUG_XEMACS
|
|
97 int x_debug_events;
|
|
98 #endif
|
|
99
|
|
100 static int process_events_occurred;
|
|
101 static int tty_events_occurred;
|
|
102
|
|
103 /* Mask of bits indicating the descriptors that we wait for input on */
|
|
104 extern SELECT_TYPE input_wait_mask, process_only_mask, tty_only_mask;
|
|
105
|
|
106 static CONST String x_fallback_resources[] =
|
|
107 {
|
|
108 /* This file is automatically generated from the app-defaults file
|
|
109 in ../etc/Emacs.ad. These resources are consulted only if no
|
|
110 app-defaults file is found at all.
|
|
111 */
|
159
|
112 #include <Emacs.ad.h>
|
0
|
113 0
|
|
114 };
|
|
115
|
|
116 void emacs_Xt_mapping_action (Widget w, XEvent *event);
|
|
117 void debug_process_finalization (struct Lisp_Process *p);
|
|
118 void emacs_Xt_event_handler (Widget wid, XtPointer closure, XEvent *event,
|
|
119 Boolean *continue_to_dispatch);
|
|
120
|
|
121 #ifdef EPOCH
|
|
122 void dispatch_epoch_event (struct frame *f, XEvent *event, Lisp_Object type);
|
|
123 #endif
|
|
124
|
|
125 static int last_quit_check_signal_tick_count;
|
|
126
|
|
127 Lisp_Object Qkey_mapping;
|
187
|
128 Lisp_Object Qsans_modifiers;
|
0
|
129
|
|
130
|
|
131 /************************************************************************/
|
|
132 /* keymap handling */
|
|
133 /************************************************************************/
|
|
134
|
|
135 /* X bogusly doesn't define the interpretations of any bits besides
|
|
136 ModControl, ModShift, and ModLock; so the Interclient Communication
|
|
137 Conventions Manual says that we have to bend over backwards to figure
|
|
138 out what the other modifier bits mean. According to ICCCM:
|
|
139
|
|
140 - Any keycode which is assigned ModControl is a "control" key.
|
|
141
|
|
142 - Any modifier bit which is assigned to a keycode which generates Meta_L
|
|
143 or Meta_R is the modifier bit meaning "meta". Likewise for Super, Hyper,
|
|
144 etc.
|
|
145
|
|
146 - Any keypress event which contains ModControl in its state should be
|
|
147 interpreted as a "control" character.
|
|
148
|
|
149 - Any keypress event which contains a modifier bit in its state which is
|
|
150 generated by a keycode whose corresponding keysym is Meta_L or Meta_R
|
|
151 should be interpreted as a "meta" character. Likewise for Super, Hyper,
|
|
152 etc.
|
|
153
|
|
154 - It is illegal for a keysym to be associated with more than one modifier
|
|
155 bit.
|
|
156
|
|
157 This means that the only thing that emacs can reasonably interpret as a
|
|
158 "meta" key is a key whose keysym is Meta_L or Meta_R, and which generates
|
|
159 one of the modifier bits Mod1-Mod5.
|
|
160
|
|
161 Unfortunately, many keyboards don't have Meta keys in their default
|
|
162 configuration. So, if there are no Meta keys, but there are "Alt" keys,
|
|
163 emacs will interpret Alt as Meta. If there are both Meta and Alt keys,
|
|
164 then the Meta keys mean "Meta", and the Alt keys mean "Alt" (it used to
|
|
165 mean "Symbol," but that just confused the hell out of way too many people).
|
|
166
|
|
167 This works with the default configurations of the 19 keyboard-types I've
|
|
168 checked.
|
|
169
|
|
170 Emacs detects keyboard configurations which violate the above rules, and
|
|
171 prints an error message on the standard-error-output. (Perhaps it should
|
|
172 use a pop-up-window instead.)
|
|
173 */
|
|
174
|
|
175 static void
|
|
176 x_reset_key_mapping (struct device *d)
|
|
177 {
|
|
178 Display *display = DEVICE_X_DISPLAY (d);
|
|
179 struct x_device *xd = DEVICE_X_DATA (d);
|
187
|
180 KeySym *keysym, *keysym_end;
|
|
181 Lisp_Object hashtable;
|
|
182 int key_code_count, keysyms_per_code;
|
|
183
|
0
|
184 if (xd->x_keysym_map)
|
|
185 XFree ((char *) xd->x_keysym_map);
|
183
|
186 XDisplayKeycodes (display,
|
|
187 &xd->x_keysym_map_min_code,
|
|
188 &xd->x_keysym_map_max_code);
|
187
|
189 key_code_count = xd->x_keysym_map_max_code - xd->x_keysym_map_min_code + 1;
|
|
190 xd->x_keysym_map =
|
|
191 XGetKeyboardMapping (display, xd->x_keysym_map_min_code, key_code_count,
|
|
192 &xd->x_keysym_map_keysyms_per_code);
|
|
193
|
|
194 xd->x_keysym_map_hashtable = hashtable =
|
|
195 make_lisp_hashtable (128, HASHTABLE_NONWEAK, HASHTABLE_EQUAL);
|
|
196
|
|
197 for (keysym = xd->x_keysym_map,
|
|
198 keysyms_per_code = xd->x_keysym_map_keysyms_per_code,
|
|
199 keysym_end = keysym + (key_code_count * keysyms_per_code);
|
|
200 keysym < keysym_end;
|
|
201 keysym += keysyms_per_code)
|
|
202 {
|
|
203 int j;
|
|
204 char *keysym_name;
|
|
205
|
|
206 if (keysym[0] == NoSymbol)
|
|
207 continue;
|
|
208
|
|
209 if ((keysym_name = XKeysymToString (keysym[0])) != NULL)
|
|
210 Fputhash (build_string (keysym_name), Qsans_modifiers, hashtable);
|
|
211
|
|
212 for (j = 1; j < keysyms_per_code; j++)
|
|
213 {
|
|
214 if (keysym[j] == keysym[0] ||
|
|
215 keysym[j] == NoSymbol)
|
|
216 continue;
|
|
217
|
|
218 if ((keysym_name = XKeysymToString (keysym[j])) != NULL)
|
|
219 {
|
|
220 Lisp_Object name = build_string (keysym_name);
|
|
221 if (NILP (Fgethash (name, hashtable, Qnil)))
|
|
222 Fputhash (name, Qt, hashtable);
|
|
223 }
|
|
224 }
|
|
225 }
|
0
|
226 }
|
|
227
|
|
228 static CONST char *
|
|
229 index_to_name (int indice)
|
|
230 {
|
2
|
231 switch (indice)
|
|
232 {
|
|
233 case ShiftMapIndex: return "ModShift";
|
183
|
234 case LockMapIndex: return "ModLock";
|
2
|
235 case ControlMapIndex: return "ModControl";
|
|
236 case Mod1MapIndex: return "Mod1";
|
|
237 case Mod2MapIndex: return "Mod2";
|
|
238 case Mod3MapIndex: return "Mod3";
|
|
239 case Mod4MapIndex: return "Mod4";
|
|
240 case Mod5MapIndex: return "Mod5";
|
|
241 default: return "???";
|
|
242 }
|
0
|
243 }
|
|
244
|
|
245 /* Boy, I really wish C had local functions... */
|
|
246 struct c_doesnt_have_closures /* #### not yet used */
|
|
247 {
|
|
248 int warned_about_overlapping_modifiers;
|
|
249 int warned_about_predefined_modifiers;
|
|
250 int warned_about_duplicate_modifiers;
|
|
251 int meta_bit;
|
|
252 int hyper_bit;
|
|
253 int super_bit;
|
|
254 int alt_bit;
|
|
255 int mode_bit;
|
|
256 };
|
|
257
|
|
258 static void
|
|
259 x_reset_modifier_mapping (struct device *d)
|
|
260 {
|
|
261 Display *display = DEVICE_X_DISPLAY (d);
|
|
262 struct x_device *xd = DEVICE_X_DATA (d);
|
|
263 int modifier_index, modifier_key, column, mkpm;
|
|
264 int warned_about_overlapping_modifiers = 0;
|
2
|
265 int warned_about_predefined_modifiers = 0;
|
|
266 int warned_about_duplicate_modifiers = 0;
|
|
267 int meta_bit = 0;
|
0
|
268 int hyper_bit = 0;
|
|
269 int super_bit = 0;
|
2
|
270 int alt_bit = 0;
|
|
271 int mode_bit = 0;
|
0
|
272
|
|
273 xd->lock_interpretation = 0;
|
|
274
|
|
275 if (xd->x_modifier_keymap)
|
|
276 XFreeModifiermap (xd->x_modifier_keymap);
|
|
277
|
|
278 x_reset_key_mapping (d);
|
|
279
|
|
280 xd->x_modifier_keymap = XGetModifierMapping (display);
|
|
281
|
|
282 /* Boy, I really wish C had local functions...
|
|
283 */
|
|
284
|
|
285 /* The call to warn_when_safe must be on the same line as the string or
|
|
286 make-msgfile won't pick it up properly (the newline doesn't confuse
|
|
287 it, but the backslash does). */
|
|
288
|
|
289 #define modwarn(name,old,other) \
|
|
290 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is generated by %s.", \
|
|
291 name, code, index_to_name (old), other), \
|
|
292 warned_about_overlapping_modifiers = 1
|
|
293
|
|
294 #define modbarf(name,other) \
|
|
295 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \
|
|
296 name, code, other), \
|
|
297 warned_about_predefined_modifiers = 1
|
|
298
|
|
299 #define check_modifier(name,mask) \
|
|
300 if ((1<<modifier_index) != mask) \
|
|
301 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates %s, which is nonsensical.", \
|
|
302 name, code, index_to_name (modifier_index)), \
|
|
303 warned_about_predefined_modifiers = 1
|
|
304
|
|
305 #define store_modifier(name,old) \
|
|
306 if (old && old != modifier_index) \
|
|
307 warn_when_safe (Qkey_mapping, Qwarning, "XEmacs: %s (0x%x) generates both %s and %s, which is nonsensical.",\
|
|
308 name, code, index_to_name (old), \
|
|
309 index_to_name (modifier_index)), \
|
|
310 warned_about_duplicate_modifiers = 1; \
|
|
311 if (modifier_index == ShiftMapIndex) modbarf (name,"ModShift"); \
|
|
312 else if (modifier_index == LockMapIndex) modbarf (name,"ModLock"); \
|
|
313 else if (modifier_index == ControlMapIndex) modbarf (name,"ModControl"); \
|
|
314 else if (sym == XK_Mode_switch) \
|
|
315 mode_bit = modifier_index; /* Mode_switch is special, see below... */ \
|
|
316 else if (modifier_index == meta_bit && old != meta_bit) \
|
|
317 modwarn (name, meta_bit, "Meta"); \
|
|
318 else if (modifier_index == super_bit && old != super_bit) \
|
|
319 modwarn (name, super_bit, "Super"); \
|
|
320 else if (modifier_index == hyper_bit && old != hyper_bit) \
|
|
321 modwarn (name, hyper_bit, "Hyper"); \
|
|
322 else if (modifier_index == alt_bit && old != alt_bit) \
|
|
323 modwarn (name, alt_bit, "Alt"); \
|
|
324 else \
|
|
325 old = modifier_index;
|
|
326
|
|
327 mkpm = xd->x_modifier_keymap->max_keypermod;
|
|
328 for (modifier_index = 0; modifier_index < 8; modifier_index++)
|
|
329 for (modifier_key = 0; modifier_key < mkpm; modifier_key++) {
|
|
330 KeySym last_sym = 0;
|
|
331 for (column = 0; column < 4; column += 2) {
|
|
332 KeyCode code = xd->x_modifier_keymap->modifiermap[modifier_index * mkpm
|
|
333 + modifier_key];
|
|
334 KeySym sym = (code ? XKeycodeToKeysym (display, code, column) : 0);
|
|
335 if (sym == last_sym) continue;
|
|
336 last_sym = sym;
|
|
337 switch (sym) {
|
|
338 case XK_Mode_switch:store_modifier ("Mode_switch", mode_bit); break;
|
|
339 case XK_Meta_L: store_modifier ("Meta_L", meta_bit); break;
|
|
340 case XK_Meta_R: store_modifier ("Meta_R", meta_bit); break;
|
|
341 case XK_Super_L: store_modifier ("Super_L", super_bit); break;
|
|
342 case XK_Super_R: store_modifier ("Super_R", super_bit); break;
|
|
343 case XK_Hyper_L: store_modifier ("Hyper_L", hyper_bit); break;
|
|
344 case XK_Hyper_R: store_modifier ("Hyper_R", hyper_bit); break;
|
|
345 case XK_Alt_L: store_modifier ("Alt_L", alt_bit); break;
|
|
346 case XK_Alt_R: store_modifier ("Alt_R", alt_bit); break;
|
|
347 case XK_Control_L: check_modifier ("Control_L", ControlMask); break;
|
|
348 case XK_Control_R: check_modifier ("Control_R", ControlMask); break;
|
|
349 case XK_Shift_L: check_modifier ("Shift_L", ShiftMask); break;
|
|
350 case XK_Shift_R: check_modifier ("Shift_R", ShiftMask); break;
|
|
351 case XK_Shift_Lock: check_modifier ("Shift_Lock", LockMask);
|
|
352 xd->lock_interpretation = XK_Shift_Lock; break;
|
|
353 case XK_Caps_Lock: check_modifier ("Caps_Lock", LockMask);
|
|
354 xd->lock_interpretation = XK_Caps_Lock; break;
|
|
355
|
|
356 /* It probably doesn't make any sense for a modifier bit to be
|
|
357 assigned to a key that is not one of the above, but OpenWindows
|
|
358 assigns modifier bits to a couple of random function keys for
|
|
359 no reason that I can discern, so printing a warning here would
|
20
|
360 be annoying. */
|
0
|
361 }
|
|
362 }
|
|
363 }
|
|
364 #undef store_modifier
|
|
365 #undef check_modifier
|
|
366 #undef modwarn
|
|
367 #undef modbarf
|
|
368
|
|
369 /* If there was no Meta key, then try using the Alt key instead.
|
|
370 If there is both a Meta key and an Alt key, then the Alt key
|
20
|
371 is not disturbed and remains an Alt key. */
|
0
|
372 if (! meta_bit && alt_bit)
|
|
373 meta_bit = alt_bit, alt_bit = 0;
|
|
374
|
|
375 /* mode_bit overrides everything, since it's processed down inside of
|
|
376 XLookupString() instead of by us. If Meta and Mode_switch both
|
|
377 generate the same modifier bit (which is an error), then we don't
|
|
378 interpret that bit as Meta, because we can't make XLookupString()
|
|
379 not interpret it as Mode_switch; and interpreting it as both would
|
20
|
380 be totally wrong. */
|
0
|
381 if (mode_bit)
|
|
382 {
|
|
383 CONST char *warn = 0;
|
|
384 if (mode_bit == meta_bit) warn = "Meta", meta_bit = 0;
|
|
385 else if (mode_bit == hyper_bit) warn = "Hyper", hyper_bit = 0;
|
|
386 else if (mode_bit == super_bit) warn = "Super", super_bit = 0;
|
|
387 else if (mode_bit == alt_bit) warn = "Alt", alt_bit = 0;
|
|
388 if (warn)
|
|
389 {
|
|
390 warn_when_safe
|
|
391 (Qkey_mapping, Qwarning,
|
|
392 "XEmacs: %s is being used for both Mode_switch and %s.",
|
|
393 index_to_name (mode_bit), warn),
|
|
394 warned_about_overlapping_modifiers = 1;
|
|
395 }
|
|
396 }
|
|
397 #undef index_to_name
|
|
398
|
|
399 xd->MetaMask = (meta_bit ? (1 << meta_bit) : 0);
|
|
400 xd->HyperMask = (hyper_bit ? (1 << hyper_bit) : 0);
|
|
401 xd->SuperMask = (super_bit ? (1 << super_bit) : 0);
|
|
402 xd->AltMask = (alt_bit ? (1 << alt_bit) : 0);
|
|
403 xd->ModeMask = (mode_bit ? (1 << mode_bit) : 0); /* unused */
|
|
404
|
|
405
|
|
406 if (warned_about_overlapping_modifiers)
|
|
407 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
408 " Two distinct modifier keys (such as Meta and Hyper) cannot generate\n"
|
|
409 " the same modifier bit, because Emacs won't be able to tell which\n"
|
|
410 " modifier was actually held down when some other key is pressed. It\n"
|
|
411 " won't be able to tell Meta-x and Hyper-x apart, for example. Change\n"
|
|
412 " one of these keys to use some other modifier bit. If you intend for\n"
|
|
413 " these keys to have the same behavior, then change them to have the\n"
|
|
414 " same keysym as well as the same modifier bit.");
|
|
415
|
|
416 if (warned_about_predefined_modifiers)
|
|
417 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
418 " The semantics of the modifier bits ModShift, ModLock, and ModControl\n"
|
|
419 " are predefined. It does not make sense to assign ModControl to any\n"
|
|
420 " keysym other than Control_L or Control_R, or to assign any modifier\n"
|
|
421 " bits to the \"control\" keysyms other than ModControl. You can't\n"
|
|
422 " turn a \"control\" key into a \"meta\" key (or vice versa) by simply\n"
|
|
423 " assigning the key a different modifier bit. You must also make that\n"
|
|
424 " key generate an appropriate keysym (Control_L, Meta_L, etc).");
|
|
425
|
20
|
426 /* No need to say anything more for warned_about_duplicate_modifiers. */
|
0
|
427
|
|
428 if (warned_about_overlapping_modifiers || warned_about_predefined_modifiers)
|
|
429 warn_when_safe (Qkey_mapping, Qwarning, "\n"
|
|
430 " The meanings of the modifier bits Mod1 through Mod5 are determined\n"
|
|
431 " by the keysyms used to control those bits. Mod1 does NOT always\n"
|
|
432 " mean Meta, although some non-ICCCM-compliant programs assume that.");
|
|
433 }
|
|
434
|
|
435 void
|
|
436 x_init_modifier_mapping (struct device *d)
|
|
437 {
|
187
|
438 struct x_device *xd = DEVICE_X_DATA (d);
|
|
439 xd->x_keysym_map_hashtable = Qnil;
|
|
440 xd->x_keysym_map = NULL;
|
|
441 xd->x_modifier_keymap = NULL;
|
0
|
442 x_reset_modifier_mapping (d);
|
|
443 }
|
|
444
|
|
445 static int
|
|
446 x_key_is_modifier_p (KeyCode keycode, struct device *d)
|
|
447 {
|
|
448 struct x_device *xd = DEVICE_X_DATA (d);
|
183
|
449 KeySym *syms;
|
0
|
450 int i;
|
183
|
451
|
|
452 if (keycode < xd->x_keysym_map_min_code ||
|
|
453 keycode > xd->x_keysym_map_max_code)
|
|
454 return 0;
|
|
455
|
|
456 syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) *
|
|
457 xd->x_keysym_map_keysyms_per_code];
|
0
|
458 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
|
|
459 if (IsModifierKey (syms [i]) ||
|
|
460 syms [i] == XK_Mode_switch) /* why doesn't IsModifierKey count this? */
|
|
461 return 1;
|
|
462 return 0;
|
|
463 }
|
|
464
|
|
465 /* key-handling code is always ugly. It just ends up working out
|
|
466 that way.
|
|
467
|
|
468 Here are some pointers:
|
|
469
|
|
470 -- DOWN_MASK indicates which modifiers should be treated as "down"
|
|
471 when the corresponding upstroke happens. It gets reset for
|
|
472 a particular modifier when that modifier goes up, and reset
|
|
473 for all modifiers when a non-modifier key is pressed. Example:
|
|
474
|
|
475 I press Control-A-Shift and then release Control-A-Shift.
|
|
476 I want the Shift key to be sticky but not the Control key.
|
|
477
|
|
478 -- LAST_DOWNKEY and RELEASE_TIME are used to keep track of
|
|
479 auto-repeat -- see below.
|
|
480
|
|
481 -- If a modifier key is sticky, I can unstick it by pressing
|
|
482 the modifier key again. */
|
|
483
|
|
484 static void
|
|
485 x_handle_sticky_modifiers (XEvent *ev, struct device *d)
|
|
486 {
|
2
|
487 struct x_device *xd;
|
|
488 KeyCode keycode;
|
|
489 int type;
|
|
490
|
|
491 if (!modifier_keys_are_sticky) /* Optimize for non-sticky modifiers */
|
0
|
492 return;
|
|
493
|
2
|
494 xd = DEVICE_X_DATA (d);
|
|
495 keycode = ev->xkey.keycode;
|
|
496 type = ev->type;
|
183
|
497
|
|
498 if (keycode < xd->x_keysym_map_min_code ||
|
|
499 keycode > xd->x_keysym_map_max_code)
|
|
500 return;
|
|
501
|
2
|
502 if (! ((type == KeyPress || type == KeyRelease) &&
|
|
503 x_key_is_modifier_p (keycode, d)))
|
|
504 { /* Not a modifier key */
|
|
505 Bool key_event_p = (type == KeyPress || type == KeyRelease);
|
183
|
506
|
0
|
507 if (type == KeyPress && !xd->last_downkey)
|
|
508 xd->last_downkey = keycode;
|
|
509 else if (type == ButtonPress ||
|
|
510 (type == KeyPress && xd->last_downkey &&
|
|
511 (keycode != xd->last_downkey ||
|
|
512 ev->xkey.time != xd->release_time)))
|
|
513 {
|
|
514 xd->need_to_add_mask = 0;
|
|
515 xd->last_downkey = 0;
|
|
516 }
|
|
517 if (type == KeyPress)
|
|
518 xd->release_time = 0;
|
|
519 if (type == KeyPress || type == ButtonPress)
|
|
520 xd->down_mask = 0;
|
|
521
|
2
|
522 if (key_event_p)
|
|
523 ev->xkey.state |= xd->need_to_add_mask;
|
|
524 else
|
|
525 ev->xbutton.state |= xd->need_to_add_mask;
|
0
|
526
|
|
527 if (type == KeyRelease && keycode == xd->last_downkey)
|
|
528 /* If I hold press-and-release the Control key and then press
|
|
529 and hold down the right arrow, I want it to auto-repeat
|
|
530 Control-Right. On the other hand, if I do the same but
|
|
531 manually press the Right arrow a bunch of times, I want
|
|
532 to see one Control-Right and then a bunch of Rights.
|
|
533 This means that we need to distinguish between an
|
|
534 auto-repeated key and a key pressed and released a bunch
|
|
535 of times.
|
|
536
|
|
537 Naturally, the designers of the X spec didn't see fit
|
|
538 to provide an obvious way to distinguish these cases.
|
|
539 So we assume that if the release and the next press
|
|
540 occur at the same time, the key was actually auto-
|
20
|
541 repeated. Under Open-Windows, at least, this works. */
|
2
|
542 xd->release_time = key_event_p ? ev->xkey.time : ev->xbutton.time;
|
0
|
543 }
|
2
|
544 else /* Modifier key pressed */
|
0
|
545 {
|
2
|
546 int i;
|
0
|
547 KeySym *syms = &xd->x_keysym_map [(keycode - xd->x_keysym_map_min_code) *
|
|
548 xd->x_keysym_map_keysyms_per_code];
|
2
|
549
|
|
550 /* If a non-modifier key was pressed in the middle of a bunch
|
|
551 of modifiers, then it unsticks all the modifiers that were
|
|
552 previously pressed. We cannot unstick the modifiers until
|
|
553 now because we want to check for auto-repeat of the
|
|
554 non-modifier key. */
|
|
555
|
|
556 if (xd->last_downkey)
|
|
557 {
|
|
558 xd->last_downkey = 0;
|
|
559 xd->need_to_add_mask = 0;
|
|
560 }
|
0
|
561
|
|
562 #define FROB(mask) \
|
|
563 do { \
|
|
564 if (type == KeyPress) \
|
|
565 { \
|
|
566 /* If modifier key is already sticky, \
|
|
567 then unstick it. Note that we do \
|
|
568 not test down_mask to deal with the \
|
|
569 unlikely but possible case that the \
|
|
570 modifier key auto-repeats. */ \
|
|
571 if (xd->need_to_add_mask & mask) \
|
|
572 { \
|
|
573 xd->need_to_add_mask &= ~mask; \
|
|
574 xd->down_mask &= ~mask; \
|
|
575 } \
|
|
576 else \
|
|
577 xd->down_mask |= mask; \
|
|
578 } \
|
|
579 else \
|
|
580 { \
|
|
581 if (xd->down_mask & mask) \
|
|
582 { \
|
|
583 xd->down_mask &= ~mask; \
|
|
584 xd->need_to_add_mask |= mask; \
|
|
585 } \
|
|
586 } \
|
|
587 } while (0)
|
|
588
|
|
589 for (i = 0; i < xd->x_keysym_map_keysyms_per_code; i++)
|
2
|
590 switch (syms[i])
|
|
591 {
|
|
592 case XK_Control_L: case XK_Control_R: FROB (ControlMask); break;
|
|
593 case XK_Shift_L: case XK_Shift_R: FROB (ShiftMask); break;
|
|
594 case XK_Meta_L: case XK_Meta_R: FROB (xd->MetaMask); break;
|
|
595 case XK_Super_L: case XK_Super_R: FROB (xd->SuperMask); break;
|
|
596 case XK_Hyper_L: case XK_Hyper_R: FROB (xd->HyperMask); break;
|
|
597 case XK_Alt_L: case XK_Alt_R: FROB (xd->AltMask); break;
|
|
598 }
|
0
|
599 }
|
|
600 #undef FROB
|
|
601 }
|
|
602
|
|
603 static void
|
|
604 clear_sticky_modifiers (struct device *d)
|
|
605 {
|
|
606 struct x_device *xd = DEVICE_X_DATA (d);
|
|
607
|
|
608 xd->need_to_add_mask = 0;
|
80
|
609 xd->last_downkey = 0;
|
|
610 xd->release_time = 0;
|
|
611 xd->down_mask = 0;
|
0
|
612 }
|
|
613
|
|
614 static int
|
|
615 keysym_obeys_caps_lock_p (KeySym sym, struct device *d)
|
|
616 {
|
|
617 struct x_device *xd = DEVICE_X_DATA (d);
|
2
|
618 /* Eeeeevil hack. Don't apply Caps_Lock to things that aren't alphabetic
|
0
|
619 characters, where "alphabetic" means something more than simply A-Z.
|
2
|
620 That is, if Caps_Lock is down, typing ESC doesn't produce Shift-ESC.
|
20
|
621 But if shift-lock is down, then it does. */
|
0
|
622 if (xd->lock_interpretation == XK_Shift_Lock)
|
|
623 return 1;
|
183
|
624
|
2
|
625 return
|
|
626 ((sym >= XK_A) && (sym <= XK_Z)) ||
|
|
627 ((sym >= XK_a) && (sym <= XK_z)) ||
|
|
628 ((sym >= XK_Agrave) && (sym <= XK_Odiaeresis)) ||
|
|
629 ((sym >= XK_agrave) && (sym <= XK_odiaeresis)) ||
|
|
630 ((sym >= XK_Ooblique) && (sym <= XK_Thorn)) ||
|
|
631 ((sym >= XK_oslash) && (sym <= XK_thorn));
|
0
|
632 }
|
|
633
|
|
634 /* called from EmacsFrame.c (actually from Xt itself) when a
|
2
|
635 MappingNotify event is received. In its infinite wisdom, Xt
|
|
636 decided that Xt event handlers never get MappingNotify events.
|
|
637 O'Reilly Xt Programming Manual 9.1.2 says:
|
183
|
638
|
20
|
639 MappingNotify is automatically handled by Xt, so it isn't passed
|
|
640 to event handlers and you don't need to worry about it.
|
2
|
641
|
|
642 Of course, we DO worry about it, so we need a special translation. */
|
0
|
643 void
|
|
644 emacs_Xt_mapping_action (Widget w, XEvent* event)
|
|
645 {
|
|
646 struct device *d = get_device_from_display (event->xany.display);
|
|
647 #if 0
|
|
648 /* nyet. Now this is handled by Xt. */
|
|
649 XRefreshKeyboardMapping (&event->xmapping);
|
|
650 #endif
|
|
651 /* xmodmap generates about a billion MappingKeyboard events, followed
|
|
652 by a single MappingModifier event, so it might be worthwhile to
|
|
653 take extra MappingKeyboard events out of the queue before requesting
|
20
|
654 the current keymap from the server. */
|
2
|
655 switch (event->xmapping.request)
|
|
656 {
|
|
657 case MappingKeyboard: x_reset_key_mapping (d); break;
|
|
658 case MappingModifier: x_reset_modifier_mapping (d); break;
|
|
659 case MappingPointer: /* Do something here? */ break;
|
|
660 default: abort();
|
|
661 }
|
0
|
662 }
|
|
663
|
|
664
|
|
665 /************************************************************************/
|
|
666 /* X to Emacs event conversion */
|
|
667 /************************************************************************/
|
|
668
|
|
669 static Lisp_Object
|
179
|
670 x_keysym_to_emacs_keysym (KeySym keysym, int simple_p)
|
0
|
671 {
|
|
672 char *name;
|
|
673 if (keysym >= XK_exclam && keysym <= XK_asciitilde)
|
|
674 /* We must assume that the X keysym numbers for the ASCII graphic
|
|
675 characters are the same as their ASCII codes. */
|
78
|
676 return make_char (keysym);
|
0
|
677
|
|
678 switch (keysym)
|
|
679 {
|
|
680 /* These would be handled correctly by the default case, but by
|
185
|
681 special-casing them here we don't garbage a string or call
|
|
682 intern(). */
|
78
|
683 case XK_BackSpace: return QKbackspace;
|
|
684 case XK_Tab: return QKtab;
|
|
685 case XK_Linefeed: return QKlinefeed;
|
|
686 case XK_Return: return QKreturn;
|
|
687 case XK_Escape: return QKescape;
|
|
688 case XK_space: return QKspace;
|
|
689 case XK_Delete: return QKdelete;
|
|
690 case 0: return Qnil;
|
0
|
691 default:
|
78
|
692 if (simple_p) return Qnil;
|
0
|
693 /* !!#### not Mule-ized */
|
|
694 name = XKeysymToString (keysym);
|
187
|
695 if (!name || !name[0])
|
|
696 /* This happens if there is a mismatch between the Xlib of
|
|
697 XEmacs and the Xlib of the X server...
|
|
698
|
|
699 Let's hard-code in some knowledge of common keysyms introduced
|
|
700 in recent X11 releases. Snarfed from X11/keysymdef.h
|
|
701
|
|
702 Probably we should add some stuff here for X11R6. */
|
|
703 switch (keysym)
|
|
704 {
|
|
705 case 0xFF95: return KEYSYM ("kp-home");
|
|
706 case 0xFF96: return KEYSYM ("kp-left");
|
|
707 case 0xFF97: return KEYSYM ("kp-up");
|
|
708 case 0xFF98: return KEYSYM ("kp-right");
|
|
709 case 0xFF99: return KEYSYM ("kp-down");
|
|
710 case 0xFF9A: return KEYSYM ("kp-prior");
|
|
711 case 0xFF9B: return KEYSYM ("kp-next");
|
|
712 case 0xFF9C: return KEYSYM ("kp-end");
|
|
713 case 0xFF9D: return KEYSYM ("kp-begin");
|
|
714 case 0xFF9E: return KEYSYM ("kp-insert");
|
|
715 case 0xFF9F: return KEYSYM ("kp-delete");
|
|
716
|
|
717 case 0x1005FF10: return KEYSYM ("SunF36"); /* labeled F11 */
|
|
718 case 0x1005FF11: return KEYSYM ("SunF37"); /* labeled F12 */
|
|
719 default:
|
|
720 {
|
|
721 char buf [64];
|
|
722 sprintf (buf, "unknown-keysym-0x%X", (int) keysym);
|
|
723 return KEYSYM (buf);
|
|
724 }
|
|
725 }
|
0
|
726 /* If it's got a one-character name, that's good enough. */
|
80
|
727 if (!name[1])
|
|
728 return make_char (name[0]);
|
183
|
729
|
0
|
730 /* If it's in the "Keyboard" character set, downcase it.
|
|
731 The case of those keysyms is too totally random for us to
|
|
732 force anyone to remember them.
|
|
733 The case of the other character sets is significant, however.
|
70
|
734 */
|
138
|
735 if ((((unsigned int) keysym) & (~0x1FF)) == ((unsigned int) 0xFE00))
|
0
|
736 {
|
|
737 char buf [255];
|
|
738 char *s1, *s2;
|
74
|
739 for (s1 = name, s2 = buf; *s1; s1++, s2++) {
|
|
740 if (*s1 == '_') {
|
|
741 *s2 = '-';
|
|
742 } else {
|
|
743 *s2 = tolower (* (unsigned char *) s1);
|
|
744 }
|
|
745 }
|
0
|
746 *s2 = 0;
|
78
|
747 return KEYSYM (buf);
|
0
|
748 }
|
78
|
749 return KEYSYM (name);
|
0
|
750 }
|
|
751 }
|
|
752
|
179
|
753 static Lisp_Object
|
|
754 x_to_emacs_keysym (XKeyPressedEvent *event, int simple_p)
|
|
755 /* simple_p means don't try too hard (ASCII only) */
|
|
756 {
|
|
757 KeySym keysym = 0;
|
|
758
|
|
759 #ifdef HAVE_XIM
|
|
760 int len;
|
|
761 char buffer[64];
|
|
762 char *bufptr = buffer;
|
|
763 int bufsiz = sizeof (buffer);
|
|
764 Status status;
|
|
765 #ifdef XIM_XLIB
|
|
766 XIC xic = FRAME_X_XIC (x_any_window_to_frame
|
|
767 (get_device_from_display (event->display),
|
|
768 event->window));
|
|
769 #endif /* XIM_XLIB */
|
|
770 #endif /* HAVE_XIM */
|
|
771
|
185
|
772 /* We use XLookupString if we're not using XIM, or are using
|
|
773 XIM_XLIB but input context creation failed. */
|
|
774 #if ! (defined (HAVE_XIM) && defined (XIM_MOTIF))
|
|
775 #if defined (HAVE_XIM) && defined (XIM_XLIB)
|
|
776 if (!xic)
|
|
777 #endif /* XIM_XLIB */
|
179
|
778 {
|
|
779 /* Apparently it's necessary to specify a dummy here (rather
|
|
780 than passing in 0) to avoid crashes on German IRIX */
|
|
781 char dummy[256];
|
|
782 XLookupString (event, dummy, 200, &keysym, 0);
|
|
783 return x_keysym_to_emacs_keysym (keysym, simple_p);
|
|
784 }
|
185
|
785 #endif /* ! XIM_MOTIF */
|
179
|
786
|
|
787 #ifdef HAVE_XIM
|
|
788 Lookup_String: /* Come-From XBufferOverflow */
|
|
789 #ifdef XIM_MOTIF
|
|
790 len = XmImMbLookupString (XtWindowToWidget (event->display, event->window),
|
|
791 event, bufptr, bufsiz, &keysym, &status);
|
|
792 #else /* XIM_XLIB */
|
|
793 len = XmbLookupString (xic, event, bufptr, bufsiz, &keysym, &status);
|
185
|
794 #endif /* HAVE_XIM */
|
179
|
795
|
|
796 #ifdef DEBUG_XEMACS
|
|
797 if (x_debug_events > 0)
|
|
798 {
|
|
799 stderr_out (" status=");
|
|
800 #define print_status_when(S) if (status == S) stderr_out (#S)
|
|
801 print_status_when (XLookupKeySym);
|
|
802 print_status_when (XLookupBoth);
|
|
803 print_status_when (XLookupChars);
|
|
804 print_status_when (XLookupNone);
|
|
805 print_status_when (XBufferOverflow);
|
183
|
806
|
179
|
807 if (status == XLookupKeySym || status == XLookupBoth)
|
|
808 stderr_out (" keysym=%s", XKeysymToString (keysym));
|
|
809 if (status == XLookupChars || status == XLookupBoth)
|
|
810 {
|
|
811 if (len != 1)
|
|
812 {
|
|
813 int j;
|
|
814 stderr_out (" chars=\"");
|
|
815 for (j=0; j<len; j++)
|
|
816 stderr_out ("%c", bufptr[j]);
|
|
817 stderr_out ("\"");
|
|
818 }
|
|
819 else if (bufptr[0] <= 32 || bufptr[0] >= 127)
|
|
820 stderr_out (" char=0x%x", bufptr[0]);
|
|
821 else
|
|
822 stderr_out (" char=%c", bufptr[0]);
|
|
823 }
|
|
824 stderr_out ("\n");
|
|
825 }
|
|
826 #endif /* DEBUG_XEMACS */
|
|
827
|
|
828 switch (status)
|
|
829 {
|
|
830 case XLookupKeySym:
|
|
831 case XLookupBoth:
|
|
832 return x_keysym_to_emacs_keysym (keysym, simple_p);
|
|
833
|
|
834 case XLookupChars:
|
|
835 {
|
|
836 /* Generate multiple emacs events */
|
|
837 struct device *d = get_device_from_display (event->display);
|
|
838 Emchar ch;
|
185
|
839 Lisp_Object instream, fb_instream;
|
|
840 Lstream *istr;
|
|
841 struct gcpro gcpro1, gcpro2;
|
|
842
|
|
843 fb_instream =
|
179
|
844 make_fixed_buffer_input_stream ((unsigned char *) bufptr, len);
|
|
845
|
|
846 /* ### Use Fget_coding_system (Vcomposed_input_coding_system) */
|
185
|
847 instream =
|
|
848 make_decoding_input_stream (XLSTREAM (fb_instream),
|
179
|
849 Fget_coding_system (Qautomatic_conversion));
|
183
|
850
|
185
|
851 istr = XLSTREAM (instream);
|
|
852
|
|
853 GCPRO2 (instream, fb_instream);
|
|
854 while ((ch = Lstream_get_emchar (istr)) != EOF)
|
179
|
855 {
|
189
|
856 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
185
|
857 struct Lisp_Event *ev = XEVENT (emacs_event);
|
|
858 ev->channel = DEVICE_CONSOLE (d);
|
|
859 ev->event_type = key_press_event;
|
|
860 ev->timestamp = event->time;
|
|
861 ev->event.key.modifiers = 0;
|
|
862 ev->event.key.keysym = make_char (ch);
|
179
|
863 enqueue_Xt_dispatch_event (emacs_event);
|
|
864 }
|
185
|
865 Lstream_close (istr);
|
|
866 UNGCPRO;
|
|
867 Lstream_delete (istr);
|
|
868 Lstream_delete (XLSTREAM (fb_instream));
|
179
|
869 return Qnil;
|
|
870 }
|
|
871 case XLookupNone: return Qnil;
|
|
872 case XBufferOverflow:
|
185
|
873 bufptr = (char *) alloca (len+1);
|
179
|
874 bufsiz = len+1;
|
|
875 goto Lookup_String;
|
|
876 }
|
185
|
877 return Qnil; /* not reached */
|
179
|
878 #endif /* HAVE_XIM */
|
|
879 }
|
|
880
|
0
|
881 static void
|
|
882 set_last_server_timestamp (struct device *d, XEvent *x_event)
|
|
883 {
|
2
|
884 Time t;
|
|
885 switch (x_event->type)
|
0
|
886 {
|
|
887 case KeyPress:
|
2
|
888 case KeyRelease: t = x_event->xkey.time; break;
|
0
|
889 case ButtonPress:
|
2
|
890 case ButtonRelease: t = x_event->xbutton.time; break;
|
0
|
891 case EnterNotify:
|
2
|
892 case LeaveNotify: t = x_event->xcrossing.time; break;
|
|
893 case MotionNotify: t = x_event->xmotion.time; break;
|
|
894 case PropertyNotify: t = x_event->xproperty.time; break;
|
|
895 case SelectionClear: t = x_event->xselectionclear.time; break;
|
|
896 case SelectionRequest: t = x_event->xselectionrequest.time; break;
|
|
897 case SelectionNotify: t = x_event->xselection.time; break;
|
|
898 default: return;
|
0
|
899 }
|
2
|
900 DEVICE_X_LAST_SERVER_TIMESTAMP (d) = t;
|
0
|
901 }
|
|
902
|
|
903 static int
|
|
904 x_event_to_emacs_event (XEvent *x_event, struct Lisp_Event *emacs_event)
|
|
905 {
|
2
|
906 Display *display = x_event->xany.display;
|
|
907 struct device *d = get_device_from_display (display);
|
0
|
908 struct x_device *xd = DEVICE_X_DATA (d);
|
|
909
|
|
910 set_last_server_timestamp (d, x_event);
|
|
911
|
2
|
912 switch (x_event->type)
|
0
|
913 {
|
|
914 case KeyRelease:
|
|
915 x_handle_sticky_modifiers (x_event, d);
|
|
916 return 0;
|
|
917
|
|
918 case KeyPress:
|
|
919 case ButtonPress:
|
|
920 case ButtonRelease:
|
|
921 {
|
20
|
922 unsigned int modifiers = 0;
|
|
923 int shift_p, lock_p;
|
|
924 Bool key_event_p = (x_event->type == KeyPress);
|
|
925 unsigned int *state =
|
|
926 key_event_p ? &x_event->xkey.state : &x_event->xbutton.state;
|
|
927
|
|
928 /* If this is a synthetic KeyPress or Button event, and the user
|
|
929 has expressed a disinterest in this security hole, then drop
|
|
930 it on the floor. */
|
|
931 if ((key_event_p
|
|
932 ? x_event->xkey.send_event
|
|
933 : x_event->xbutton.send_event)
|
2
|
934 #ifdef EXTERNAL_WIDGET
|
20
|
935 /* ben: events get sent to an ExternalShell using XSendEvent.
|
|
936 This is not a perfect solution. */
|
|
937 && !FRAME_X_EXTERNAL_WINDOW_P
|
|
938 (x_any_window_to_frame (d, x_event->xany.window))
|
2
|
939 #endif
|
20
|
940 && !x_allow_sendevents)
|
|
941 return 0;
|
2
|
942
|
20
|
943 DEVICE_X_MOUSE_TIMESTAMP (d) =
|
|
944 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d) =
|
|
945 key_event_p ? x_event->xkey.time : x_event->xbutton.time;
|
2
|
946
|
20
|
947 x_handle_sticky_modifiers (x_event, d);
|
183
|
948
|
20
|
949 if (*state & ControlMask) modifiers |= MOD_CONTROL;
|
|
950 if (*state & xd->MetaMask) modifiers |= MOD_META;
|
|
951 if (*state & xd->SuperMask) modifiers |= MOD_SUPER;
|
|
952 if (*state & xd->HyperMask) modifiers |= MOD_HYPER;
|
|
953 if (*state & xd->AltMask) modifiers |= MOD_ALT;
|
0
|
954
|
20
|
955 /* Ignore the Caps_Lock key if:
|
|
956 - any other modifiers are down, so that Caps_Lock doesn't
|
|
957 turn C-x into C-X, which would suck.
|
|
958 - the event was a mouse event. */
|
|
959 if (modifiers || ! key_event_p)
|
70
|
960 *state &= (~LockMask);
|
2
|
961
|
20
|
962 shift_p = *state & ShiftMask;
|
|
963 lock_p = *state & LockMask;
|
2
|
964
|
20
|
965 if (shift_p || lock_p)
|
|
966 modifiers |= MOD_SHIFT;
|
0
|
967
|
20
|
968 if (key_event_p)
|
|
969 {
|
|
970 Lisp_Object keysym;
|
|
971 XKeyEvent *ev = &x_event->xkey;
|
|
972 KeyCode keycode = ev->keycode;
|
2
|
973
|
20
|
974 if (x_key_is_modifier_p (keycode, d)) /* it's a modifier key */
|
|
975 return 0;
|
0
|
976
|
20
|
977 /* This used to compute the frame from the given X window and
|
|
978 store it here, but we really don't care about the frame. */
|
|
979 emacs_event->channel = DEVICE_CONSOLE (d);
|
|
980 keysym = x_to_emacs_keysym (&x_event->xkey, 0);
|
183
|
981
|
20
|
982 /* If the emacs keysym is nil, then that means that the
|
|
983 X keysym was NoSymbol, which probably means that
|
|
984 we're in the midst of reading a Multi_key sequence,
|
183
|
985 or a "dead" key prefix, or XIM input. Ignore it. */
|
20
|
986 if (NILP (keysym))
|
|
987 return 0;
|
|
988
|
|
989 /* More Caps_Lock garbage: Caps_Lock should *only* add the
|
|
990 shift modifier to two-case keys (that is, A-Z and
|
|
991 related characters). So at this point (after looking up
|
|
992 the keysym) if the keysym isn't a dual-case alphabetic,
|
|
993 and if the caps lock key was down but the shift key
|
|
994 wasn't, then turn off the shift modifier. Gag barf */
|
|
995 /* #### type lossage: assuming equivalence of emacs and
|
|
996 X keysyms */
|
|
997 /* !!#### maybe fix for Mule */
|
|
998 if (lock_p && !shift_p &&
|
|
999 ! (CHAR_OR_CHAR_INTP (keysym)
|
|
1000 && keysym_obeys_caps_lock_p
|
|
1001 ((KeySym) XCHAR_OR_CHAR_INT (keysym), d)))
|
|
1002 modifiers &= (~MOD_SHIFT);
|
|
1003
|
|
1004 /* If this key contains two distinct keysyms, that is,
|
|
1005 "shift" generates a different keysym than the
|
|
1006 non-shifted key, then don't apply the shift modifier
|
|
1007 bit: it's implicit. Otherwise, if there would be no
|
|
1008 other way to tell the difference between the shifted
|
|
1009 and unshifted version of this key, apply the shift bit.
|
|
1010 Non-graphics, like Backspace and F1 get the shift bit
|
|
1011 in the modifiers slot. Neither the characters "a",
|
|
1012 "A", "2", nor "@" normally have the shift bit set.
|
|
1013 However, "F1" normally does. */
|
|
1014 if (modifiers & MOD_SHIFT)
|
|
1015 {
|
|
1016 int Mode_switch_p = *state & xd->ModeMask;
|
|
1017 KeySym bot = XLookupKeysym (ev, Mode_switch_p ? 2 : 0);
|
|
1018 KeySym top = XLookupKeysym (ev, Mode_switch_p ? 3 : 1);
|
|
1019 if (top && bot && top != bot)
|
|
1020 modifiers &= ~MOD_SHIFT;
|
|
1021 }
|
|
1022 emacs_event->event_type = key_press_event;
|
|
1023 emacs_event->timestamp = ev->time;
|
|
1024 emacs_event->event.key.modifiers = modifiers;
|
|
1025 emacs_event->event.key.keysym = keysym;
|
|
1026 }
|
|
1027 else /* Mouse press/release event */
|
|
1028 {
|
|
1029 XButtonEvent *ev = &x_event->xbutton;
|
|
1030 struct frame *frame = x_window_to_frame (d, ev->window);
|
|
1031 if (! frame)
|
|
1032 return 0; /* not for us */
|
|
1033 XSETFRAME (emacs_event->channel, frame);
|
183
|
1034
|
20
|
1035 emacs_event->event_type = (x_event->type == ButtonPress) ?
|
|
1036 button_press_event : button_release_event;
|
183
|
1037
|
20
|
1038 emacs_event->event.button.modifiers = modifiers;
|
70
|
1039 emacs_event->timestamp = ev->time;
|
|
1040 emacs_event->event.button.button = ev->button;
|
|
1041 emacs_event->event.button.x = ev->x;
|
|
1042 emacs_event->event.button.y = ev->y;
|
197
|
1043
|
70
|
1044 }
|
0
|
1045 }
|
2
|
1046 break;
|
183
|
1047
|
0
|
1048 case MotionNotify:
|
|
1049 {
|
2
|
1050 XMotionEvent *ev = &x_event->xmotion;
|
|
1051 struct frame *frame = x_window_to_frame (d, ev->window);
|
|
1052 unsigned int modifiers = 0;
|
|
1053 XMotionEvent event2;
|
183
|
1054
|
2
|
1055 if (! frame)
|
|
1056 return 0; /* not for us */
|
183
|
1057
|
2
|
1058 /* We use MotionHintMask, so we will get only one motion event
|
|
1059 until the next time we call XQueryPointer or the user
|
|
1060 clicks the mouse. So call XQueryPointer now (meaning that
|
|
1061 the event will be in sync with the server just before
|
|
1062 Fnext_event() returns). If the mouse is still in motion,
|
|
1063 then the server will immediately generate exactly one more
|
|
1064 motion event, which will be on the queue waiting for us
|
|
1065 next time around. */
|
|
1066 event2 = *ev;
|
|
1067 if (XQueryPointer (event2.display, event2.window,
|
|
1068 &event2.root, &event2.subwindow,
|
|
1069 &event2.x_root, &event2.y_root,
|
|
1070 &event2.x, &event2.y,
|
|
1071 &event2.state))
|
|
1072 ev = &event2; /* only one structure copy */
|
183
|
1073
|
2
|
1074 DEVICE_X_MOUSE_TIMESTAMP (d) = ev->time;
|
|
1075
|
|
1076 XSETFRAME (emacs_event->channel, frame);
|
|
1077 emacs_event->event_type = pointer_motion_event;
|
|
1078 emacs_event->timestamp = ev->time;
|
|
1079 emacs_event->event.motion.x = ev->x;
|
|
1080 emacs_event->event.motion.y = ev->y;
|
|
1081 if (ev->state & ShiftMask) modifiers |= MOD_SHIFT;
|
|
1082 if (ev->state & ControlMask) modifiers |= MOD_CONTROL;
|
|
1083 if (ev->state & xd->MetaMask) modifiers |= MOD_META;
|
|
1084 if (ev->state & xd->SuperMask) modifiers |= MOD_SUPER;
|
|
1085 if (ev->state & xd->HyperMask) modifiers |= MOD_HYPER;
|
|
1086 if (ev->state & xd->AltMask) modifiers |= MOD_ALT;
|
|
1087 /* Currently ignores Shift_Lock but probably shouldn't
|
|
1088 (but it definitely should ignore Caps_Lock). */
|
|
1089 emacs_event->event.motion.modifiers = modifiers;
|
0
|
1090 }
|
2
|
1091 break;
|
183
|
1092
|
0
|
1093 case ClientMessage:
|
2
|
1094 {
|
|
1095 /* Patch bogus TAKE_FOCUS messages from MWM; CurrentTime is
|
|
1096 passed as the timestamp of the TAKE_FOCUS, which the ICCCM
|
|
1097 explicitly prohibits. */
|
|
1098 XClientMessageEvent *ev = &x_event->xclient;
|
197
|
1099 #ifdef HAVE_OFFIX_DND
|
|
1100 if (DndIsDropMessage(x_event))
|
|
1101 {
|
|
1102 unsigned int state, modifiers = 0, button=0;
|
|
1103 struct frame *frame = x_any_window_to_frame (d, ev->window);
|
|
1104 unsigned char *data;
|
|
1105 unsigned long size, dtype;
|
|
1106 Lisp_Object l_type = Qnil, l_data = Qnil;
|
|
1107 Lisp_Object l_dndlist = Qnil, l_item = Qnil;
|
|
1108 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
1109
|
|
1110 GCPRO4 (l_type, l_data, l_dndlist, l_item);
|
|
1111
|
|
1112 if (! frame)
|
|
1113 return 0; /* not for us */
|
|
1114 XSETFRAME (emacs_event->channel, frame);
|
|
1115
|
|
1116 emacs_event->event_type = dnd_drop_event;
|
|
1117 emacs_event->timestamp = DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
1118
|
|
1119 state=DndDragButtons(x_event);
|
|
1120
|
|
1121 if (state & ShiftMask) modifiers |= MOD_SHIFT;
|
|
1122 if (state & ControlMask) modifiers |= MOD_CONTROL;
|
|
1123 if (state & xd->MetaMask) modifiers |= MOD_META;
|
|
1124 if (state & xd->SuperMask) modifiers |= MOD_SUPER;
|
|
1125 if (state & xd->HyperMask) modifiers |= MOD_HYPER;
|
|
1126 if (state & xd->AltMask) modifiers |= MOD_ALT;
|
|
1127
|
|
1128 if (state & Button5Mask) button = Button5;
|
|
1129 if (state & Button4Mask) button = Button4;
|
|
1130 if (state & Button3Mask) button = Button3;
|
|
1131 if (state & Button2Mask) button = Button2;
|
|
1132 if (state & Button1Mask) button = Button1;
|
|
1133
|
|
1134 emacs_event->event.dnd_drop.modifiers = modifiers;
|
|
1135 emacs_event->event.dnd_drop.button = button;
|
|
1136
|
|
1137 DndDropCoordinates(FRAME_X_TEXT_WIDGET(frame), x_event,
|
|
1138 &(emacs_event->event.dnd_drop.x),
|
|
1139 &(emacs_event->event.dnd_drop.y) );
|
|
1140
|
|
1141 DndGetData(x_event,&data,&size);
|
|
1142
|
|
1143 dtype=DndDataType(x_event);
|
|
1144 switch (dtype)
|
|
1145 {
|
|
1146 case DndFiles: /* null terminated strings, end null */
|
|
1147 {
|
|
1148 int len;
|
|
1149 while (*data)
|
|
1150 {
|
|
1151 len = strlen ((char*) data);
|
|
1152 l_item = make_ext_string ((char*) data, len,
|
|
1153 FORMAT_FILENAME);
|
|
1154 /* order is irrelevant */
|
|
1155 l_dndlist = Fcons (l_item, l_dndlist);
|
|
1156 data += len+1;
|
|
1157 }
|
|
1158 }
|
|
1159 break;
|
|
1160 case DndText:
|
|
1161 case DndMIME:
|
|
1162 /* is there a better way to format this ? */
|
|
1163 l_dndlist = make_ext_string ((char*) data, strlen(data),
|
|
1164 FORMAT_BINARY);
|
|
1165 break;
|
|
1166 case DndFile:
|
|
1167 case DndDir:
|
|
1168 case DndLink:
|
|
1169 case DndExe:
|
|
1170 case DndURL: /* this could also break with FORMAT_FILENAME */
|
|
1171 l_dndlist = make_ext_string ((char*) data, strlen(data),
|
|
1172 FORMAT_FILENAME);
|
|
1173 break;
|
|
1174 default: /* Unknown, RawData and any other type */
|
|
1175 l_dndlist = make_ext_string ((char*) data, size,
|
|
1176 FORMAT_BINARY);
|
|
1177 break;
|
|
1178 }
|
|
1179
|
|
1180 l_type=make_int(dtype);
|
|
1181
|
|
1182 emacs_event->event.dnd_drop.data = Fcons (l_type, Fcons (l_dndlist, Qnil));
|
|
1183
|
|
1184 UNGCPRO;
|
|
1185
|
|
1186 break;
|
|
1187 }
|
|
1188 #endif
|
2
|
1189 if (ev->message_type == DEVICE_XATOM_WM_PROTOCOLS (d)
|
|
1190 && ev->data.l[0] == DEVICE_XATOM_WM_TAKE_FOCUS (d)
|
|
1191 && ev->data.l[1] == 0)
|
|
1192 {
|
|
1193 ev->data.l[1] = DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
1194 }
|
|
1195 }
|
|
1196 /* fall through */
|
183
|
1197
|
0
|
1198 default: /* it's a magic event */
|
|
1199 {
|
2
|
1200 struct frame *frame;
|
|
1201 Window w;
|
183
|
1202 XEvent *x_event_copy = &emacs_event->event.magic.underlying_x_event;
|
|
1203
|
|
1204 #define FROB(event_member, window_member) \
|
|
1205 x_event_copy->event_member = x_event->event_member; \
|
|
1206 w = x_event->event_member.window_member
|
|
1207
|
2
|
1208 switch (x_event->type)
|
|
1209 {
|
183
|
1210 case SelectionRequest: FROB(xselectionrequest, owner); break;
|
|
1211 case SelectionClear: FROB(xselectionclear, window); break;
|
|
1212 case SelectionNotify: FROB(xselection, requestor); break;
|
|
1213 case PropertyNotify: FROB(xproperty, window); break;
|
|
1214 case ClientMessage: FROB(xclient, window); break;
|
|
1215 case ConfigureNotify: FROB(xconfigure, window); break;
|
|
1216 case Expose:
|
|
1217 case GraphicsExpose: FROB(xexpose, window); break;
|
|
1218 case MapNotify:
|
|
1219 case UnmapNotify: FROB(xmap, window); break;
|
|
1220 case EnterNotify:
|
|
1221 case LeaveNotify: FROB(xcrossing, window); break;
|
|
1222 case FocusIn:
|
|
1223 case FocusOut: FROB(xfocus, window); break;
|
|
1224 case VisibilityNotify: FROB(xvisibility, window); break;
|
|
1225 default:
|
|
1226 w = x_event->xany.window;
|
|
1227 *x_event_copy = *x_event;
|
|
1228 break;
|
2
|
1229 }
|
183
|
1230 #undef FROB
|
2
|
1231 frame = x_any_window_to_frame (d, w);
|
183
|
1232
|
2
|
1233 if (!frame)
|
|
1234 return 0;
|
0
|
1235
|
2
|
1236 emacs_event->event_type = magic_event;
|
|
1237 XSETFRAME (emacs_event->channel, frame);
|
183
|
1238
|
2
|
1239 break;
|
0
|
1240 }
|
|
1241 }
|
|
1242 return 1;
|
|
1243 }
|
|
1244
|
70
|
1245
|
0
|
1246
|
|
1247 /************************************************************************/
|
|
1248 /* magic-event handling */
|
|
1249 /************************************************************************/
|
|
1250
|
|
1251 static void
|
|
1252 handle_focus_event_1 (struct frame *f, int in_p)
|
|
1253 {
|
70
|
1254 #ifdef HAVE_XIM
|
|
1255 XIM_focus_event (f, in_p);
|
|
1256 #endif /* HAVE_XIM */
|
|
1257
|
0
|
1258 /* On focus change, clear all memory of sticky modifiers
|
|
1259 to avoid non-intuitive behavior. */
|
|
1260 clear_sticky_modifiers (XDEVICE (FRAME_DEVICE (f)));
|
|
1261
|
|
1262 /* We don't want to handle the focus change now, because we might
|
|
1263 be in an accept-process-output, sleep-for, or sit-for. So
|
|
1264 we enqueue it.
|
|
1265
|
|
1266 Actually, we half handle it: we handle it as far as changing the
|
|
1267 box cursor for redisplay, but we don't call any hooks or do any
|
|
1268 select-frame stuff until after the sit-for.
|
|
1269 */
|
|
1270 {
|
|
1271 Lisp_Object frm;
|
|
1272 Lisp_Object conser;
|
|
1273 struct gcpro gcpro1;
|
183
|
1274
|
0
|
1275 XSETFRAME (frm, f);
|
|
1276 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
1277 GCPRO1 (conser);
|
|
1278 emacs_handle_focus_change_preliminary (conser);
|
|
1279 enqueue_magic_eval_event (emacs_handle_focus_change_final,
|
|
1280 conser);
|
|
1281 UNGCPRO;
|
|
1282 }
|
|
1283 }
|
|
1284
|
|
1285 /* This is called from the external-widget code */
|
|
1286
|
|
1287 void emacs_Xt_handle_focus_event (XEvent *event);
|
|
1288 void
|
|
1289 emacs_Xt_handle_focus_event (XEvent *event)
|
|
1290 {
|
|
1291 /*
|
|
1292 * It's curious that we're using x_any_window_to_frame() instead
|
|
1293 * of x_window_to_frame(). I don't know what the impact of this is.
|
|
1294 */
|
183
|
1295
|
0
|
1296 struct frame *f =
|
|
1297 x_any_window_to_frame (get_device_from_display (event->xany.display),
|
|
1298 event->xfocus.window);
|
|
1299 if (!f)
|
|
1300 /* focus events are sometimes generated just before
|
|
1301 a frame is destroyed. */
|
|
1302 return;
|
2
|
1303 handle_focus_event_1 (f, event->type == FocusIn);
|
0
|
1304 }
|
|
1305
|
108
|
1306 /* both MapNotify and VisibilityNotify can cause this
|
|
1307 JV is_visible has the same semantics as f->visible*/
|
104
|
1308 static void
|
|
1309 change_frame_visibility (struct frame *f, int is_visible)
|
|
1310 {
|
|
1311 Lisp_Object frame = Qnil;
|
|
1312
|
|
1313 XSETFRAME (frame, f);
|
|
1314
|
|
1315 if (!FRAME_VISIBLE_P (f) && is_visible)
|
|
1316 {
|
108
|
1317 FRAME_VISIBLE_P (f) = is_visible;
|
104
|
1318 /* This improves the double flicker when uniconifying a frame
|
|
1319 some. A lot of it is not showing a buffer which has changed
|
|
1320 while the frame was iconified. To fix it further requires
|
|
1321 the good 'ol double redisplay structure. */
|
|
1322 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1323 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1324 #ifdef EPOCH
|
|
1325 dispatch_epoch_event (f, event, Qx_map);
|
|
1326 #endif
|
|
1327 }
|
183
|
1328 else if (FRAME_VISIBLE_P (f) && !is_visible)
|
104
|
1329 {
|
|
1330 FRAME_VISIBLE_P (f) = 0;
|
|
1331 va_run_hook_with_args (Qunmap_frame_hook, 1, frame);
|
|
1332 #ifdef EPOCH
|
|
1333 dispatch_epoch_event (f, event, Qx_unmap);
|
|
1334 #endif
|
|
1335 }
|
108
|
1336 else if (FRAME_VISIBLE_P (f) * is_visible < 0)
|
|
1337 {
|
|
1338 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f);
|
|
1339 if (FRAME_REPAINT_P(f))
|
|
1340 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1341 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1342 #ifdef EPOCH
|
|
1343 dispatch_epoch_event (f, event, Qx_map);
|
|
1344 #endif
|
|
1345 }
|
104
|
1346 }
|
|
1347
|
0
|
1348 static void
|
|
1349 handle_map_event (struct frame *f, XEvent *event)
|
|
1350 {
|
|
1351 Lisp_Object frame = Qnil;
|
|
1352
|
|
1353 XSETFRAME (frame, f);
|
2
|
1354 if (event->type == MapNotify)
|
0
|
1355 {
|
|
1356 XWindowAttributes xwa;
|
|
1357
|
|
1358 /* Bleagh!!!!!! Apparently some window managers (e.g. MWM)
|
|
1359 send synthetic MapNotify events when a window is first
|
|
1360 created, EVENT IF IT'S CREATED ICONIFIED OR INVISIBLE.
|
|
1361 Or something like that. We initially tried a different
|
|
1362 solution below, but that ran into a different window-
|
|
1363 manager bug.
|
|
1364
|
|
1365 It seems that the only reliable way is to treat a
|
|
1366 MapNotify event as a "hint" that the window might or
|
|
1367 might not be visible, and check explicitly. */
|
|
1368
|
|
1369 XGetWindowAttributes (event->xany.display, event->xmap.window,
|
|
1370 &xwa);
|
|
1371 if (xwa.map_state != IsViewable)
|
|
1372 {
|
|
1373 /* Calling Fframe_iconified_p is the only way we have to
|
|
1374 correctly update FRAME_ICONIFIED_P */
|
|
1375 Fframe_iconified_p (frame);
|
|
1376 return;
|
|
1377 }
|
|
1378
|
|
1379 FRAME_X_TOTALLY_VISIBLE_P (f) = 1;
|
|
1380 #if 0
|
|
1381 /* Bleagh again!!!! We initially tried the following hack
|
|
1382 around the MWM problem, but it turns out that TWM
|
|
1383 has a race condition when you un-iconify, where it maps
|
|
1384 the window and then tells the server that the window
|
|
1385 is un-iconified. Usually, XEmacs wakes up between
|
|
1386 those two occurrences, and thus thinks that un-iconified
|
|
1387 windows are still iconified.
|
|
1388
|
|
1389 Ah, the joys of X. */
|
|
1390
|
|
1391 /* By Emacs definition, a frame that is iconified is not
|
|
1392 visible. Marking a frame as visible will automatically cause
|
|
1393 frame-iconified-p to return nil, regardless of whether the
|
|
1394 frame is actually iconified. Therefore, we have to ignore
|
|
1395 MapNotify events on iconified frames. (It's not obvious
|
|
1396 to me why these are being sent, but it happens at startup
|
|
1397 with frames that are initially iconified; perhaps they are
|
|
1398 synthetic MapNotify events coming from the window manager.)
|
|
1399 Note that `frame-iconified-p' queries the server
|
|
1400 to determine whether the frame is currently iconified,
|
|
1401 rather than consulting some internal (and likely
|
|
1402 inaccurate) state flag. Therefore, ignoring the MapNotify
|
|
1403 is correct. */
|
104
|
1404 if (!FRAME_VISIBLE_P (f) && NILP (Fframe_iconified_p (frame)))
|
185
|
1405 #endif /* 0 */
|
104
|
1406 change_frame_visibility (f, 1);
|
0
|
1407 }
|
|
1408 else
|
|
1409 {
|
|
1410 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
104
|
1411 change_frame_visibility (f, 0);
|
0
|
1412 /* Calling Fframe_iconified_p is the only way we have to
|
|
1413 correctly update FRAME_ICONIFIED_P */
|
|
1414 Fframe_iconified_p (frame);
|
|
1415 }
|
|
1416 }
|
|
1417
|
|
1418 static void
|
|
1419 handle_client_message (struct frame *f, XEvent *event)
|
|
1420 {
|
|
1421 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
|
1422 Lisp_Object frame = Qnil;
|
|
1423
|
|
1424 XSETFRAME (frame, f);
|
|
1425
|
|
1426 if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1427 event->xclient.data.l[0] == DEVICE_XATOM_WM_DELETE_WINDOW (d))
|
|
1428 {
|
|
1429 /* WM_DELETE_WINDOW is a misc-user event, but other ClientMessages,
|
|
1430 such as WM_TAKE_FOCUS, are eval events. That's because delete-window
|
|
1431 was probably executed with a mouse click, while the others could
|
|
1432 have been sent as a result of mouse motion or some other implicit
|
|
1433 action. (Call this a "heuristic"...) The reason for caring about
|
|
1434 this is so that clicking on the close-box will make emacs prompt
|
|
1435 using a dialog box instead of the minibuffer if there are unsaved
|
|
1436 buffers.
|
70
|
1437 */
|
0
|
1438 enqueue_misc_user_event (frame, Qeval,
|
|
1439 list3 (Qdelete_frame, frame, Qt));
|
|
1440 }
|
|
1441 else if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1442 event->xclient.data.l[0] == DEVICE_XATOM_WM_TAKE_FOCUS (d))
|
|
1443 {
|
|
1444 handle_focus_event_1 (f, 1);
|
|
1445 #if 0
|
|
1446 /* If there is a dialog box up, focus on it.
|
183
|
1447
|
0
|
1448 #### Actually, we're raising it too, which is wrong. We should
|
|
1449 #### just focus on it, but lwlib doesn't currently give us an
|
|
1450 #### easy way to do that. This should be fixed.
|
|
1451 */
|
|
1452 unsigned long take_focus_timestamp = event->xclient.data.l[1];
|
|
1453 Widget widget = lw_raise_all_pop_up_widgets ();
|
|
1454 if (widget)
|
|
1455 {
|
|
1456 /* kludge: raise_all returns bottommost widget, but we really
|
|
1457 want the topmost. So just raise it for now. */
|
|
1458 XMapRaised (XtDisplay (widget), XtWindow (widget));
|
|
1459 /* Grab the focus with the timestamp of the TAKE_FOCUS. */
|
|
1460 XSetInputFocus (XtDisplay (widget), XtWindow (widget),
|
|
1461 RevertToParent, take_focus_timestamp);
|
|
1462 }
|
|
1463 #endif
|
|
1464 }
|
|
1465 #ifdef EPOCH
|
|
1466 dispatch_epoch_event (f, event, Qx_client_message);
|
|
1467 #endif
|
|
1468 }
|
|
1469
|
|
1470 static void
|
|
1471 emacs_Xt_handle_magic_event (struct Lisp_Event *emacs_event)
|
|
1472 {
|
|
1473 /* This function can GC */
|
183
|
1474 XEvent *event = &emacs_event->event.magic.underlying_x_event;
|
0
|
1475 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
1476
|
|
1477 if (!FRAME_LIVE_P (f))
|
|
1478 return;
|
|
1479
|
|
1480 switch (event->type)
|
|
1481 {
|
|
1482 case SelectionRequest:
|
|
1483 x_handle_selection_request (&event->xselectionrequest);
|
|
1484 break;
|
183
|
1485
|
0
|
1486 case SelectionClear:
|
|
1487 x_handle_selection_clear (&event->xselectionclear);
|
|
1488 break;
|
183
|
1489
|
0
|
1490 case SelectionNotify:
|
|
1491 x_handle_selection_notify (&event->xselection);
|
|
1492 break;
|
183
|
1493
|
0
|
1494 case PropertyNotify:
|
|
1495 x_handle_property_notify (&event->xproperty);
|
|
1496 #ifdef EPOCH
|
|
1497 dispatch_epoch_event (f, event, Qx_property_change);
|
|
1498 #endif
|
|
1499 break;
|
183
|
1500
|
0
|
1501 case Expose:
|
|
1502 x_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1503 event->xexpose.width, event->xexpose.height);
|
|
1504 break;
|
183
|
1505
|
0
|
1506 case GraphicsExpose: /* This occurs when an XCopyArea's source area was
|
|
1507 obscured or not available. */
|
|
1508 x_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1509 event->xexpose.width, event->xexpose.height);
|
|
1510 break;
|
183
|
1511
|
0
|
1512 case MapNotify:
|
|
1513 case UnmapNotify:
|
|
1514 handle_map_event (f, event);
|
|
1515 break;
|
183
|
1516
|
0
|
1517 case EnterNotify:
|
|
1518 if (event->xcrossing.detail != NotifyInferior)
|
|
1519 {
|
|
1520 Lisp_Object frame;
|
183
|
1521
|
0
|
1522 XSETFRAME (frame, f);
|
|
1523 /* FRAME_X_MOUSE_P (f) = 1; */
|
|
1524 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame);
|
|
1525 }
|
|
1526 break;
|
183
|
1527
|
0
|
1528 case LeaveNotify:
|
|
1529 if (event->xcrossing.detail != NotifyInferior)
|
|
1530 {
|
|
1531 Lisp_Object frame;
|
183
|
1532
|
0
|
1533 XSETFRAME (frame, f);
|
|
1534 /* FRAME_X_MOUSE_P (f) = 0; */
|
|
1535 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame);
|
|
1536 }
|
|
1537 break;
|
183
|
1538
|
0
|
1539 case FocusIn:
|
|
1540 case FocusOut:
|
|
1541 #ifdef EXTERNAL_WIDGET
|
|
1542 /* External widget lossage: Ben said:
|
|
1543 YUCK. The only way to make focus changes work properly is to
|
|
1544 completely ignore all FocusIn/FocusOut events and depend only
|
|
1545 on notifications from the ExternalClient widget. */
|
|
1546 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1547 break;
|
|
1548 #endif
|
2
|
1549 handle_focus_event_1 (f, event->type == FocusIn);
|
0
|
1550 break;
|
183
|
1551
|
0
|
1552 case ClientMessage:
|
|
1553 handle_client_message (f, event);
|
|
1554 break;
|
183
|
1555
|
0
|
1556 case VisibilityNotify: /* window visiblity has changed */
|
82
|
1557 if (event->xvisibility.window == XtWindow (FRAME_X_SHELL_WIDGET (f)))
|
102
|
1558 {
|
104
|
1559 FRAME_X_TOTALLY_VISIBLE_P (f) =
|
|
1560 (event->xvisibility.state == VisibilityUnobscured);
|
100
|
1561 /* Note that the fvwm pager only sends VisibilityNotify when
|
|
1562 changing pages. Is this all we need to do ? JV */
|
183
|
1563 /* Nope. We must at least trigger a redisplay here.
|
|
1564 Since this case seems similar to MapNotify, I've
|
|
1565 factored out some code to change_frame_visibility().
|
104
|
1566 This triggers the necessary redisplay and runs
|
|
1567 (un)map-frame-hook. - dkindred@cs.cmu.edu */
|
108
|
1568 /* Changed it again to support the tristate visibility flag */
|
104
|
1569 change_frame_visibility (f, (event->xvisibility.state
|
108
|
1570 != VisibilityFullyObscured) ? 1 : -1);
|
100
|
1571 }
|
20
|
1572 break;
|
183
|
1573
|
0
|
1574 case ConfigureNotify:
|
2
|
1575 #ifdef HAVE_XIM
|
20
|
1576 XIM_SetGeometry (f);
|
2
|
1577 #endif
|
0
|
1578 break;
|
|
1579
|
|
1580 default:
|
|
1581 break;
|
|
1582 }
|
|
1583 }
|
|
1584
|
|
1585
|
|
1586 /************************************************************************/
|
|
1587 /* timeout events */
|
|
1588 /************************************************************************/
|
|
1589
|
|
1590 static int timeout_id_tick;
|
|
1591
|
|
1592 /* Xt interval id's might not fit into an int (they're pointers, as it
|
|
1593 happens), so we need to provide a conversion list. */
|
|
1594
|
|
1595 struct Xt_timeout
|
|
1596 {
|
|
1597 int id;
|
|
1598 XtIntervalId interval_id;
|
|
1599 struct Xt_timeout *next;
|
|
1600 } *pending_timeouts, *completed_timeouts;
|
|
1601
|
|
1602 struct Xt_timeout_blocktype
|
|
1603 {
|
|
1604 Blocktype_declare (struct Xt_timeout);
|
|
1605 } *the_Xt_timeout_blocktype;
|
|
1606
|
|
1607 /* called by XtAppNextEvent() */
|
|
1608 static void
|
|
1609 Xt_timeout_callback (XtPointer closure, XtIntervalId *id)
|
|
1610 {
|
|
1611 struct Xt_timeout *timeout = (struct Xt_timeout *) closure;
|
|
1612 struct Xt_timeout *t2 = pending_timeouts;
|
|
1613 /* Remove this one from the list of pending timeouts */
|
|
1614 if (t2 == timeout)
|
|
1615 pending_timeouts = pending_timeouts->next;
|
|
1616 else
|
|
1617 {
|
|
1618 while (t2->next && t2->next != timeout) t2 = t2->next;
|
|
1619 assert (t2->next);
|
|
1620 t2->next = t2->next->next;
|
|
1621 }
|
|
1622 /* Add this one to the list of completed timeouts */
|
|
1623 timeout->next = completed_timeouts;
|
|
1624 completed_timeouts = timeout;
|
|
1625 }
|
|
1626
|
|
1627 static int
|
|
1628 emacs_Xt_add_timeout (EMACS_TIME thyme)
|
|
1629 {
|
|
1630 struct Xt_timeout *timeout = Blocktype_alloc (the_Xt_timeout_blocktype);
|
|
1631 EMACS_TIME current_time;
|
|
1632 int milliseconds;
|
|
1633
|
|
1634 timeout->id = timeout_id_tick++;
|
|
1635 timeout->next = pending_timeouts;
|
|
1636 pending_timeouts = timeout;
|
|
1637 EMACS_GET_TIME (current_time);
|
|
1638 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
1639 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
1640 EMACS_USECS (thyme) / 1000;
|
|
1641 if (milliseconds < 1)
|
|
1642 milliseconds = 1;
|
|
1643 timeout->interval_id = XtAppAddTimeOut (Xt_app_con, milliseconds,
|
|
1644 Xt_timeout_callback,
|
|
1645 (XtPointer) timeout);
|
|
1646 return timeout->id;
|
|
1647 }
|
|
1648
|
|
1649 static void
|
|
1650 emacs_Xt_remove_timeout (int id)
|
|
1651 {
|
|
1652 struct Xt_timeout *timeout, *t2;
|
|
1653
|
|
1654 /* Find the timeout on the list of pending ones, if it's still there. */
|
|
1655 if (!pending_timeouts) return;
|
|
1656 if (id == pending_timeouts->id)
|
|
1657 {
|
|
1658 timeout = pending_timeouts;
|
|
1659 pending_timeouts = pending_timeouts->next;
|
|
1660 }
|
|
1661 else
|
|
1662 {
|
|
1663 t2 = pending_timeouts;
|
|
1664 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
1665 if (! t2->next) return;
|
|
1666 timeout = t2->next;
|
|
1667 t2->next = t2->next->next;
|
|
1668 }
|
|
1669
|
|
1670 /* At this point, we've found the thing on the list of pending timeouts,
|
|
1671 and removed it.
|
|
1672 */
|
|
1673
|
|
1674 XtRemoveTimeOut (timeout->interval_id);
|
|
1675 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
1676 }
|
|
1677
|
|
1678 static void
|
|
1679 Xt_timeout_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
1680 {
|
|
1681 struct Xt_timeout *timeout = completed_timeouts;
|
|
1682 assert (timeout);
|
|
1683 completed_timeouts = completed_timeouts->next;
|
|
1684 emacs_event->event_type = timeout_event;
|
|
1685 /* timeout events have nil as channel */
|
|
1686 emacs_event->timestamp = 0; /* #### wrong!! */
|
|
1687 emacs_event->event.timeout.interval_id = timeout->id;
|
|
1688 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
1689 }
|
|
1690
|
|
1691
|
|
1692 /************************************************************************/
|
|
1693 /* process and tty events */
|
|
1694 /************************************************************************/
|
|
1695
|
|
1696 struct what_is_ready_closure
|
|
1697 {
|
|
1698 int fd;
|
|
1699 Lisp_Object what;
|
|
1700 XtInputId id;
|
|
1701 };
|
|
1702
|
|
1703 static Lisp_Object *filedesc_with_input;
|
|
1704 static struct what_is_ready_closure **filedesc_to_what_closure;
|
|
1705
|
|
1706 static void
|
|
1707 init_what_input_once (void)
|
|
1708 {
|
|
1709 int i;
|
|
1710
|
185
|
1711 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC);
|
|
1712 filedesc_to_what_closure =
|
|
1713 xnew_array (struct what_is_ready_closure *, MAXDESC);
|
0
|
1714
|
|
1715 for (i = 0; i < MAXDESC; i++)
|
|
1716 {
|
|
1717 filedesc_to_what_closure[i] = 0;
|
|
1718 filedesc_with_input[i] = Qnil;
|
|
1719 }
|
|
1720
|
|
1721 process_events_occurred = 0;
|
|
1722 tty_events_occurred = 0;
|
|
1723 }
|
|
1724
|
|
1725 static void
|
|
1726 mark_what_as_being_ready (struct what_is_ready_closure *closure)
|
|
1727 {
|
|
1728 if (NILP (filedesc_with_input[closure->fd]))
|
|
1729 {
|
|
1730 SELECT_TYPE temp_mask;
|
|
1731 FD_ZERO (&temp_mask);
|
|
1732 FD_SET (closure->fd, &temp_mask);
|
|
1733 /* Check to make sure there's *really* input available.
|
|
1734 Sometimes things seem to get confused and this gets called
|
|
1735 for the tty fd when there's really only input available
|
|
1736 on some process's fd. (It will subsequently get called
|
|
1737 for that process's fd, so returning without setting any
|
|
1738 flags will take care of it.) To see the problem, uncomment
|
|
1739 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS
|
183
|
1740 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log'
|
0
|
1741 and press return repeatedly. (Seen under AIX & Linux.)
|
|
1742 -dkindred@cs.cmu.edu */
|
183
|
1743 if (!poll_fds_for_input (temp_mask))
|
0
|
1744 {
|
|
1745 #if 0
|
|
1746 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n",
|
|
1747 closure->fd);
|
|
1748 #endif
|
|
1749 return;
|
|
1750 }
|
|
1751 filedesc_with_input[closure->fd] = closure->what;
|
|
1752 if (PROCESSP (closure->what))
|
|
1753 /* Don't increment this if the current process is already marked
|
|
1754 * as having input. */
|
|
1755 process_events_occurred++;
|
|
1756 else
|
|
1757 tty_events_occurred++;
|
|
1758 }
|
|
1759 }
|
|
1760
|
|
1761 static void
|
|
1762 Xt_what_callback (void *closure, int *source, XtInputId *id)
|
|
1763 {
|
|
1764 /* If closure is 0, then we got a fake event from a signal handler.
|
|
1765 The only purpose of this is to make XtAppProcessEvent() stop
|
|
1766 blocking. */
|
|
1767 if (closure)
|
|
1768 mark_what_as_being_ready ((struct what_is_ready_closure *) closure);
|
|
1769 else
|
|
1770 {
|
|
1771 fake_event_occurred++;
|
|
1772 drain_signal_event_pipe ();
|
|
1773 }
|
|
1774 }
|
|
1775
|
|
1776 static void
|
|
1777 select_filedesc (int fd, Lisp_Object what)
|
|
1778 {
|
|
1779 struct what_is_ready_closure *closure;
|
|
1780
|
|
1781 /* If somebody is trying to select something that's already selected
|
|
1782 for, then something went wrong. The generic routines ought to
|
|
1783 detect this and error before here. */
|
|
1784 assert (!filedesc_to_what_closure[fd]);
|
|
1785
|
185
|
1786 closure = xnew (struct what_is_ready_closure);
|
0
|
1787 closure->fd = fd;
|
|
1788 closure->what = what;
|
183
|
1789 closure->id =
|
0
|
1790 XtAppAddInput (Xt_app_con, fd,
|
|
1791 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
1792 Xt_what_callback, closure);
|
|
1793 filedesc_to_what_closure[fd] = closure;
|
|
1794 }
|
|
1795
|
|
1796 static void
|
|
1797 unselect_filedesc (int fd)
|
|
1798 {
|
|
1799 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd];
|
|
1800
|
|
1801 assert (closure);
|
|
1802 if (!NILP (filedesc_with_input[fd]))
|
|
1803 {
|
|
1804 /* We are unselecting this process before we have drained the rest of
|
|
1805 the input from it, probably from status_notify() in the command loop.
|
|
1806 This can happen like so:
|
|
1807
|
|
1808 - We are waiting in XtAppNextEvent()
|
|
1809 - Process generates output
|
|
1810 - Process is marked as being ready
|
|
1811 - Process dies, SIGCHLD gets generated before we return (!?)
|
|
1812 It could happen I guess.
|
|
1813 - sigchld_handler() marks process as dead
|
|
1814 - Somehow we end up getting a new KeyPress event on the queue
|
|
1815 at the same time (I'm really so sure how that happens but I'm
|
|
1816 not sure it can't either so let's assume it can...).
|
|
1817 - Key events have priority so we return that instead of the proc.
|
|
1818 - Before dispatching the lisp key event we call status_notify()
|
|
1819 - Which deselects the process that SIGCHLD marked as dead.
|
|
1820
|
|
1821 Thus we never remove it from _with_input and turn it into a lisp
|
|
1822 event, so we need to do it here. But this does not mean that we're
|
|
1823 throwing away the last block of output - status_notify() has already
|
|
1824 taken care of running the proc filter or whatever.
|
|
1825 */
|
|
1826 filedesc_with_input[fd] = Qnil;
|
|
1827 if (PROCESSP (closure->what))
|
|
1828 {
|
|
1829 assert (process_events_occurred > 0);
|
|
1830 process_events_occurred--;
|
|
1831 }
|
|
1832 else
|
|
1833 {
|
|
1834 assert (tty_events_occurred > 0);
|
|
1835 tty_events_occurred--;
|
|
1836 }
|
|
1837 }
|
|
1838 XtRemoveInput (closure->id);
|
|
1839 xfree (closure);
|
|
1840 filedesc_to_what_closure[fd] = 0;
|
|
1841 }
|
|
1842
|
|
1843 static void
|
|
1844 emacs_Xt_select_process (struct Lisp_Process *p)
|
|
1845 {
|
|
1846 Lisp_Object process;
|
183
|
1847 int infd = event_stream_unixoid_select_process (p);
|
0
|
1848
|
|
1849 XSETPROCESS (process, p);
|
|
1850 select_filedesc (infd, process);
|
|
1851 }
|
|
1852
|
|
1853 static void
|
|
1854 emacs_Xt_unselect_process (struct Lisp_Process *p)
|
|
1855 {
|
183
|
1856 int infd = event_stream_unixoid_unselect_process (p);
|
0
|
1857
|
|
1858 unselect_filedesc (infd);
|
|
1859 }
|
|
1860
|
|
1861 /* This is called from GC when a process object is about to be freed.
|
|
1862 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
1863 */
|
|
1864 void
|
|
1865 debug_process_finalization (struct Lisp_Process *p)
|
|
1866 {
|
|
1867 #if 0 /* #### */
|
|
1868 int i;
|
|
1869 int infd, outfd;
|
|
1870 get_process_file_descriptors (p, &infd, &outfd);
|
|
1871 /* if it still has fds, then it hasn't been killed yet. */
|
|
1872 assert (infd < 0);
|
|
1873 assert (outfd < 0);
|
|
1874 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
1875 for (i = 0; i < MAXDESC; i++)
|
|
1876 {
|
|
1877 Lisp_Object process = filedesc_fds_with_input [i];
|
|
1878 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
1879 }
|
|
1880 #endif
|
|
1881 }
|
|
1882
|
|
1883 static void
|
|
1884 Xt_process_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
1885 {
|
|
1886 int i;
|
|
1887 Lisp_Object process;
|
|
1888
|
|
1889 assert (process_events_occurred > 0);
|
|
1890 for (i = 0; i < MAXDESC; i++)
|
|
1891 {
|
|
1892 process = filedesc_with_input[i];
|
|
1893 if (PROCESSP (process))
|
|
1894 break;
|
|
1895 }
|
|
1896 assert (i < MAXDESC);
|
|
1897 filedesc_with_input[i] = Qnil;
|
|
1898 process_events_occurred--;
|
|
1899 /* process events have nil as channel */
|
|
1900 emacs_event->event_type = process_event;
|
|
1901 emacs_event->timestamp = 0; /* #### */
|
|
1902 emacs_event->event.process.process = process;
|
|
1903 }
|
|
1904
|
|
1905 static void
|
|
1906 emacs_Xt_select_console (struct console *con)
|
|
1907 {
|
|
1908 Lisp_Object console = Qnil;
|
|
1909 int infd;
|
153
|
1910 #ifdef HAVE_GPM
|
|
1911 int mousefd;
|
|
1912 #endif
|
0
|
1913
|
|
1914 if (CONSOLE_X_P (con))
|
|
1915 return; /* X consoles are automatically selected for when we
|
|
1916 initialize them in Xt */
|
|
1917 infd = event_stream_unixoid_select_console (con);
|
|
1918 XSETCONSOLE (console, con);
|
|
1919 select_filedesc (infd, console);
|
153
|
1920 #ifdef HAVE_GPM
|
|
1921 /* On a stream device (ie: noninteractive), bad things can happen. */
|
|
1922 if (EQ (CONSOLE_TYPE (con), Qtty)) {
|
|
1923 mousefd = CONSOLE_TTY_MOUSE_FD (con);
|
183
|
1924 /* We check filedesc_to_what_closure[fd] here because if you run
|
|
1925 ** XEmacs from a TTY, it will fire up GPM, select the mouse fd, then
|
|
1926 ** if you run gnuattach to connect to another TTY, it will fire up
|
|
1927 ** GPM again, and try to reselect the mouse fd. GPM uses the same
|
|
1928 ** fd for every connection apparently, and select_filedesc will
|
|
1929 ** fail its assertion if we try to select it twice.
|
|
1930 */
|
|
1931 if ((mousefd >= 0) && !filedesc_to_what_closure[mousefd]) {
|
153
|
1932 select_filedesc (mousefd, console);
|
|
1933 }
|
|
1934 }
|
|
1935 #endif
|
0
|
1936 }
|
|
1937
|
|
1938 static void
|
|
1939 emacs_Xt_unselect_console (struct console *con)
|
|
1940 {
|
|
1941 Lisp_Object console = Qnil;
|
|
1942 int infd;
|
153
|
1943 #ifdef HAVE_GPM
|
|
1944 int mousefd;
|
|
1945 #endif
|
0
|
1946
|
|
1947 if (CONSOLE_X_P (con))
|
|
1948 return; /* X consoles are automatically selected for when we
|
|
1949 initialize them in Xt */
|
|
1950 infd = event_stream_unixoid_unselect_console (con);
|
|
1951 XSETCONSOLE (console, con);
|
|
1952 unselect_filedesc (infd);
|
153
|
1953 #ifdef HAVE_GPM
|
|
1954 /* On a stream device (ie: noninteractive), bad things can happen. */
|
|
1955 if (EQ (CONSOLE_TYPE (con), Qtty)) {
|
|
1956 mousefd = CONSOLE_TTY_MOUSE_FD (con);
|
|
1957 if (mousefd >= 0) {
|
|
1958 unselect_filedesc (mousefd);
|
|
1959 }
|
|
1960 }
|
|
1961 #endif
|
0
|
1962 }
|
|
1963
|
|
1964 /* read an event from a tty, if one is available. Returns non-zero
|
|
1965 if an event was available. Note that when this function is
|
|
1966 called, there should always be a tty marked as ready for input.
|
|
1967 However, the input condition might actually be EOF, so there
|
|
1968 may not really be any input available. (In this case,
|
|
1969 read_event_from_tty_or_stream_desc() will arrange for the TTY device
|
|
1970 to be deleted.) */
|
|
1971
|
|
1972 static int
|
|
1973 Xt_tty_to_emacs_event (struct Lisp_Event *emacs_event)
|
|
1974 {
|
|
1975 int i;
|
|
1976
|
|
1977 assert (tty_events_occurred > 0);
|
|
1978 for (i = 0; i < MAXDESC; i++)
|
|
1979 {
|
|
1980 Lisp_Object console = filedesc_with_input[i];
|
|
1981 if (CONSOLEP (console))
|
|
1982 {
|
|
1983 assert (tty_events_occurred > 0);
|
|
1984 tty_events_occurred--;
|
|
1985 filedesc_with_input[i] = Qnil;
|
|
1986 if (read_event_from_tty_or_stream_desc
|
|
1987 (emacs_event, XCONSOLE (console), i))
|
|
1988 return 1;
|
|
1989 }
|
|
1990 }
|
|
1991
|
|
1992 return 0;
|
|
1993 }
|
|
1994
|
|
1995
|
|
1996 /************************************************************************/
|
|
1997 /* debugging functions to decipher an event */
|
|
1998 /************************************************************************/
|
|
1999
|
|
2000 #ifdef DEBUG_XEMACS
|
|
2001 #include "xintrinsicp.h" /* only describe_event() needs this */
|
|
2002 #include <X11/Xproto.h> /* only describe_event() needs this */
|
|
2003
|
|
2004 static void
|
|
2005 describe_event_window (Window window, Display *display)
|
|
2006 {
|
|
2007 struct frame *f;
|
|
2008 Widget w;
|
175
|
2009 stderr_out (" window: 0x%lx", (unsigned long) window);
|
0
|
2010 w = XtWindowToWidget (display, window);
|
|
2011 if (w)
|
|
2012 stderr_out (" %s", w->core.widget_class->core_class.class_name);
|
|
2013 f = x_any_window_to_frame (get_device_from_display (display), window);
|
|
2014 if (f) {
|
|
2015 char buf[500];
|
14
|
2016 sprintf (buf, " \"%s\"", XSTRING_DATA (f->name));
|
0
|
2017 write_string_to_stdio_stream (stderr, 0, (Bufbyte *) buf, 0, strlen (buf),
|
16
|
2018 FORMAT_TERMINAL);
|
0
|
2019 }
|
|
2020 stderr_out ("\n");
|
|
2021 }
|
|
2022
|
|
2023 static CONST char *
|
|
2024 XEvent_mode_to_string (int mode)
|
|
2025 {
|
|
2026 switch (mode)
|
|
2027 {
|
2
|
2028 case NotifyNormal: return "Normal";
|
|
2029 case NotifyGrab: return "Grab";
|
|
2030 case NotifyUngrab: return "Ungrab";
|
0
|
2031 case NotifyWhileGrabbed: return "WhileGrabbed";
|
2
|
2032 default: return "???";
|
0
|
2033 }
|
|
2034 }
|
|
2035
|
|
2036 static CONST char *
|
|
2037 XEvent_detail_to_string (int detail)
|
|
2038 {
|
|
2039 switch (detail)
|
|
2040 {
|
2
|
2041 case NotifyAncestor: return "Ancestor";
|
|
2042 case NotifyInferior: return "Inferior";
|
|
2043 case NotifyNonlinear: return "Nonlinear";
|
|
2044 case NotifyNonlinearVirtual: return "NonlinearVirtual";
|
|
2045 case NotifyPointer: return "Pointer";
|
|
2046 case NotifyPointerRoot: return "PointerRoot";
|
|
2047 case NotifyDetailNone: return "DetailNone";
|
|
2048 default: return "???";
|
0
|
2049 }
|
|
2050 }
|
|
2051
|
|
2052 static CONST char *
|
|
2053 XEvent_visibility_to_string (int state)
|
|
2054 {
|
|
2055 switch (state)
|
|
2056 {
|
2
|
2057 case VisibilityFullyObscured: return "FullyObscured";
|
0
|
2058 case VisibilityPartiallyObscured: return "PartiallyObscured";
|
2
|
2059 case VisibilityUnobscured: return "Unobscured";
|
|
2060 default: return "???";
|
0
|
2061 }
|
|
2062 }
|
|
2063
|
|
2064 static void
|
|
2065 describe_event (XEvent *event)
|
|
2066 {
|
|
2067 char buf[100];
|
|
2068 struct device *d = get_device_from_display (event->xany.display);
|
|
2069
|
|
2070 sprintf (buf, "%s%s", x_event_name (event->type),
|
|
2071 event->xany.send_event ? " (send)" : "");
|
|
2072 stderr_out ("%-30s", buf);
|
|
2073 switch (event->type)
|
|
2074 {
|
|
2075 case FocusIn:
|
|
2076 case FocusOut:
|
|
2077 {
|
|
2078 XFocusChangeEvent *ev = &event->xfocus;
|
|
2079 describe_event_window (ev->window, ev->display);
|
|
2080 stderr_out (" mode: %s\n", XEvent_mode_to_string (ev->mode));
|
|
2081 stderr_out (" detail: %s\n", XEvent_detail_to_string(ev->detail));
|
|
2082 break;
|
|
2083 }
|
183
|
2084
|
0
|
2085 case KeyPress:
|
|
2086 {
|
|
2087 XKeyEvent *ev = &event->xkey;
|
|
2088 unsigned int state = ev->state;
|
183
|
2089
|
0
|
2090 describe_event_window (ev->window, ev->display);
|
|
2091 stderr_out (" subwindow: %ld\n", ev->subwindow);
|
|
2092 stderr_out (" state: ");
|
20
|
2093 /* Complete list of modifier key masks */
|
0
|
2094 if (state & ShiftMask) stderr_out ("Shift ");
|
|
2095 if (state & LockMask) stderr_out ("Lock ");
|
|
2096 if (state & ControlMask) stderr_out ("Control ");
|
|
2097 if (state & Mod1Mask) stderr_out ("Mod1 ");
|
|
2098 if (state & Mod2Mask) stderr_out ("Mod2 ");
|
|
2099 if (state & Mod3Mask) stderr_out ("Mod3 ");
|
|
2100 if (state & Mod4Mask) stderr_out ("Mod4 ");
|
|
2101 if (state & Mod5Mask) stderr_out ("Mod5 ");
|
183
|
2102
|
0
|
2103 if (! state)
|
|
2104 stderr_out ("vanilla\n");
|
|
2105 else
|
|
2106 stderr_out ("\n");
|
|
2107 if (x_key_is_modifier_p (ev->keycode, d))
|
|
2108 stderr_out (" Modifier key");
|
|
2109 stderr_out (" keycode: 0x%x\n", ev->keycode);
|
|
2110 }
|
|
2111 break;
|
183
|
2112
|
0
|
2113 case Expose:
|
|
2114 if (x_debug_events > 1)
|
|
2115 {
|
|
2116 XExposeEvent *ev = &event->xexpose;
|
|
2117 describe_event_window (ev->window, ev->display);
|
2
|
2118 stderr_out (" region: x=%d y=%d width=%d height=%d\n",
|
|
2119 ev->x, ev->y, ev->width, ev->height);
|
0
|
2120 stderr_out (" count: %d\n", ev->count);
|
|
2121 }
|
|
2122 else
|
|
2123 stderr_out ("\n");
|
|
2124 break;
|
183
|
2125
|
0
|
2126 case GraphicsExpose:
|
|
2127 if (x_debug_events > 1)
|
|
2128 {
|
|
2129 XGraphicsExposeEvent *ev = &event->xgraphicsexpose;
|
|
2130 describe_event_window (ev->drawable, ev->display);
|
|
2131 stderr_out (" major: %s\n",
|
|
2132 (ev ->major_code == X_CopyArea ? "CopyArea" :
|
|
2133 (ev->major_code == X_CopyPlane ? "CopyPlane" : "?")));
|
2
|
2134 stderr_out (" region: x=%d y=%d width=%d height=%d\n",
|
|
2135 ev->x, ev->y, ev->width, ev->height);
|
0
|
2136 stderr_out (" count: %d\n", ev->count);
|
|
2137 }
|
|
2138 else
|
|
2139 stderr_out ("\n");
|
|
2140 break;
|
183
|
2141
|
0
|
2142 case EnterNotify:
|
|
2143 case LeaveNotify:
|
|
2144 if (x_debug_events > 1)
|
|
2145 {
|
|
2146 XCrossingEvent *ev = &event->xcrossing;
|
|
2147 describe_event_window (ev->window, ev->display);
|
|
2148 #if 0
|
|
2149 stderr_out(" subwindow: 0x%x\n", ev->subwindow);
|
|
2150 stderr_out(" pos: %d %d\n", ev->x, ev->y);
|
|
2151 stderr_out(" root pos: %d %d\n", ev->x_root, ev->y_root);
|
|
2152 #endif
|
|
2153 stderr_out(" mode: %s\n", XEvent_mode_to_string(ev->mode));
|
|
2154 stderr_out(" detail: %s\n", XEvent_detail_to_string(ev->detail));
|
|
2155 stderr_out(" focus: %d\n", ev->focus);
|
|
2156 #if 0
|
|
2157 stderr_out(" state: 0x%x\n", ev->state);
|
|
2158 #endif
|
|
2159 }
|
|
2160 else
|
|
2161 stderr_out("\n");
|
|
2162 break;
|
|
2163
|
|
2164 case ConfigureNotify:
|
|
2165 if (x_debug_events > 1)
|
|
2166 {
|
|
2167 XConfigureEvent *ev = &event->xconfigure;
|
|
2168 describe_event_window (ev->window, ev->display);
|
|
2169 stderr_out(" above: 0x%lx\n", ev->above);
|
|
2170 stderr_out(" size: %d %d %d %d\n", ev->x, ev->y,
|
|
2171 ev->width, ev->height);
|
|
2172 stderr_out(" redirect: %d\n", ev->override_redirect);
|
|
2173 }
|
|
2174 else
|
|
2175 stderr_out("\n");
|
|
2176 break;
|
|
2177
|
|
2178 case VisibilityNotify:
|
|
2179 if (x_debug_events > 1)
|
|
2180 {
|
|
2181 XVisibilityEvent *ev = &event->xvisibility;
|
|
2182 describe_event_window (ev->window, ev->display);
|
|
2183 stderr_out(" state: %s\n", XEvent_visibility_to_string(ev->state));
|
|
2184 }
|
|
2185 else
|
|
2186 stderr_out ("\n");
|
|
2187 break;
|
183
|
2188
|
0
|
2189 case ClientMessage:
|
|
2190 {
|
|
2191 XClientMessageEvent *ev = &event->xclient;
|
|
2192 char *name = XGetAtomName (ev->display, ev->message_type);
|
|
2193 stderr_out ("%s", name);
|
|
2194 if (!strcmp (name, "WM_PROTOCOLS")) {
|
|
2195 char *protname = XGetAtomName (ev->display, ev->data.l[0]);
|
|
2196 stderr_out ("(%s)", protname);
|
|
2197 XFree (protname);
|
|
2198 }
|
|
2199 XFree (name);
|
|
2200 stderr_out ("\n");
|
|
2201 break;
|
|
2202 }
|
183
|
2203
|
0
|
2204 default:
|
|
2205 stderr_out ("\n");
|
|
2206 break;
|
|
2207 }
|
|
2208
|
|
2209 fflush (stdout);
|
|
2210 }
|
|
2211
|
|
2212 #endif /* include describe_event definition */
|
|
2213
|
|
2214
|
|
2215 /************************************************************************/
|
|
2216 /* get the next event from Xt */
|
|
2217 /************************************************************************/
|
|
2218
|
|
2219 static Lisp_Object dispatch_event_queue, dispatch_event_queue_tail;
|
|
2220
|
|
2221 static void
|
|
2222 enqueue_Xt_dispatch_event (Lisp_Object event)
|
|
2223 {
|
|
2224 enqueue_event (event, &dispatch_event_queue, &dispatch_event_queue_tail);
|
|
2225 }
|
|
2226
|
20
|
2227 static Lisp_Object
|
0
|
2228 dequeue_Xt_dispatch_event (void)
|
|
2229 {
|
|
2230 return dequeue_event (&dispatch_event_queue, &dispatch_event_queue_tail);
|
|
2231 }
|
|
2232
|
|
2233 /* This business exists because menu events "happen" when
|
|
2234 menubar_selection_callback() is called from somewhere deep
|
|
2235 within XtAppProcessEvent in emacs_Xt_next_event(). The
|
|
2236 callback needs to terminate the modal loop in that function
|
|
2237 or else it will continue waiting until another event is
|
|
2238 received.
|
|
2239
|
|
2240 Same business applies to scrollbar events. */
|
|
2241
|
|
2242 void
|
|
2243 signal_special_Xt_user_event (Lisp_Object channel, Lisp_Object function,
|
|
2244 Lisp_Object object)
|
|
2245 {
|
189
|
2246 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
0
|
2247
|
|
2248 XEVENT (event)->event_type = misc_user_event;
|
|
2249 XEVENT (event)->channel = channel;
|
|
2250 XEVENT (event)->event.eval.function = function;
|
|
2251 XEVENT (event)->event.eval.object = object;
|
|
2252
|
|
2253 enqueue_Xt_dispatch_event (event);
|
183
|
2254 }
|
0
|
2255
|
|
2256 static void
|
|
2257 emacs_Xt_next_event (struct Lisp_Event *emacs_event)
|
|
2258 {
|
|
2259 we_didnt_get_an_event:
|
|
2260
|
|
2261 while (NILP (dispatch_event_queue) &&
|
2
|
2262 !completed_timeouts &&
|
|
2263 !fake_event_occurred &&
|
|
2264 !process_events_occurred &&
|
0
|
2265 !tty_events_occurred)
|
|
2266 {
|
|
2267
|
|
2268 /* Stupid logic in XtAppProcessEvent() dictates that, if process
|
|
2269 events and X events are both available, the process event gets
|
|
2270 taken first. This will cause an infinite loop if we're being
|
|
2271 called from Fdiscard_input().
|
|
2272 */
|
|
2273 if (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2274 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2275 else
|
|
2276 {
|
|
2277 Lisp_Object devcons, concons;
|
|
2278
|
|
2279 /* We're about to block. Xt has a bug in it (big surprise,
|
|
2280 there) in that it blocks using select() and doesn't
|
|
2281 flush the Xlib output buffers (XNextEvent() does this
|
|
2282 automatically before blocking). So it's necessary
|
|
2283 for us to do this ourselves. If we don't do it, then
|
|
2284 display output may not be seen until the next time
|
|
2285 an X event is received. (This happens esp. with
|
|
2286 subprocess output that gets sent to a visible buffer.)
|
|
2287
|
|
2288 #### The above comment may not have any validity. */
|
|
2289
|
|
2290 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
2291 {
|
|
2292 struct device *d;
|
|
2293 d = XDEVICE (XCAR (devcons));
|
|
2294
|
|
2295 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2296 /* emacs may be exiting */
|
|
2297 XFlush (DEVICE_X_DISPLAY (d));
|
|
2298 }
|
|
2299 XtAppProcessEvent (Xt_app_con, XtIMAll);
|
|
2300 }
|
|
2301 }
|
|
2302
|
|
2303 if (!NILP (dispatch_event_queue))
|
|
2304 {
|
|
2305 Lisp_Object event, event2;
|
|
2306 XSETEVENT (event2, emacs_event);
|
|
2307 event = dequeue_Xt_dispatch_event ();
|
|
2308 Fcopy_event (event, event2);
|
|
2309 Fdeallocate_event (event);
|
|
2310 }
|
|
2311 else if (tty_events_occurred)
|
|
2312 {
|
|
2313 if (!Xt_tty_to_emacs_event (emacs_event))
|
|
2314 goto we_didnt_get_an_event;
|
|
2315 }
|
|
2316 else if (completed_timeouts)
|
|
2317 Xt_timeout_to_emacs_event (emacs_event);
|
|
2318 else if (fake_event_occurred)
|
|
2319 {
|
183
|
2320 /* A dummy event, so that a cycle of the command loop will occur. */
|
0
|
2321 fake_event_occurred = 0;
|
|
2322 /* eval events have nil as channel */
|
|
2323 emacs_event->event_type = eval_event;
|
|
2324 emacs_event->event.eval.function = Qidentity;
|
|
2325 emacs_event->event.eval.object = Qnil;
|
|
2326 }
|
|
2327 else /* if (process_events_occurred) */
|
|
2328 Xt_process_to_emacs_event (emacs_event);
|
|
2329
|
|
2330 /* No need to call XFilterEvent; Xt does it for us */
|
|
2331 }
|
|
2332
|
|
2333 void
|
|
2334 emacs_Xt_event_handler (Widget wid /* unused */,
|
|
2335 XtPointer closure /* unused */,
|
|
2336 XEvent *event,
|
|
2337 Boolean *continue_to_dispatch /* unused */)
|
|
2338 {
|
189
|
2339 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
0
|
2340
|
|
2341 #ifdef DEBUG_XEMACS
|
|
2342 if (x_debug_events > 0)
|
|
2343 {
|
|
2344 describe_event (event);
|
|
2345 }
|
|
2346 #endif /* DEBUG_XEMACS */
|
|
2347 if (x_event_to_emacs_event (event, XEVENT (emacs_event)))
|
|
2348 enqueue_Xt_dispatch_event (emacs_event);
|
|
2349 else
|
|
2350 Fdeallocate_event (emacs_event);
|
|
2351 }
|
|
2352
|
|
2353
|
|
2354 /************************************************************************/
|
|
2355 /* input pending / C-g checking */
|
|
2356 /************************************************************************/
|
|
2357
|
|
2358 static Bool
|
|
2359 quit_char_predicate (Display *display, XEvent *event, XPointer data)
|
|
2360 {
|
|
2361 struct device *d = get_device_from_display (display);
|
|
2362 struct x_device *xd = DEVICE_X_DATA (d);
|
|
2363 char c, quit_char;
|
|
2364 Bool *critical = (Bool *) data;
|
|
2365 Lisp_Object keysym;
|
|
2366
|
149
|
2367 if (critical)
|
|
2368 *critical = False;
|
|
2369 if ((event->type != KeyPress) ||
|
|
2370 (! x_any_window_to_frame (d, event->xany.window)) ||
|
|
2371 (event->xkey.state
|
|
2372 & (xd->MetaMask | xd->HyperMask | xd->SuperMask | xd->AltMask)))
|
0
|
2373 return 0;
|
|
2374
|
|
2375 /* This duplicates some code that exists elsewhere, but it's relatively
|
149
|
2376 fast and doesn't cons. */
|
20
|
2377 keysym = x_to_emacs_keysym (&event->xkey, 1);
|
0
|
2378 if (NILP (keysym)) return 0;
|
|
2379 if (CHAR_OR_CHAR_INTP (keysym))
|
|
2380 c = XCHAR_OR_CHAR_INT (keysym);
|
|
2381 /* Highly doubtful that these are the quit character, but... */
|
|
2382 else if (EQ (keysym, QKbackspace)) c = '\b';
|
|
2383 else if (EQ (keysym, QKtab)) c = '\t';
|
|
2384 else if (EQ (keysym, QKlinefeed)) c = '\n';
|
|
2385 else if (EQ (keysym, QKreturn)) c = '\r';
|
|
2386 else if (EQ (keysym, QKescape)) c = 27;
|
|
2387 else if (EQ (keysym, QKspace)) c = ' ';
|
|
2388 else if (EQ (keysym, QKdelete)) c = 127;
|
|
2389 else return 0;
|
|
2390
|
|
2391 if (event->xkey.state & xd->MetaMask) c |= 0x80;
|
|
2392 if ((event->xkey.state & ControlMask) && !(c >= 'A' && c <= 'Z'))
|
|
2393 c &= 0x1F; /* unshifted control characters */
|
|
2394 quit_char = CONSOLE_QUIT_CHAR (XCONSOLE (DEVICE_CONSOLE (d)));
|
|
2395 if (c == quit_char)
|
|
2396 return True;
|
|
2397 /* If we've got Control-Shift-G instead of Control-G, that means
|
|
2398 we have a critical_quit. Caps_Lock is its own modifier, so it
|
|
2399 won't cause ^G to act differently than before. */
|
|
2400 if (event->xkey.state & ControlMask) c &= 0x1F;
|
|
2401 if (c == quit_char)
|
|
2402 {
|
|
2403 if (critical) *critical = True;
|
|
2404 return True;
|
|
2405 }
|
|
2406 return False;
|
|
2407 }
|
|
2408
|
|
2409 /* This scans the X input queue for a KeyPress event that matches the
|
|
2410 quit character, and sets Vquit_flag. This is called from the
|
|
2411 QUIT macro to determine whether we should quit.
|
|
2412
|
|
2413 In a SIGIO world, this won't be called unless a SIGIO has happened
|
|
2414 since the last time we checked.
|
|
2415
|
|
2416 In a non-SIGIO world, this is called from emacs_Xt_event_pending_p
|
|
2417 (which is called from input_pending_p).
|
|
2418 */
|
|
2419 static void
|
|
2420 x_check_for_quit_char (Display *display)
|
|
2421 {
|
|
2422 XEvent event;
|
|
2423 int queued;
|
|
2424 Bool critical_quit = False;
|
|
2425 XEventsQueued (display, QueuedAfterReading);
|
|
2426 queued = XCheckIfEvent (display, &event,
|
|
2427 quit_char_predicate,
|
185
|
2428 (char *) &critical_quit);
|
0
|
2429 if (queued)
|
|
2430 {
|
|
2431 Vquit_flag = (critical_quit ? Qcritical : Qt);
|
|
2432 /* don't put the event back onto the queue. Those functions that
|
|
2433 wanted to read a ^G directly have arranged to do this. */
|
|
2434 }
|
|
2435 }
|
|
2436
|
|
2437 static void
|
|
2438 check_for_tty_quit_char (struct device *d)
|
|
2439 {
|
|
2440 SELECT_TYPE temp_mask;
|
|
2441 int infd = DEVICE_INFD (d);
|
|
2442 struct console *con = XCONSOLE (DEVICE_CONSOLE (d));
|
|
2443 Emchar quit_char = CONSOLE_QUIT_CHAR (con);
|
|
2444
|
|
2445 FD_ZERO (&temp_mask);
|
|
2446 FD_SET (infd, &temp_mask);
|
|
2447
|
|
2448 while (1)
|
|
2449 {
|
|
2450 Lisp_Object event;
|
|
2451 Emchar the_char;
|
|
2452
|
|
2453 if (!poll_fds_for_input (temp_mask))
|
|
2454 return;
|
|
2455
|
189
|
2456 event = Fmake_event (Qnil, Qnil);
|
0
|
2457 if (!read_event_from_tty_or_stream_desc (XEVENT (event), con, infd))
|
|
2458 /* EOF, or something ... */
|
|
2459 return;
|
|
2460 /* #### bogus. quit-char should be allowed to be any sort
|
|
2461 of event. */
|
|
2462 the_char = event_to_character (XEVENT (event), 1, 0, 0);
|
|
2463 if (the_char >= 0 && the_char == quit_char)
|
|
2464 {
|
|
2465 Vquit_flag = Qt;
|
|
2466 /* do not queue the C-g. See above. */
|
|
2467 return;
|
|
2468 }
|
|
2469
|
|
2470 /* queue the read event to be read for real later. */
|
|
2471 enqueue_Xt_dispatch_event (event);
|
|
2472 }
|
|
2473 }
|
|
2474
|
|
2475 static void
|
|
2476 emacs_Xt_quit_p (void)
|
|
2477 {
|
|
2478 Lisp_Object devcons, concons;
|
|
2479 CONSOLE_LOOP (concons)
|
|
2480 {
|
|
2481 struct console *con = XCONSOLE (XCAR (concons));
|
|
2482 if (!con->input_enabled)
|
|
2483 continue;
|
|
2484
|
|
2485 CONSOLE_DEVICE_LOOP (devcons, con)
|
|
2486 {
|
|
2487 struct device *d;
|
|
2488 d = XDEVICE (XCAR (devcons));
|
|
2489
|
|
2490 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2491 /* emacs may be exiting */
|
|
2492 x_check_for_quit_char (DEVICE_X_DISPLAY (d));
|
|
2493 else if (DEVICE_TTY_P (d))
|
|
2494 check_for_tty_quit_char (d);
|
|
2495 }
|
|
2496 }
|
|
2497 }
|
|
2498
|
|
2499 static void
|
|
2500 drain_X_queue (void)
|
|
2501 {
|
|
2502 while (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2503 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2504 }
|
|
2505
|
|
2506 static int
|
|
2507 emacs_Xt_event_pending_p (int user_p)
|
|
2508 {
|
|
2509 Lisp_Object event;
|
|
2510 int tick_count_val;
|
|
2511
|
|
2512 /* If `user_p' is false, then this function returns whether there are any
|
|
2513 X, timeout, or fd events pending (that is, whether emacs_Xt_next_event()
|
|
2514 would return immediately without blocking).
|
|
2515
|
|
2516 if `user_p' is true, then this function returns whether there are any
|
|
2517 *user generated* events available (that is, whether there are keyboard
|
|
2518 or mouse-click events ready to be read). This also implies that
|
|
2519 emacs_Xt_next_event() would not block.
|
|
2520
|
|
2521 In a non-SIGIO world, this also checks whether the user has typed ^G,
|
|
2522 since this is a convenient place to do so. We don't need to do this
|
|
2523 in a SIGIO world, since input causes an interrupt.
|
|
2524 */
|
|
2525
|
|
2526 #if 0
|
|
2527 /* I don't think there's any point to this and it will nullify
|
|
2528 the speed gains achieved by the sigio_happened checking below.
|
|
2529 Its only advantage is that it may possibly make C-g response
|
|
2530 a bit faster. The C-g will be noticed within 0.25 second, anyway,
|
|
2531 even without this. */
|
|
2532 #ifndef SIGIO
|
|
2533 /* First check for C-g if necessary */
|
|
2534 emacs_Xt_quit_p ();
|
|
2535 #endif
|
|
2536 #endif
|
|
2537
|
|
2538 /* This function used to simply check whether there were any X
|
149
|
2539 events (or if user_p was 1, it iterated over all the pending
|
0
|
2540 X events using XCheckIfEvent(), looking for keystrokes and
|
|
2541 button events). That worked in the old cheesoid event loop,
|
|
2542 which didn't go through XtAppDispatchEvent(), but it doesn't
|
|
2543 work any more -- X events may not result in anything. For
|
|
2544 example, a button press in a blank part of the menubar appears
|
|
2545 as an X event but will not result in any Emacs events (a
|
|
2546 button press that activates the menubar results in an Emacs
|
|
2547 event through the stop_next_event mechanism).
|
|
2548
|
|
2549 The only accurate way of determining whether these X events
|
|
2550 translate into Emacs events is to go ahead and dispatch them
|
|
2551 until there's something on the dispatch queue. */
|
|
2552
|
|
2553 /* See if there are any user events already on the queue. */
|
|
2554 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
2555 if (!user_p || command_event_p (event))
|
|
2556 return 1;
|
|
2557
|
|
2558 /* See if there's any TTY input available.
|
|
2559 */
|
|
2560 if (poll_fds_for_input (tty_only_mask))
|
|
2561 return 1;
|
|
2562
|
|
2563 if (!user_p)
|
|
2564 {
|
|
2565 /* If not user_p and there are any timer or file-desc events
|
|
2566 pending, we know there will be an event so we're through. */
|
|
2567 XtInputMask pending_value;
|
|
2568
|
|
2569 /* Note that formerly we just checked the value of XtAppPending()
|
|
2570 to determine if there was file-desc input. This doesn't
|
|
2571 work any more with the signal_event_pipe; XtAppPending()
|
|
2572 will says "yes" in this case but there isn't really any
|
|
2573 input. Another way of fixing this problem is for the
|
|
2574 signal_event_pipe to generate actual input in the form
|
|
2575 of an identity eval event or something. (#### maybe this
|
|
2576 actually happens?) */
|
183
|
2577
|
0
|
2578 if (poll_fds_for_input (process_only_mask))
|
|
2579 return 1;
|
|
2580
|
|
2581 pending_value = XtAppPending (Xt_app_con);
|
|
2582
|
|
2583 if (pending_value & XtIMTimer)
|
|
2584 return 1;
|
|
2585 }
|
|
2586
|
|
2587 /* XtAppPending() can be super-slow, esp. over a network connection.
|
|
2588 Quantify results have indicated that in some cases the
|
|
2589 call to detect_input_pending() completely dominates the
|
|
2590 running time of redisplay(). Fortunately, in a SIGIO world
|
|
2591 we can more quickly determine whether there are any X events:
|
|
2592 if an event has happened since the last time we checked, then
|
|
2593 a SIGIO will have happened. On a machine with broken SIGIO,
|
|
2594 we'll still be in an OK state -- the sigio_happened flag
|
|
2595 will get set at least once a second, so we'll be no more than
|
|
2596 one second behind reality. (In general it's OK if we
|
|
2597 erroneously report no input pending when input is actually
|
|
2598 pending() -- preemption is just a bit less efficient, that's
|
|
2599 all. It's bad bad bad if you err the other way -- you've
|
|
2600 promised that `next-event' won't block but it actually will,
|
|
2601 and some action might get delayed until the next time you
|
|
2602 hit a key.)
|
|
2603 */
|
|
2604
|
|
2605 /* quit_check_signal_tick_count is volatile so try to avoid race conditions
|
|
2606 by using a temporary variable */
|
|
2607 tick_count_val = quit_check_signal_tick_count;
|
|
2608 if (last_quit_check_signal_tick_count != tick_count_val)
|
|
2609 {
|
|
2610 last_quit_check_signal_tick_count = tick_count_val;
|
|
2611
|
|
2612 /* We need to drain the entire queue now -- if we only
|
|
2613 drain part of it, we may later on end up with events
|
|
2614 actually pending but detect_input_pending() returning
|
|
2615 false because there wasn't another SIGIO. */
|
|
2616 drain_X_queue ();
|
|
2617
|
|
2618 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
2619 if (!user_p || command_event_p (event))
|
|
2620 return 1;
|
|
2621 }
|
|
2622
|
|
2623 return 0;
|
|
2624 }
|
|
2625
|
|
2626
|
|
2627 /************************************************************************/
|
|
2628 /* replacement for standard string-to-pixel converter */
|
|
2629 /************************************************************************/
|
|
2630
|
|
2631 /* This was constructed by ripping off the standard string-to-pixel
|
|
2632 converter from Converters.c in the Xt source code and modifying
|
|
2633 appropriately. */
|
|
2634
|
|
2635 #if 0
|
|
2636
|
|
2637 /* This is exported by the Xt library (at least by mine). If this
|
|
2638 isn't the case somewhere, rename this appropriately and remove
|
|
2639 the '#if 0'. Note, however, that I got "unknown structure"
|
|
2640 errors when I tried this. */
|
|
2641 XtConvertArgRec Const colorConvertArgs[] = {
|
|
2642 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
|
|
2643 sizeof(Screen *)},
|
|
2644 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
|
|
2645 sizeof(Colormap)}
|
|
2646 };
|
|
2647
|
|
2648 #endif
|
|
2649
|
|
2650 #define done(type, value) \
|
|
2651 if (toVal->addr != NULL) { \
|
|
2652 if (toVal->size < sizeof(type)) { \
|
|
2653 toVal->size = sizeof(type); \
|
|
2654 return False; \
|
|
2655 } \
|
|
2656 *(type*)(toVal->addr) = (value); \
|
|
2657 } else { \
|
|
2658 static type static_val; \
|
|
2659 static_val = (value); \
|
|
2660 toVal->addr = (XPointer)&static_val; \
|
|
2661 } \
|
|
2662 toVal->size = sizeof(type); \
|
|
2663 return True /* Caller supplies `;' */
|
|
2664
|
|
2665 static
|
|
2666 Boolean EmacsXtCvtStringToPixel (
|
|
2667 Display *dpy,
|
|
2668 XrmValuePtr args,
|
|
2669 Cardinal *num_args,
|
|
2670 XrmValuePtr fromVal,
|
|
2671 XrmValuePtr toVal,
|
|
2672 XtPointer *closure_ret)
|
|
2673 {
|
|
2674 String str = (String)fromVal->addr;
|
|
2675 XColor screenColor;
|
|
2676 XColor exactColor;
|
|
2677 Screen *screen;
|
|
2678 Colormap colormap;
|
|
2679 Status status;
|
|
2680 String params[1];
|
|
2681 Cardinal num_params = 1;
|
|
2682 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy);
|
183
|
2683
|
0
|
2684 if (*num_args != 2) {
|
|
2685 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToPixel",
|
|
2686 "XtToolkitError",
|
|
2687 "String to pixel conversion needs screen and colormap arguments",
|
|
2688 (String *)NULL, (Cardinal *)NULL);
|
|
2689 return False;
|
|
2690 }
|
|
2691
|
|
2692 screen = *((Screen **) args[0].addr);
|
|
2693 colormap = *((Colormap *) args[1].addr);
|
|
2694
|
|
2695 /* The original uses the private function CompareISOLatin1().
|
|
2696 Use XmuCompareISOLatin1() if you want, but I don't think it
|
|
2697 makes any difference here. */
|
|
2698 if (strcmp(str, XtDefaultBackground) == 0) {
|
|
2699 *closure_ret = False;
|
|
2700 /* This refers to the display's "*reverseVideo" resource.
|
|
2701 These display resources aren't documented anywhere that
|
|
2702 I can find, so I'm going to ignore this. */
|
|
2703 /* if (pd->rv) done(Pixel, BlackPixelOfScreen(screen)) else */
|
|
2704 done(Pixel, WhitePixelOfScreen(screen));
|
|
2705 }
|
|
2706 if (strcmp(str, XtDefaultForeground) == 0) {
|
|
2707 *closure_ret = False;
|
|
2708 /* if (pd->rv) done(Pixel, WhitePixelOfScreen(screen)) else */
|
|
2709 done(Pixel, BlackPixelOfScreen(screen));
|
|
2710 }
|
|
2711
|
|
2712 /* Originally called XAllocNamedColor() here. */
|
|
2713 status = XParseColor (DisplayOfScreen(screen), colormap, (char*)str,
|
|
2714 &screenColor);
|
|
2715 if (status) {
|
|
2716 status = allocate_nearest_color (DisplayOfScreen(screen), colormap,
|
|
2717 &screenColor);
|
|
2718 }
|
183
|
2719
|
0
|
2720 if (status == 0) {
|
|
2721 params[0] = str;
|
|
2722 /* Server returns a specific error code but Xlib discards it. Ugh */
|
183
|
2723 if (XLookupColor(DisplayOfScreen(screen), colormap, (char*) str,
|
0
|
2724 &exactColor, &screenColor)) {
|
|
2725 XtAppWarningMsg(the_app_con, "noColormap", "cvtStringToPixel",
|
|
2726 "XtToolkitError",
|
|
2727 "Cannot allocate colormap entry for \"%s\"",
|
|
2728 params, &num_params);
|
|
2729
|
|
2730 } else {
|
|
2731 XtAppWarningMsg(the_app_con, "badValue", "cvtStringToPixel",
|
|
2732 "XtToolkitError",
|
|
2733 "Color name \"%s\" is not defined", params, &num_params);
|
|
2734 }
|
183
|
2735
|
0
|
2736 *closure_ret = False;
|
|
2737 return False;
|
|
2738 } else {
|
|
2739 *closure_ret = (char*)True;
|
|
2740 done(Pixel, screenColor.pixel);
|
|
2741 }
|
|
2742 }
|
|
2743
|
|
2744 /* ARGSUSED */
|
|
2745 static void EmacsFreePixel (
|
|
2746 XtAppContext app,
|
|
2747 XrmValuePtr toVal,
|
|
2748 XtPointer closure,
|
|
2749 XrmValuePtr args,
|
|
2750 Cardinal *num_args)
|
|
2751 {
|
|
2752 if (*num_args != 2) {
|
|
2753 XtAppWarningMsg(app, "wrongParameters","freePixel","XtToolkitError",
|
|
2754 "Freeing a pixel requires screen and colormap arguments",
|
|
2755 (String *)NULL, (Cardinal *)NULL);
|
|
2756 return;
|
|
2757 }
|
|
2758
|
|
2759 if (closure) {
|
|
2760 Screen *screen = *((Screen **) args[0].addr);
|
|
2761 Colormap colormap = *((Colormap *) args[1].addr);
|
|
2762 XFreeColors(DisplayOfScreen(screen), colormap,
|
|
2763 (unsigned long*)toVal->addr, 1, (unsigned long)0);
|
|
2764 }
|
|
2765 }
|
|
2766
|
|
2767
|
|
2768 /************************************************************************/
|
|
2769 /* initialization */
|
|
2770 /************************************************************************/
|
|
2771
|
|
2772 void
|
|
2773 syms_of_event_Xt (void)
|
|
2774 {
|
|
2775 defsymbol (&Qkey_mapping, "key-mapping");
|
187
|
2776 defsymbol (&Qsans_modifiers, "sans-modifiers");
|
0
|
2777 }
|
|
2778
|
|
2779 void
|
|
2780 vars_of_event_Xt (void)
|
|
2781 {
|
|
2782 dispatch_event_queue = Qnil;
|
|
2783 staticpro (&dispatch_event_queue);
|
|
2784 dispatch_event_queue_tail = Qnil;
|
|
2785
|
|
2786 /* this function only makes safe calls */
|
|
2787 init_what_input_once ();
|
|
2788
|
185
|
2789 Xt_event_stream = xnew (struct event_stream);
|
0
|
2790 Xt_event_stream->event_pending_p = emacs_Xt_event_pending_p;
|
|
2791 Xt_event_stream->next_event_cb = emacs_Xt_next_event;
|
|
2792 Xt_event_stream->handle_magic_event_cb= emacs_Xt_handle_magic_event;
|
|
2793 Xt_event_stream->add_timeout_cb = emacs_Xt_add_timeout;
|
|
2794 Xt_event_stream->remove_timeout_cb = emacs_Xt_remove_timeout;
|
|
2795 Xt_event_stream->select_console_cb = emacs_Xt_select_console;
|
|
2796 Xt_event_stream->unselect_console_cb = emacs_Xt_unselect_console;
|
|
2797 Xt_event_stream->select_process_cb = emacs_Xt_select_process;
|
|
2798 Xt_event_stream->unselect_process_cb = emacs_Xt_unselect_process;
|
|
2799 Xt_event_stream->quit_p_cb = emacs_Xt_quit_p;
|
|
2800
|
|
2801 DEFVAR_BOOL ("modifier-keys-are-sticky", &modifier_keys_are_sticky /*
|
|
2802 *Non-nil makes modifier keys sticky.
|
|
2803 This means that you can release the modifier key before pressing down
|
|
2804 the key that you wish to be modified. Although this is non-standard
|
|
2805 behavior, it is recommended because it reduces the strain on your hand,
|
|
2806 thus reducing the incidence of the dreaded Emacs-pinky syndrome.
|
|
2807 */ );
|
|
2808 modifier_keys_are_sticky = 0;
|
|
2809
|
|
2810 DEFVAR_BOOL ("x-allow-sendevents", &x_allow_sendevents /*
|
|
2811 *Non-nil means to allow synthetic events. Nil means they are ignored.
|
|
2812 Beware: allowing emacs to process SendEvents opens a big security hole.
|
|
2813 */ );
|
|
2814 x_allow_sendevents = 0;
|
|
2815
|
|
2816 #ifdef DEBUG_XEMACS
|
|
2817 DEFVAR_INT ("x-debug-events", &x_debug_events /*
|
|
2818 If non-zero, display debug information about X events that XEmacs sees.
|
|
2819 Information is displayed on stderr. Currently defined values are:
|
|
2820
|
|
2821 1 == non-verbose output
|
|
2822 2 == verbose output
|
|
2823 */ );
|
|
2824 x_debug_events = 0;
|
|
2825 #endif
|
|
2826
|
|
2827 the_Xt_timeout_blocktype = Blocktype_new (struct Xt_timeout_blocktype);
|
|
2828
|
|
2829 last_quit_check_signal_tick_count = 0;
|
|
2830 }
|
|
2831
|
|
2832 void
|
|
2833 init_event_Xt_late (void) /* called when already initialized */
|
|
2834 {
|
|
2835 timeout_id_tick = 1;
|
|
2836 pending_timeouts = 0;
|
|
2837 completed_timeouts = 0;
|
|
2838
|
|
2839 event_stream = Xt_event_stream;
|
183
|
2840
|
136
|
2841 #if defined(HAVE_XIM) || defined(USE_XFONTSET)
|
70
|
2842 Initialize_Locale();
|
136
|
2843 #endif /* HAVE_XIM || USE_XFONTSET */
|
183
|
2844
|
0
|
2845 XtToolkitInitialize ();
|
|
2846 Xt_app_con = XtCreateApplicationContext ();
|
|
2847 XtAppSetFallbackResources (Xt_app_con, (String *) x_fallback_resources);
|
183
|
2848
|
0
|
2849 /* In xselect.c */
|
|
2850 x_selection_timeout = (XtAppGetSelectionTimeout (Xt_app_con) / 1000);
|
|
2851 XSetErrorHandler (x_error_handler);
|
|
2852 XSetIOErrorHandler (x_IO_error_handler);
|
|
2853
|
155
|
2854 #ifndef WINDOWSNT
|
0
|
2855 XtAppAddInput (Xt_app_con, signal_event_pipe[0],
|
|
2856 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
2857 Xt_what_callback, 0);
|
155
|
2858 #endif
|
0
|
2859
|
|
2860 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRPixel,
|
|
2861 EmacsXtCvtStringToPixel,
|
|
2862 (XtConvertArgList) colorConvertArgs,
|
|
2863 2, XtCacheByDisplay, EmacsFreePixel);
|
70
|
2864
|
|
2865 #ifdef XIM_XLIB
|
|
2866 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRXimStyles,
|
|
2867 EmacsXtCvtStringToXIMStyles,
|
|
2868 NULL, 0,
|
|
2869 XtCacheByDisplay, EmacsFreeXIMStyles);
|
|
2870 #endif /* XIM_XLIB */
|
183
|
2871
|
0
|
2872 }
|