comparison src/xterm.c @ 1436:e7c5faab6571

* xterm.c (compose_status): New variable. (XTread_socket): Pass it by reference to XLookupString. * xterm.c: Clean up some of the caps lock handling: (x_shift_lock_mask): New variable. (x_find_modifier_mappings): Set it, based on the modifier mappings. (x_convert_modifiers): Use x_shift_lock_mask, instead of assuming that the lock bit always means to shift the character. (XTread_socket): When handling KeyPress events, don't pass an XComposeStatus structure along to XLookupString. When handling MappingNotify events, call XRefreshKeyboardMapping for both MappingModifier and MappingKeyboard events, not just the latter.
author Jim Blandy <jimb@redhat.com>
date Mon, 19 Oct 1992 18:31:34 +0000
parents 517c3893ec5b
children a7f8a1fe258e
comparison
equal deleted inserted replaced
1435:4fef92b213f6 1436:e7c5faab6571
1429 unsigned int x_mouse_grabbed; 1429 unsigned int x_mouse_grabbed;
1430 1430
1431 /* Which modifier keys are on which modifier bits? 1431 /* Which modifier keys are on which modifier bits?
1432 1432
1433 With each keystroke, X returns eight bits indicating which modifier 1433 With each keystroke, X returns eight bits indicating which modifier
1434 keys were held down when the key was pressed. The low three bits 1434 keys were held down when the key was pressed. The interpretation
1435 indicate the state of the shift, shift lock, caps lock, and control 1435 of the top five modifier bits depends on what keys are attached
1436 keys; their interpretation is fixed. However, the interpretation
1437 of the other five modifier bits depends on what keys are attached
1438 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5 1436 to them. If the Meta_L and Meta_R keysyms are on mod5, then mod5
1439 is the meta bit. 1437 is the meta bit.
1440 1438
1441 x_meta_mod_mask is a mask containing the bits used for the meta key. 1439 x_meta_mod_mask is a mask containing the bits used for the meta key.
1442 It may have more than one bit set, if more than one modifier bit 1440 It may have more than one bit set, if more than one modifier bit
1443 has meta keys on it. Basically, if EVENT is a KeyPress event, 1441 has meta keys on it. Basically, if EVENT is a KeyPress event,
1444 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0. */ 1442 the meta key is pressed if (EVENT.state & x_meta_mod_mask) != 0.
1445 static int x_meta_mod_mask; 1443
1444 x_shift_lock_mask is LockMask if the XK_Shift_Lock keysym is on the
1445 lock modifier bit, or zero otherwise. Non-alphabetic keys should
1446 only be affected by the lock modifier bit if XK_Shift_Lock is in
1447 use; XK_Caps_Lock should only affect alphabetic keys. With this
1448 arrangement, the lock modifier should shift the character if
1449 (EVENT.state & x_shift_lock_mask) != 0. */
1450 static int x_meta_mod_mask, x_shift_lock_mask;
1446 1451
1447 /* Initialize mode_switch_bit and modifier_meaning. */ 1452 /* Initialize mode_switch_bit and modifier_meaning. */
1448 static void 1453 static void
1449 x_find_modifier_meanings () 1454 x_find_modifier_meanings ()
1450 { 1455 {
1453 int syms_per_code; 1458 int syms_per_code;
1454 XModifierKeymap *mods; 1459 XModifierKeymap *mods;
1455 int alt_mod_mask = 0; 1460 int alt_mod_mask = 0;
1456 1461
1457 x_meta_mod_mask = 0; 1462 x_meta_mod_mask = 0;
1463 x_shift_lock_mask = 0;
1458 1464
1459 XDisplayKeycodes (x_current_display, &min_code, &max_code); 1465 XDisplayKeycodes (x_current_display, &min_code, &max_code);
1460 syms = XGetKeyboardMapping (x_current_display, 1466 syms = XGetKeyboardMapping (x_current_display,
1461 min_code, max_code - min_code + 1, 1467 min_code, max_code - min_code + 1,
1462 &syms_per_code); 1468 &syms_per_code);
1463 mods = XGetModifierMapping (x_current_display); 1469 mods = XGetModifierMapping (x_current_display);
1464 1470
1465 /* If CapsLock is on the lock modifier, then only letters should be 1471 /* Scan the modifier table to see which modifier bits the Meta and
1466 affected; since XLookupString takes care of this for us, the lock 1472 Alt keysyms are on. */
1467 modifier shouldn't set shift_modifier. However, if ShiftLock is
1468 on the lock modifier, then lock should mean shift. */
1469 { 1473 {
1470 int row, col; /* The row and column in the modifier table. */ 1474 int row, col; /* The row and column in the modifier table. */
1471 1475
1472 for (row = 3; row < 8; row++) 1476 for (row = 3; row < 8; row++)
1473 for (col = 0; col < mods->max_keypermod; col++) 1477 for (col = 0; col < mods->max_keypermod; col++)
1492 1496
1493 case XK_Alt_L: 1497 case XK_Alt_L:
1494 case XK_Alt_R: 1498 case XK_Alt_R:
1495 alt_mod_mask |= (1 << row); 1499 alt_mod_mask |= (1 << row);
1496 break; 1500 break;
1501
1502 case XK_Shift_Lock:
1503 /* Ignore this if it's not on the lock modifier. */
1504 if ((1 << row) == LockMask)
1505 x_shift_lock_mask = LockMask;
1506 break;
1497 } 1507 }
1498 } 1508 }
1499 } 1509 }
1500 } 1510 }
1501 } 1511 }
1514 1524
1515 static Lisp_Object 1525 static Lisp_Object
1516 x_convert_modifiers (state) 1526 x_convert_modifiers (state)
1517 unsigned int state; 1527 unsigned int state;
1518 { 1528 {
1519 return ( ((state & (ShiftMask | LockMask)) ? shift_modifier : 0) 1529 return ( ((state & (ShiftMask | x_shift_lock_mask)) ? shift_modifier : 0)
1520 | ((state & ControlMask) ? ctrl_modifier : 0) 1530 | ((state & ControlMask) ? ctrl_modifier : 0)
1521 | ((state & x_meta_mod_mask) ? meta_modifier : 0)); 1531 | ((state & x_meta_mod_mask) ? meta_modifier : 0));
1522 } 1532 }
1523 1533
1524 extern struct frame *x_window_to_scrollbar (); 1534 extern struct frame *x_window_to_scrollbar ();
1525 extern Lisp_Object Vmouse_event; 1535 extern Lisp_Object Vmouse_event;
1526 1536
1743 1753
1744 /* Timestamp of enter window event. This is only used by XTread_socket, 1754 /* Timestamp of enter window event. This is only used by XTread_socket,
1745 but we have to put it out here, since static variables within functions 1755 but we have to put it out here, since static variables within functions
1746 sometimes don't work. */ 1756 sometimes don't work. */
1747 static Time enter_timestamp; 1757 static Time enter_timestamp;
1758
1759 /* This holds the state XLookupString needs to implement dead keys
1760 and other tricks known as "compose processing". _X Window System_
1761 says that a portable program can't use this, but Stephen Gildea assures
1762 me that letting the compiler initialize it to zeros will work okay.
1763
1764 This must be defined outside of XTread_socket, for the same reasons
1765 given for enter_timestamp, above. */
1766 static XComposeStatus compose_status;
1748 1767
1749 /* Communication with window managers. */ 1768 /* Communication with window managers. */
1750 Atom Xatom_wm_protocols; 1769 Atom Xatom_wm_protocols;
1751 1770
1752 /* Kinds of protocol things we may receive. */ 1771 /* Kinds of protocol things we may receive. */
2028 case KeyPress: 2047 case KeyPress:
2029 f = x_window_to_frame (event.xkey.window); 2048 f = x_window_to_frame (event.xkey.window);
2030 if (f != 0) 2049 if (f != 0)
2031 { 2050 {
2032 KeySym keysym; 2051 KeySym keysym;
2033 XComposeStatus status;
2034 char copy_buffer[80]; 2052 char copy_buffer[80];
2035 int modifiers = event.xkey.state; 2053 int modifiers = event.xkey.state;
2036 2054
2037 /* Some keyboards generate different characters 2055 /* Some keyboards generate different characters
2038 depending on the state of the meta key, in an attempt 2056 depending on the state of the meta key, in an attempt
2039 to support non-English typists. It would be nice to 2057 to support non-English typists. It would be nice to
2040 keep this functionality somehow, but for now, we will 2058 keep this functionality somehow, but for now, we will
2041 just clear the meta-key flag to get the 'pure' character. */ 2059 just clear the meta-key flag to get the 'pure' character. */
2042 event.xkey.state &= ~Mod1Mask; 2060 event.xkey.state &= ~Mod1Mask;
2043 2061
2044 /* This will have to go some day... */ 2062 /* This will have to go some day... */
2045 nbytes = XLookupString (&event.xkey, 2063 nbytes =
2046 copy_buffer, 2064 XLookupString (&event.xkey, copy_buffer, 80, &keysym,
2047 80, 2065 &compose_status);
2048 &keysym,
2049 &status);
2050 2066
2051 /* Strip off the vendor-specific keysym bit, and take a shot 2067 /* Strip off the vendor-specific keysym bit, and take a shot
2052 at recognizing the codes. HP servers have extra keysyms 2068 at recognizing the codes. HP servers have extra keysyms
2053 that fit into the MiscFunctionKey category. */ 2069 that fit into the MiscFunctionKey category. */
2054 keysym &= ~(1<<28); 2070 keysym &= ~(1<<28);
2398 break; 2414 break;
2399 2415
2400 #endif /* ! defined (HAVE_X11) */ 2416 #endif /* ! defined (HAVE_X11) */
2401 2417
2402 case MappingNotify: 2418 case MappingNotify:
2403 if (event.xmapping.request == MappingKeyboard) 2419 /* Someone has changed the keyboard mapping - update the
2404 /* Someone has changed the keyboard mapping - flush the 2420 local cache. */
2405 local cache. */ 2421 switch (event.xmapping.request)
2406 XRefreshKeyboardMapping (&event.xmapping); 2422 {
2407 else if (event.xmapping.request == MappingModifier) 2423 case MappingModifier:
2408 x_find_modifier_meanings (); 2424 x_find_modifier_meanings ();
2425 /* This is meant to fall through. */
2426 case MappingKeyboard:
2427 XRefreshKeyboardMapping (&event.xmapping);
2428 }
2409 break; 2429 break;
2410 2430
2411 default: 2431 default:
2412 break; 2432 break;
2413 } 2433 }