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