dmx: Remove non-evdev hardware input drivers

Use evdev.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
This commit is contained in:
Adam Jackson 2017-01-19 17:30:39 -05:00
parent 6f531b0cdf
commit d740e1830a
10 changed files with 3 additions and 2078 deletions

View File

@ -2336,9 +2336,6 @@ if test "x$DMX" = xyes; then
dnl USB sources in DMX require <linux/input.h> dnl USB sources in DMX require <linux/input.h>
AC_CHECK_HEADER([linux/input.h], DMX_BUILD_USB="yes", AC_CHECK_HEADER([linux/input.h], DMX_BUILD_USB="yes",
DMX_BUILD_USB="no") DMX_BUILD_USB="no")
dnl Linux sources in DMX require <linux/keyboard.h>
AC_CHECK_HEADER([linux/keyboard.h], DMX_BUILD_LNX="yes",
DMX_BUILD_LNX="no")
AC_SUBST(XDMXCONFIG_DEP_CFLAGS) AC_SUBST(XDMXCONFIG_DEP_CFLAGS)
AC_SUBST(XDMXCONFIG_DEP_LIBS) AC_SUBST(XDMXCONFIG_DEP_LIBS)
PKG_CHECK_MODULES([DMXEXAMPLES_DEP], [$LIBDMX $LIBXEXT x11]) PKG_CHECK_MODULES([DMXEXAMPLES_DEP], [$LIBDMX $LIBXEXT x11])
@ -2355,7 +2352,6 @@ dnl Linux sources in DMX require <linux/keyboard.h>
AC_SUBST(X11EXAMPLES_DEP_LIBS) AC_SUBST(X11EXAMPLES_DEP_LIBS)
fi fi
AM_CONDITIONAL([DMX_BUILD_LNX], [test "x$DMX_BUILD_LNX" = xyes])
AM_CONDITIONAL([DMX_BUILD_USB], [test "x$DMX_BUILD_USB" = xyes]) AM_CONDITIONAL([DMX_BUILD_USB], [test "x$DMX_BUILD_USB" = xyes])
dnl kdrive DDX dnl kdrive DDX

View File

@ -1,14 +1,5 @@
noinst_LIBRARIES = libdmxinput.a noinst_LIBRARIES = libdmxinput.a
if DMX_BUILD_LNX
RAWSRCS = lnx-keyboard.c \
lnx-keyboard.h \
lnx-ms.c \
lnx-ms.h \
lnx-ps2.c \
lnx-ps2.h
endif
if DMX_BUILD_USB if DMX_BUILD_USB
USBSRCS = usb-keyboard.c \ USBSRCS = usb-keyboard.c \
usb-keyboard.h \ usb-keyboard.h \

View File

