Thu Jul 30 14:15:49 2020 UTC ()
Initialize ModMap dynamically using keymap data per each keyboard.

Now ScrollLock LED works properly.


(tsutsui)
diff -r1.3 -r1.4 xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c
diff -r1.1 -r1.2 xsrc/external/mit/xorg-server/dist/hw/sun/sunKeyMap.c

cvs diff -r1.3 -r1.4 xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c (expand / switch to unified diff)

--- xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c 2020/07/29 17:29:53 1.3
+++ xsrc/external/mit/xorg-server/dist/hw/sun/sunKbd.c 2020/07/30 14:15:49 1.4
@@ -48,47 +48,55 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. @@ -48,47 +48,55 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
48#include "mi.h" 48#include "mi.h"
49 49
50#include <X11/extensions/XKB.h> 50#include <X11/extensions/XKB.h>
51#include "xkbsrv.h" 51#include "xkbsrv.h"
52#include "xkbstr.h" 52#include "xkbstr.h"
53 53
54#ifdef __sun 54#ifdef __sun
55#define SUN_LED_MASK 0x0f 55#define SUN_LED_MASK 0x0f
56#else 56#else
57#define SUN_LED_MASK 0x07 57#define SUN_LED_MASK 0x07
58#endif 58#endif
59#define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */ 59#define MIN_KEYCODE 7 /* necessary to avoid the mouse buttons */
60#define MAX_KEYCODE 255 /* limited by the protocol */ 60#define MAX_KEYCODE 255 /* limited by the protocol */
 61#define NUM_KEYCODES (MAX_KEYCODE - MIN_KEYCODE + 1)
61#ifndef KB_SUN4 62#ifndef KB_SUN4
62#define KB_SUN4 4 63#define KB_SUN4 4
63#endif 64#endif
64 65
 66#define Meta_Mask Mod1Mask
 67#define Mode_switch_Mask Mod2Mask
 68#define Alt_Mask Mod3Mask
 69#define Num_Lock_Mask Mod4Mask
 70#define ScrollLockMask Mod5Mask
 71
65#define tvminus(tv, tv1, tv2) /* tv = tv1 - tv2 */ \ 72#define tvminus(tv, tv1, tv2) /* tv = tv1 - tv2 */ \
66 if ((tv1).tv_usec < (tv2).tv_usec) { \ 73 if ((tv1).tv_usec < (tv2).tv_usec) { \
67 (tv1).tv_usec += 1000000; \ 74 (tv1).tv_usec += 1000000; \
68 (tv1).tv_sec -= 1; \ 75 (tv1).tv_sec -= 1; \
69 } \ 76 } \
70 (tv).tv_usec = (tv1).tv_usec - (tv2).tv_usec; \ 77 (tv).tv_usec = (tv1).tv_usec - (tv2).tv_usec; \
71 (tv).tv_sec = (tv1).tv_sec - (tv2).tv_sec; 78 (tv).tv_sec = (tv1).tv_sec - (tv2).tv_sec;
72 79
73#define tvplus(tv, tv1, tv2) /* tv = tv1 + tv2 */ \ 80#define tvplus(tv, tv1, tv2) /* tv = tv1 + tv2 */ \
74 (tv).tv_sec = (tv1).tv_sec + (tv2).tv_sec; \ 81 (tv).tv_sec = (tv1).tv_sec + (tv2).tv_sec; \
75 (tv).tv_usec = (tv1).tv_usec + (tv2).tv_usec; \ 82 (tv).tv_usec = (tv1).tv_usec + (tv2).tv_usec; \
76 if ((tv).tv_usec > 1000000) { \ 83 if ((tv).tv_usec > 1000000) { \
77 (tv).tv_usec -= 1000000; \ 84 (tv).tv_usec -= 1000000; \
78 (tv).tv_sec += 1; \ 85 (tv).tv_sec += 1; \
79 } 86 }
80 87
81static void sunKbdHandlerNotify(int, int, void *); 88static void sunKbdHandlerNotify(int, int, void *);
 89static void sunInitModMap(const KeySymsRec *, CARD8 *);
