diff options
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/Imakefile | 4 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/dmxinputinit.c | 31 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/lnx-keyboard.c | 5 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/lnx-keyboard.h | 4 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/lnx-ms.c | 3 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/lnx-ps2.c | 1 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/usb-keyboard.c | 487 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/usb-keyboard.h | 55 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/usb-mouse.c | 218 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/input/usb-mouse.h | 48 |
10 files changed, 845 insertions, 11 deletions
diff --git a/xc/programs/Xserver/hw/dmx/input/Imakefile b/xc/programs/Xserver/hw/dmx/input/Imakefile index 78af2ef42..8d4e0b428 100644 --- a/xc/programs/Xserver/hw/dmx/input/Imakefile +++ b/xc/programs/Xserver/hw/dmx/input/Imakefile @@ -3,8 +3,8 @@ XCOMM $XFree86$ #include <Server.tmpl> #include <lnxdoc.rules> -RAWSRCS = lnx-keyboard.c lnx-ms.c lnx-ps2.c -RAWOBJS = lnx-keyboard.o lnx-ms.o lnx-ps2.o +RAWSRCS = lnx-keyboard.c lnx-ms.c lnx-ps2.c usb-keyboard.c usb-mouse.c +RAWOBJS = lnx-keyboard.o lnx-ms.o lnx-ps2.o usb-keyboard.o usb-mouse.o DRVSRCS = dmxdummy.c dmxbackend.c dmxconsole.c dmxcommon.c DRVOBJS = dmxdummy.o dmxbackend.o dmxconsole.o dmxcommon.o diff --git a/xc/programs/Xserver/hw/dmx/input/dmxinputinit.c b/xc/programs/Xserver/hw/dmx/input/dmxinputinit.c index 46bfae525..3ca56afe5 100644 --- a/xc/programs/Xserver/hw/dmx/input/dmxinputinit.c +++ b/xc/programs/Xserver/hw/dmx/input/dmxinputinit.c @@ -48,6 +48,8 @@ #include "lnx-keyboard.h" #include "lnx-ms.h" #include "lnx-ps2.h" +#include "usb-keyboard.h" +#include "usb-mouse.h" #include "dmxsigio.h" #include "dmxarg.h" @@ -194,6 +196,35 @@ static DMXLocalInputInfoRec DMXLocalDevices[] = { ps2LinuxRead, ps2LinuxGetMap }, + { + "usb-kbd", + DMX_LOCAL_KEYBOARD, + kbdUSBCreatePrivate, + kbdUSBDestroyPrivate, + kbdUSBInit, + kbdUSBOn, + kbdUSBOff, + NULL, + NULL, NULL, NULL, + NULL, NULL, NULL, + kbdUSBRead, + kbdUSBGetMap, + kbdUSBCtrl, + }, + { + "usb-mou", + DMX_LOCAL_MOUSE, + mouUSBCreatePrivate, + mouUSBDestroyPrivate, + mouUSBInit, + mouUSBOn, + mouUSBOff, + NULL, + NULL, NULL, + NULL, + mouUSBRead, + mouUSBGetMap + }, { NULL } /* Must be last */ }; diff --git a/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.c b/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.c index 33583aee6..e7c56a058 100644 --- a/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.c +++ b/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.c @@ -84,7 +84,7 @@ */ /* - * Copyright 2001 Red Hat Inc., Durham, North Carolina. + * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina. * * All Rights Reserved. * @@ -117,7 +117,6 @@ */ #include "inputstr.h" -#include "input.h" #include "Xos.h" #include <sys/ioctl.h> #include <errno.h> @@ -125,8 +124,6 @@ #include <sys/vt.h> #include <sys/kd.h> #include <termios.h> -#include <unistd.h> - #include "atKeynames.h" #include "xf86Keymap.h" #include <linux/keyboard.h> diff --git a/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.h b/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.h index 7fcd7544e..99fccb042 100644 --- a/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.h +++ b/xc/programs/Xserver/hw/dmx/input/lnx-keyboard.h @@ -32,8 +32,8 @@ * */ -#ifndef _KBD_LINUX_H_ -#define _KBD_LINUX_H_ +#ifndef _LNX_KEYBOARD_H_ +#define _LNX_KEYBOARD_H_ extern pointer kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard); extern void kbdLinuxDestroyPrivate(pointer private); diff --git a/xc/programs/Xserver/hw/dmx/input/lnx-ms.c b/xc/programs/Xserver/hw/dmx/input/lnx-ms.c index de292ef0e..7031a656d 100644 --- a/xc/programs/Xserver/hw/dmx/input/lnx-ms.c +++ b/xc/programs/Xserver/hw/dmx/input/lnx-ms.c @@ -31,7 +31,7 @@ */ /* - * Copyright 2001 Red Hat Inc., Durham, North Carolina. + * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina. * * All Rights Reserved. * @@ -67,7 +67,6 @@ #include "Xos.h" #include <errno.h> #include <termios.h> -#include <unistd.h> /*****************************************************************************/ /* Define some macros to make it easier to move this file to another diff --git a/xc/programs/Xserver/hw/dmx/input/lnx-ps2.c b/xc/programs/Xserver/hw/dmx/input/lnx-ps2.c index 98d03b8c1..f8ead4c6e 100644 --- a/xc/programs/Xserver/hw/dmx/input/lnx-ps2.c +++ b/xc/programs/Xserver/hw/dmx/input/lnx-ps2.c @@ -64,7 +64,6 @@ #include "Xos.h" #include <errno.h> #include <termios.h> -#include <unistd.h> /*****************************************************************************/ /* Define some macros to make it easier to move this file to another diff --git a/xc/programs/Xserver/hw/dmx/input/usb-keyboard.c b/xc/programs/Xserver/hw/dmx/input/usb-keyboard.c new file mode 100644 index 000000000..bf2d98c59 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/input/usb-keyboard.c @@ -0,0 +1,487 @@ +/* $XFree86$ */ +/* Portions of this file were derived from the following files: + * + ********************************************************************** + * + * xfree86/common/xf86KbdLnx.c + * + * Linux version of keymapping setup. The kernel (since 0.99.14) has support + * for fully remapping the keyboard, but there are some differences between + * the Linux map and the SVR4 map (esp. in the extended keycodes). We also + * remove the restriction on what keycodes can be remapped. + * Orest Zborowski. + * + * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Thomas Roell not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Thomas Roell makes no representations + * about the suitability of this software for any purpose. It is provided + * "as is" without express or implied warranty. + * + * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ + +/* + * Copyright 2001,2002 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +#include "inputstr.h" +#include "Xos.h" +#include "atKeynames.h" +#include <errno.h> +#include <linux/input.h> +#include <X11/Xmu/SysUtil.h> + +#define NUM_STATE_ENTRIES (256/32) + +/*****************************************************************************/ +/* Define some macros to make it easier to move this file to another + * part of the Xserver tree. All calls to the dmx* layer are #defined + * here for the .c file. The .h file will also have to be edited. */ +#include "dmxinputinit.h" +#include "usb-keyboard.h" + +#define GETPRIV myPrivate *priv \ + = ((DMXLocalInputInfoPtr) \ + ((DMXInputInfo *) \ + (pDev->devicePrivate))->kbd)->private + +#define LOG0(f) dmxLog(dmxDebug,f) +#define LOG1(f,a) dmxLog(dmxDebug,f,a) +#define LOG2(f,a,b) dmxLog(dmxDebug,f,a,b) +#define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c) +#define FATAL0(f) dmxLog(dmxFatal,f) +#define FATAL1(f,a) dmxLog(dmxFatal,f,a) +#define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b) +#define ENQUEUEPROC dmxEnqueueProcPtr +#define CHECKPROC dmxCheckSpecialProcPtr + +/* End of interface definitions. */ +/*****************************************************************************/ + +typedef struct _myPrivate { + int fd; + + CARD32 kbdState[NUM_STATE_ENTRIES]; + CARD32 modState; + DeviceIntPtr pKeyboard; + + /* For bell */ + int pitch; + unsigned long duration; +} myPrivate; + +#define GLYPHS_PER_KEY 4 +#define NUM_KEYCODES 248 +#define MIN_KEYCODE 8 +#define MAX_KEYCODE (NUM_KEYCODES + MIN_KEYCODE - 1) + +static KeySym map[NUM_KEYCODES * GLYPHS_PER_KEY] = { +/* Table modified from xc/programs/Xserver/hw/xfree86/common/xf86Keymap.h */ + /* 0x00 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x01 */ XK_Escape, NoSymbol, NoSymbol, NoSymbol, + /* 0x02 */ XK_1, XK_exclam, NoSymbol, NoSymbol, + /* 0x03 */ XK_2, XK_at, NoSymbol, NoSymbol, + /* 0x04 */ XK_3, XK_numbersign, NoSymbol, NoSymbol, + /* 0x05 */ XK_4, XK_dollar, NoSymbol, NoSymbol, + /* 0x06 */ XK_5, XK_percent, NoSymbol, NoSymbol, + /* 0x07 */ XK_6, XK_asciicircum, NoSymbol, NoSymbol, + /* 0x08 */ XK_7, XK_ampersand, NoSymbol, NoSymbol, + /* 0x09 */ XK_8, XK_asterisk, NoSymbol, NoSymbol, + /* 0x0a */ XK_9, XK_parenleft, NoSymbol, NoSymbol, + /* 0x0b */ XK_0, XK_parenright, NoSymbol, NoSymbol, + /* 0x0c */ XK_minus, XK_underscore, NoSymbol, NoSymbol, + /* 0x0d */ XK_equal, XK_plus, NoSymbol, NoSymbol, + /* 0x0e */ XK_BackSpace, NoSymbol, NoSymbol, NoSymbol, + /* 0x0f */ XK_Tab, XK_ISO_Left_Tab,NoSymbol, NoSymbol, + /* 0x10 */ XK_Q, NoSymbol, NoSymbol, NoSymbol, + /* 0x11 */ XK_W, NoSymbol, NoSymbol, NoSymbol, + /* 0x12 */ XK_E, NoSymbol, NoSymbol, NoSymbol, + /* 0x13 */ XK_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x14 */ XK_T, NoSymbol, NoSymbol, NoSymbol, + /* 0x15 */ XK_Y, NoSymbol, NoSymbol, NoSymbol, + /* 0x16 */ XK_U, NoSymbol, NoSymbol, NoSymbol, + /* 0x17 */ XK_I, NoSymbol, NoSymbol, NoSymbol, + /* 0x18 */ XK_O, NoSymbol, NoSymbol, NoSymbol, + /* 0x19 */ XK_P, NoSymbol, NoSymbol, NoSymbol, + /* 0x1a */ XK_bracketleft, XK_braceleft, NoSymbol, NoSymbol, + /* 0x1b */ XK_bracketright,XK_braceright, NoSymbol, NoSymbol, + /* 0x1c */ XK_Return, NoSymbol, NoSymbol, NoSymbol, + /* 0x1d */ XK_Control_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x1e */ XK_A, NoSymbol, NoSymbol, NoSymbol, + /* 0x1f */ XK_S, NoSymbol, NoSymbol, NoSymbol, + /* 0x20 */ XK_D, NoSymbol, NoSymbol, NoSymbol, + /* 0x21 */ XK_F, NoSymbol, NoSymbol, NoSymbol, + /* 0x22 */ XK_G, NoSymbol, NoSymbol, NoSymbol, + /* 0x23 */ XK_H, NoSymbol, NoSymbol, NoSymbol, + /* 0x24 */ XK_J, NoSymbol, NoSymbol, NoSymbol, + /* 0x25 */ XK_K, NoSymbol, NoSymbol, NoSymbol, + /* 0x26 */ XK_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x27 */ XK_semicolon, XK_colon, NoSymbol, NoSymbol, + /* 0x28 */ XK_quoteright, XK_quotedbl, NoSymbol, NoSymbol, + /* 0x29 */ XK_quoteleft, XK_asciitilde, NoSymbol, NoSymbol, + /* 0x2a */ XK_Shift_L, NoSymbol, NoSymbol, NoSymbol, + /* 0x2b */ XK_backslash, XK_bar, NoSymbol, NoSymbol, + /* 0x2c */ XK_Z, NoSymbol, NoSymbol, NoSymbol, + /* 0x2d */ XK_X, NoSymbol, NoSymbol, NoSymbol, + /* 0x2e */ XK_C, NoSymbol, NoSymbol, NoSymbol, + /* 0x2f */ XK_V, NoSymbol, NoSymbol, NoSymbol, + /* 0x30 */ XK_B, NoSymbol, NoSymbol, NoSymbol, + /* 0x31 */ XK_N, NoSymbol, NoSymbol, NoSymbol, + /* 0x32 */ XK_M, NoSymbol, NoSymbol, NoSymbol, + /* 0x33 */ XK_comma, XK_less, NoSymbol, NoSymbol, + /* 0x34 */ XK_period, XK_greater, NoSymbol, NoSymbol, + /* 0x35 */ XK_slash, XK_question, NoSymbol, NoSymbol, + /* 0x36 */ XK_Shift_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x37 */ XK_KP_Multiply, NoSymbol, NoSymbol, NoSymbol, + /* 0x38 */ XK_Alt_L, XK_Meta_L, NoSymbol, NoSymbol, + /* 0x39 */ XK_space, NoSymbol, NoSymbol, NoSymbol, + /* 0x3a */ XK_Caps_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x3b */ XK_F1, NoSymbol, NoSymbol, NoSymbol, + /* 0x3c */ XK_F2, NoSymbol, NoSymbol, NoSymbol, + /* 0x3d */ XK_F3, NoSymbol, NoSymbol, NoSymbol, + /* 0x3e */ XK_F4, NoSymbol, NoSymbol, NoSymbol, + /* 0x3f */ XK_F5, NoSymbol, NoSymbol, NoSymbol, + /* 0x40 */ XK_F6, NoSymbol, NoSymbol, NoSymbol, + /* 0x41 */ XK_F7, NoSymbol, NoSymbol, NoSymbol, + /* 0x42 */ XK_F8, NoSymbol, NoSymbol, NoSymbol, + /* 0x43 */ XK_F9, NoSymbol, NoSymbol, NoSymbol, + /* 0x44 */ XK_F10, NoSymbol, NoSymbol, NoSymbol, + /* 0x45 */ XK_Num_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x46 */ XK_Scroll_Lock, NoSymbol, NoSymbol, NoSymbol, + /* 0x47 */ XK_KP_Home, XK_KP_7, NoSymbol, NoSymbol, + /* 0x48 */ XK_KP_Up, XK_KP_8, NoSymbol, NoSymbol, + /* 0x49 */ XK_KP_Prior, XK_KP_9, NoSymbol, NoSymbol, + /* 0x4a */ XK_KP_Subtract, NoSymbol, NoSymbol, NoSymbol, + /* 0x4b */ XK_KP_Left, XK_KP_4, NoSymbol, NoSymbol, + /* 0x4c */ XK_KP_Begin, XK_KP_5, NoSymbol, NoSymbol, + /* 0x4d */ XK_KP_Right, XK_KP_6, NoSymbol, NoSymbol, + /* 0x4e */ XK_KP_Add, NoSymbol, NoSymbol, NoSymbol, + /* 0x4f */ XK_KP_End, XK_KP_1, NoSymbol, NoSymbol, + /* 0x50 */ XK_KP_Down, XK_KP_2, NoSymbol, NoSymbol, + /* 0x51 */ XK_KP_Next, XK_KP_3, NoSymbol, NoSymbol, + /* 0x52 */ XK_KP_Insert, XK_KP_0, NoSymbol, NoSymbol, + /* 0x53 */ XK_KP_Delete, XK_KP_Decimal, NoSymbol, NoSymbol, + /* 0x54 */ XK_Sys_Req, NoSymbol, NoSymbol, NoSymbol, + /* 0x55 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x56 */ XK_less, XK_greater, NoSymbol, NoSymbol, + /* 0x57 */ XK_F11, NoSymbol, NoSymbol, NoSymbol, + /* 0x58 */ XK_F12, NoSymbol, NoSymbol, NoSymbol, + /* 0x59 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5a */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5d */ XK_Begin, NoSymbol, NoSymbol, NoSymbol, + /* 0x5e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x5f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x60 */ XK_KP_Enter, NoSymbol, NoSymbol, NoSymbol, + /* 0x61 */ XK_Control_R, NoSymbol, NoSymbol, NoSymbol, + /* 0x62 */ XK_KP_Divide, NoSymbol, NoSymbol, NoSymbol, + /* 0x63 */ XK_Print, NoSymbol, NoSymbol, NoSymbol, + /* 0x64 */ XK_Alt_R, XK_Meta_R, NoSymbol, NoSymbol, + /* 0x65 */ XK_Break, NoSymbol, NoSymbol, NoSymbol, + /* 0x66 */ XK_Home, NoSymbol, NoSymbol, NoSymbol, + /* 0x67 */ XK_Up, NoSymbol, NoSymbol, NoSymbol, + /* 0x68 */ XK_Prior, NoSymbol, NoSymbol, NoSymbol, + /* 0x69 */ XK_Left, NoSymbol, NoSymbol, NoSymbol, + /* 0x6a */ XK_Right, NoSymbol, NoSymbol, NoSymbol, + /* 0x6b */ XK_End, NoSymbol, NoSymbol, NoSymbol, + /* 0x6c */ XK_Down, NoSymbol, NoSymbol, NoSymbol, + /* 0x6d */ XK_Next, NoSymbol, NoSymbol, NoSymbol, + /* 0x6e */ XK_Insert, NoSymbol, NoSymbol, NoSymbol, + /* 0x6f */ XK_Delete, NoSymbol, NoSymbol, NoSymbol, + /* 0x70 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x71 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x72 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x73 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x74 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x75 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x76 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x77 */ XK_Pause, NoSymbol, NoSymbol, NoSymbol, + /* 0x78 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x79 */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7a */ XK_Menu, NoSymbol, NoSymbol, NoSymbol, + /* 0x7b */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7c */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7d */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7e */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, + /* 0x7f */ NoSymbol, NoSymbol, NoSymbol, NoSymbol, +}; + +static int kbdLinuxKeyDown(myPrivate *priv, xEvent *xE) +{ + CARD8 key = xE->u.u.detail; + CARD8 byte = key >> 5; + CARD32 bit = 1 << (key & 0x1f); + + if (byte > NUM_STATE_ENTRIES) return 0; + return priv->kbdState[byte] & bit; +} + +static void kbdLinuxKeyState(myPrivate *priv, xEvent *xE) +{ + CARD8 key = xE->u.u.detail; + CARD8 byte = key >> 5; + CARD32 bit = 1 << (key & 0x1f); + + if (byte > NUM_STATE_ENTRIES) return; + if (xE->u.u.type == KeyPress) priv->kbdState[byte] |= bit; + else priv->kbdState[byte] &= ~bit; +} + +pointer kbdUSBCreatePrivate(DeviceIntPtr pKeyboard) +{ + myPrivate *priv = xalloc(sizeof(*priv)); + memset(priv, 0, sizeof(*priv)); + priv->fd = -1; + priv->pKeyboard = pKeyboard; + return priv; +} + +void kbdUSBDestroyPrivate(pointer priv) +{ + if (priv) xfree(priv); +} + +void kbdUSBCtrl(DevicePtr pDev, KeybdCtrl *ctrl) +{ + GETPRIV; + +} + +Bool kbdUSBLegalModifier(unsigned int key, DevicePtr pDev) +{ + return TRUE; +} + +void kbdUSBInit(DevicePtr pDev) +{ + GETPRIV; + char name[64]; + int i, j; + char buf[256] = { 0, }; + int version; + unsigned char mask[EV_MAX/8 + 1]; + + if (priv->fd >=0) return; + +#define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8))) + + for (i = 0; i < 32; i++) { + XmuSnprintf(name, sizeof(name), "/dev/input/event%d", i); + if ((priv->fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) { + ioctl(priv->fd, EVIOCGVERSION, &version); + dmxLog(dmxInfo, "evdev version %d.%d.%d\n", + version >> 16, (version >> 8) & 0xff, version & 0xff); + ioctl(priv->fd, EVIOCGNAME(sizeof(buf)), buf); + dmxLog(dmxInfo, "%s: %s\n", name, buf); + ioctl(priv->fd, EVIOCGBIT(0, sizeof(mask)), mask); + for (j = 0; j < EV_MAX; j++) { + if (test_bit(j)) { + const char *type = "unknown"; + switch(j) { + case EV_KEY: type = "keys/buttons"; break; + case EV_REL: type = "relative"; break; + case EV_ABS: type = "absolute"; break; + case EV_MSC: type = "reserved"; break; + case EV_LED: type = "leds"; break; + case EV_SND: type = "sound"; break; + case EV_REP: type = "repeat"; break; + case EV_FF: type = "feedback"; break; + } + dmxLog(dmxInfo, "%s: Feature 0x%02x = %s\n", + name, j, type); + } + } + if (test_bit(EV_KEY) && test_bit(EV_LED)) break; + close(priv->fd); + priv->fd = -1; + } + } + if (priv->fd < 0) + FATAL1("kbdUSBInit: Cannot open mouse port (%s)\n", + strerror(errno)); +} + +static void kbdUSBConvert(myPrivate *priv, + unsigned int scanCode, + int value, + dmxEnqueueProcPtr enqueue, + dmxCheckSpecialProcPtr checkspecial, + pointer data) +{ + KeySymsPtr pKeySyms = &priv->pKeyboard->key->curKeySyms; + unsigned short state = priv->pKeyboard->key->state; + KeySym keySym = NoSymbol; + int keyCode; + xEvent xE; + int switching; + + /* Set up xEvent information */ + xE.u.keyButtonPointer.time = GetTimeInMillis(); + xE.u.u.type = value ? KeyPress : KeyRelease; + xE.u.u.detail = keyCode = (scanCode & 0xff) + MIN_KEYCODE; + + /* Handle repeats */ + + dmxLog(dmxDebug, "code = %d, min = %d, max = %d\n", + keyCode, pKeySyms->minKeyCode, pKeySyms->maxKeyCode); + if (keyCode >= pKeySyms->minKeyCode && keyCode <= pKeySyms->maxKeyCode) { + keySym = pKeySyms->map[(keyCode - pKeySyms->minKeyCode) + * pKeySyms->mapWidth]; + dmxLog(dmxDebug, "code = 0x%02x (%d), symbol = 0x%04x (%d)\n", + keyCode, keyCode, keySym, keySym); +#if 0 + switch (keySym) { + case XK_Num_Lock: + case XK_Scroll_Lock: + case XK_Shift_Lock: + case XK_Caps_Lock: + /* Ignore releases and all but first press */ + if (kbdLinuxModIgnore(priv, &xE, keySym)) return; + if (kbdLinuxKeyDown(priv, &xE)) xE.u.u.type = KeyRelease; + else xE.u.u.type = KeyPress; + break; + } +#endif + + /* If key is already down, ignore or autorepeat */ + if (xE.u.u.type == KeyPress && kbdLinuxKeyDown(priv, &xE)) { + KbdFeedbackClassRec *feed = priv->pKeyboard->kbdfeed; + + /* No auto-repeat? */ + if ((feed && !feed->ctrl.autoRepeat) + || priv->pKeyboard->key->modifierMap[keyCode] + || (feed + && !(feed->ctrl.autoRepeats[keyCode >> 3] + & (1 << (keyCode & 7))))) return; /* Ignore */ + + /* Do auto-repeat */ + xE.u.u.type = KeyRelease; + enqueue(&xE); + xE.u.u.type = KeyPress; + } + + /* If key is already up, ignore */ + if (xE.u.u.type == KeyRelease && !kbdLinuxKeyDown(priv, &xE)) return; + } + + switching = 0; + if (checkspecial) switching = checkspecial(data, &xE, keySym, state); + if (!switching) { + if (enqueue) enqueue(&xE); + kbdLinuxKeyState(priv, &xE); /* Update our state bitmap */ + } +} + +void kbdUSBRead(pointer p, + ENQUEUEPROC enqueue, + CHECKPROC checkspecial, + pointer data) +{ + myPrivate *priv = p; + struct { + struct timeval time; + unsigned short type; + unsigned short code; + unsigned int value; + } raw; + + while (read(priv->fd, &raw, sizeof(raw)) > 0) { + dmxLog(dmxDebug, "KBD: type = %d, code = 0x%02x, value = %d\n", + raw.type, raw.code, raw.value); + kbdUSBConvert(priv, raw.code, raw.value, enqueue, checkspecial, data); + } +} + +int kbdUSBOn(DevicePtr pDev) +{ + GETPRIV; + + if (priv->fd < 0) kbdUSBInit(pDev); + return priv->fd; +} + +void kbdUSBOff(DevicePtr pDev) +{ + GETPRIV; + + if (priv->fd >= 0) close(priv->fd); + priv->fd = -1; +} + + +pointer kbdUSBGetMap(DevicePtr pDev, KeySymsPtr pKeySyms, CARD8 *pModMap) +{ + KeySym *k; + int i; + + /* compute the modifier map */ + for (i = 0; i < MAP_LENGTH; i++) + pModMap[i] = NoSymbol; /* make sure it is restored */ + + dmxLog(dmxDebug, "map[0x66] = 0x%04x 0x%04x\n", + map[0x66*4], map[(0x66+8)*4]); + for (k = map, i = MIN_KEYCODE; i < NUM_KEYCODES + MIN_KEYCODE; i++, k += 4) + switch(*k) { + case XK_Shift_L: + case XK_Shift_R: pModMap[i] = ShiftMask; break; + case XK_Control_L: + case XK_Control_R: pModMap[i] = ControlMask; break; + case XK_Caps_Lock: pModMap[i] = LockMask; break; + case XK_Alt_L: + case XK_Alt_R: pModMap[i] = AltMask; break; + case XK_Num_Lock: pModMap[i] = NumLockMask; break; + case XK_Scroll_Lock: pModMap[i] = ScrollLockMask; break; + case XK_Kana_Lock: + case XK_Kana_Shift: pModMap[i] = KanaMask; break; + case XK_Mode_switch: pModMap[i] = AltLangMask; break; + } + + pKeySyms->map = map; + pKeySyms->mapWidth = GLYPHS_PER_KEY; + pKeySyms->minKeyCode = MIN_KEYCODE; + pKeySyms->maxKeyCode = MAX_KEYCODE; + return NULL; +} diff --git a/xc/programs/Xserver/hw/dmx/input/usb-keyboard.h b/xc/programs/Xserver/hw/dmx/input/usb-keyboard.h new file mode 100644 index 000000000..b5c49a5fe --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/input/usb-keyboard.h @@ -0,0 +1,55 @@ +/* $XFree86$ */ +/* + * Copyright 2002 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +#ifndef _USB_KEYBOARD_H_ +#define _USB_KEYBOARD_H_ + +extern pointer kbdUSBCreatePrivate(DeviceIntPtr pKeyboard); +extern void kbdUSBDestroyPrivate(pointer private); + +extern void kbdUSBInit(DevicePtr pDev); +extern int kbdUSBOn(DevicePtr pDev); +extern void kbdUSBOff(DevicePtr pDev); + +extern void kbdUSBRead(pointer priv, + dmxEnqueueProcPtr enqueue, + dmxCheckSpecialProcPtr checkspecial, + pointer data); + +extern pointer kbdUSBGetMap(DevicePtr pDev, + KeySymsPtr pKeySyms, CARD8 *pModMap); +extern void kbdUSBCtrl(DevicePtr pDev, KeybdCtrl *ctrl); + +extern Bool kbdUSBLegalModifier(unsigned int key, DevicePtr pDev); +#endif diff --git a/xc/programs/Xserver/hw/dmx/input/usb-mouse.c b/xc/programs/Xserver/hw/dmx/input/usb-mouse.c new file mode 100644 index 000000000..c0c413373 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/input/usb-mouse.c @@ -0,0 +1,218 @@ +/* $XFree86$ */ +/* + * Copyright 2002 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +#include "inputstr.h" +#include "Xos.h" +#include <errno.h> +#include <linux/input.h> +#include <X11/Xmu/SysUtil.h> + + +/*****************************************************************************/ +/* Define some macros to make it easier to move this file to another + * part of the Xserver tree. All calls to the dmx* layer are #defined + * here for the .c file. The .h file will also have to be edited. */ +#include "dmxinputinit.h" +#include "usb-mouse.h" + +#define GETPRIV myPrivate *priv \ + = ((DMXLocalInputInfoPtr) \ + ((DMXInputInfo *) \ + (pDev->devicePrivate))->mou)->private + +#define LOG0(f) dmxLog(dmxDebug,f) +#define LOG1(f,a) dmxLog(dmxDebug,f,a) +#define LOG2(f,a,b) dmxLog(dmxDebug,f,a,b) +#define LOG3(f,a,b,c) dmxLog(dmxDebug,f,a,b,c) +#define FATAL0(f) dmxLog(dmxFatal,f) +#define FATAL1(f,a) dmxLog(dmxFatal,f,a) +#define FATAL2(f,a,b) dmxLog(dmxFatal,f,a,b) +#define ENQUEUEPROC dmxEnqueueProcPtr +#define MOTIONPROC dmxMotionProcPtr + +/* End of interface definitions. */ +/*****************************************************************************/ + +typedef struct _myPrivate { + DeviceIntPtr pMouse; + int fd; +} myPrivate; + +void mouUSBRead(pointer p, ENQUEUEPROC enqueue, MOTIONPROC motion) +{ + myPrivate *priv = p; + xEvent xE; + struct { + struct timeval time; + unsigned short type; + unsigned short code; + unsigned int value; + } raw; + +#define PRESS(b) \ + do { \ + xE.u.keyButtonPointer.time = GetTimeInMillis(); \ + xE.u.u.type = ButtonPress; \ + xE.u.u.detail = priv->pMouse->button->map[b]; \ + enqueue(&xE); \ + } while (0) + +#define RELEASE(b) \ + do { \ + xE.u.keyButtonPointer.time = GetTimeInMillis(); \ + xE.u.u.type = ButtonRelease; \ + xE.u.u.detail = priv->pMouse->button->map[b]; \ + enqueue(&xE); \ + } while (0) + + while (read(priv->fd, &raw, sizeof(raw)) > 0) { + dmxLog(dmxDebug, "MOU: type = %d, code = 0x%02x, value = %d\n", + raw.type, raw.code, raw.value); + switch (raw.type) { + case EV_KEY: + /* raw.value = 1 for first, 2 for repeat */ + if (raw.code > BTN_MISC) { + if (raw.value) PRESS(raw.code & 0x0f); + else RELEASE(raw.code & 0x0f); + } else { + xE.u.keyButtonPointer.time = GetTimeInMillis(); + xE.u.u.type = raw.value ? KeyPress : KeyRelease; + xE.u.u.detail = (raw.code & 0xff) + 8; + enqueue(&xE); + } + break; + case EV_REL: + switch (raw.code) { + case REL_X: motion(-raw.value, 0, 1); break; + case REL_Y: motion(0, -raw.value, 1); break; + case REL_WHEEL: + if (raw.value > 0) { + PRESS(4); + RELEASE(4); + } else if (raw.value < 0) { + PRESS(5); + RELEASE(5); + } + } + break; + } + } +} + +void mouUSBInit(DevicePtr pDev) +{ + GETPRIV; + char name[64]; + int i, j; + char buf[256] = { 0, }; + int version; + unsigned char mask[EV_MAX/8 + 1]; + + if (priv->fd >=0) return; + +#define test_bit(bit) (mask[(bit)/8] & (1 << ((bit)%8))) + + for (i = 0; i < 32; i++) { + XmuSnprintf(name, sizeof(name), "/dev/input/event%d", i); + if ((priv->fd = open(name, O_RDWR | O_NONBLOCK, 0)) >= 0) { + ioctl(priv->fd, EVIOCGVERSION, &version); + dmxLog(dmxInfo, "evdev version %d.%d.%d\n", + version >> 16, (version >> 8) & 0xff, version & 0xff); + ioctl(priv->fd, EVIOCGNAME(sizeof(buf)), buf); + dmxLog(dmxInfo, "%s: %s\n", name, buf); + ioctl(priv->fd, EVIOCGBIT(0, sizeof(mask)), mask); + for (j = 0; j < EV_MAX; j++) { + if (test_bit(j)) { + const char *type = "unknown"; + switch(j) { + case EV_KEY: type = "keys/buttons"; break; + case EV_REL: type = "relative"; break; + case EV_ABS: type = "absolute"; break; + case EV_MSC: type = "reserved"; break; + case EV_LED: type = "leds"; break; + case EV_SND: type = "sound"; break; + case EV_REP: type = "repeat"; break; + case EV_FF: type = "feedback"; break; + } + dmxLog(dmxInfo, "%s: Feature 0x%02x = %s\n", + name, j, type); + } + } + if (test_bit(EV_REL) && test_bit(EV_KEY)) break; + close(priv->fd); + priv->fd = -1; + } + } + if (priv->fd < 0) + FATAL1("mouUSBInit: Cannot open mouse port (%s)\n", + strerror(errno)); +} + +int mouUSBOn(DevicePtr pDev) +{ + GETPRIV; + + if (priv->fd < 0) mouUSBInit(pDev); + return priv->fd; +} + +void mouUSBOff(DevicePtr pDev) +{ + GETPRIV; + + if (priv->fd >= 0) close(priv->fd); + priv->fd = -1; +} + +void mouUSBGetMap(DevicePtr pDev, unsigned char *map, int *nButtons) +{ + int i; + + if (nButtons) *nButtons = 3; + if (map) for (i = 0; i <= *nButtons; i++) map[i] = i; +} + +pointer mouUSBCreatePrivate(DeviceIntPtr pMouse) +{ + myPrivate *priv = xalloc(sizeof(*priv)); + memset(priv, 0, sizeof(*priv)); + priv->fd = -1; + priv->pMouse = pMouse; + return priv; +} + +void mouUSBDestroyPrivate(pointer priv) +{ + if (priv) xfree(priv); +} diff --git a/xc/programs/Xserver/hw/dmx/input/usb-mouse.h b/xc/programs/Xserver/hw/dmx/input/usb-mouse.h new file mode 100644 index 000000000..6e800c372 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/input/usb-mouse.h @@ -0,0 +1,48 @@ +/* $XFree86$ */ +/* + * Copyright 2002 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +#ifndef _USB_MOU_H_ +#define _USB_MOU_H_ + +extern pointer mouUSBCreatePrivate(DeviceIntPtr pMouse); +extern void mouUSBDestroyPrivate(pointer priv); +extern void mouUSBRead(pointer p, dmxEnqueueProcPtr enqueue, + dmxMotionProcPtr motion); +extern void mouUSBInit(DevicePtr pDev); +extern int mouUSBOn(DevicePtr pDev); +extern void mouUSBOff(DevicePtr pDev); +extern void mouUSBGetMap(DevicePtr pDev, unsigned char *map, int *nButtons); +extern void mouUSBCtrl(DevicePtr pDev, PtrCtrl *ctrl); + +#endif |