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