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