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