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