@ -55,9 +55,6 @@
#include "config/dmxconfig.h" #include "config/dmxconfig.h"
#include "dmxcursor.h" #include "dmxcursor.h"
#include "lnx-keyboard.h"
#include "lnx-ms.h"
#include "lnx-ps2.h"
#include "usb-keyboard.h" #include "usb-keyboard.h"
#include "usb-mouse.h" #include "usb-mouse.h"
#include "usb-other.h" #include "usb-other.h"
@ -133,31 +130,6 @@ static DMXLocalInputInfoRec DMXConsoleKbd = {
static DMXLocalInputInfoRec DMXLocalDevices[] = { static DMXLocalInputInfoRec DMXLocalDevices[] = {
/* Dummy drivers that can compile on any OS */ /* Dummy drivers that can compile on any OS */
#ifdef __linux__
/* Linux-specific drivers */
{
"kbd", DMX_LOCAL_KEYBOARD, DMX_LOCAL_TYPE_LOCAL, 1,
kbdLinuxCreatePrivate, kbdLinuxDestroyPrivate,
kbdLinuxInit, NULL, NULL, kbdLinuxGetInfo,
kbdLinuxOn, kbdLinuxOff, NULL,
kbdLinuxVTPreSwitch, kbdLinuxVTPostSwitch, kbdLinuxVTSwitch,
kbdLinuxRead, NULL, NULL, NULL,
NULL, kbdLinuxCtrl, kbdLinuxBell},
{
"ms", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
msLinuxCreatePrivate, msLinuxDestroyPrivate,
msLinuxInit, NULL, NULL, msLinuxGetInfo,
msLinuxOn, msLinuxOff, NULL,
msLinuxVTPreSwitch, msLinuxVTPostSwitch, NULL,
msLinuxRead},
{
"ps2", DMX_LOCAL_MOUSE, DMX_LOCAL_TYPE_LOCAL, 1,
ps2LinuxCreatePrivate, ps2LinuxDestroyPrivate,
ps2LinuxInit, NULL, NULL, ps2LinuxGetInfo,
ps2LinuxOn, ps2LinuxOff, NULL,
ps2LinuxVTPreSwitch, ps2LinuxVTPostSwitch, NULL,
ps2LinuxRead},
#endif
#ifdef __linux__ #ifdef __linux__
/* USB drivers, currently only for /* USB drivers, currently only for
Linux, but relatively easy to port to Linux, but relatively easy to port to

File diff suppressed because it is too large Load Diff

View File

@ -1,63 +0,0 @@
/*
* Copyright 2001 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>
*
*/
/** \file
* Interface to Linux keyboard driver. \see lnx-keyboard.c */
#ifndef _LNX_KEYBOARD_H_
#define _LNX_KEYBOARD_H_
extern void *kbdLinuxCreatePrivate(DeviceIntPtr pKeyboard);
extern void kbdLinuxDestroyPrivate(void *private);
extern void kbdLinuxInit(DevicePtr pDev);
extern void kbdLinuxGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info);
extern int kbdLinuxOn(DevicePtr pDev);
extern void kbdLinuxOff(DevicePtr pDev);
extern void kbdLinuxVTPreSwitch(void *p);
extern void kbdLinuxVTPostSwitch(void *p);
extern int kbdLinuxVTSwitch(void *p, int vt,
dmxVTSwitchReturnProcPtr switch_return,
void *switch_return_data);
extern void kbdLinuxRead(DevicePtr pDev,
dmxMotionProcPtr motion,
dmxEnqueueProcPtr enqueue,
dmxCheckSpecialProcPtr checkspecial,
DMXBlockType block);
extern void kbdLinuxCtrl(DevicePtr pDev, KeybdCtrl * ctrl);
extern void kbdLinuxBell(DevicePtr pDev, int percent,
int volume, int pitch, int duration);
#endif

View File

@ -1,349 +0,0 @@
/* Portions of this file were derived from the following files:
*
**********************************************************************
*
* Xserver/hw/kdrive/linux/ms.c
*
* Copyright (c) 2001 by Juliusz Chroboczek
* Copyright (c) 1999 by Keith Packard
*
* 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 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 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
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* 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.
*
*/
/*
* Copyright 2001-2003 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>
*
*/
/** \file
*
* This code implements a low-level device driver for a serial MS mouse.
* The code is derived from code by Juliusz Chroboczek and Keith Packard
* (see the source code for complete references). */
#ifdef HAVE_DMX_CONFIG_H
#include <dmx-config.h>
#endif
#include "inputstr.h"
#include <X11/Xos.h>
#include <errno.h>
#include <termios.h>
#include <xserver_poll.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 "lnx-ms.h"
#define GETPRIV myPrivate *priv \
= ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->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 MOTIONPROC dmxMotionProcPtr
#define ENQUEUEPROC dmxEnqueueProcPtr
#define CHECKPROC dmxCheckSpecialProcPtr
#define BLOCK DMXBlockType
/* End of interface definitions. */
/*****************************************************************************/
/* Private area for MS mouse devices. */
typedef struct _myPrivate {
DeviceIntPtr pMouse;
int fd;
struct termios tty;
enum {
button1 = 0x0001,
button2 = 0x0002,
button3 = 0x0004,
button4 = 0x0008,
button5 = 0x0010
} buttons;
} myPrivate;
static int
msLinuxReadBytes(int fd, unsigned char *buf, int len, int min)
{
int n, tot;
struct pollfd poll_fd;
tot = 0;
poll_fd.fd = fd;
poll_fd.events = POLLIN;
while (len) {
n = read(fd, buf, len);
if (n > 0) {
tot += n;
buf += n;
len -= n;
}
if (tot % min == 0)
break;
n = xserver_poll(&poll_fd, 1, 100);
if (n <= 0)
break;
}
return tot;
}
static void
msLinuxButton(DevicePtr pDev, ENQUEUEPROC enqueue, int buttons, BLOCK block)
{
GETPRIV;
#define PRESS(b) \
do { \
enqueue(pDev, ButtonPress, 0, 0, NULL, block); \
} while (0)
#define RELEASE(b) \
do { \
enqueue(pDev, ButtonRelease, 0, 0, NULL, block); \
} while (0)
if ((buttons & button1) && !(priv->buttons & button1))
PRESS(1);
if (!(buttons & button1) && (priv->buttons & button1))
RELEASE(1);
if ((buttons & button2) && !(priv->buttons & button2))
PRESS(2);
if (!(buttons & button2) && (priv->buttons & button2))
RELEASE(2);
if ((buttons & button3) && !(priv->buttons & button3))
PRESS(3);
if (!(buttons & button3) && (priv->buttons & button3))
RELEASE(3);
if ((buttons & button4) && !(priv->buttons & button4))
PRESS(4);
if (!(buttons & button4) && (priv->buttons & button4))
RELEASE(4);
if ((buttons & button5) && !(priv->buttons & button5))
PRESS(5);
if (!(buttons & button5) && (priv->buttons & button5))
RELEASE(5);
priv->buttons = buttons;
}
/** Read an event from the \a pDev device. If the event is a motion
* event, enqueue it with the \a motion function. Otherwise, check for
* special keys with the \a checkspecial function and enqueue the event
* with the \a enqueue function. The \a block type is passed to the
* functions so that they may block the input thread as appropriate to the
* caller of this function. */
void
msLinuxRead(DevicePtr pDev,
MOTIONPROC motion,
ENQUEUEPROC enqueue, CHECKPROC checkspecial, BLOCK block)
{
GETPRIV;
unsigned char buf[3 * 200]; /* RATS: Use ok */
unsigned char *b;
int n;
int dx, dy, v[2];
while ((n = msLinuxReadBytes(priv->fd, buf, sizeof(buf), 3)) > 0) {
b = buf;
while (n >= 3) {
dx = (char) (((b[0] & 0x03) << 6) | (b[1] & 0x3f));
dy = (char) (((b[0] & 0x0c) << 4) | (b[2] & 0x3f));
v[0] = -dx;
v[1] = -dy;
motion(pDev, v, 0, 2, 1, block);
msLinuxButton(pDev, enqueue, (((b[0] & 0x10) ? button3 : 0)
| ((b[0] & 0x20) ? button1 : 0)),
block);
n -= 3;
b += 3;
}
}
}
/** Initialize \a pDev. */
void
msLinuxInit(DevicePtr pDev)
{
GETPRIV;
const char *names[] = { "/dev/serialmouse", "/dev/mouse", NULL };
int i;
if (priv->fd >= 0)
return;
for (i = 0; names[i]; i++) {
if ((priv->fd = open(names[i], O_RDWR | O_NONBLOCK, 0)) >= 0)
break;
}
if (priv->fd < 0)
FATAL1("msLinuxInit: Cannot open mouse port (%s)\n", strerror(errno));
if (!isatty(priv->fd))
FATAL1("msLinuxInit: Mouse port %s is not a tty\n", names[i]);
if (tcgetattr(priv->fd, &priv->tty) < 0)
FATAL1("msLinuxInit: tcgetattr failed (%s)\n", strerror(errno));
i = write(priv->fd, "*n", 2); /* 1200 baud */
(void) i;
usleep(100000);
}
/** Turn \a pDev on (i.e., take input from \a pDev). */
int
msLinuxOn(DevicePtr pDev)
{
GETPRIV;
struct termios nTty;
int i;
if (priv->fd < 0)
msLinuxInit(pDev);
nTty = priv->tty;
nTty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR
| IGNCR | ICRNL | IXON | IXOFF);
nTty.c_oflag &= ~OPOST;
nTty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
nTty.c_cflag &= ~(CSIZE | PARENB);
nTty.c_cflag |= CS8 | CLOCAL | CSTOPB;
nTty.c_cc[VTIME] = 0;
nTty.c_cc[VMIN] = 1;
cfsetispeed(&nTty, B1200);
cfsetospeed(&nTty, B1200);
if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
FATAL1("msLinuxInit: tcsetattr failed (%s)\n", strerror(errno));
i = write(priv->fd, "*V", 2); /* 2 button 3 byte protocol */
(void) i;
return priv->fd;
}
/** Turn \a pDev off (i.e., stop taking input from \a pDev). */
void
msLinuxOff(DevicePtr pDev)
{
GETPRIV;
tcsetattr(priv->fd, TCSANOW, &priv->tty);
close(priv->fd);
priv->fd = -1;
}
static void
msLinuxGetMap(DevicePtr pDev, unsigned char *map, int *nButtons)
{
int i;
if (nButtons)
*nButtons = 3;
if (map)
for (i = 0; i <= *nButtons; i++)
map[i] = i;
}
/** Currently unused hook called prior to an VT switch. */
void
msLinuxVTPreSwitch(void *p)
{
}
/** Currently unused hook called after returning from a VT switch. */
void
msLinuxVTPostSwitch(void *p)
{
}
/** Create a private structure for use within this file. */
void *
msLinuxCreatePrivate(DeviceIntPtr pMouse)
{
myPrivate *priv = calloc(1, sizeof(*priv));
priv->fd = -1;
priv->pMouse = pMouse;
return priv;
}
/** Destroy a private structure. */
void
msLinuxDestroyPrivate(void *priv)
{
free(priv);
}
/** Fill the \a info structure with information needed to initialize \a
* pDev. */
void
msLinuxGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
{
info->buttonClass = 1;
msLinuxGetMap(pDev, info->map, &info->numButtons);
info->valuatorClass = 1;
info->numRelAxes = 2;
info->minval[0] = 0;
info->maxval[0] = 0;
info->res[0] = 1;
info->minres[0] = 0;
info->maxres[0] = 1;
info->ptrFeedbackClass = 1;
}

View File

@ -1,55 +0,0 @@
/*
* Copyright 2001 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>
*
*/
/** \file
* Interface to Linux MS mouse driver. \see lnx-ms.c */
#ifndef _LNX_MS_H_
#define _LNX_MS_H_
extern void *msLinuxCreatePrivate(DeviceIntPtr pMouse);
extern void msLinuxDestroyPrivate(void *priv);
extern void msLinuxRead(DevicePtr pDev,
dmxMotionProcPtr motion,
dmxEnqueueProcPtr enqueue,
dmxCheckSpecialProcPtr checkspecial,
DMXBlockType block);
extern void msLinuxInit(DevicePtr pDev);
extern void msLinuxGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info);
extern int msLinuxOn(DevicePtr pDev);
extern void msLinuxOff(DevicePtr pDev);
extern void msLinuxCtrl(DevicePtr pDev, PtrCtrl * ctrl);
extern void msLinuxVTPreSwitch(void *p);
extern void msLinuxVTPostSwitch(void *p);
#endif

