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