1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Io.c,v 3.56 2003/11/03 05:11:02 tsi Exp $ */
3
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
5
* Permission to use, copy, modify, distribute, and sell this software and its
6
* documentation for any purpose is hereby granted without fee, provided that
7
* the above copyright notice appear in all copies and that both that
8
* copyright notice and this permission notice appear in supporting
9
* documentation, and that the name of Thomas Roell not be used in
10
* advertising or publicity pertaining to distribution of the software without
11
* specific, written prior permission. Thomas Roell makes no representations
12
* about the suitability of this software for any purpose. It is provided
13
* "as is" without express or implied warranty.
15
* THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17
* EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
* PERFORMANCE OF THIS SOFTWARE.
25
* Copyright (c) 1992-2003 by The XFree86 Project, Inc.
27
* Permission is hereby granted, free of charge, to any person obtaining a
28
* copy of this software and associated documentation files (the "Software"),
29
* to deal in the Software without restriction, including without limitation
30
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
31
* and/or sell copies of the Software, and to permit persons to whom the
32
* Software is furnished to do so, subject to the following conditions:
34
* The above copyright notice and this permission notice shall be included in
35
* all copies or substantial portions of the Software.
37
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
40
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
41
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
42
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43
* OTHER DEALINGS IN THE SOFTWARE.
45
* Except as contained in this notice, the name of the copyright holder(s)
46
* and author(s) shall not be used in advertising or otherwise to promote
47
* the sale, use or other dealings in this Software without prior written
48
* authorization from the copyright holder(s) and author(s).
51
/* $XConsortium: xf86Io.c /main/27 1996/10/19 17:58:55 kaleb $ */
52
/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Io.c,v 1.5 2005/07/03 07:01:24 daniels Exp $ */
55
#ifdef HAVE_XORG_CONFIG_H
56
#include <xorg-config.h>
60
#include <X11/Xproto.h>
62
#include "scrnintstr.h"
69
#include "xf86_OSlib.h"
70
#include "mipointer.h"
73
#include "xf86Xinput.h"
74
#include <X11/extensions/XIproto.h>
79
#include <X11/extensions/XKB.h>
80
#include <X11/extensions/XKBstr.h>
81
#include <X11/extensions/XKBsrv.h>
84
unsigned int xf86InitialCaps = 0;
85
unsigned int xf86InitialNum = 0;
86
unsigned int xf86InitialScroll = 0;
88
#include "atKeynames.h"
92
* Ring the terminal/keyboard bell for an amount of time proportional to
97
xf86KbdBell(percent, pKeyboard, ctrl, unused)
98
int percent; /* Percentage of full volume */
99
DeviceIntPtr pKeyboard; /* Keyboard to ring */
103
xf86SoundKbdBell(percent, xf86Info.bell_pitch, xf86Info.bell_duration);
110
if (xf86Info.capsLock) leds |= XLED1;
111
if (xf86Info.numLock) leds |= XLED2;
112
if (xf86Info.scrollLock || xf86Info.modeSwitchLock) leds |= XLED3;
113
if (xf86Info.composeLock) leds |= XLED4;
114
xf86Info.leds = (xf86Info.leds & xf86Info.xleds) | (leds & ~xf86Info.xleds);
121
int leds, real_leds = 0;
123
#if defined (__sparc__) && defined(__linux__)
124
static int kbdSun = -1;
126
if ((xf86Info.xkbmodel && !strcmp(xf86Info.xkbmodel, "sun")) ||
127
(xf86Info.xkbrules && !strcmp(xf86Info.xkbrules, "sun")))
133
if (xf86Info.leds & 0x08) real_leds |= XLED1;
134
if (xf86Info.leds & 0x04) real_leds |= XLED3;
135
if (xf86Info.leds & 0x02) real_leds |= XLED4;
136
if (xf86Info.leds & 0x01) real_leds |= XLED2;
140
leds = xf86Info.leds;
143
leds = xf86Info.leds;
144
#endif /* defined (__sparc__) */
147
if (leds & XLED1) real_leds |= LED_CAP;
148
if (leds & XLED2) real_leds |= LED_NUM;
149
if (leds & XLED3) real_leds |= LED_SCR;
151
if (leds & XLED4) real_leds |= LED_COMP;
153
if (leds & XLED4) real_leds |= LED_SCR;
157
/* Pass through any additional LEDs, such as Kana LED on Sun Japanese kbd */
158
real_leds |= (leds & 0xFFFFFFF0);
160
xf86SetKbdLeds(real_leds);
166
* Alter some of the keyboard control parameters. All special protocol
167
* values are handled by dix (ProgChangeKeyboardControl)
171
xf86KbdCtrl (pKeyboard, ctrl)
172
DevicePtr pKeyboard; /* Keyboard to alter */
176
xf86Info.bell_pitch = ctrl->bell_pitch;
177
xf86Info.bell_duration = ctrl->bell_duration;
178
xf86Info.autoRepeat = ctrl->autoRepeat;
180
xf86Info.composeLock = (ctrl->leds & XCOMP) ? TRUE : FALSE;
182
leds = (ctrl->leds & ~(XCAPS | XNUM | XSCR));
184
if (noXkbExtension) {
186
xf86Info.leds = (leds & xf86Info.xleds)|(xf86Info.leds & ~xf86Info.xleds);
189
xf86Info.leds = leds;
198
* Reinitialize the keyboard. Only set Lockkeys according to ours leds.
199
* Depress all other keys.
209
DeviceIntPtr pKeyboard = xf86Info.pKeyboard;
210
KeyClassRec *keyc = xf86Info.pKeyboard->key;
211
KeySym *map = keyc->curKeySyms.map;
213
kevent.u.keyButtonPointer.time = GetTimeInMillis();
214
kevent.u.keyButtonPointer.rootX = 0;
215
kevent.u.keyButtonPointer.rootY = 0;
218
* Hmm... here is the biggest hack of every time !
219
* It may be possible that a switch-vt procedure has finished BEFORE
220
* you released all keys neccessary to do this. That peculiar behavior
221
* can fool the X-server pretty much, cause it assumes that some keys
222
* were not released. TWM may stuck alsmost completly....
223
* OK, what we are doing here is after returning from the vt-switch
224
* exeplicitely unrelease all keyboard keys before the input-devices
227
for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
228
i < keyc->curKeySyms.maxKeyCode;
229
i++, map += keyc->curKeySyms.mapWidth)
233
/* Don't release the lock keys */
241
kevent.u.u.detail = i;
242
kevent.u.u.type = KeyRelease;
243
(* pKeyboard->public.processInputProc)(&kevent, pKeyboard, 1);
247
xf86Info.scanPrefix = 0;
252
* we must deal here with the fact, that on some cases the numlock or
253
* capslock key are enabled BEFORE the server is started up. So look
254
* here at the state on the according LEDS to determine whether a
255
* lock-key is already set.
258
xf86Info.capsLock = FALSE;
259
xf86Info.numLock = FALSE;
260
xf86Info.scrollLock = FALSE;
261
xf86Info.modeSwitchLock = FALSE;
262
xf86Info.composeLock = FALSE;
265
#ifdef INHERIT_LOCK_STATE
266
leds = xf86Info.leds;
268
for (i = keyc->curKeySyms.minKeyCode, map = keyc->curKeySyms.map;
269
i < keyc->curKeySyms.maxKeyCode;
270
i++, map += keyc->curKeySyms.mapWidth)
279
xf86Info.capsLock = TRUE;
287
xf86Info.numLock = TRUE;
295
xf86InitialScroll = i;
296
xf86Info.scrollLock = TRUE;
300
#endif /* INHERIT_LOCK_STATE */
301
xf86SetKbdLeds(leds);
305
if (xf86Info.kbdDelay <= 375) rad = 0x00;
306
else if (xf86Info.kbdDelay <= 625) rad = 0x20;
307
else if (xf86Info.kbdDelay <= 875) rad = 0x40;
310
if (xf86Info.kbdRate <= 2) rad |= 0x1F;
311
else if (xf86Info.kbdRate >= 30) rad |= 0x00;
312
else rad |= ((58 / xf86Info.kbdRate) - 2);
314
xf86SetKbdRepeat(rad);
320
* Handle the initialization, etc. of a keyboard.
324
xf86KbdProc (pKeyboard, what)
325
DeviceIntPtr pKeyboard; /* Keyboard to manipulate */
326
int what; /* What to do to it */
329
CARD8 modMap[MAP_LENGTH];
336
* First open and find the current state of the keyboard.
341
xf86KbdGetMapping(&keySyms, modMap);
345
defaultKeyboardControl.leds = xf86GetKbdLeds();
347
defaultKeyboardControl.leds = 0;
351
* Perform final initialization of the system private keyboard
352
* structure and fill in various slots in the device record
353
* itself which couldn't be filled in before.
356
pKeyboard->public.on = FALSE;
359
if (noXkbExtension) {
361
InitKeyboardDeviceStruct((DevicePtr)xf86Info.pKeyboard,
365
(KbdCtrlProcPtr)xf86KbdCtrl);
368
XkbComponentNamesRec names;
370
Bool foundTerminate = FALSE;
373
if ((xf86Info.xkbkeymap = strchr(XkbInitialMap, '/')) != NULL)
374
xf86Info.xkbkeymap++;
376
xf86Info.xkbkeymap = XkbInitialMap;
378
if (xf86Info.xkbkeymap) {
379
names.keymap = xf86Info.xkbkeymap;
380
names.keycodes = NULL;
383
names.symbols = NULL;
384
names.geometry = NULL;
387
names.keycodes = xf86Info.xkbkeycodes;
388
names.types = xf86Info.xkbtypes;
389
names.compat = xf86Info.xkbcompat;
390
names.symbols = xf86Info.xkbsymbols;
391
names.geometry = xf86Info.xkbgeometry;
393
if ((xf86Info.xkbkeymap || xf86Info.xkbcomponents_specified)
394
&& (xf86Info.xkbmodel == NULL || xf86Info.xkblayout == NULL)) {
395
xf86Info.xkbrules = NULL;
397
XkbSetRulesDflts(xf86Info.xkbrules, xf86Info.xkbmodel,
398
xf86Info.xkblayout, xf86Info.xkbvariant,
399
xf86Info.xkboptions);
401
XkbInitKeyboardDeviceStruct(pKeyboard,
406
(KbdCtrlProcPtr)xf86KbdCtrl);
408
/* Search keymap for Terminate action */
409
desc = pKeyboard->key->xkbInfo->desc;
410
for (keyc = desc->min_key_code; keyc <= desc->max_key_code; keyc++) {
412
for (i = 1; i <= XkbKeyNumActions(desc, keyc); i++) {
413
if (XkbKeyAction(desc, keyc, i)
414
&& XkbKeyAction(desc, keyc, i)->type == XkbSA_Terminate) {
415
foundTerminate = TRUE;
421
xf86Info.ActionKeyBindingsSet = foundTerminate;
423
xf86Msg(X_INFO, "Server_Terminate keybinding not found\n");
432
* Set the keyboard into "direct" mode and turn on
438
* Discard any pending input after a VT switch to prevent the server
439
* passing on parts of the VT switch sequence.
442
#if defined(WSCONS_SUPPORT)
443
if (xf86Info.consType != WSCONS) {
447
read(kbdFd, buf, 16);
449
#if defined(WSCONS_SUPPORT)
453
#if !defined(__UNIXOS2__) /* Under EMX, keyboard cannot be select()'ed */
455
AddEnabledDevice(kbdFd);
456
#endif /* __UNIXOS2__ */
458
pKeyboard->public.on = TRUE;
465
* Restore original keyboard directness and translation.
468
kbdFd = xf86KbdOff();
471
RemoveEnabledDevice(kbdFd);
473
pKeyboard->public.on = FALSE;
480
#if defined(DDXTIME) && !defined(QNX4)
482
* These are getting tossed in here until I can think of where
485
#define HALFMONTH ((unsigned long) 1<<31)
492
static CARD32 oldval = 0;
493
static CARD32 time = 0;
495
gettimeofday(&tp, 0);
496
val = (tp.tv_sec * 1000) + (tp.tv_usec / 1000);
506
#endif /* DDXTIME && !QNX4 */