82static void SwapLKeys(KeySymsRec *); 90static void SwapLKeys(KeySymsRec *);
83static void SetLights(KeybdCtrl *, int); 91static void SetLights(KeybdCtrl *, int);
84static KeyCode LookupKeyCode(KeySym, XkbDescPtr, KeySymsPtr); 92static KeyCode LookupKeyCode(KeySym, XkbDescPtr, KeySymsPtr);
85static void pseudoKey(DeviceIntPtr, Bool, KeyCode); 93static void pseudoKey(DeviceIntPtr, Bool, KeyCode);
86static void DoLEDs(DeviceIntPtr, KeybdCtrl *, sunKbdPrivPtr); 94static void DoLEDs(DeviceIntPtr, KeybdCtrl *, sunKbdPrivPtr);
87 95
88DeviceIntPtr sunKeyboardDevice = NULL; 96DeviceIntPtr sunKeyboardDevice = NULL;
89 97
90static void 98static void
91sunKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused) 99sunKbdHandlerNotify(int fd __unused, int ready __unused, void *data __unused)
92{ 100{
93} 101}
94 102
@@ -595,62 +603,55 @@ sunInitKbdNames(XkbRMLVOSet *rmlvo, sunK @@ -595,62 +603,55 @@ sunInitKbdNames(XkbRMLVOSet *rmlvo, sunK
595 *----------------------------------------------------------------------- 603 *-----------------------------------------------------------------------
596 * sunKbdProc -- 604 * sunKbdProc --
597 * Handle the initialization, etc. of a keyboard. 605 * Handle the initialization, etc. of a keyboard.
598 * 606 *
599 * Results: 607 * Results:
600 * None. 608 * None.
601 * 609 *
602 *----------------------------------------------------------------------- 610 *-----------------------------------------------------------------------
603 */ 611 */
604 612
605int 613int
606sunKbdProc(DeviceIntPtr device, int what) 614sunKbdProc(DeviceIntPtr device, int what)
607{ 615{
608 int i; 
609 DevicePtr pKeyboard = (DevicePtr) device; 616 DevicePtr pKeyboard = (DevicePtr) device;
610 sunKbdPrivPtr pPriv; 617 sunKbdPrivPtr pPriv;
611 KeybdCtrl* ctrl = &device->kbdfeed->ctrl; 618 KeybdCtrl* ctrl = &device->kbdfeed->ctrl;
612 XkbRMLVOSet rmlvo; 619 XkbRMLVOSet rmlvo;
 620 CARD8 workingModMap[MAP_LENGTH];
613 621
614 static CARD8 *workingModMap = NULL; 
615 static KeySymsRec *workingKeySyms; 622 static KeySymsRec *workingKeySyms;
616 623
617 switch (what) { 624 switch (what) {
618 case DEVICE_INIT: 625 case DEVICE_INIT:
619 if (pKeyboard != (DevicePtr)sunKeyboardDevice) { 626 if (pKeyboard != (DevicePtr)sunKeyboardDevice) {
620 ErrorF ("Cannot open non-system keyboard\n"); 627 ErrorF ("Cannot open non-system keyboard\n");
621 return (!Success); 628 return (!Success);
622 } 629 }
623 630
624 if (!workingKeySyms) { 631 if (!workingKeySyms) {
625 workingKeySyms = &sunKeySyms[sunKbdPriv.type]; 632 workingKeySyms = &sunKeySyms[sunKbdPriv.type];
626 633
627 if (sunKbdPriv.type == KB_SUN4 && sunSwapLkeys) 634 if (sunKbdPriv.type == KB_SUN4 && sunSwapLkeys)
628 SwapLKeys(workingKeySyms); 635 SwapLKeys(workingKeySyms);
629 636
630 if (workingKeySyms->minKeyCode < MIN_KEYCODE) { 637 if (workingKeySyms->minKeyCode < MIN_KEYCODE) {
631 workingKeySyms->minKeyCode += MIN_KEYCODE; 638 workingKeySyms->minKeyCode += MIN_KEYCODE;
632 workingKeySyms->maxKeyCode += MIN_KEYCODE; 639 workingKeySyms->maxKeyCode += MIN_KEYCODE;
633 } 640 }
634 if (workingKeySyms->maxKeyCode > MAX_KEYCODE) 641 if (workingKeySyms->maxKeyCode > MAX_KEYCODE)
635 workingKeySyms->maxKeyCode = MAX_KEYCODE; 642 workingKeySyms->maxKeyCode = MAX_KEYCODE;
636 } 
637 643
638 if (!workingModMap) { 644 sunInitModMap(workingKeySyms, workingModMap);
639 workingModMap = malloc(MAP_LENGTH); 
640 (void) memset(workingModMap, 0, MAP_LENGTH); 
641 for(i=0; sunModMaps[sunKbdPriv.type][i].key != 0; i++) 
642 workingModMap[sunModMaps[sunKbdPriv.type][i].key + MIN_KEYCODE] = 
643 sunModMaps[sunKbdPriv.type][i].modifiers; 
644 } 645 }
645 646
646 pKeyboard->devicePrivate = (void *)&sunKbdPriv; 647 pKeyboard->devicePrivate = (void *)&sunKbdPriv;
647 pKeyboard->on = FALSE; 648 pKeyboard->on = FALSE;
648 649
649 sunInitKbdNames(&rmlvo, pKeyboard->devicePrivate); 650 sunInitKbdNames(&rmlvo, pKeyboard->devicePrivate);
650#if 0 /* XXX needs more work for Xorg xkb */ 651#if 0 /* XXX needs more work for Xorg xkb */
651 InitKeyboardDeviceStruct(device, rmlvo, 652 InitKeyboardDeviceStruct(device, rmlvo,
652 sunBell, sunKbdCtrl); 653 sunBell, sunKbdCtrl);
653#else 654#else
654 InitKeyboardDeviceStruct(device, NULL, 655 InitKeyboardDeviceStruct(device, NULL,
655 sunBell, sunKbdCtrl); 656 sunBell, sunKbdCtrl);
656 XkbApplyMappingChange(device, workingKeySyms, 657 XkbApplyMappingChange(device, workingKeySyms,
@@ -686,26 +687,93 @@ sunKbdProc(DeviceIntPtr device, int what @@ -686,26 +687,93 @@ sunKbdProc(DeviceIntPtr device, int what
686 * Restore original keyboard directness and translation. 687 * Restore original keyboard directness and translation.
687 */ 688 */
688 if (sunChangeKbdTranslation(pPriv->fd,FALSE) == -1) 689 if (sunChangeKbdTranslation(pPriv->fd,FALSE) == -1)
689 FatalError("Can't reset keyboard translation\n"); 690 FatalError("Can't reset keyboard translation\n");
690 RemoveNotifyFd(pPriv->fd); 691 RemoveNotifyFd(pPriv->fd);
691 pKeyboard->on = FALSE; 692 pKeyboard->on = FALSE;
692 break; 693 break;
693 default: 694 default:
694 FatalError("Unknown keyboard operation\n"); 695 FatalError("Unknown keyboard operation\n");
695 } 696 }
696 return Success; 697 return Success;
697} 698}
698 699
 700/*-------------------------------------------------------------------------
 701 * sunInitModMap --
 702 * Initialize ModMap per specified KeyMap table.
 703 *
 704 * Results:
 705 * None.
 706 *
 707 * Side Effects:
 708 * None.
 709 *-----------------------------------------------------------------------*/
 710static void
 711sunInitModMap(
 712 const KeySymsRec *KeySyms, /* KeyMap data to set ModMap */
 713 CARD8 *ModMap /* ModMap to be initialized */
 714)
 715{
 716 KeySym *k;
 717 int i, min, max, width;
 718
 719 for (i = 0; i < MAP_LENGTH; i++)
 720 ModMap[i] = NoSymbol;
 721
 722 min = KeySyms->minKeyCode;
 723 max = KeySyms->maxKeyCode;
 724 width = KeySyms->mapWidth;
 725 for (i = min, k = KeySyms->map; i < max; i++, k += width) {
 726 switch (*k) {
 727
 728 case XK_Shift_L:
 729 case XK_Shift_R:
 730 ModMap[i] = ShiftMask;
 731 break;
 732
 733 case XK_Control_L:
 734 case XK_Control_R:
 735 ModMap[i] = ControlMask;
 736 break;
 737
 738 case XK_Caps_Lock:
 739 ModMap[i] = LockMask;
 740 break;
 741
 742 case XK_Alt_L:
 743 case XK_Alt_R:
 744 ModMap[i] = Alt_Mask;
 745 break;
 746
 747 case XK_Num_Lock:
 748 ModMap[i] = Num_Lock_Mask;
 749 break;
 750
 751 case XK_Scroll_Lock:
 752 ModMap[i] = ScrollLockMask;
 753 break;
 754
 755 case XK_Meta_L:
 756 case XK_Meta_R:
 757 ModMap[i] = Meta_Mask;
 758 break;
 759
 760 case SunXK_AltGraph:
 761 ModMap[i] = Mode_switch_Mask;
 762 break;
 763 }
 764 }
 765}
 766
699/*- 767/*-
700 *----------------------------------------------------------------------- 768 *-----------------------------------------------------------------------
701 * sunKbdGetEvents -- 769 * sunKbdGetEvents --
702 * Return the events waiting in the wings for the given keyboard. 770 * Return the events waiting in the wings for the given keyboard.
703 * 771 *
704 * Results: 772 * Results:
705 * A pointer to an array of Firm_events or (Firm_event *)0 if no events 773 * A pointer to an array of Firm_events or (Firm_event *)0 if no events
706 * The number of events contained in the array. 774 * The number of events contained in the array.
707 * A boolean as to whether more events might be available. 775 * A boolean as to whether more events might be available.
708 * 776 *
709 * Side Effects: 777 * Side Effects:
710 * None. 778 * None.
711 *----------------------------------------------------------------------- 779 *-----------------------------------------------------------------------

cvs diff -r1.1 -r1.2 xsrc/external/mit/xorg-server/dist/hw/sun/sunKeyMap.c (expand / switch to unified diff)

--- xsrc/external/mit/xorg-server/dist/hw/sun/sunKeyMap.c 2020/07/22 20:38:29 1.1
+++ xsrc/external/mit/xorg-server/dist/hw/sun/sunKeyMap.c 2020/07/30 14:15:49 1.2
@@ -101,41 +101,26 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. @@ -101,41 +101,26 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE.
101#define XK_R9 NoSymbol 101#define XK_R9 NoSymbol
102#define XK_L7 XK_Execute 102#define XK_L7 XK_Execute
103#define XK_L8 XK_Print 103#define XK_L8 XK_Print
104#define XK_R10 XK_Left 104#define XK_R10 XK_Left
105#define XK_R11 XK_Home 105#define XK_R11 XK_Home
106#define XK_R12 XK_Right 106#define XK_R12 XK_Right
107#define XK_L9 XK_Find 107#define XK_L9 XK_Find
108#define XK_L10 XK_Help 108#define XK_L10 XK_Help
109#define XK_R13 NoSymbol 109#define XK_R13 NoSymbol
110#define XK_R14 XK_Down 110#define XK_R14 XK_Down
111#define XK_R15 NoSymbol 111#define XK_R15 NoSymbol
112#endif 112#endif
113 113
114/* twm and Motif have hard-coded dependencies on Meta being Mod1 :-( */ 
115#if 0 
116/* This set has optimal characteristics for use in the Toolkit... */ 
117#define Meta_Mask Mod1Mask 
118#define Mode_switch_Mask Mod2Mask 
119#define Num_Lock_Mask Mod3Mask 
120#define Alt_Mask Mod4Mask 
121#else 
122/* but this set is compatible with what we shipped in R6. */ 
123#define Meta_Mask Mod1Mask 
124#define Mode_switch_Mask Mod2Mask 
125#define Alt_Mask Mod3Mask 
126#define Num_Lock_Mask Mod4Mask 
127#endif 
128 
129#ifdef US2 114#ifdef US2
130 115
131static KeySym US2Keymap[] = { 116static KeySym US2Keymap[] = {
132 XK_L1, NoSymbol, /* 0x1 */ 117 XK_L1, NoSymbol, /* 0x1 */
133 NoSymbol, NoSymbol, /* 0x2 */ 118 NoSymbol, NoSymbol, /* 0x2 */
134 XK_L2, NoSymbol, /* 0x3 */ 119 XK_L2, NoSymbol, /* 0x3 */
135 NoSymbol, NoSymbol, /* 0x4 */ 120 NoSymbol, NoSymbol, /* 0x4 */
136 XK_F1, NoSymbol, /* 0x5 */ 121 XK_F1, NoSymbol, /* 0x5 */
137 XK_F2, NoSymbol, /* 0x6 */ 122 XK_F2, NoSymbol, /* 0x6 */
138 NoSymbol, NoSymbol, /* 0x7 */ 123 NoSymbol, NoSymbol, /* 0x7 */
139 XK_F3, NoSymbol, /* 0x8 */ 124 XK_F3, NoSymbol, /* 0x8 */
140 NoSymbol, NoSymbol, /* 0x9 */ 125 NoSymbol, NoSymbol, /* 0x9 */
141 XK_F4, NoSymbol, /* 0xa */ 126 XK_F4, NoSymbol, /* 0xa */