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);
|
2956
|
1317 hurl = dnd_url_hexify_string (dataint,
|
|
1318 (const Ibyte *) "file:");
|
2367
|
1319 l_item = build_intstring (hurl);
|
428
|
1320 l_dndlist = Fcons (l_item, l_dndlist);
|
|
1321 data += len + 1;
|
2367
|
1322 xfree (hurl, Ibyte *);
|
428
|
1323 }
|
|
1324 l_type = Qdragdrop_URL;
|
|
1325 }
|
|
1326 break;
|
|
1327 case DndText:
|
|
1328 l_type = Qdragdrop_MIME;
|
2367
|
1329 l_dndlist = list1 (list3 (list1 (build_string ("text/plain")),
|
|
1330 build_string ("8bit"),
|
|
1331 build_ext_string (data,
|
|
1332 Qctext)));
|
428
|
1333 break;
|
|
1334 case DndMIME:
|
|
1335 /* we have to parse this in some way to extract
|
|
1336 content-type and params (in the tm way) and
|
|
1337 content encoding.
|
|
1338 OR: if data is string, let tm do the job
|
|
1339 if data is list[2], give the first two
|
|
1340 to tm...
|
|
1341 */
|
|
1342 l_type = Qdragdrop_MIME;
|
2367
|
1343 l_dndlist = list1 (build_ext_string (data, Qbinary));
|
428
|
1344 break;
|
|
1345 case DndFile:
|
|
1346 case DndDir:
|
|
1347 case DndLink:
|
|
1348 case DndExe:
|
|
1349 {
|
2367
|
1350 Ibyte *dataint, *hurl;
|
|
1351 EXTERNAL_TO_C_STRING (data, dataint, Qfile_name);
|
|
1352 hurl = dnd_url_hexify_string (dataint, "file:");
|
|
1353 l_dndlist = list1 (build_intstring (hurl));
|
|
1354 xfree (hurl, Ibyte *);
|
428
|
1355 }
|
|
1356 break;
|
|
1357 case DndURL:
|
|
1358 /* as it is a real URL it should already be escaped
|
|
1359 and escaping again will break them (cause % is unsave) */
|
2367
|
1360 l_dndlist = list1 (build_ext_string (data,
|
|
1361 Qfile_name));
|
428
|
1362 l_type = Qdragdrop_URL;
|
|
1363 break;
|
|
1364 default: /* Unknown, RawData and any other type */
|
2367
|
1365 l_dndlist = list1 (list3 (list1 (build_string
|
|
1366 ("application/octet-stream")),
|
|
1367 build_string ("8bit"),
|
|
1368 make_ext_string (data, size,
|
|
1369 Qbinary)));
|
428
|
1370 l_type = Qdragdrop_MIME;
|
|
1371 break;
|
|
1372 }
|
|
1373
|
2367
|
1374 SET_EVENT_MISC_USER_FUNCTION (emacs_event,
|
|
1375 Qdragdrop_drop_dispatch);
|
|
1376 SET_EVENT_MISC_USER_OBJECT (emacs_event,
|
|
1377 Fcons (l_type, l_dndlist));
|
428
|
1378
|
|
1379 UNGCPRO;
|
|
1380
|
|
1381 break;
|
|
1382 }
|
|
1383 #endif /* HAVE_OFFIX_DND */
|
|
1384 if (ev->message_type == DEVICE_XATOM_WM_PROTOCOLS (d)
|
|
1385 && (Atom) (ev->data.l[0]) == DEVICE_XATOM_WM_TAKE_FOCUS (d)
|
|
1386 && (Atom) (ev->data.l[1]) == 0)
|
|
1387 {
|
|
1388 ev->data.l[1] = DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
1389 }
|
|
1390 }
|
|
1391 /* fall through */
|
|
1392
|
|
1393 default: /* it's a magic event */
|
|
1394 {
|
|
1395 struct frame *frame;
|
|
1396 Window w;
|
934
|
1397 XEvent *x_event_copy;
|
|
1398 SET_EVENT_TYPE (emacs_event, magic_event);
|
1204
|
1399 x_event_copy = &EVENT_MAGIC_X_EVENT (emacs_event);
|
428
|
1400
|
|
1401 #define FROB(event_member, window_member) \
|
|
1402 x_event_copy->event_member = x_event->event_member; \
|
|
1403 w = x_event->event_member.window_member
|
|
1404
|
|
1405 switch (x_event->type)
|
|
1406 {
|
|
1407 case SelectionRequest: FROB(xselectionrequest, owner); break;
|
|
1408 case SelectionClear: FROB(xselectionclear, window); break;
|
|
1409 case SelectionNotify: FROB(xselection, requestor); break;
|
|
1410 case PropertyNotify: FROB(xproperty, window); break;
|
|
1411 case ClientMessage: FROB(xclient, window); break;
|
|
1412 case ConfigureNotify: FROB(xconfigure, window); break;
|
|
1413 case Expose:
|
|
1414 case GraphicsExpose: FROB(xexpose, window); break;
|
|
1415 case MapNotify:
|
|
1416 case UnmapNotify: FROB(xmap, window); break;
|
|
1417 case EnterNotify:
|
|
1418 case LeaveNotify: FROB(xcrossing, window); break;
|
|
1419 case FocusIn:
|
|
1420 case FocusOut: FROB(xfocus, window); break;
|
|
1421 case VisibilityNotify: FROB(xvisibility, window); break;
|
442
|
1422 case CreateNotify: FROB(xcreatewindow, window); break;
|
428
|
1423 default:
|
|
1424 w = x_event->xany.window;
|
|
1425 *x_event_copy = *x_event;
|
|
1426 break;
|
|
1427 }
|
|
1428 #undef FROB
|
|
1429 frame = x_any_window_to_frame (d, w);
|
|
1430
|
|
1431 if (!frame)
|
|
1432 return 0;
|
|
1433
|
1204
|
1434 SET_EVENT_CHANNEL (emacs_event, wrap_frame (frame));
|
|
1435 SET_EVENT_MAGIC_X_EVENT (emacs_event, *x_event_copy);
|
428
|
1436 break;
|
|
1437 }
|
|
1438 }
|
|
1439 return 1;
|
|
1440 }
|
|
1441
|
|
1442
|
|
1443
|
|
1444 /************************************************************************/
|
|
1445 /* magic-event handling */
|
|
1446 /************************************************************************/
|
|
1447
|
|
1448 static void
|
|
1449 handle_focus_event_1 (struct frame *f, int in_p)
|
|
1450 {
|
863
|
1451 handle_focus_event_2 (XtWindow (FRAME_X_TEXT_WIDGET (f)), f, in_p);
|
|
1452 }
|
|
1453
|
|
1454 static void
|
|
1455 handle_focus_event_2 (Window win, struct frame *f, int in_p)
|
|
1456 {
|
|
1457 /* Although this treats focus differently for all widgets (including
|
|
1458 the frame) it seems to work ok. */
|
|
1459 Widget needs_it = XtWindowToWidget (FRAME_X_DISPLAY (f), win);
|
|
1460
|
428
|
1461 #if XtSpecificationRelease > 5
|
450
|
1462 widget_with_focus = XtGetKeyboardFocusWidget (FRAME_X_TEXT_WIDGET (f));
|
428
|
1463 #endif
|
|
1464 #ifdef HAVE_XIM
|
|
1465 XIM_focus_event (f, in_p);
|
|
1466 #endif /* HAVE_XIM */
|
450
|
1467
|
428
|
1468 /* On focus change, clear all memory of sticky modifiers
|
|
1469 to avoid non-intuitive behavior. */
|
|
1470 clear_sticky_modifiers (XDEVICE (FRAME_DEVICE (f)));
|
|
1471
|
|
1472 /* We don't want to handle the focus change now, because we might
|
|
1473 be in an accept-process-output, sleep-for, or sit-for. So
|
|
1474 we enqueue it.
|
|
1475
|
|
1476 Actually, we half handle it: we handle it as far as changing the
|
|
1477 box cursor for redisplay, but we don't call any hooks or do any
|
|
1478 select-frame stuff until after the sit-for.
|
|
1479
|
|
1480 Unfortunately native widgets break the model because they grab
|
|
1481 the keyboard focus and nothing sets it back again. I cannot find
|
|
1482 any reasonable way to do this elsewhere so we assert here that
|
|
1483 the keyboard focus is on the emacs text widget. Menus and dialogs
|
|
1484 do this in their selection callback, but we don't want that since
|
|
1485 a button having focus is legitimate. An edit field having focus
|
|
1486 is mandatory. Weirdly you get a FocusOut event when you click in
|
442
|
1487 a widget-glyph but you don't get a corresponding FocusIn when you
|
428
|
1488 click in the frame. Why is this? */
|
438
|
1489 if (in_p
|
|
1490 #if XtSpecificationRelease > 5
|
863
|
1491 && needs_it != widget_with_focus
|
428
|
1492 #endif
|
|
1493 )
|
|
1494 {
|
863
|
1495 lw_set_keyboard_focus (FRAME_X_SHELL_WIDGET (f), needs_it);
|
428
|
1496 }
|
450
|
1497
|
863
|
1498 /* If we are focusing on a native widget then record and exit. */
|
|
1499 if (needs_it != FRAME_X_TEXT_WIDGET (f)) {
|
|
1500 widget_with_focus = needs_it;
|
|
1501 return;
|
|
1502 }
|
|
1503
|
450
|
1504 /* We have the focus now. See comment in
|
|
1505 emacs_Xt_handle_widget_losing_focus (). */
|
|
1506 if (in_p)
|
|
1507 widget_with_focus = NULL;
|
|
1508
|
428
|
1509 /* do the generic event-stream stuff. */
|
|
1510 {
|
|
1511 Lisp_Object frm;
|
|
1512 Lisp_Object conser;
|
|
1513 struct gcpro gcpro1;
|
|
1514
|
793
|
1515 frm = wrap_frame (f);
|
428
|
1516 conser = Fcons (frm, Fcons (FRAME_DEVICE (f), in_p ? Qt : Qnil));
|
|
1517 GCPRO1 (conser);
|
|
1518 emacs_handle_focus_change_preliminary (conser);
|
|
1519 enqueue_magic_eval_event (emacs_handle_focus_change_final,
|
|
1520 conser);
|
|
1521 UNGCPRO;
|
|
1522 }
|
|
1523 }
|
|
1524
|
863
|
1525 /* Create a synthetic X focus event. */
|
1111
|
1526 void emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame,
|
|
1527 int in_p);
|
863
|
1528 void
|
1111
|
1529 emacs_Xt_enqueue_focus_event (Widget wants_it, Lisp_Object frame, int in_p)
|
863
|
1530 {
|
|
1531 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
1532 Lisp_Event *ev = XEVENT (emacs_event);
|
960
|
1533 XEvent *x_event;
|
|
1534
|
|
1535 XSET_EVENT_TYPE (emacs_event, magic_event);
|
1204
|
1536 x_event = &EVENT_MAGIC_X_EVENT (ev);
|
863
|
1537
|
|
1538 x_event->type = in_p ? FocusIn : FocusOut;
|
|
1539 x_event->xfocus.window = XtWindow (wants_it);
|
|
1540
|
960
|
1541 SET_EVENT_CHANNEL (ev, frame);
|
1204
|
1542
|
|
1543 enqueue_dispatch_event (emacs_event);
|
863
|
1544 }
|
|
1545
|
450
|
1546 /* The idea here is that when a widget glyph gets unmapped we don't
|
|
1547 want the focus to stay with it if it has focus - because it may
|
863
|
1548 well just get deleted next and then we have lost the focus until the
|
450
|
1549 user does something. So handle_focus_event_1 records the widget
|
|
1550 with keyboard focus when FocusOut is processed, and then, when a
|
|
1551 widget gets unmapped, it calls this function to restore focus if
|
|
1552 appropriate. */
|
853
|
1553 void emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget);
|
450
|
1554 void
|
853
|
1555 emacs_Xt_handle_widget_losing_focus (struct frame *f, Widget losing_widget)
|
450
|
1556 {
|
|
1557 if (losing_widget == widget_with_focus)
|
|
1558 {
|
|
1559 handle_focus_event_1 (f, 1);
|
|
1560 }
|
|
1561 }
|
|
1562
|
428
|
1563 /* This is called from the external-widget code */
|
|
1564
|
|
1565 void emacs_Xt_handle_focus_event (XEvent *event);
|
|
1566 void
|
|
1567 emacs_Xt_handle_focus_event (XEvent *event)
|
|
1568 {
|
|
1569 struct device *d = get_device_from_display (event->xany.display);
|
|
1570 struct frame *f;
|
|
1571
|
|
1572 if (DEVICE_X_BEING_DELETED (d))
|
|
1573 return;
|
|
1574
|
|
1575 /*
|
|
1576 * It's curious that we're using x_any_window_to_frame() instead
|
|
1577 * of x_window_to_frame(). I don't know what the impact of this is.
|
|
1578 */
|
|
1579 f = x_any_window_to_frame (d, event->xfocus.window);
|
|
1580 if (!f)
|
|
1581 /* focus events are sometimes generated just before
|
|
1582 a frame is destroyed. */
|
|
1583 return;
|
|
1584 handle_focus_event_1 (f, event->type == FocusIn);
|
|
1585 }
|
|
1586
|
|
1587 /* both MapNotify and VisibilityNotify can cause this
|
|
1588 JV is_visible has the same semantics as f->visible*/
|
|
1589 static void
|
|
1590 change_frame_visibility (struct frame *f, int is_visible)
|
|
1591 {
|
793
|
1592 Lisp_Object frame = wrap_frame (f);
|
|
1593
|
428
|
1594
|
|
1595 if (!FRAME_VISIBLE_P (f) && is_visible)
|
|
1596 {
|
|
1597 FRAME_VISIBLE_P (f) = is_visible;
|
872
|
1598 /* [[ This improves the double flicker when uniconifying a frame
|
428
|
1599 some. A lot of it is not showing a buffer which has changed
|
|
1600 while the frame was iconified. To fix it further requires
|
872
|
1601 the good 'ol double redisplay structure. ]] -- comment is
|
|
1602 invalid, obviously predates 19.12, when the double redisplay
|
|
1603 structure (i.e. current + desired) was put back in. --ben */
|
428
|
1604 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1605 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1606 }
|
|
1607 else if (FRAME_VISIBLE_P (f) && !is_visible)
|
|
1608 {
|
|
1609 FRAME_VISIBLE_P (f) = 0;
|
|
1610 va_run_hook_with_args (Qunmap_frame_hook, 1, frame);
|
|
1611 }
|
|
1612 else if (FRAME_VISIBLE_P (f) * is_visible < 0)
|
|
1613 {
|
|
1614 FRAME_VISIBLE_P(f) = - FRAME_VISIBLE_P(f);
|
|
1615 if (FRAME_REPAINT_P(f))
|
|
1616 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1617 va_run_hook_with_args (Qmap_frame_hook, 1, frame);
|
|
1618 }
|
|
1619 }
|
|
1620
|
|
1621 static void
|
593
|
1622 update_frame_iconify_status (struct frame *f)
|
|
1623 {
|
|
1624 f->iconified = (x_frame_window_state (f) == IconicState);
|
|
1625 }
|
|
1626
|
|
1627 static void
|
428
|
1628 handle_map_event (struct frame *f, XEvent *event)
|
|
1629 {
|
593
|
1630
|
|
1631 /* It seems that, given the multiplicity of window managers and X
|
|
1632 implementations, plus the fact that X was designed without
|
|
1633 window managers or icons in mind and this was then grafted on
|
|
1634 with about the skill of a drunk freshman med student attempting
|
|
1635 surgery with a rusty razor blade, we cannot treat any off
|
|
1636 MapNotify/UnmapNotify/VisibilityNotify as more than vague hints
|
|
1637 as to the actual situation.
|
|
1638
|
|
1639 So we should just query the actual status. Unfortunately, things
|
|
1640 are worse because (a) there aren't obvious ways to query some
|
|
1641 of these values (e.g. "totally visible"), and (b) there may be
|
|
1642 race conditions (see below).
|
|
1643
|
638
|
1644 However, according to the ICCCM, there's a specific way to
|
593
|
1645 ask the window manager whether the state is (a) visible,
|
|
1646 (b) iconic, (c) withdrawn. It must be one of these three.
|
|
1647 We already use this call to check for the iconified state.
|
|
1648 I'd suggest we do the same for visible (i.e. NormalState),
|
|
1649 and scrap most of the nasty code below.
|
|
1650
|
|
1651 --ben
|
|
1652 */
|
|
1653
|
|
1654 update_frame_iconify_status (f);
|
|
1655
|
|
1656 /* #### Ben suggests rewriting the code below using
|
|
1657 x_frame_window_state (f). */
|
|
1658
|
428
|
1659 if (event->type == MapNotify)
|
|
1660 {
|
|
1661 XWindowAttributes xwa;
|
|
1662
|
|
1663 /* Bleagh!!!!!! Apparently some window managers (e.g. MWM)
|
|
1664 send synthetic MapNotify events when a window is first
|
|
1665 created, EVEN IF IT'S CREATED ICONIFIED OR INVISIBLE.
|
|
1666 Or something like that. We initially tried a different
|
|
1667 solution below, but that ran into a different window-
|
|
1668 manager bug.
|
|
1669
|
|
1670 It seems that the only reliable way is to treat a
|
|
1671 MapNotify event as a "hint" that the window might or
|
|
1672 might not be visible, and check explicitly. */
|
|
1673
|
|
1674 XGetWindowAttributes (event->xany.display, event->xmap.window,
|
|
1675 &xwa);
|
|
1676 if (xwa.map_state != IsViewable)
|
593
|
1677 return;
|
428
|
1678
|
|
1679 FRAME_X_TOTALLY_VISIBLE_P (f) = 1;
|
|
1680 #if 0
|
|
1681 /* Bleagh again!!!! We initially tried the following hack
|
|
1682 around the MWM problem, but it turns out that TWM
|
|
1683 has a race condition when you un-iconify, where it maps
|
|
1684 the window and then tells the server that the window
|
|
1685 is un-iconified. Usually, XEmacs wakes up between
|
|
1686 those two occurrences, and thus thinks that un-iconified
|
|
1687 windows are still iconified.
|
|
1688
|
|
1689 Ah, the joys of X. */
|
|
1690
|
|
1691 /* By Emacs definition, a frame that is iconified is not
|
|
1692 visible. Marking a frame as visible will automatically cause
|
|
1693 frame-iconified-p to return nil, regardless of whether the
|
|
1694 frame is actually iconified. Therefore, we have to ignore
|
|
1695 MapNotify events on iconified frames. (It's not obvious
|
|
1696 to me why these are being sent, but it happens at startup
|
|
1697 with frames that are initially iconified; perhaps they are
|
|
1698 synthetic MapNotify events coming from the window manager.)
|
|
1699 Note that `frame-iconified-p' queries the server
|
|
1700 to determine whether the frame is currently iconified,
|
|
1701 rather than consulting some internal (and likely
|
|
1702 inaccurate) state flag. Therefore, ignoring the MapNotify
|
|
1703 is correct. */
|
793
|
1704 if (!FRAME_VISIBLE_P (f) && NILP (Fframe_iconified_p (wrap_frame (f))))
|
428
|
1705 #endif /* 0 */
|
|
1706 change_frame_visibility (f, 1);
|
|
1707 }
|
|
1708 else
|
|
1709 {
|
|
1710 FRAME_X_TOTALLY_VISIBLE_P (f) = 0;
|
|
1711 change_frame_visibility (f, 0);
|
|
1712 }
|
|
1713 }
|
|
1714
|
|
1715 static void
|
|
1716 handle_client_message (struct frame *f, XEvent *event)
|
|
1717 {
|
|
1718 struct device *d = XDEVICE (FRAME_DEVICE (f));
|
793
|
1719 Lisp_Object frame = wrap_frame (f);
|
428
|
1720
|
|
1721 if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1722 (Atom) (event->xclient.data.l[0]) == DEVICE_XATOM_WM_DELETE_WINDOW (d))
|
|
1723 {
|
|
1724 /* WM_DELETE_WINDOW is a misc-user event, but other ClientMessages,
|
|
1725 such as WM_TAKE_FOCUS, are eval events. That's because delete-window
|
|
1726 was probably executed with a mouse click, while the others could
|
|
1727 have been sent as a result of mouse motion or some other implicit
|
|
1728 action. (Call this a "heuristic"...) The reason for caring about
|
|
1729 this is so that clicking on the close-box will make emacs prompt
|
|
1730 using a dialog box instead of the minibuffer if there are unsaved
|
|
1731 buffers.
|
|
1732 */
|
|
1733 enqueue_misc_user_event (frame, Qeval,
|
|
1734 list3 (Qdelete_frame, frame, Qt));
|
|
1735 }
|
|
1736 else if (event->xclient.message_type == DEVICE_XATOM_WM_PROTOCOLS (d) &&
|
|
1737 (Atom) event->xclient.data.l[0] == DEVICE_XATOM_WM_TAKE_FOCUS (d))
|
|
1738 {
|
|
1739 handle_focus_event_1 (f, 1);
|
|
1740 #if 0
|
|
1741 /* If there is a dialog box up, focus on it.
|
|
1742
|
|
1743 #### Actually, we're raising it too, which is wrong. We should
|
|
1744 #### just focus on it, but lwlib doesn't currently give us an
|
|
1745 #### easy way to do that. This should be fixed.
|
|
1746 */
|
|
1747 unsigned long take_focus_timestamp = event->xclient.data.l[1];
|
|
1748 Widget widget = lw_raise_all_pop_up_widgets ();
|
|
1749 if (widget)
|
|
1750 {
|
|
1751 /* kludge: raise_all returns bottommost widget, but we really
|
|
1752 want the topmost. So just raise it for now. */
|
|
1753 XMapRaised (XtDisplay (widget), XtWindow (widget));
|
|
1754 /* Grab the focus with the timestamp of the TAKE_FOCUS. */
|
|
1755 XSetInputFocus (XtDisplay (widget), XtWindow (widget),
|
|
1756 RevertToParent, take_focus_timestamp);
|
|
1757 }
|
|
1758 #endif
|
|
1759 }
|
|
1760 }
|
|
1761
|
448
|
1762 /* #### I'm struggling to understand how the X event loop really works.
|
|
1763 Here is the problem:
|
|
1764
|
|
1765 When widgets get mapped / changed etc the actual display updates
|
|
1766 are done asynchronously via X events being processed - this
|
|
1767 normally happens when XtAppProcessEvent() gets called. However, if
|
|
1768 we are executing lisp code or even doing redisplay we won't
|
|
1769 necessarily process X events for a very long time. This has the
|
|
1770 effect of widgets only getting updated when XEmacs only goes into
|
|
1771 idle, or some other event causes processing of the X event queue.
|
|
1772
|
|
1773 XtAppProcessEvent can get called from the following places:
|
|
1774
|
|
1775 emacs_Xt_next_event () - this is normal event processing, almost
|
|
1776 any non-X event will take precedence and this means that we
|
|
1777 cannot rely on it to do the right thing at the right time for
|
|
1778 widget display.
|
|
1779
|
1204
|
1780 emacs_Xt_drain_queue () - this happens when SIGIO gets tripped,
|
|
1781 processing the event queue allows C-g to be checked for. It gets
|
|
1782 called from emacs_Xt_event_pending_p (). #### Update this comment.
|
448
|
1783
|
|
1784 In order to solve this I have tried introducing a list primitive -
|
|
1785 dispatch-non-command-events - which forces processing of X events
|
|
1786 related to display. Unfortunately this has a number of problems,
|
|
1787 one is that it is possible for event_stream_event_pending_p to
|
|
1788 block for ever if there isn't actually an event. I guess this can
|
|
1789 happen if we drop the synthetic event for reason. It also relies on
|
|
1790 SIGIO processing which makes things rather fragile.
|
|
1791
|
|
1792 People have seen behaviour whereby XEmacs blocks until you move the
|
|
1793 mouse. This seems to indicate that dispatch-non-command-events is
|
|
1794 blocking. It may be that in a SIGIO world forcing SIGIO processing
|
|
1795 does the wrong thing.
|
|
1796 */
|
428
|
1797 static void
|
853
|
1798 emacs_Xt_force_event_pending (struct frame *f)
|
442
|
1799 {
|
|
1800 XEvent event;
|
|
1801
|
853
|
1802 Display *dpy = DEVICE_X_DISPLAY (XDEVICE (FRAME_DEVICE (f)));
|
442
|
1803 event.xclient.type = ClientMessage;
|
|
1804 event.xclient.display = dpy;
|
|
1805 event.xclient.message_type = XInternAtom (dpy, "BumpQueue", False);
|
|
1806 event.xclient.format = 32;
|
|
1807 event.xclient.window = 0;
|
|
1808
|
|
1809 /* Send the drop message */
|
|
1810 XSendEvent(dpy, XtWindow (FRAME_X_SHELL_WIDGET (f)),
|
|
1811 True, NoEventMask, &event);
|
448
|
1812 /* We rely on SIGIO and friends to realise we have generated an
|
|
1813 event. */
|
442
|
1814 }
|
|
1815
|
|
1816 static void
|
788
|
1817 emacs_Xt_format_magic_event (Lisp_Event *event, Lisp_Object pstream)
|
|
1818 {
|
|
1819 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
|
|
1820 if (CONSOLE_X_P (XCONSOLE (console)))
|
826
|
1821 write_c_string
|
1204
|
1822 (pstream, x_event_name ((EVENT_MAGIC_X_EVENT (event)).type));
|
788
|
1823 }
|
|
1824
|
|
1825 static int
|
|
1826 emacs_Xt_compare_magic_event (Lisp_Event *e1, Lisp_Event *e2)
|
|
1827 {
|
|
1828 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) &&
|
|
1829 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
1204
|
1830 return ((EVENT_MAGIC_X_EVENT (e1)).xany.serial ==
|
|
1831 (EVENT_MAGIC_X_EVENT (e2)).xany.serial);
|
788
|
1832 if (CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e1)))) ||
|
|
1833 CONSOLE_X_P (XCONSOLE (CDFW_CONSOLE (EVENT_CHANNEL (e2)))))
|
|
1834 return 0;
|
|
1835 return 1;
|
|
1836 }
|
|
1837
|
|
1838 static Hashcode
|
|
1839 emacs_Xt_hash_magic_event (Lisp_Event *e)
|
|
1840 {
|
|
1841 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
|
|
1842 if (CONSOLE_X_P (XCONSOLE (console)))
|
1204
|
1843 return (EVENT_MAGIC_X_EVENT (e)).xany.serial;
|
788
|
1844 return 0;
|
|
1845 }
|
|
1846
|
|
1847 static void
|
440
|
1848 emacs_Xt_handle_magic_event (Lisp_Event *emacs_event)
|
428
|
1849 {
|
|
1850 /* This function can GC */
|
1204
|
1851 XEvent *event = &EVENT_MAGIC_X_EVENT (emacs_event);
|
428
|
1852 struct frame *f = XFRAME (EVENT_CHANNEL (emacs_event));
|
|
1853
|
|
1854 if (!FRAME_LIVE_P (f) || DEVICE_X_BEING_DELETED (XDEVICE (FRAME_DEVICE (f))))
|
|
1855 return;
|
|
1856
|
|
1857 switch (event->type)
|
|
1858 {
|
|
1859 case SelectionRequest:
|
|
1860 x_handle_selection_request (&event->xselectionrequest);
|
|
1861 break;
|
934
|
1862
|
428
|
1863 case SelectionClear:
|
|
1864 x_handle_selection_clear (&event->xselectionclear);
|
|
1865 break;
|
934
|
1866
|
428
|
1867 case SelectionNotify:
|
|
1868 x_handle_selection_notify (&event->xselection);
|
|
1869 break;
|
934
|
1870
|
428
|
1871 case PropertyNotify:
|
|
1872 x_handle_property_notify (&event->xproperty);
|
|
1873 break;
|
934
|
1874
|
428
|
1875 case Expose:
|
|
1876 if (!check_for_ignored_expose (f, event->xexpose.x, event->xexpose.y,
|
1318
|
1877 event->xexpose.width,
|
|
1878 event->xexpose.height)
|
428
|
1879 &&
|
|
1880 !find_matching_subwindow (f, event->xexpose.x, event->xexpose.y,
|
|
1881 event->xexpose.width, event->xexpose.height))
|
1318
|
1882 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1883 event->xexpose.width,
|
|
1884 event->xexpose.height);
|
428
|
1885 break;
|
|
1886
|
|
1887 case GraphicsExpose: /* This occurs when an XCopyArea's source area was
|
|
1888 obscured or not available. */
|
1318
|
1889 redisplay_redraw_exposed_area (f, event->xexpose.x, event->xexpose.y,
|
|
1890 event->xexpose.width,
|
|
1891 event->xexpose.height);
|
428
|
1892 break;
|
|
1893
|
|
1894 case MapNotify:
|
|
1895 case UnmapNotify:
|
|
1896 handle_map_event (f, event);
|
|
1897 break;
|
|
1898
|
|
1899 case EnterNotify:
|
|
1900 if (event->xcrossing.detail != NotifyInferior)
|
|
1901 {
|
793
|
1902 Lisp_Object frame = wrap_frame (f);
|
|
1903
|
428
|
1904 /* FRAME_X_MOUSE_P (f) = 1; */
|
|
1905 va_run_hook_with_args (Qmouse_enter_frame_hook, 1, frame);
|
|
1906 }
|
|
1907 break;
|
|
1908
|
|
1909 case LeaveNotify:
|
|
1910 if (event->xcrossing.detail != NotifyInferior)
|
|
1911 {
|
793
|
1912 Lisp_Object frame = wrap_frame (f);
|
|
1913
|
428
|
1914 /* FRAME_X_MOUSE_P (f) = 0; */
|
|
1915 va_run_hook_with_args (Qmouse_leave_frame_hook, 1, frame);
|
|
1916 }
|
|
1917 break;
|
|
1918
|
|
1919 case FocusIn:
|
|
1920 case FocusOut:
|
|
1921
|
|
1922 #ifdef EXTERNAL_WIDGET
|
|
1923 /* External widget lossage: Ben said:
|
|
1924 YUCK. The only way to make focus changes work properly is to
|
|
1925 completely ignore all FocusIn/FocusOut events and depend only
|
|
1926 on notifications from the ExternalClient widget. */
|
|
1927 if (FRAME_X_EXTERNAL_WINDOW_P (f))
|
|
1928 break;
|
|
1929 #endif
|
863
|
1930 handle_focus_event_2 (event->xfocus.window, f, event->type == FocusIn);
|
428
|
1931 break;
|
|
1932
|
|
1933 case ClientMessage:
|
|
1934 handle_client_message (f, event);
|
|
1935 break;
|
|
1936
|
|
1937 case VisibilityNotify: /* window visibility has changed */
|
|
1938 if (event->xvisibility.window == XtWindow (FRAME_X_SHELL_WIDGET (f)))
|
|
1939 {
|
593
|
1940 /* See comment in handle_map_event */
|
|
1941 update_frame_iconify_status (f);
|
|
1942
|
|
1943 /* #### Ben suggests rewriting the code below using
|
|
1944 x_frame_window_state (f). */
|
428
|
1945 FRAME_X_TOTALLY_VISIBLE_P (f) =
|
|
1946 (event->xvisibility.state == VisibilityUnobscured);
|
|
1947 /* Note that the fvwm pager only sends VisibilityNotify when
|
|
1948 changing pages. Is this all we need to do ? JV */
|
|
1949 /* Nope. We must at least trigger a redisplay here.
|
|
1950 Since this case seems similar to MapNotify, I've
|
|
1951 factored out some code to change_frame_visibility().
|
|
1952 This triggers the necessary redisplay and runs
|
|
1953 (un)map-frame-hook. - dkindred@cs.cmu.edu */
|
|
1954 /* Changed it again to support the tristate visibility flag */
|
|
1955 change_frame_visibility (f, (event->xvisibility.state
|
|
1956 != VisibilityFullyObscured) ? 1 : -1);
|
|
1957 }
|
|
1958 break;
|
|
1959
|
|
1960 case ConfigureNotify:
|
|
1961 #ifdef HAVE_XIM
|
|
1962 XIM_SetGeometry (f);
|
|
1963 #endif
|
|
1964 break;
|
|
1965
|
442
|
1966 case CreateNotify:
|
|
1967 break;
|
|
1968
|
428
|
1969 default:
|
|
1970 break;
|
|
1971 }
|
|
1972 }
|
|
1973
|
|
1974
|
|
1975 /************************************************************************/
|
|
1976 /* timeout events */
|
|
1977 /************************************************************************/
|
|
1978
|
|
1979 static int timeout_id_tick;
|
|
1980
|
|
1981 /* Xt interval id's might not fit into an int (they're pointers, as it
|
|
1982 happens), so we need to provide a conversion list. */
|
|
1983
|
|
1984 static struct Xt_timeout
|
|
1985 {
|
|
1986 int id;
|
|
1987 XtIntervalId interval_id;
|
|
1988 struct Xt_timeout *next;
|
|
1989 } *pending_timeouts, *completed_timeouts;
|
|
1990
|
|
1991 static struct Xt_timeout_blocktype
|
|
1992 {
|
|
1993 Blocktype_declare (struct Xt_timeout);
|
|
1994 } *the_Xt_timeout_blocktype;
|
|
1995
|
|
1996 /* called by XtAppNextEvent() */
|
|
1997 static void
|
2286
|
1998 Xt_timeout_callback (XtPointer closure, XtIntervalId *UNUSED (id))
|
428
|
1999 {
|
|
2000 struct Xt_timeout *timeout = (struct Xt_timeout *) closure;
|
|
2001 struct Xt_timeout *t2 = pending_timeouts;
|
|
2002 /* Remove this one from the list of pending timeouts */
|
|
2003 if (t2 == timeout)
|
|
2004 pending_timeouts = pending_timeouts->next;
|
|
2005 else
|
|
2006 {
|
|
2007 while (t2->next && t2->next != timeout) t2 = t2->next;
|
|
2008 assert (t2->next);
|
|
2009 t2->next = t2->next->next;
|
|
2010 }
|
|
2011 /* Add this one to the list of completed timeouts */
|
|
2012 timeout->next = completed_timeouts;
|
|
2013 completed_timeouts = timeout;
|
|
2014 }
|
|
2015
|
|
2016 static int
|
|
2017 emacs_Xt_add_timeout (EMACS_TIME thyme)
|
|
2018 {
|
|
2019 struct Xt_timeout *timeout = Blocktype_alloc (the_Xt_timeout_blocktype);
|
|
2020 EMACS_TIME current_time;
|
|
2021 int milliseconds;
|
|
2022
|
|
2023 timeout->id = timeout_id_tick++;
|
|
2024 timeout->next = pending_timeouts;
|
|
2025 pending_timeouts = timeout;
|
|
2026 EMACS_GET_TIME (current_time);
|
|
2027 EMACS_SUB_TIME (thyme, thyme, current_time);
|
|
2028 milliseconds = EMACS_SECS (thyme) * 1000 +
|
|
2029 EMACS_USECS (thyme) / 1000;
|
|
2030 if (milliseconds < 1)
|
|
2031 milliseconds = 1;
|
|
2032 timeout->interval_id = XtAppAddTimeOut (Xt_app_con, milliseconds,
|
|
2033 Xt_timeout_callback,
|
|
2034 (XtPointer) timeout);
|
|
2035 return timeout->id;
|
|
2036 }
|
|
2037
|
|
2038 static void
|
|
2039 emacs_Xt_remove_timeout (int id)
|
|
2040 {
|
|
2041 struct Xt_timeout *timeout, *t2;
|
|
2042
|
|
2043 timeout = NULL;
|
|
2044
|
|
2045 /* Find the timeout on the list of pending ones, if it's still there. */
|
|
2046 if (pending_timeouts)
|
|
2047 {
|
|
2048 if (id == pending_timeouts->id)
|
|
2049 {
|
|
2050 timeout = pending_timeouts;
|
|
2051 pending_timeouts = pending_timeouts->next;
|
|
2052 }
|
|
2053 else
|
|
2054 {
|
|
2055 t2 = pending_timeouts;
|
|
2056 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
2057 if ( t2->next) /*found it */
|
|
2058 {
|
|
2059 timeout = t2->next;
|
|
2060 t2->next = t2->next->next;
|
|
2061 }
|
|
2062 }
|
|
2063 /* if it was pending, we have removed it from the list */
|
|
2064 if (timeout)
|
|
2065 XtRemoveTimeOut (timeout->interval_id);
|
|
2066 }
|
|
2067
|
|
2068 /* It could be that the Xt call back was already called but we didn't convert
|
|
2069 into an Emacs event yet */
|
|
2070 if (!timeout && completed_timeouts)
|
|
2071 {
|
|
2072 /* Code duplication! */
|
|
2073 if (id == completed_timeouts->id)
|
|
2074 {
|
|
2075 timeout = completed_timeouts;
|
|
2076 completed_timeouts = completed_timeouts->next;
|
|
2077 }
|
|
2078 else
|
|
2079 {
|
|
2080 t2 = completed_timeouts;
|
|
2081 while (t2->next && t2->next->id != id) t2 = t2->next;
|
|
2082 if ( t2->next) /*found it */
|
|
2083 {
|
|
2084 timeout = t2->next;
|
|
2085 t2->next = t2->next->next;
|
|
2086 }
|
|
2087 }
|
|
2088 }
|
|
2089
|
|
2090 /* If we found the thing on the lists of timeouts,
|
|
2091 and removed it, deallocate
|
|
2092 */
|
|
2093 if (timeout)
|
|
2094 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
2095 }
|
|
2096
|
|
2097 static void
|
440
|
2098 Xt_timeout_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2099 {
|
|
2100 struct Xt_timeout *timeout = completed_timeouts;
|
|
2101 assert (timeout);
|
|
2102 completed_timeouts = completed_timeouts->next;
|
934
|
2103 /* timeout events have nil as channel */
|
1204
|
2104 set_event_type (emacs_event, timeout_event);
|
934
|
2105 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### wrong!! */
|
1204
|
2106 SET_EVENT_TIMEOUT_INTERVAL_ID (emacs_event, timeout->id);
|
|
2107 SET_EVENT_TIMEOUT_FUNCTION (emacs_event, Qnil);
|
|
2108 SET_EVENT_TIMEOUT_OBJECT (emacs_event, Qnil);
|
428
|
2109 Blocktype_free (the_Xt_timeout_blocktype, timeout);
|
|
2110 }
|
|
2111
|
|
2112
|
|
2113 /************************************************************************/
|
|
2114 /* process and tty events */
|
|
2115 /************************************************************************/
|
|
2116
|
|
2117 struct what_is_ready_closure
|
|
2118 {
|
|
2119 int fd;
|
|
2120 Lisp_Object what;
|
|
2121 XtInputId id;
|
|
2122 };
|
|
2123
|
|
2124 static Lisp_Object *filedesc_with_input;
|
|
2125 static struct what_is_ready_closure **filedesc_to_what_closure;
|
|
2126
|
|
2127 static void
|
|
2128 init_what_input_once (void)
|
|
2129 {
|
|
2130 int i;
|
|
2131
|
|
2132 filedesc_with_input = xnew_array (Lisp_Object, MAXDESC);
|
|
2133 filedesc_to_what_closure =
|
|
2134 xnew_array (struct what_is_ready_closure *, MAXDESC);
|
|
2135
|
|
2136 for (i = 0; i < MAXDESC; i++)
|
|
2137 {
|
|
2138 filedesc_to_what_closure[i] = 0;
|
|
2139 filedesc_with_input[i] = Qnil;
|
|
2140 }
|
|
2141
|
|
2142 process_events_occurred = 0;
|
|
2143 tty_events_occurred = 0;
|
|
2144 }
|
|
2145
|
|
2146 static void
|
|
2147 mark_what_as_being_ready (struct what_is_ready_closure *closure)
|
|
2148 {
|
|
2149 if (NILP (filedesc_with_input[closure->fd]))
|
|
2150 {
|
|
2151 SELECT_TYPE temp_mask;
|
|
2152 FD_ZERO (&temp_mask);
|
|
2153 FD_SET (closure->fd, &temp_mask);
|
|
2154 /* Check to make sure there's *really* input available.
|
|
2155 Sometimes things seem to get confused and this gets called
|
|
2156 for the tty fd when there's really only input available
|
|
2157 on some process's fd. (It will subsequently get called
|
|
2158 for that process's fd, so returning without setting any
|
|
2159 flags will take care of it.) To see the problem, uncomment
|
|
2160 the stderr_out below, turn NORMAL_QUIT_CHECK_TIMEOUT_MSECS
|
|
2161 down to 25, do sh -c 'xemacs -nw -q -f shell 2>/tmp/log'
|
|
2162 and press return repeatedly. (Seen under AIX & Linux.)
|
|
2163 -dkindred@cs.cmu.edu */
|
|
2164 if (!poll_fds_for_input (temp_mask))
|
|
2165 {
|
|
2166 #if 0
|
|
2167 stderr_out ("mark_what_as_being_ready: no input available (fd=%d)\n",
|
|
2168 closure->fd);
|
|
2169 #endif
|
|
2170 return;
|
|
2171 }
|
|
2172 filedesc_with_input[closure->fd] = closure->what;
|
|
2173 if (PROCESSP (closure->what))
|
|
2174 /* Don't increment this if the current process is already marked
|
|
2175 * as having input. */
|
|
2176 process_events_occurred++;
|
|
2177 else
|
|
2178 tty_events_occurred++;
|
|
2179 }
|
|
2180 }
|
|
2181
|
|
2182 static void
|
2286
|
2183 Xt_what_callback (void *closure, int *UNUSED (source), XtInputId *UNUSED (id))
|
428
|
2184 {
|
|
2185 /* If closure is 0, then we got a fake event from a signal handler.
|
|
2186 The only purpose of this is to make XtAppProcessEvent() stop
|
|
2187 blocking. */
|
|
2188 if (closure)
|
|
2189 mark_what_as_being_ready ((struct what_is_ready_closure *) closure);
|
|
2190 else
|
|
2191 {
|
|
2192 fake_event_occurred++;
|
|
2193 drain_signal_event_pipe ();
|
|
2194 }
|
|
2195 }
|
|
2196
|
|
2197 static void
|
|
2198 select_filedesc (int fd, Lisp_Object what)
|
|
2199 {
|
|
2200 struct what_is_ready_closure *closure;
|
|
2201
|
|
2202 /* If somebody is trying to select something that's already selected
|
|
2203 for, then something went wrong. The generic routines ought to
|
|
2204 detect this and error before here. */
|
|
2205 assert (!filedesc_to_what_closure[fd]);
|
|
2206
|
|
2207 closure = xnew (struct what_is_ready_closure);
|
|
2208 closure->fd = fd;
|
|
2209 closure->what = what;
|
|
2210 closure->id =
|
|
2211 XtAppAddInput (Xt_app_con, fd,
|
|
2212 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
2213 Xt_what_callback, closure);
|
|
2214 filedesc_to_what_closure[fd] = closure;
|
|
2215 }
|
|
2216
|
|
2217 static void
|
|
2218 unselect_filedesc (int fd)
|
|
2219 {
|
|
2220 struct what_is_ready_closure *closure = filedesc_to_what_closure[fd];
|
|
2221
|
|
2222 assert (closure);
|
|
2223 if (!NILP (filedesc_with_input[fd]))
|
|
2224 {
|
|
2225 /* We are unselecting this process before we have drained the rest of
|
|
2226 the input from it, probably from status_notify() in the command loop.
|
|
2227 This can happen like so:
|
|
2228
|
|
2229 - We are waiting in XtAppNextEvent()
|
|
2230 - Process generates output
|
|
2231 - Process is marked as being ready
|
|
2232 - Process dies, SIGCHLD gets generated before we return (!?)
|
|
2233 It could happen I guess.
|
|
2234 - sigchld_handler() marks process as dead
|
|
2235 - Somehow we end up getting a new KeyPress event on the queue
|
|
2236 at the same time (I'm really so sure how that happens but I'm
|
|
2237 not sure it can't either so let's assume it can...).
|
|
2238 - Key events have priority so we return that instead of the proc.
|
|
2239 - Before dispatching the lisp key event we call status_notify()
|
|
2240 - Which deselects the process that SIGCHLD marked as dead.
|
|
2241
|
|
2242 Thus we never remove it from _with_input and turn it into a lisp
|
|
2243 event, so we need to do it here. But this does not mean that we're
|
|
2244 throwing away the last block of output - status_notify() has already
|
|
2245 taken care of running the proc filter or whatever.
|
|
2246 */
|
|
2247 filedesc_with_input[fd] = Qnil;
|
|
2248 if (PROCESSP (closure->what))
|
|
2249 {
|
|
2250 assert (process_events_occurred > 0);
|
|
2251 process_events_occurred--;
|
|
2252 }
|
|
2253 else
|
|
2254 {
|
|
2255 assert (tty_events_occurred > 0);
|
|
2256 tty_events_occurred--;
|
|
2257 }
|
|
2258 }
|
|
2259 XtRemoveInput (closure->id);
|
1726
|
2260 xfree (closure, struct what_is_ready_closure *);
|
428
|
2261 filedesc_to_what_closure[fd] = 0;
|
|
2262 }
|
|
2263
|
|
2264 static void
|
853
|
2265 emacs_Xt_select_process (Lisp_Process *process, int doin, int doerr)
|
428
|
2266 {
|
853
|
2267 Lisp_Object proc;
|
|
2268 int infd, errfd;
|
|
2269
|
|
2270 event_stream_unixoid_select_process (process, doin, doerr, &infd, &errfd);
|
|
2271
|
|
2272 proc = wrap_process (process);
|
|
2273 if (doin)
|
|
2274 select_filedesc (infd, proc);
|
|
2275 if (doerr)
|
|
2276 select_filedesc (errfd, proc);
|
|
2277 }
|
|
2278
|
|
2279 static void
|
|
2280 emacs_Xt_unselect_process (Lisp_Process *process, int doin, int doerr)
|
|
2281 {
|
|
2282 int infd, errfd;
|
|
2283
|
|
2284 event_stream_unixoid_unselect_process (process, doin, doerr, &infd, &errfd);
|
|
2285
|
|
2286 if (doin)
|
|
2287 unselect_filedesc (infd);
|
|
2288 if (doerr)
|
|
2289 unselect_filedesc (errfd);
|
428
|
2290 }
|
|
2291
|
|
2292 static void
|
853
|
2293 emacs_Xt_create_io_streams (void *inhandle, void *outhandle,
|
|
2294 void *errhandle, Lisp_Object *instream,
|
|
2295 Lisp_Object *outstream,
|
|
2296 Lisp_Object *errstream,
|
|
2297 USID *in_usid,
|
|
2298 USID *err_usid,
|
|
2299 int flags)
|
428
|
2300 {
|
853
|
2301 event_stream_unixoid_create_io_streams
|
|
2302 (inhandle, outhandle, errhandle, instream, outstream,
|
|
2303 errstream, in_usid, err_usid, flags);
|
|
2304 if (*in_usid != USID_ERROR)
|
|
2305 *in_usid = USID_DONTHASH;
|
|
2306 if (*err_usid != USID_ERROR)
|
|
2307 *err_usid = USID_DONTHASH;
|
428
|
2308 }
|
|
2309
|
853
|
2310 static void
|
|
2311 emacs_Xt_delete_io_streams (Lisp_Object instream,
|
|
2312 Lisp_Object outstream,
|
|
2313 Lisp_Object errstream,
|
|
2314 USID *in_usid,
|
|
2315 USID *err_usid)
|
428
|
2316 {
|
853
|
2317 event_stream_unixoid_delete_io_streams
|
|
2318 (instream, outstream, errstream, in_usid, err_usid);
|
|
2319 *in_usid = USID_DONTHASH;
|
|
2320 *err_usid = USID_DONTHASH;
|
428
|
2321 }
|
|
2322
|
|
2323 /* This is called from GC when a process object is about to be freed.
|
|
2324 If we've still got pointers to it in this file, we're gonna lose hard.
|
|
2325 */
|
|
2326 void
|
2286
|
2327 debug_process_finalization (Lisp_Process *UNUSED (p))
|
428
|
2328 {
|
|
2329 #if 0 /* #### */
|
|
2330 int i;
|
853
|
2331 Lisp_Object instr, outstr, errstr;
|
|
2332
|
|
2333 get_process_streams (p, &instr, &outstr, &errstr);
|
428
|
2334 /* if it still has fds, then it hasn't been killed yet. */
|
|
2335 assert (NILP(instr));
|
|
2336 assert (NILP(outstr));
|
853
|
2337 assert (NILP(errstr));
|
428
|
2338 /* Better not still be in the "with input" table; we know it's got no fds. */
|
|
2339 for (i = 0; i < MAXDESC; i++)
|
|
2340 {
|
|
2341 Lisp_Object process = filedesc_fds_with_input [i];
|
|
2342 assert (!PROCESSP (process) || XPROCESS (process) != p);
|
|
2343 }
|
|
2344 #endif
|
|
2345 }
|
|
2346
|
|
2347 static void
|
440
|
2348 Xt_process_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2349 {
|
|
2350 int i;
|
|
2351
|
|
2352 assert (process_events_occurred > 0);
|
438
|
2353
|
428
|
2354 for (i = 0; i < MAXDESC; i++)
|
|
2355 {
|
438
|
2356 Lisp_Object process = filedesc_with_input[i];
|
428
|
2357 if (PROCESSP (process))
|
438
|
2358 {
|
|
2359 filedesc_with_input[i] = Qnil;
|
|
2360 process_events_occurred--;
|
|
2361 /* process events have nil as channel */
|
934
|
2362 set_event_type (emacs_event, process_event);
|
|
2363 SET_EVENT_TIMESTAMP_ZERO (emacs_event); /* #### */
|
1204
|
2364 SET_EVENT_PROCESS_PROCESS (emacs_event, process);
|
438
|
2365 return;
|
|
2366 }
|
428
|
2367 }
|
2500
|
2368 ABORT ();
|
428
|
2369 }
|
|
2370
|
|
2371 static void
|
|
2372 emacs_Xt_select_console (struct console *con)
|
|
2373 {
|
|
2374 Lisp_Object console;
|
|
2375 int infd;
|
|
2376
|
|
2377 if (CONSOLE_X_P (con))
|
|
2378 return; /* X consoles are automatically selected for when we
|
|
2379 initialize them in Xt */
|
|
2380 infd = event_stream_unixoid_select_console (con);
|
793
|
2381 console = wrap_console (con);
|
428
|
2382 select_filedesc (infd, console);
|
|
2383 }
|
|
2384
|
|
2385 static void
|
|
2386 emacs_Xt_unselect_console (struct console *con)
|
|
2387 {
|
|
2388 int infd;
|
|
2389
|
|
2390 if (CONSOLE_X_P (con))
|
|
2391 return; /* X consoles are automatically selected for when we
|
|
2392 initialize them in Xt */
|
|
2393 infd = event_stream_unixoid_unselect_console (con);
|
|
2394 unselect_filedesc (infd);
|
|
2395 }
|
|
2396
|
|
2397 /* read an event from a tty, if one is available. Returns non-zero
|
|
2398 if an event was available. Note that when this function is
|
|
2399 called, there should always be a tty marked as ready for input.
|
|
2400 However, the input condition might actually be EOF, so there
|
|
2401 may not really be any input available. (In this case,
|
|
2402 read_event_from_tty_or_stream_desc() will arrange for the TTY device
|
|
2403 to be deleted.) */
|
|
2404
|
|
2405 static int
|
440
|
2406 Xt_tty_to_emacs_event (Lisp_Event *emacs_event)
|
428
|
2407 {
|
|
2408 int i;
|
|
2409
|
|
2410 assert (tty_events_occurred > 0);
|
|
2411 for (i = 0; i < MAXDESC; i++)
|
|
2412 {
|
|
2413 Lisp_Object console = filedesc_with_input[i];
|
|
2414 if (CONSOLEP (console))
|
|
2415 {
|
|
2416 assert (tty_events_occurred > 0);
|
|
2417 tty_events_occurred--;
|
|
2418 filedesc_with_input[i] = Qnil;
|
771
|
2419 if (read_event_from_tty_or_stream_desc (emacs_event,
|
|
2420 XCONSOLE (console)))
|
428
|
2421 return 1;
|
|
2422 }
|
|
2423 }
|
|
2424
|
|
2425 return 0;
|
|
2426 }
|
|
2427
|
|
2428
|
|
2429 /************************************************************************/
|
|
2430 /* debugging functions to decipher an event */
|
|
2431 /************************************************************************/
|
|
2432
|
|
2433 #ifdef DEBUG_XEMACS
|
|
2434 #include "xintrinsicp.h" /* only describe_event() needs this */
|
|
2435 #include <X11/Xproto.h> /* only describe_event() needs this */
|
|
2436
|
|
2437 static void
|
788
|
2438 describe_event_window (Window window, Display *display, Lisp_Object pstream)
|
428
|
2439 {
|
|
2440 struct frame *f;
|
|
2441 Widget w;
|
788
|
2442 write_fmt_string (pstream, " window: 0x%lx", (unsigned long) window);
|
428
|
2443 w = XtWindowToWidget (display, window);
|
|
2444 if (w)
|
788
|
2445 write_fmt_string (pstream, " %s",
|
|
2446 w->core.widget_class->core_class.class_name);
|
428
|
2447 f = x_any_window_to_frame (get_device_from_display (display), window);
|
|
2448 if (f)
|
788
|
2449 write_fmt_string_lisp (pstream, " \"%s\"", 1, f->name);
|
|
2450 write_fmt_string (pstream, "\n");
|
428
|
2451 }
|
|
2452
|
442
|
2453 static const char *
|
428
|
2454 XEvent_mode_to_string (int mode)
|
|
2455 {
|
|
2456 switch (mode)
|
|
2457 {
|
|
2458 case NotifyNormal: return "Normal";
|
|
2459 case NotifyGrab: return "Grab";
|
|
2460 case NotifyUngrab: return "Ungrab";
|
|
2461 case NotifyWhileGrabbed: return "WhileGrabbed";
|
|
2462 default: return "???";
|
|
2463 }
|
|
2464 }
|
|
2465
|
442
|
2466 static const char *
|
428
|
2467 XEvent_detail_to_string (int detail)
|
|
2468 {
|
|
2469 switch (detail)
|
|
2470 {
|
|
2471 case NotifyAncestor: return "Ancestor";
|
|
2472 case NotifyInferior: return "Inferior";
|
|
2473 case NotifyNonlinear: return "Nonlinear";
|
|
2474 case NotifyNonlinearVirtual: return "NonlinearVirtual";
|
|
2475 case NotifyPointer: return "Pointer";
|
|
2476 case NotifyPointerRoot: return "PointerRoot";
|
|
2477 case NotifyDetailNone: return "DetailNone";
|
|
2478 default: return "???";
|
|
2479 }
|
|
2480 }
|
|
2481
|
442
|
2482 static const char *
|
428
|
2483 XEvent_visibility_to_string (int state)
|
|
2484 {
|
|
2485 switch (state)
|
|
2486 {
|
|
2487 case VisibilityFullyObscured: return "FullyObscured";
|
|
2488 case VisibilityPartiallyObscured: return "PartiallyObscured";
|
|
2489 case VisibilityUnobscured: return "Unobscured";
|
|
2490 default: return "???";
|
|
2491 }
|
|
2492 }
|
|
2493
|
|
2494 static void
|
788
|
2495 describe_event (XEvent *event, Lisp_Object pstream)
|
428
|
2496 {
|
|
2497 char buf[100];
|
|
2498 struct device *d = get_device_from_display (event->xany.display);
|
|
2499
|
|
2500 sprintf (buf, "%s%s", x_event_name (event->type),
|
|
2501 event->xany.send_event ? " (send)" : "");
|
788
|
2502 write_fmt_string (pstream, "%-30s", buf);
|
428
|
2503 switch (event->type)
|
|
2504 {
|
|
2505 case FocusIn:
|
|
2506 case FocusOut:
|
|
2507 {
|
|
2508 XFocusChangeEvent *ev = &event->xfocus;
|
788
|
2509 describe_event_window (ev->window, ev->display, pstream);
|
|
2510 write_fmt_string (pstream, " mode: %s\n",
|
|
2511 XEvent_mode_to_string (ev->mode));
|
|
2512 write_fmt_string (pstream, " detail: %s\n",
|
|
2513 XEvent_detail_to_string (ev->detail));
|
428
|
2514 break;
|
|
2515 }
|
|
2516
|
|
2517 case KeyPress:
|
|
2518 {
|
|
2519 XKeyEvent *ev = &event->xkey;
|
|
2520 unsigned int state = ev->state;
|
|
2521
|
788
|
2522 describe_event_window (ev->window, ev->display, pstream);
|
|
2523 write_fmt_string (pstream, " subwindow: %ld\n", ev->subwindow);
|
|
2524 write_fmt_string (pstream, " state: ");
|
428
|
2525 /* Complete list of modifier key masks */
|
788
|
2526 if (state & ShiftMask) write_fmt_string (pstream, "Shift ");
|
|
2527 if (state & LockMask) write_fmt_string (pstream, "Lock ");
|
|
2528 if (state & ControlMask) write_fmt_string (pstream, "Control ");
|
|
2529 if (state & Mod1Mask) write_fmt_string (pstream, "Mod1 ");
|
|
2530 if (state & Mod2Mask) write_fmt_string (pstream, "Mod2 ");
|
|
2531 if (state & Mod3Mask) write_fmt_string (pstream, "Mod3 ");
|
|
2532 if (state & Mod4Mask) write_fmt_string (pstream, "Mod4 ");
|
|
2533 if (state & Mod5Mask) write_fmt_string (pstream, "Mod5 ");
|
428
|
2534
|
|
2535 if (! state)
|
788
|
2536 write_fmt_string (pstream, "vanilla\n");
|
428
|
2537 else
|
788
|
2538 write_fmt_string (pstream, "\n");
|
428
|
2539 if (x_key_is_modifier_p (ev->keycode, d))
|
788
|
2540 write_fmt_string (pstream, " Modifier key");
|
|
2541 write_fmt_string (pstream, " keycode: 0x%x\n", ev->keycode);
|
428
|
2542 }
|
|
2543 break;
|
|
2544
|
|
2545 case Expose:
|
442
|
2546 if (debug_x_events > 1)
|
428
|
2547 {
|
|
2548 XExposeEvent *ev = &event->xexpose;
|
788
|
2549 describe_event_window (ev->window, ev->display, pstream);
|
|
2550 write_fmt_string (pstream,
|
|
2551 " region: x=%d y=%d width=%d height=%d\n",
|
428
|
2552 ev->x, ev->y, ev->width, ev->height);
|
788
|
2553 write_fmt_string (pstream, " count: %d\n", ev->count);
|
428
|
2554 }
|
|
2555 else
|
788
|
2556 write_fmt_string (pstream, "\n");
|
428
|
2557 break;
|
|
2558
|
|
2559 case GraphicsExpose:
|
442
|
2560 if (debug_x_events > 1)
|
428
|
2561 {
|
|
2562 XGraphicsExposeEvent *ev = &event->xgraphicsexpose;
|
788
|
2563 describe_event_window (ev->drawable, ev->display, pstream);
|
|
2564 write_fmt_string (pstream, " major: %s\n",
|
428
|
2565 (ev ->major_code == X_CopyArea ? "CopyArea" :
|
|
2566 (ev->major_code == X_CopyPlane ? "CopyPlane" : "?")));
|
788
|
2567 write_fmt_string (pstream,
|
|
2568 " region: x=%d y=%d width=%d height=%d\n",
|
428
|
2569 ev->x, ev->y, ev->width, ev->height);
|
788
|
2570 write_fmt_string (pstream, " count: %d\n", ev->count);
|
428
|
2571 }
|
|
2572 else
|
788
|
2573 write_fmt_string (pstream, "\n");
|
428
|
2574 break;
|
|
2575
|
|
2576 case EnterNotify:
|
|
2577 case LeaveNotify:
|
442
|
2578 if (debug_x_events > 1)
|
428
|
2579 {
|
|
2580 XCrossingEvent *ev = &event->xcrossing;
|
788
|
2581 describe_event_window (ev->window, ev->display, pstream);
|
428
|
2582 #if 0
|
788
|
2583 write_fmt_string (pstream, " subwindow: 0x%x\n", ev->subwindow);
|
|
2584 write_fmt_string (pstream, " pos: %d %d\n", ev->x, ev->y);
|
|
2585 write_fmt_string (pstream, " root pos: %d %d\n", ev->x_root,
|
|
2586 ev->y_root);
|
428
|
2587 #endif
|
788
|
2588 write_fmt_string (pstream, " mode: %s\n",
|
|
2589 XEvent_mode_to_string(ev->mode));
|
|
2590 write_fmt_string (pstream, " detail: %s\n",
|
|
2591 XEvent_detail_to_string(ev->detail));
|
|
2592 write_fmt_string (pstream, " focus: %d\n", ev->focus);
|
428
|
2593 #if 0
|
788
|
2594 write_fmt_string (pstream, " state: 0x%x\n", ev->state);
|
428
|
2595 #endif
|
|
2596 }
|
|
2597 else
|
788
|
2598 write_fmt_string (pstream, "\n");
|
428
|
2599 break;
|
|
2600
|
|
2601 case ConfigureNotify:
|
442
|
2602 if (debug_x_events > 1)
|
428
|
2603 {
|
|
2604 XConfigureEvent *ev = &event->xconfigure;
|
788
|
2605 describe_event_window (ev->window, ev->display, pstream);
|
|
2606 write_fmt_string (pstream, " above: 0x%lx\n", ev->above);
|
|
2607 write_fmt_string (pstream, " size: %d %d %d %d\n", ev->x, ev->y,
|
428
|
2608 ev->width, ev->height);
|
788
|
2609 write_fmt_string (pstream, " redirect: %d\n",
|
|
2610 ev->override_redirect);
|
428
|
2611 }
|
|
2612 else
|
788
|
2613 write_fmt_string (pstream, "\n");
|
428
|
2614 break;
|
|
2615
|
|
2616 case VisibilityNotify:
|
442
|
2617 if (debug_x_events > 1)
|
428
|
2618 {
|
|
2619 XVisibilityEvent *ev = &event->xvisibility;
|
788
|
2620 describe_event_window (ev->window, ev->display, pstream);
|
|
2621 write_fmt_string (pstream, " state: %s\n",
|
|
2622 XEvent_visibility_to_string (ev->state));
|
428
|
2623 }
|
|
2624 else
|
788
|
2625 write_fmt_string (pstream, "\n");
|
428
|
2626 break;
|
|
2627
|
|
2628 case ClientMessage:
|
|
2629 {
|
|
2630 XClientMessageEvent *ev = &event->xclient;
|
|
2631 char *name = XGetAtomName (ev->display, ev->message_type);
|
788
|
2632 write_fmt_string (pstream, "%s", name);
|
|
2633 if (!strcmp (name, "WM_PROTOCOLS"))
|
|
2634 {
|
|
2635 char *protname = XGetAtomName (ev->display, ev->data.l[0]);
|
|
2636 write_fmt_string (pstream, "(%s)", protname);
|
|
2637 XFree (protname);
|
|
2638 }
|
428
|
2639 XFree (name);
|
788
|
2640 write_fmt_string (pstream, "\n");
|
428
|
2641 break;
|
|
2642 }
|
|
2643
|
|
2644 default:
|
788
|
2645 write_fmt_string (pstream, "\n");
|
428
|
2646 break;
|
|
2647 }
|
|
2648
|
|
2649 fflush (stdout);
|
|
2650 }
|
|
2651
|
|
2652 #endif /* include describe_event definition */
|
|
2653
|
|
2654
|
|
2655 /************************************************************************/
|
|
2656 /* get the next event from Xt */
|
|
2657 /************************************************************************/
|
|
2658
|
|
2659 /* This business exists because menu events "happen" when
|
|
2660 menubar_selection_callback() is called from somewhere deep
|
|
2661 within XtAppProcessEvent in emacs_Xt_next_event(). The
|
|
2662 callback needs to terminate the modal loop in that function
|
|
2663 or else it will continue waiting until another event is
|
|
2664 received.
|
|
2665
|
|
2666 Same business applies to scrollbar events. */
|
|
2667
|
|
2668 void
|
|
2669 signal_special_Xt_user_event (Lisp_Object channel, Lisp_Object function,
|
|
2670 Lisp_Object object)
|
|
2671 {
|
|
2672 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
2673
|
934
|
2674 XSET_EVENT_TYPE (event, misc_user_event);
|
|
2675 XSET_EVENT_CHANNEL (event, channel);
|
1204
|
2676 XSET_EVENT_MISC_USER_FUNCTION (event, function);
|
|
2677 XSET_EVENT_MISC_USER_OBJECT (event, object);
|
|
2678 enqueue_dispatch_event (event);
|
428
|
2679 }
|
|
2680
|
|
2681 static void
|
440
|
2682 emacs_Xt_next_event (Lisp_Event *emacs_event)
|
428
|
2683 {
|
|
2684 we_didnt_get_an_event:
|
|
2685
|
|
2686 while (NILP (dispatch_event_queue) &&
|
|
2687 !completed_timeouts &&
|
|
2688 !fake_event_occurred &&
|
|
2689 !process_events_occurred &&
|
|
2690 !tty_events_occurred)
|
|
2691 {
|
1268
|
2692 if (in_modal_loop)
|
|
2693 {
|
|
2694 /* in_modal_loop gets set when we are in the process of
|
|
2695 dispatching an event (more specifically, when we are inside of
|
|
2696 a menu callback -- if we get here, it means we called a filter
|
|
2697 and the filter did something that tried to fetch an event,
|
|
2698 e.g. sit-for). In such a case, we cannot safely dispatch any
|
|
2699 more events. This is because those dispatching those events
|
|
2700 could cause lwlib to be entered reentranty, specifically if
|
|
2701 they are menu events. lwlib is not designed for this and will
|
|
2702 crash. We used to see this crash constantly as a result of
|
|
2703 QUIT checking, but QUIT will not now function in a modal loop.
|
|
2704 However, we can't just not process any events at all, because
|
|
2705 that will make sit-for etc. hang. So we go ahead and process
|
|
2706 the non-X kinds of events. */
|
1292
|
2707 #ifdef WIN32_ANY
|
|
2708 mswindows_is_blocking = 1;
|
|
2709 #endif
|
|
2710 XtAppProcessEvent (Xt_app_con, XtIMTimer | XtIMAlternateInput);
|
|
2711 #ifdef WIN32_ANY
|
|
2712 mswindows_is_blocking = 0;
|
|
2713 #endif
|
1268
|
2714 }
|
428
|
2715 else
|
|
2716 {
|
1268
|
2717 /* Stupid logic in XtAppProcessEvent() dictates that, if process
|
|
2718 events and X events are both available, the process event gets
|
|
2719 taken first. This will cause an infinite loop if we're being
|
|
2720 called from Fdiscard_input().
|
|
2721 */
|
|
2722
|
|
2723 if (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2724 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2725 else
|
428
|
2726 {
|
1268
|
2727 Lisp_Object devcons, concons;
|
|
2728
|
|
2729 /* We're about to block. Xt has a bug in it (big surprise,
|
|
2730 there) in that it blocks using select() and doesn't
|
|
2731 flush the Xlib output buffers (XNextEvent() does this
|
|
2732 automatically before blocking). So it's necessary
|
|
2733 for us to do this ourselves. If we don't do it, then
|
|
2734 display output may not be seen until the next time
|
|
2735 an X event is received. (This happens esp. with
|
|
2736 subprocess output that gets sent to a visible buffer.)
|
|
2737
|
|
2738 #### The above comment may not have any validity. */
|
|
2739
|
|
2740 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
2741 {
|
|
2742 struct device *d;
|
|
2743 d = XDEVICE (XCAR (devcons));
|
|
2744
|
|
2745 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2746 /* emacs may be exiting */
|
|
2747 XFlush (DEVICE_X_DISPLAY (d));
|
|
2748 }
|
1292
|
2749 #ifdef WIN32_ANY
|
|
2750 mswindows_is_blocking = 1;
|
|
2751 #endif
|
1268
|
2752 XtAppProcessEvent (Xt_app_con, XtIMAll);
|
1292
|
2753 #ifdef WIN32_ANY
|
|
2754 mswindows_is_blocking = 0;
|
|
2755 #endif
|
428
|
2756 }
|
|
2757 }
|
|
2758 }
|
|
2759
|
|
2760 if (!NILP (dispatch_event_queue))
|
|
2761 {
|
|
2762 Lisp_Object event, event2;
|
793
|
2763 event2 = wrap_event (emacs_event);
|
1204
|
2764 event = dequeue_dispatch_event ();
|
428
|
2765 Fcopy_event (event, event2);
|
|
2766 Fdeallocate_event (event);
|
|
2767 }
|
|
2768 else if (tty_events_occurred)
|
|
2769 {
|
|
2770 if (!Xt_tty_to_emacs_event (emacs_event))
|
|
2771 goto we_didnt_get_an_event;
|
|
2772 }
|
|
2773 else if (completed_timeouts)
|
|
2774 Xt_timeout_to_emacs_event (emacs_event);
|
|
2775 else if (fake_event_occurred)
|
|
2776 {
|
|
2777 /* A dummy event, so that a cycle of the command loop will occur. */
|
|
2778 fake_event_occurred = 0;
|
|
2779 /* eval events have nil as channel */
|
934
|
2780 set_event_type (emacs_event, eval_event);
|
1204
|
2781 SET_EVENT_EVAL_FUNCTION (emacs_event, Qidentity);
|
|
2782 SET_EVENT_EVAL_OBJECT (emacs_event, Qnil);
|
428
|
2783 }
|
|
2784 else /* if (process_events_occurred) */
|
|
2785 Xt_process_to_emacs_event (emacs_event);
|
|
2786
|
|
2787 /* No need to call XFilterEvent; Xt does it for us */
|
|
2788 }
|
|
2789
|
|
2790 void
|
2286
|
2791 emacs_Xt_event_handler (Widget UNUSED (wid),
|
|
2792 XtPointer UNUSED (closure),
|
428
|
2793 XEvent *event,
|
2286
|
2794 Boolean *UNUSED (continue_to_dispatch))
|
428
|
2795 {
|
|
2796 Lisp_Object emacs_event = Fmake_event (Qnil, Qnil);
|
|
2797
|
|
2798 #ifdef DEBUG_XEMACS
|
442
|
2799 if (debug_x_events > 0)
|
788
|
2800 describe_event (event, Qexternal_debugging_output);
|
428
|
2801 #endif /* DEBUG_XEMACS */
|
|
2802 if (x_event_to_emacs_event (event, XEVENT (emacs_event)))
|
1204
|
2803 enqueue_dispatch_event (emacs_event);
|
428
|
2804 else
|
|
2805 Fdeallocate_event (emacs_event);
|
|
2806 }
|
|
2807
|
|
2808
|
|
2809 /************************************************************************/
|
1204
|
2810 /* input pending */
|
428
|
2811 /************************************************************************/
|
|
2812
|
|
2813 static void
|
1204
|
2814 emacs_Xt_drain_queue (void)
|
428
|
2815 {
|
|
2816 Lisp_Object devcons, concons;
|
1268
|
2817 if (!in_modal_loop)
|
428
|
2818 {
|
1268
|
2819 CONSOLE_LOOP (concons)
|
428
|
2820 {
|
1268
|
2821 struct console *con = XCONSOLE (XCAR (concons));
|
|
2822 if (!con->input_enabled)
|
|
2823 continue;
|
|
2824
|
|
2825 CONSOLE_DEVICE_LOOP (devcons, con)
|
1204
|
2826 {
|
1268
|
2827 struct device *d;
|
|
2828 Display *display;
|
|
2829 d = XDEVICE (XCAR (devcons));
|
|
2830 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d))
|
|
2831 {
|
|
2832 display = DEVICE_X_DISPLAY (d);
|
|
2833 while (XEventsQueued (display, QueuedAfterReading))
|
|
2834 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2835 }
|
1204
|
2836 }
|
428
|
2837 }
|
1268
|
2838 /*
|
|
2839 while (XtAppPending (Xt_app_con) & XtIMXEvent)
|
|
2840 XtAppProcessEvent (Xt_app_con, XtIMXEvent);
|
|
2841 */
|
428
|
2842 }
|
1268
|
2843
|
|
2844 #ifdef HAVE_TTY
|
1204
|
2845 drain_tty_devices ();
|
428
|
2846 #endif
|
|
2847 }
|
|
2848
|
1204
|
2849 int
|
|
2850 check_if_pending_expose_event (struct device *dev)
|
|
2851 {
|
|
2852 Display *d = DEVICE_X_DISPLAY (dev);
|
|
2853 Lisp_Object event;
|
|
2854
|
|
2855 emacs_Xt_drain_queue ();
|
|
2856
|
|
2857 EVENT_CHAIN_LOOP (event, dispatch_event_queue)
|
|
2858 if (XEVENT_TYPE (event) == magic_event)
|
|
2859 {
|
|
2860 XEvent *xev = &XEVENT_MAGIC_X_EVENT (event);
|
|
2861 if (xev->type == Expose &&
|
|
2862 xev->xexpose.display == d)
|
|
2863 return 1;
|
|
2864 }
|
|
2865
|
|
2866 return 0;
|
|
2867 }
|
|
2868
|
442
|
2869 static int
|
|
2870 emacs_Xt_current_event_timestamp (struct console *c)
|
|
2871 {
|
|
2872 /* semi-yuck. */
|
|
2873 Lisp_Object devs = CONSOLE_DEVICE_LIST (c);
|
|
2874
|
|
2875 if (NILP (devs))
|
|
2876 return 0;
|
|
2877 else
|
|
2878 {
|
|
2879 struct device *d = XDEVICE (XCAR (devs));
|
|
2880 return DEVICE_X_LAST_SERVER_TIMESTAMP (d);
|
|
2881 }
|
|
2882 }
|
|
2883
|
428
|
2884
|
|
2885 /************************************************************************/
|
|
2886 /* replacement for standard string-to-pixel converter */
|
|
2887 /************************************************************************/
|
|
2888
|
|
2889 /* This was constructed by ripping off the standard string-to-pixel
|
|
2890 converter from Converters.c in the Xt source code and modifying
|
|
2891 appropriately. */
|
|
2892
|
|
2893 #if 0
|
|
2894
|
|
2895 /* This is exported by the Xt library (at least by mine). If this
|
|
2896 isn't the case somewhere, rename this appropriately and remove
|
|
2897 the '#if 0'. Note, however, that I got "unknown structure"
|
|
2898 errors when I tried this. */
|
|
2899 XtConvertArgRec Const colorConvertArgs[] = {
|
440
|
2900 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
|
|
2901 sizeof (Screen *) },
|
|
2902 { XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
|
|
2903 sizeof (Colormap) }
|
428
|
2904 };
|
|
2905
|
|
2906 #endif
|
|
2907
|
|
2908 #define done(type, value) \
|
|
2909 if (toVal->addr != NULL) { \
|
|
2910 if (toVal->size < sizeof(type)) { \
|
|
2911 toVal->size = sizeof(type); \
|
|
2912 return False; \
|
|
2913 } \
|
|
2914 *(type*)(toVal->addr) = (value); \
|
|
2915 } else { \
|
|
2916 static type static_val; \
|
|
2917 static_val = (value); \
|
|
2918 toVal->addr = (XPointer)&static_val; \
|
|
2919 } \
|
|
2920 toVal->size = sizeof(type); \
|
|
2921 return True /* Caller supplies `;' */
|
|
2922
|
|
2923 /* JH: We use this because I think there's a possibility this
|
|
2924 is called before the device is properly set up, in which case
|
|
2925 I don't want to abort. */
|
|
2926 extern struct device *get_device_from_display_1 (Display *dpy);
|
|
2927
|
|
2928 static
|
|
2929 Boolean EmacsXtCvtStringToPixel (
|
|
2930 Display *dpy,
|
|
2931 XrmValuePtr args,
|
|
2932 Cardinal *num_args,
|
|
2933 XrmValuePtr fromVal,
|
|
2934 XrmValuePtr toVal,
|
|
2935 XtPointer *closure_ret)
|
|
2936 {
|
|
2937 String str = (String)fromVal->addr;
|
|
2938 XColor screenColor;
|
|
2939 XColor exactColor;
|
|
2940 Screen *screen;
|
|
2941 Colormap colormap;
|
|
2942 Visual *visual;
|
|
2943 struct device *d;
|
|
2944 Status status;
|
|
2945 String params[1];
|
|
2946 Cardinal num_params = 1;
|
|
2947 XtAppContext the_app_con = XtDisplayToApplicationContext (dpy);
|
|
2948
|
|
2949 if (*num_args != 2) {
|
|
2950 XtAppWarningMsg(the_app_con, "wrongParameters", "cvtStringToPixel",
|
|
2951 "XtToolkitError",
|
|
2952 "String to pixel conversion needs screen and colormap arguments",
|
|
2953 (String *)NULL, (Cardinal *)NULL);
|
|
2954 return False;
|
|
2955 }
|
|
2956
|
|
2957 screen = *((Screen **) args[0].addr);
|
|
2958 colormap = *((Colormap *) args[1].addr);
|
|
2959
|
|
2960 /* The original uses the private function CompareISOLatin1().
|
|
2961 Use XmuCompareISOLatin1() if you want, but I don't think it
|
|
2962 makes any difference here. */
|
|
2963 if (strcmp(str, XtDefaultBackground) == 0) {
|
|
2964 *closure_ret = False;
|
|
2965 /* This refers to the display's "*reverseVideo" resource.
|
|
2966 These display resources aren't documented anywhere that
|
|
2967 I can find, so I'm going to ignore this. */
|
|
2968 /* if (pd->rv) done(Pixel, BlackPixelOfScreen(screen)) else */
|
|
2969 done(Pixel, WhitePixelOfScreen(screen));
|
|
2970 }
|
|
2971 if (strcmp(str, XtDefaultForeground) == 0) {
|
|
2972 *closure_ret = False;
|
|
2973 /* if (pd->rv) done(Pixel, WhitePixelOfScreen(screen)) else */
|
|
2974 done(Pixel, BlackPixelOfScreen(screen));
|
|
2975 }
|
|
2976
|
|
2977 /* Originally called XAllocNamedColor() here. */
|
|
2978 if ((d = get_device_from_display_1(dpy))) {
|
|
2979 visual = DEVICE_X_VISUAL(d);
|
|
2980 if (colormap != DEVICE_X_COLORMAP(d)) {
|
442
|
2981 XtAppWarningMsg(the_app_con, "weirdColormap", "cvtStringToPixel",
|
428
|
2982 "XtToolkitWarning",
|
442
|
2983 "The colormap passed to cvtStringToPixel doesn't match the one registered to the device.\n",
|
428
|
2984 NULL, 0);
|
|
2985 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor);
|
|
2986 } else {
|
|
2987 status = XParseColor (dpy, colormap, (char*)str, &screenColor);
|
|
2988 if (status) {
|
|
2989 status = allocate_nearest_color (dpy, colormap, visual, &screenColor);
|
|
2990 }
|
|
2991 }
|
|
2992 } else {
|
|
2993 /* We haven't set up this device totally yet, so just punt */
|
|
2994 status = XAllocNamedColor(dpy, colormap, (char*)str, &screenColor, &exactColor);
|
|
2995 }
|
|
2996 if (status == 0) {
|
|
2997 params[0] = str;
|
|
2998 /* Server returns a specific error code but Xlib discards it. Ugh */
|
|
2999 if (XLookupColor(DisplayOfScreen(screen), colormap, (char*) str,
|
|
3000 &exactColor, &screenColor)) {
|
|
3001 XtAppWarningMsg(the_app_con, "noColormap", "cvtStringToPixel",
|
|
3002 "XtToolkitError",
|
|
3003 "Cannot allocate colormap entry for \"%s\"",
|
|
3004 params, &num_params);
|
|
3005
|
|
3006 } else {
|
|
3007 XtAppWarningMsg(the_app_con, "badValue", "cvtStringToPixel",
|
|
3008 "XtToolkitError",
|
|
3009 "Color name \"%s\" is not defined", params, &num_params);
|
|
3010 }
|
|
3011
|
|
3012 *closure_ret = False;
|
|
3013 return False;
|
|
3014 } else {
|
|
3015 *closure_ret = (char*)True;
|
|
3016 done(Pixel, screenColor.pixel);
|
|
3017 }
|
|
3018 }
|
|
3019
|
|
3020 /* ARGSUSED */
|
|
3021 static void EmacsFreePixel (
|
|
3022 XtAppContext app,
|
|
3023 XrmValuePtr toVal,
|
|
3024 XtPointer closure,
|
|
3025 XrmValuePtr args,
|
|
3026 Cardinal *num_args)
|
|
3027 {
|
|
3028 if (*num_args != 2) {
|
|
3029 XtAppWarningMsg(app, "wrongParameters","freePixel","XtToolkitError",
|
|
3030 "Freeing a pixel requires screen and colormap arguments",
|
|
3031 (String *)NULL, (Cardinal *)NULL);
|
|
3032 return;
|
|
3033 }
|
|
3034
|
|
3035 if (closure) {
|
|
3036 Screen *screen = *((Screen **) args[0].addr);
|
|
3037 Colormap colormap = *((Colormap *) args[1].addr);
|
|
3038 XFreeColors(DisplayOfScreen(screen), colormap,
|
|
3039 (unsigned long*)toVal->addr, 1, (unsigned long)0);
|
|
3040 }
|
|
3041 }
|
|
3042
|
|
3043
|
|
3044 /************************************************************************/
|
442
|
3045 /* handle focus changes for native widgets */
|
|
3046 /************************************************************************/
|
|
3047 static void
|
|
3048 emacs_Xt_event_widget_focus_in (Widget w,
|
|
3049 XEvent *event,
|
2286
|
3050 String *UNUSED (params),
|
|
3051 Cardinal *UNUSED (num_params))
|
442
|
3052 {
|
853
|
3053 struct frame *f =
|
442
|
3054 x_any_widget_or_parent_to_frame (get_device_from_display (event->xany.display), w);
|
|
3055
|
|
3056 XtSetKeyboardFocus (FRAME_X_SHELL_WIDGET (f), w);
|
|
3057 }
|
|
3058
|
|
3059 static void
|
2286
|
3060 emacs_Xt_event_widget_focus_out (Widget UNUSED (w),
|
|
3061 XEvent *UNUSED (event),
|
|
3062 String *UNUSED (params),
|
|
3063 Cardinal *UNUSED (num_params))
|
442
|
3064 {
|
|
3065 }
|
|
3066
|
|
3067 static XtActionsRec widgetActionsList[] =
|
|
3068 {
|
|
3069 {"widget-focus-in", emacs_Xt_event_widget_focus_in },
|
|
3070 {"widget-focus-out", emacs_Xt_event_widget_focus_out },
|
|
3071 };
|
|
3072
|
|
3073 static void
|
|
3074 emacs_Xt_event_add_widget_actions (XtAppContext ctx)
|
|
3075 {
|
|
3076 XtAppAddActions (ctx, widgetActionsList, 2);
|
|
3077 }
|
|
3078
|
|
3079
|
|
3080 /************************************************************************/
|
428
|
3081 /* initialization */
|
|
3082 /************************************************************************/
|
|
3083
|
|
3084 void
|
|
3085 syms_of_event_Xt (void)
|
|
3086 {
|
563
|
3087 DEFSYMBOL (Qsans_modifiers);
|
|
3088 DEFSYMBOL (Qself_insert_command);
|
428
|
3089 }
|
|
3090
|
|
3091 void
|
|
3092 reinit_vars_of_event_Xt (void)
|
|
3093 {
|
1204
|
3094 Xt_event_stream = xnew_and_zero (struct event_stream);
|
428
|
3095 Xt_event_stream->event_pending_p = emacs_Xt_event_pending_p;
|
1204
|
3096 Xt_event_stream->force_event_pending_cb= emacs_Xt_force_event_pending;
|
428
|
3097 Xt_event_stream->next_event_cb = emacs_Xt_next_event;
|
|
3098 Xt_event_stream->handle_magic_event_cb = emacs_Xt_handle_magic_event;
|
788
|
3099 Xt_event_stream->format_magic_event_cb = emacs_Xt_format_magic_event;
|
|
3100 Xt_event_stream->compare_magic_event_cb= emacs_Xt_compare_magic_event;
|
|
3101 Xt_event_stream->hash_magic_event_cb = emacs_Xt_hash_magic_event;
|
428
|
3102 Xt_event_stream->add_timeout_cb = emacs_Xt_add_timeout;
|
|
3103 Xt_event_stream->remove_timeout_cb = emacs_Xt_remove_timeout;
|
|
3104 Xt_event_stream->select_console_cb = emacs_Xt_select_console;
|
|
3105 Xt_event_stream->unselect_console_cb = emacs_Xt_unselect_console;
|
|
3106 Xt_event_stream->select_process_cb = emacs_Xt_select_process;
|
|
3107 Xt_event_stream->unselect_process_cb = emacs_Xt_unselect_process;
|
1204
|
3108 Xt_event_stream->drain_queue_cb = emacs_Xt_drain_queue;
|
853
|
3109 Xt_event_stream->create_io_streams_cb = emacs_Xt_create_io_streams;
|
|
3110 Xt_event_stream->delete_io_streams_cb = emacs_Xt_delete_io_streams;
|
442
|
3111 Xt_event_stream->current_event_timestamp_cb =
|
|
3112 emacs_Xt_current_event_timestamp;
|
428
|
3113
|
|
3114 the_Xt_timeout_blocktype = Blocktype_new (struct Xt_timeout_blocktype);
|
|
3115
|
|
3116 last_quit_check_signal_tick_count = 0;
|
|
3117
|
|
3118 /* this function only makes safe calls */
|
|
3119 init_what_input_once ();
|
|
3120 }
|
|
3121
|
|
3122 void
|
|
3123 vars_of_event_Xt (void)
|
|
3124 {
|
|
3125 DEFVAR_BOOL ("x-allow-sendevents", &x_allow_sendevents /*
|
|
3126 *Non-nil means to allow synthetic events. Nil means they are ignored.
|
|
3127 Beware: allowing emacs to process SendEvents opens a big security hole.
|
|
3128 */ );
|
|
3129 x_allow_sendevents = 0;
|
|
3130
|
|
3131 #ifdef DEBUG_XEMACS
|
442
|
3132 DEFVAR_INT ("debug-x-events", &debug_x_events /*
|
428
|
3133 If non-zero, display debug information about X events that XEmacs sees.
|
|
3134 Information is displayed on stderr. Currently defined values are:
|
|
3135
|
|
3136 1 == non-verbose output
|
|
3137 2 == verbose output
|
|
3138 */ );
|
442
|
3139 debug_x_events = 0;
|
428
|
3140 #endif
|
|
3141 }
|
|
3142
|
|
3143 /* This mess is a hack that patches the shell widget to treat visual inheritance
|
|
3144 the same as colormap and depth inheritance */
|
|
3145
|
|
3146 static XtInitProc orig_shell_init_proc;
|
|
3147
|
2956
|
3148 static void ShellVisualPatch(Widget wanted, Widget new_,
|
428
|
3149 ArgList args, Cardinal *num_args)
|
|
3150 {
|
|
3151 Widget p;
|
2956
|
3152 ShellWidget w = (ShellWidget) new_;
|
428
|
3153
|
|
3154 /* first, call the original setup */
|
2956
|
3155 (*orig_shell_init_proc)(wanted, new_, args, num_args);
|
428
|
3156
|
|
3157 /* if the visual isn't explicitly set, grab it from the nearest shell ancestor */
|
|
3158 if (w->shell.visual == CopyFromParent) {
|
|
3159 p = XtParent(w);
|
|
3160 while (p && !XtIsShell(p)) p = XtParent(p);
|
|
3161 if (p) w->shell.visual = ((ShellWidget)p)->shell.visual;
|
|
3162 }
|
|
3163 }
|
|
3164
|
|
3165 void
|
|
3166 init_event_Xt_late (void) /* called when already initialized */
|
|
3167 {
|
|
3168 timeout_id_tick = 1;
|
|
3169 pending_timeouts = 0;
|
|
3170 completed_timeouts = 0;
|
|
3171
|
|
3172 event_stream = Xt_event_stream;
|
|
3173
|
|
3174 XtToolkitInitialize ();
|
|
3175 Xt_app_con = XtCreateApplicationContext ();
|
|
3176 XtAppSetFallbackResources (Xt_app_con, (String *) x_fallback_resources);
|
|
3177
|
442
|
3178 /* In select-x.c */
|
428
|
3179 x_selection_timeout = (XtAppGetSelectionTimeout (Xt_app_con) / 1000);
|
|
3180 XSetErrorHandler (x_error_handler);
|
|
3181 XSetIOErrorHandler (x_IO_error_handler);
|
|
3182
|
442
|
3183 #ifndef WIN32_NATIVE
|
428
|
3184 XtAppAddInput (Xt_app_con, signal_event_pipe[0],
|
|
3185 (XtPointer) (XtInputReadMask /* | XtInputExceptMask */),
|
|
3186 Xt_what_callback, 0);
|
|
3187 #endif
|
|
3188
|
|
3189 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRPixel,
|
|
3190 EmacsXtCvtStringToPixel,
|
|
3191 (XtConvertArgList) colorConvertArgs,
|
|
3192 2, XtCacheByDisplay, EmacsFreePixel);
|
|
3193
|
|
3194 #ifdef XIM_XLIB
|
|
3195 XtAppSetTypeConverter (Xt_app_con, XtRString, XtRXimStyles,
|
|
3196 EmacsXtCvtStringToXIMStyles,
|
|
3197 NULL, 0,
|
|
3198 XtCacheByDisplay, EmacsFreeXIMStyles);
|
|
3199 #endif /* XIM_XLIB */
|
442
|
3200 /* Add extra actions to native widgets to handle focus and friends. */
|
|
3201 emacs_Xt_event_add_widget_actions (Xt_app_con);
|
428
|
3202
|
|
3203 /* insert the visual inheritance patch/hack described above */
|
|
3204 orig_shell_init_proc = shellClassRec.core_class.initialize;
|
|
3205 shellClassRec.core_class.initialize = ShellVisualPatch;
|
|
3206
|
|
3207 }
|