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