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