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