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