3 Copyright 1993 by Davor Matic
5 Permission to use, copy, modify, distribute, and sell this software
6 and its documentation for any purpose is hereby granted without fee,
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in
9 supporting documentation. Davor Matic makes no representations about
10 the suitability of this software for any purpose. It is provided "as
11 is" without express or implied warranty.
16 #ifdef HAVE_XNEST_CONFIG_H
17 #include <xnest-config.h>
21 #include <X11/Xproto.h>
22 #include <X11/keysym.h>
23 #include "screenint.h"
26 #include "scrnintstr.h"
38 #include <X11/extensions/XKB.h>
40 #include <X11/extensions/XKBconfig.h>
45 int * /* opcodeReturn */,
46 int * /* eventBaseReturn */,
47 int * /* errorBaseReturn */,
48 int * /* majorRtrn */,
52 extern XkbDescPtr
XkbGetKeyboard(
54 unsigned int /* which */,
55 unsigned int /* deviceSpec */
58 extern Status
XkbGetControls(
60 unsigned long /* which */,
64 #ifndef XKB_BASE_DIRECTORY
65 #define XKB_BASE_DIRECTORY "/usr/X11R6/lib/X11/xkb/"
67 #ifndef XKB_CONFIG_FILE
68 #define XKB_CONFIG_FILE "X0-config.keyboard"
70 #ifndef XKB_DFLT_RULES_FILE
71 #define XKB_DFLT_RULES_FILE __XKBDEFRULES__
73 #ifndef XKB_DFLT_KB_LAYOUT
74 #define XKB_DFLT_KB_LAYOUT "us"
76 #ifndef XKB_DFLT_KB_MODEL
77 #define XKB_DFLT_KB_MODEL "pc101"
79 #ifndef XKB_DFLT_KB_VARIANT
80 #define XKB_DFLT_KB_VARIANT NULL
82 #ifndef XKB_DFLT_KB_OPTIONS
83 #define XKB_DFLT_KB_OPTIONS NULL
88 DeviceIntPtr xnestKeyboardDevice
= NULL
;
91 xnestBell(int volume
, DeviceIntPtr pDev
, pointer ctrl
, int cls
)
93 XBell(xnestDisplay
, volume
);
97 DDXRingBell(int volume
, int pitch
, int duration
)
99 XBell(xnestDisplay
, volume
);
103 xnestChangeKeyboardControl(DeviceIntPtr pDev
, KeybdCtrl
*ctrl
)
106 unsigned long value_mask
;
107 XKeyboardControl values
;
110 value_mask
= KBKeyClickPercent
|
116 values
.key_click_percent
= ctrl
->click
;
117 values
.bell_percent
= ctrl
->bell
;
118 values
.bell_pitch
= ctrl
->bell_pitch
;
119 values
.bell_duration
= ctrl
->bell_duration
;
120 values
.auto_repeat_mode
= ctrl
->autoRepeat
?
121 AutoRepeatModeOn
: AutoRepeatModeOff
;
123 XChangeKeyboardControl(xnestDisplay
, value_mask
, &values
);
126 value_mask = KBKey | KBAutoRepeatMode;
127 At this point, we need to walk through the vector and compare it
128 to the current server vector. If there are differences, report them.
131 value_mask
= KBLed
| KBLedMode
;
132 for (i
= 1; i
<= 32; i
++) {
134 values
.led_mode
= (ctrl
->leds
& (1 << (i
- 1))) ? LedModeOn
: LedModeOff
;
135 XChangeKeyboardControl(xnestDisplay
, value_mask
, &values
);
141 xnestKeyboardProc(DeviceIntPtr pDev
, int onoff
)
143 XModifierKeymap
*modifier_keymap
;
146 int min_keycode
, max_keycode
;
148 CARD8 modmap
[MAP_LENGTH
];
150 XKeyboardState values
;
155 modifier_keymap
= XGetModifierMapping(xnestDisplay
);
156 XDisplayKeycodes(xnestDisplay
, &min_keycode
, &max_keycode
);
161 keymap64
= XGetKeyboardMapping(xnestDisplay
,
163 max_keycode
- min_keycode
+ 1,
165 len
= (max_keycode
- min_keycode
+ 1) * mapWidth
;
166 keymap
= (KeySym
*)xalloc(len
* sizeof(KeySym
));
167 for(i
= 0; i
< len
; ++i
)
168 keymap
[i
] = keymap64
[i
];
172 keymap
= XGetKeyboardMapping(xnestDisplay
,
174 max_keycode
- min_keycode
+ 1,
178 for (i
= 0; i
< MAP_LENGTH
; i
++)
180 for (j
= 0; j
< 8; j
++)
181 for(i
= 0; i
< modifier_keymap
->max_keypermod
; i
++) {
185 modifiermap
[j
* modifier_keymap
->max_keypermod
+ i
]))
186 modmap
[keycode
] |= 1<<j
;
188 XFreeModifiermap(modifier_keymap
);
190 keySyms
.minKeyCode
= min_keycode
;
191 keySyms
.maxKeyCode
= max_keycode
;
192 keySyms
.mapWidth
= mapWidth
;
193 keySyms
.map
= keymap
;
196 if (noXkbExtension
) {
199 XGetKeyboardControl(xnestDisplay
, &values
);
201 memmove((char *) defaultKeyboardControl
.autoRepeats
,
202 (char *) values
.auto_repeats
, sizeof(values
.auto_repeats
));
204 InitKeyboardDeviceStruct(&pDev
->public, &keySyms
, modmap
,
205 xnestBell
, xnestChangeKeyboardControl
);
208 XkbComponentNamesRec names
;
209 char *rules
, *model
, *layout
, *variants
, *options
;
212 int op
, event
, error
, major
, minor
;
214 if (XkbQueryExtension(xnestDisplay
, &op
, &event
, &error
, &major
, &minor
) == 0) {
215 ErrorF("Unable to initialize XKEYBOARD extension.\n");
218 xkb
= XkbGetKeyboard(xnestDisplay
, XkbGBN_AllComponentsMask
, XkbUseCoreKbd
);
219 if (xkb
== NULL
|| xkb
->geom
== NULL
) {
220 ErrorF("Couldn't get keyboard.\n");
223 XkbGetControls(xnestDisplay
, XkbAllControlsMask
, xkb
);
225 memset(&names
, 0, sizeof(XkbComponentNamesRec
));
226 rules
= XKB_DFLT_RULES_FILE
;
227 model
= XKB_DFLT_KB_MODEL
;
228 layout
= XKB_DFLT_KB_LAYOUT
;
229 variants
= XKB_DFLT_KB_VARIANT
;
230 options
= XKB_DFLT_KB_OPTIONS
;
232 XkbSetRulesDflts(rules
, model
, layout
, variants
, options
);
233 XkbInitKeyboardDeviceStruct(pDev
, &names
, &keySyms
, modmap
,
234 xnestBell
, xnestChangeKeyboardControl
);
235 XkbDDXChangeControls(pDev
, xkb
->ctrls
, xkb
->ctrls
);
236 XkbFreeKeyboard(xkb
, 0, False
);
246 xnestEventMask
|= XNEST_KEYBOARD_EVENT_MASK
;
247 for (i
= 0; i
< xnestNumScreens
; i
++)
248 XSelectInput(xnestDisplay
, xnestDefaultWindows
[i
], xnestEventMask
);
251 xnestEventMask
&= ~XNEST_KEYBOARD_EVENT_MASK
;
252 for (i
= 0; i
< xnestNumScreens
; i
++)
253 XSelectInput(xnestDisplay
, xnestDefaultWindows
[i
], xnestEventMask
);
262 LegalModifier(unsigned int key
, DeviceIntPtr pDev
)
268 xnestUpdateModifierState(unsigned int state
)
270 DeviceIntPtr pDev
= xnestKeyboardDevice
;
271 KeyClassPtr keyc
= pDev
->key
;
275 state
= state
& 0xff;
277 if (keyc
->state
== state
)
280 for (i
= 0, mask
= 1; i
< 8; i
++, mask
<<= 1) {
283 /* Modifier is down, but shouldn't be
285 if ((keyc
->state
& mask
) && !(state
& mask
)) {
286 int count
= keyc
->modifierKeyCount
[i
];
288 for (key
= 0; key
< MAP_LENGTH
; key
++)
289 if (keyc
->modifierMap
[key
] & mask
) {
293 kptr
= &keyc
->down
[key
>> 3];
294 bit
= 1 << (key
& 7);
297 xnestQueueKeyEvent(KeyRelease
, key
);
304 /* Modifier shoud be down, but isn't
306 if (!(keyc
->state
& mask
) && (state
& mask
))
307 for (key
= 0; key
< MAP_LENGTH
; key
++)
308 if (keyc
->modifierMap
[key
] & mask
) {
309 xnestQueueKeyEvent(KeyPress
, key
);