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