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