View File

@ -1,316 +0,0 @@
/* Portions of this file were derived from the following files:
*
**********************************************************************
*
* Xserver/hw/kdrive/linux/ps2.c
*
* Copyright (c) 1999 by Keith Packard
*
* 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 Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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,2003 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>
*
*/
/** \file
*
* This code implements a low-level device driver for a serial MS mouse.
* The code is derived from code by Keith Packard (see the source code
* for complete references). */
#ifdef HAVE_DMX_CONFIG_H
#include <dmx-config.h>
#endif
#include "inputstr.h"
#include <X11/Xos.h>
#include <errno.h>
#include <termios.h>
#include <xserver_poll.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 "lnx-ps2.h"
#define GETPRIV myPrivate *priv \
= ((DMXLocalInputInfoPtr)(pDev->devicePrivate))->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 MOTIONPROC dmxMotionProcPtr
#define ENQUEUEPROC dmxEnqueueProcPtr
#define CHECKPROC dmxCheckSpecialProcPtr
#define BLOCK DMXBlockType
/* End of interface definitions. */
/*****************************************************************************/
/* Private area for PS/2 devices. */
typedef struct _myPrivate {
DeviceIntPtr pMouse;
int fd;
enum {
button1 = 0x0001,
button2 = 0x0002,
button3 = 0x0004,
button4 = 0x0008,
button5 = 0x0010
} buttons;
} myPrivate;
static int
ps2LinuxReadBytes(int fd, unsigned char *buf, int len, int min)
{
int n, tot;
struct pollfd poll_fd;
poll_fd.fd = fd;
poll_fd.events = POLLIN;
tot = 0;
while (len) {
n = read(fd, buf, len);
if (n > 0) {
tot += n;
buf += n;
len -= n;
}
if (tot % min == 0)
break;
n = xserver_poll(&poll_fd, 1, 100);
if (n <= 0)
break;
}
return tot;
}
static void
ps2LinuxButton(DevicePtr pDev, ENQUEUEPROC enqueue, int buttons, BLOCK block)
{
GETPRIV;
#define PRESS(b) \
do { \
enqueue(pDev, ButtonPress, 0, 0, NULL, block); \
} while (0)
#define RELEASE(b) \
do { \
enqueue(pDev, ButtonRelease, 0, 0, NULL, block); \
} while (0)
if ((buttons & button1) && !(priv->buttons & button1))
PRESS(1);
if (!(buttons & button1) && (priv->buttons & button1))
RELEASE(1);
if ((buttons & button2) && !(priv->buttons & button2))
PRESS(2);
if (!(buttons & button2) && (priv->buttons & button2))
RELEASE(2);
if ((buttons & button3) && !(priv->buttons & button3))
PRESS(3);
if (!(buttons & button3) && (priv->buttons & button3))
RELEASE(3);
if ((buttons & button4) && !(priv->buttons & button4))
PRESS(4);
if (!(buttons & button4) && (priv->buttons & button4))
RELEASE(4);
if ((buttons & button5) && !(priv->buttons & button5))
PRESS(5);
if (!(buttons & button5) && (priv->buttons & button5))
RELEASE(5);
priv->buttons = buttons;
}
/** Read an event from the \a pDev device. If the event is a motion
* event, enqueue it with the \a motion function. Otherwise, check for
* special keys with the \a checkspecial function and enqueue the event
* with the \a enqueue function. The \a block type is passed to the
* functions so that they may block the input thread as appropriate to the
* caller of this function. */
void
ps2LinuxRead(DevicePtr pDev, MOTIONPROC motion,
ENQUEUEPROC enqueue, CHECKPROC checkspecial, BLOCK block)
{
GETPRIV;
unsigned char buf[3 * 200]; /* RATS: Use ok */
unsigned char *b;
int n;
int dx, dy, v[2];
while ((n = ps2LinuxReadBytes(priv->fd, buf, sizeof(buf), 3)) > 0) {
b = buf;
while (n >= 3) {
dx = b[1] - ((b[0] & 0x10) ? 256 : 0);
dy = -b[2] + ((b[0] & 0x20) ? 256 : 0);
v[0] = -dx;
v[1] = -dy;
motion(pDev, v, 0, 2, 1, block);
ps2LinuxButton(pDev, enqueue, (((b[0] & 4) ? button2 : 0)
| ((b[0] & 2) ? button3 : 0)
| ((b[0] & 1) ? button1 : 0)),
block);
n -= 3;
b += 3;
}
}
}
/** Initialize \a pDev. */
void
ps2LinuxInit(DevicePtr pDev)
{
GETPRIV;
const char *names[] = { "/dev/mouse", "/dev/psaux", NULL };
int i;
if (priv->fd >= 0)
return;
for (i = 0; names[i]; i++) {
if ((priv->fd = open(names[i], O_RDWR | O_NONBLOCK, 0)) >= 0)
break;
}
if (priv->fd < 0)
FATAL1("ps2LinuxInit: Cannot open mouse port (%s)\n", strerror(errno));
}
/** Turn \a pDev on (i.e., take input from \a pDev). */
int
ps2LinuxOn(DevicePtr pDev)
{
GETPRIV;
if (priv->fd < 0)
ps2LinuxInit(pDev);
return priv->fd;
}
/** Turn \a pDev off (i.e., stop taking input from \a pDev). */
void
ps2LinuxOff(DevicePtr pDev)
{
GETPRIV;
close(priv->fd);
priv->fd = -1;
}
static void
ps2LinuxGetMap(DevicePtr pDev, unsigned char *map, int *nButtons)
{
int i;
if (nButtons)
*nButtons = 3;
if (map)
for (i = 0; i <= *nButtons; i++)
map[i] = i;
}
/** Currently unused hook called prior to an VT switch. */
void
ps2LinuxVTPreSwitch(void *p)
{
}
/** Currently unused hook called after returning from a VT switch. */
void
ps2LinuxVTPostSwitch(void *p)
{
}
/** Create a private structure for use within this file. */
void *
ps2LinuxCreatePrivate(DeviceIntPtr pMouse)
{
myPrivate *priv = calloc(1, sizeof(*priv));
priv->fd = -1;
priv->pMouse = pMouse;
return priv;
}
/** Destroy a private structure. */
void
ps2LinuxDestroyPrivate(void *priv)
{
free(priv);
}
/** Fill the \a info structure with information needed to initialize \a
* pDev. */
void
ps2LinuxGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info)
{
info->buttonClass = 1;
ps2LinuxGetMap(pDev, info->map, &info->numButtons);
info->valuatorClass = 1;
info->numRelAxes = 2;
info->minval[0] = 0;
info->maxval[0] = 0;
info->res[0] = 1;
info->minres[0] = 0;
info->maxres[0] = 1;
info->ptrFeedbackClass = 1;
}

