1
/* $Xorg: Keyboard.c,v 1.3 2000/08/17 19:53:28 cpqbld Exp $ */
2
/* $XdotOrg: xserver/xorg/hw/xnest/Keyboard.c,v 1.8 2005/07/14 03:36:44 kem Exp $ */
5
Copyright 1993 by Davor Matic
7
Permission to use, copy, modify, distribute, and sell this software
8
and its documentation for any purpose is hereby granted without fee,
9
provided that the above copyright notice appear in all copies and that
10
both that copyright notice and this permission notice appear in
11
supporting documentation. Davor Matic makes no representations about
12
the suitability of this software for any purpose. It is provided "as
13
is" without express or implied warranty.
16
/* $XFree86: xc/programs/Xserver/hw/xnest/Keyboard.c,v 1.9 2003/09/13 21:33:09 dawes Exp $ */
19
#ifdef HAVE_XNEST_CONFIG_H
20
#include <xnest-config.h>
24
#include <X11/Xproto.h>
25
#include <X11/keysym.h>
26
#include "screenint.h"
29
#include "scrnintstr.h"
41
#include <X11/extensions/XKB.h>
42
#include <X11/extensions/XKBsrv.h>
43
#include <X11/extensions/XKBconfig.h>
48
int * /* opcodeReturn */,
49
int * /* eventBaseReturn */,
50
int * /* errorBaseReturn */,
51
int * /* majorRtrn */,
55
extern XkbDescPtr XkbGetKeyboard(
57
unsigned int /* which */,
58
unsigned int /* deviceSpec */
61
extern Status XkbGetControls(
63
unsigned long /* which */,
67
#ifndef XKB_BASE_DIRECTORY
68
#define XKB_BASE_DIRECTORY "/usr/X11R6/lib/X11/xkb/"
70
#ifndef XKB_CONFIG_FILE
71
#define XKB_CONFIG_FILE "X0-config.keyboard"
73
#ifndef XKB_DFLT_RULES_FILE
74
#define XKB_DFLT_RULES_FILE __XKBDEFRULES__
76
#ifndef XKB_DFLT_KB_LAYOUT
77
#define XKB_DFLT_KB_LAYOUT "us"
79
#ifndef XKB_DFLT_KB_MODEL
80
#define XKB_DFLT_KB_MODEL "pc101"
82
#ifndef XKB_DFLT_KB_VARIANT
83
#define XKB_DFLT_KB_VARIANT NULL
85
#ifndef XKB_DFLT_KB_OPTIONS
86
#define XKB_DFLT_KB_OPTIONS NULL
91
DeviceIntPtr xnestKeyboardDevice = NULL;
94
xnestBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls)
96
XBell(xnestDisplay, volume);
100
xnestChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl)
103
unsigned long value_mask;
104
XKeyboardControl values;
107
value_mask = KBKeyClickPercent |
113
values.key_click_percent = ctrl->click;
114
values.bell_percent = ctrl->bell;
115
values.bell_pitch = ctrl->bell_pitch;
116
values.bell_duration = ctrl->bell_duration;
117
values.auto_repeat_mode = ctrl->autoRepeat ?
118
AutoRepeatModeOn : AutoRepeatModeOff;
120
XChangeKeyboardControl(xnestDisplay, value_mask, &values);
123
value_mask = KBKey | KBAutoRepeatMode;
124
At this point, we need to walk through the vector and compare it
125
to the current server vector. If there are differences, report them.
128
value_mask = KBLed | KBLedMode;
129
for (i = 1; i <= 32; i++) {
131
values.led_mode = (ctrl->leds & (1 << (i - 1))) ? LedModeOn : LedModeOff;
132
XChangeKeyboardControl(xnestDisplay, value_mask, &values);
138
xnestKeyboardProc(DeviceIntPtr pDev, int onoff)
140
XModifierKeymap *modifier_keymap;
143
int min_keycode, max_keycode;
145
CARD8 modmap[MAP_LENGTH];
147
XKeyboardState values;
152
modifier_keymap = XGetModifierMapping(xnestDisplay);
153
XDisplayKeycodes(xnestDisplay, &min_keycode, &max_keycode);
158
keymap64 = XGetKeyboardMapping(xnestDisplay,
160
max_keycode - min_keycode + 1,
162
len = (max_keycode - min_keycode + 1) * mapWidth;
163
keymap = (KeySym *)xalloc(len * sizeof(KeySym));
164
for(i = 0; i < len; ++i)
165
keymap[i] = keymap64[i];
169
keymap = XGetKeyboardMapping(xnestDisplay,
171
max_keycode - min_keycode + 1,
175
for (i = 0; i < MAP_LENGTH; i++)
177
for (j = 0; j < 8; j++)
178
for(i = 0; i < modifier_keymap->max_keypermod; i++) {
182
modifiermap[j * modifier_keymap->max_keypermod + i]))
183
modmap[keycode] |= 1<<j;
185
XFreeModifiermap(modifier_keymap);
187
keySyms.minKeyCode = min_keycode;
188
keySyms.maxKeyCode = max_keycode;
189
keySyms.mapWidth = mapWidth;
190
keySyms.map = keymap;
193
if (noXkbExtension) {
196
XGetKeyboardControl(xnestDisplay, &values);
198
memmove((char *) defaultKeyboardControl.autoRepeats,
199
(char *) values.auto_repeats, sizeof(values.auto_repeats));
201
InitKeyboardDeviceStruct(&pDev->public, &keySyms, modmap,
202
xnestBell, xnestChangeKeyboardControl);
206
XkbConfigRtrnRec config;
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
if ((names.keymap = strchr(XkbInitialMap, '/')) != NULL)
235
names.keymap = XkbInitialMap;
238
if ((file = fopen(XKB_BASE_DIRECTORY XKB_CONFIG_FILE, "r")) != NULL) {
239
if (XkbCFParse(file, XkbCFDflts, xkb, &config) == 0) {
240
ErrorF("Error parsing config file.\n");
244
if (config.rules_file)
245
rules = config.rules_file;
247
model = config.model;
249
layout = config.layout;
251
variants = config.variant;
253
options = config.options;
258
XkbSetRulesDflts(rules, model, layout, variants, options);
259
XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, modmap,
260
xnestBell, xnestChangeKeyboardControl);
261
XkbDDXChangeControls(pDev, xkb->ctrls, xkb->ctrls);
262
XkbFreeKeyboard(xkb, 0, False);
272
xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK;
273
for (i = 0; i < xnestNumScreens; i++)
274
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
277
xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK;
278
for (i = 0; i < xnestNumScreens; i++)
279
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
288
LegalModifier(unsigned int key, DevicePtr pDev)
294
xnestUpdateModifierState(unsigned int state)
296
DeviceIntPtr pDev = xnestKeyboardDevice;
297
KeyClassPtr keyc = pDev->key;
301
state = state & 0xff;
303
if (keyc->state == state)
306
for (i = 0, mask = 1; i < 8; i++, mask <<= 1) {
309
/* Modifier is down, but shouldn't be
311
if ((keyc->state & mask) && !(state & mask)) {
312
int count = keyc->modifierKeyCount[i];
314
for (key = 0; key < MAP_LENGTH; key++)
315
if (keyc->modifierMap[key] & mask) {
319
kptr = &keyc->down[key >> 3];
320
bit = 1 << (key & 7);
323
xnestQueueKeyEvent(KeyRelease, key);
330
/* Modifier shoud be down, but isn't
332
if (!(keyc->state & mask) && (state & mask))
333
for (key = 0; key < MAP_LENGTH; key++)
334
if (keyc->modifierMap[key] & mask) {
335
xnestQueueKeyEvent(KeyPress, key);