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