View File

@ -1,55 +0,0 @@
/*
* Copyright 2001 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>
*
*/
/** \file
* Interface to Linux PS/2 mouse driver. \see lnx-ps2.c */
#ifndef _LNX_PS2_H_
#define _LNX_PS2_H_
extern void *ps2LinuxCreatePrivate(DeviceIntPtr pMouse);
extern void ps2LinuxDestroyPrivate(void *priv);
extern void ps2LinuxRead(DevicePtr pDev,
dmxMotionProcPtr motion,
dmxEnqueueProcPtr enqueue,
dmxCheckSpecialProcPtr checkspecial,
DMXBlockType block);
extern void ps2LinuxInit(DevicePtr pDev);
extern void ps2LinuxGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info);
extern int ps2LinuxOn(DevicePtr pDev);
extern void ps2LinuxOff(DevicePtr pDev);
extern void ps2LinuxCtrl(DevicePtr pDev, PtrCtrl * ctrl);
extern void ps2LinuxVTPreSwitch(void *p);
extern void ps2LinuxVTPostSwitch(void *p);
#endif

View File

@ -83,11 +83,8 @@ input events.
.TP 4 .TP 4
.B local .B local
The raw keyboard and pointer from the local computer are used. A The raw keyboard and pointer from the local computer are used. A
comma-separated list of driver names can be appended. For example, to comma-separated list of driver names can be appended.
select the example Linux keyboard and PS/2 mouse driver use: The following drivers have been implemented for Linux: usb-mou
.BR "-input local,kbd,ps2" .
The following drivers have been implemented for Linux: kbd, ms (a
two-button Microsoft mouse driver), ps2 (a PS/2 mouse driver), usb-mou
(a USB mouse driver), usb-kbd (a USB keyboard driver), and usb-oth (a (a USB mouse driver), usb-kbd (a USB keyboard driver), and usb-oth (a
USB non-keyboard, non-mouse driver). Additional drivers may be USB non-keyboard, non-mouse driver). Additional drivers may be
implemented in the future. Appropriate defaults will be used if no implemented in the future. Appropriate defaults will be used if no
@ -603,7 +600,7 @@ Xdmx :1 -display d0:0 -display d1:0 -input :0 +xinerama
.PP .PP
As above, except with core input from the local keyboard and mouse: As above, except with core input from the local keyboard and mouse:
.RS .RS
Xdmx :1 -display d0:0 -display d1:0 -input local,kbd,ps2 +xinerama Xdmx :1 -display d0:0 -display d1:0 -input local,usb-kbd,usb-mou +xinerama
.RE .RE
Note that local input can be used under Linux while another X session is Note that local input can be used under Linux while another X session is
running on :0 (assuming the user can access the Linux console tty and running on :0 (assuming the user can access the Linux console tty and