Compare commits

..

9 Commits

Author SHA1 Message Date
Peter Hutterer
f135e07462 evdev 2.0.2 2008-07-14 13:34:36 +09:30
Peter Hutterer
e926356eb0 Don't enable the device if the grab failed with ENODEV.
After suspend/resume, sometimes the device doesn't come back up on the same
node. Since we do not call PreInit for the device (which would detect this
situation), we continue to try to read a nonexisting file, spamming the log
file with "Read Error".
(cherry picked from commit bf0d81011e)
2008-07-14 13:17:39 +09:30
Peter Hutterer
bd56ab3d72 Add .gitignore file.
(cherry picked from commit ef4bb69c1a)
2008-07-10 19:34:05 +09:30
Peter Hutterer
2b30413598 Remove static ChangeLog, autogenerate as part of make dist.
Hook taken from xserver's Makefile.am
(cherry picked from commit ec23c6b2f5)
2008-07-10 19:29:57 +09:30
Ander Conselvan de Oliveira
52fc8ee846 Mice with a lot of buttons (e.g. Logitech MX1000) generate button events greater than BTN_TASK.
Signed-off-by: Peter Hutterer <peter@cs.unisa.edu.au>
(cherry picked from commit 0830676a0c)
2008-07-10 19:29:45 +09:30
Peter Hutterer
b125b834f4 evdev 2.0.1 2008-06-22 17:52:58 +09:30
Peter Hutterer
05b20db8db No need to finalize MB emulation after EvdevProbe anymore.
Follow-up to 76800bfa75.
(cherry picked from commit 5a0ea39b79)
2008-06-22 16:26:10 +09:30
Simon Munton
43768d59da Close file descriptor if EvdevProbe fails.
Signed-off-by: Peter Hutterer <peter@cs.unisa.edu.au>
(cherry picked from commit 373e13ae35)
2008-06-22 16:25:48 +09:30
Keith Packard
9c524f6963 Enable middle button emulation at DEVICE_ON instead of DEVICE_INIT.
This ensures that the middle button emulation is re-enabled after VT switch,
otherwise the block handler that deals with the timeouts would not get
re-registered.

Signed-off-by: Keith Packard <keithp@keithp.com>
(cherry picked from commit 76800bfa75)
2008-06-22 16:24:57 +09:30
15 changed files with 192 additions and 1780 deletions

1
.gitignore vendored
View File

@@ -24,4 +24,3 @@ missing
stamp-h1
*.bz2
*.gz
*.pc

99
COPYING
View File

@@ -1,95 +1,12 @@
Various copyright notices found in this driver:
This is a stub file. This package has not yet had its complete licensing
information compiled. Please see the individual source files for details on
your rights to use and modify this software.
Copyright © 2004-2008 Red Hat, Inc.
Please submit updated COPYING files to the Xorg bugzilla:
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 Red Hat
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission. Red
Hat makes no representations about the suitability of this software
for any purpose. It is provided "as is" without express or implied
warranty.
https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL THE AUTHORS 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 2005 Sun Microsystems, Inc. All rights reserved.
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.
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 OPEN GROUP 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.
Except as contained in this notice, the name of the copyright holders shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the copyright holders.
Copyright © 2008 University of South Australia
copyrights taken from xf86-input-mouse, partly valid for this driver.
Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
Copyright 1993 by David Dawes <dawes@xfree86.org>
Copyright 2002 by SuSE Linux AG, Author: Egbert Eich
Copyright 1994-2002 by The XFree86 Project, Inc.
Copyright 2002 by Paul Elliott
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 the authors
not be used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission. The authors make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL THE AUTHORS 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 2005 Adam Jackson.
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, sub
license, 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
ADAM JACKSON 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.
All licensing questions regarding this software should be directed at the
Xorg mailing list:
http://lists.freedesktop.org/mailman/listinfo/xorg

View File

@@ -19,10 +19,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AUTOMAKE_OPTIONS = foreign
SUBDIRS = src man include
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xorg-evdev.pc
SUBDIRS = src man
EXTRA_DIST = ChangeLog autogen.sh

View File

@@ -22,7 +22,7 @@
AC_PREREQ(2.57)
AC_INIT([xf86-input-evdev],
2.0.99.1,
2.0.2,
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
xf86-input-evdev)
@@ -44,6 +44,24 @@ AC_PROG_CC
AH_TOP([#include "xorg-server.h"])
#AC_DEFINE(XFree86LOADER,1,[Stub define for loadable drivers])
#
#AC_ARG_ENABLE(XINPUT, AS_HELP_STRING([--enable-xinput],
# [Build XInput support (default: yes)]),
# [XINPUT=$enableval],[XINPUT=yes])
#AM_CONDITIONAL(XINPUT, test "x$XINPUT" = "xyes")
#if test "x$XINPUT" = "xyes" ; then
# AC_DEFINE(XINPUT,1,[Enable XInput support])
#fi
#
#AC_ARG_ENABLE(XKB, AS_HELP_STRING([--enable-xkb],
# [Build XKB support (default: yes)]),
# [XKB=$enableval],[XKB=yes])
#AM_CONDITIONAL(XKB, test "x$XKB" = "xyes")
#if test "x$XKB" = "xyes" ; then
# AC_DEFINE(XKB,1,[Enable XKB support])
#fi
AC_ARG_WITH(xorg-module-dir,
AC_HELP_STRING([--with-xorg-module-dir=DIR],
[Default xorg module directory [[default=$libdir/xorg/modules]]]),
@@ -53,12 +71,12 @@ inputdir=${moduledir}/input
AC_SUBST(inputdir)
# Checks for extensions
XORG_DRIVER_CHECK_EXT(RANDR, randrproto)
XORG_DRIVER_CHECK_EXT(XINPUT, inputproto)
# Checks for pkg-config packages
PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES)
sdkdir=$(pkg-config --variable=sdkdir xorg-server)
AC_SUBST(sdkdir)
CFLAGS="$CFLAGS $XORG_CFLAGS "' -I$(top_srcdir)/src'
AC_SUBST([CFLAGS])
@@ -71,8 +89,4 @@ AC_HEADER_STDC
XORG_MANPAGE_SECTIONS
XORG_RELEASE_VERSION
AC_OUTPUT([Makefile
src/Makefile
man/Makefile
include/Makefile
xorg-evdev.pc])
AC_OUTPUT([Makefile src/Makefile man/Makefile])

View File

@@ -1,2 +0,0 @@
EXTRA_DIST = evdev-properties.h
sdk_HEADERS = evdev-properties.h

View File

@@ -1,61 +0,0 @@
/*
* Copyright © 2008 Red Hat, Inc.
*
* 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 Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS 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.
*
* Authors:
* Peter Hutterer (peter.hutterer@redhat.com)
*/
#ifndef _EVDEV_PROPERTIES_H_
#define _EVDEV_PROPERTIES_H_
/* Middle mouse button emulation */
/* BOOL */
#define EVDEV_PROP_MIDBUTTON "Evdev Middle Button Emulation"
/* CARD16 */
#define EVDEV_PROP_MIDBUTTON_TIMEOUT "Evdev Middle Button Timeout"
/* Wheel emulation */
/* BOOL */
#define EVDEV_PROP_WHEEL "Evdev Wheel Emulation"
/* CARD8, 4 values [x up, x down, y up, y down], 0 to disable a value*/
#define EVDEV_PROP_WHEEL_AXES "Evdev Wheel Emulation Axes"
/* CARD16 */
#define EVDEV_PROP_WHEEL_INERTIA "Evdev Wheel Emulation Inertia"
/* CARD16 */
#define EVDEV_PROP_WHEEL_TIMEOUT "Evdev Wheel Emulation Timeout"
/* CARD8, value range 0-32, 0 to disable a value */
#define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
/* Drag lock */
/* CARD8, either 1 value or pairs, value range 0-32, 0 to disable a value*/
#define EVDEV_PROP_DRAGLOCK "Evdev Drag Lock Buttons"
/* Axis inversion */
/* BOOL, 2 values [x, y], 1 inverts axis */
#define EVDEV_PROP_INVERT_AXES "Evdev Axis Inversion"
/* Reopen attempts. */
/* CARD8 */
#define EVDEV_PROP_REOPEN "Evdev Reopen Attempts"
#endif

View File

@@ -1,3 +1,5 @@
# $Id$
#
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
#
# Permission to use, copy, modify, distribute, and sell this software and its

View File

@@ -9,6 +9,7 @@ evdev \- Generic Linux input driver
.BI " Identifier \*q" devname \*q
.B " Driver \*qevdev\*q"
.BI " Option \*qDevice\*q \*q" devpath \*q
.BI " Option \*qPath\*q \*q" path \*q
.BI " Option \*qEmulate3Buttons\*q \*q" True \*q
.BI " Option \*qEmulate3Timeout\*q \*q" 50 \*q
\ \ ...
@@ -46,139 +47,26 @@ are supported:
.BI "Option \*qDevice\*q \*q" string \*q
Specifies the device through which the device can be accessed. This will
generally be of the form \*q/dev/input/eventX\*q, where X is some integer.
The mapping from device node to hardware is system-dependent.
The mapping from device node to hardware is system-dependent. This option is
mandatory unless \*qPath\*q is given, and there is no default setting.
.TP 7
.BI "Option \*qPath\*q \*q" string \*q
Specifies the device through which the device can be accessed. This will
generally be of the form \*q/dev/input/by-path/xyz\*q, where xyz includes the
name of the device. The mapping from device node to hardware is
system-dependent. This option has precedence over the \*qDevice\*q option but
one of \*qPath\*q or \*qDevice\*q must be given.
.TP 7
.BI "Option \*qEmulate3Buttons\*q \*q" boolean \*q
Enable/disable the emulation of the third (middle) mouse button for mice
which only have two physical buttons. The third button is emulated by
pressing both buttons simultaneously. Default: on, until a middle mouse
button event is registered. Property: "Evdev Middle Button Emulation".
button event is registered.
.TP 7
.BI "Option \*qEmulate3Timeout\*q \*q" integer \*q
Sets the timeout (in milliseconds) that the driver waits before deciding
if two buttons where pressed "simultaneously" when 3 button emulation is
enabled. Default: 50. Property: "Evdev Middle Button Timeout".
.TP 7
.BI "Option \*qButtonMapping\*q \*q" string \*q
Sets the button mapping for this device. The mapping is a space-separated list
of button mappings that correspond in order to the physical buttons on the
device (i.e. the first number is the mapping for button 1, etc.). The default
mapping is "1 2 3 ... 32". A mapping of 0 deactivates the button. Multiple
buttons can have the same mapping.
For example, a left-handed mouse with deactivated scroll-wheel would use a
mapping of "3 2 1 0 0". Invalid mappings are ignored and the default mapping
is used. Buttons not specified in the user's mapping use the default mapping.
.TP 7
.BI "Option \*qDragLockButtons\*q \*q" "L1 B2 L3 B4" \*q
Sets \*qdrag lock buttons\*q that simulate holding a button down, so
that low dexterity people do not have to hold a button down at the
same time they move a mouse cursor. Button numbers occur in pairs,
with the lock button number occurring first, followed by the button
number that is the target of the lock button. Property: "Evdev
Drag Lock Buttons".
.TP 7
.BI "Option \*qDragLockButtons\*q \*q" "M1" \*q
Sets a \*qmaster drag lock button\*q that acts as a \*qMeta Key\*q
indicating that the next button pressed is to be
\*qdrag locked\*q. Property: "Evdev Drag Lock Buttons".
.TP 7
.BI "Option \*qEmulateWheel\*q \*q" boolean \*q
Enable/disable "wheel" emulation. Wheel emulation means emulating button
press/release events when the mouse is moved while a specific real button
is pressed. Wheel button events (typically buttons 4 and 5) are
usually used for scrolling. Wheel emulation is useful for getting wheel-like
behaviour with trackballs. It can also be useful for mice with 4 or
more buttons but no wheel. See the description of the
.BR EmulateWheelButton ,
.BR EmulateWheelInertia ,
.BR EmulateWheelTimeout ,
.BR XAxisMapping ,
and
.B YAxisMapping
options below. Default: off. Property "Evdev Wheel Emulation".
.TP 7
.BI "Option \*qEmulateWheelButton\*q \*q" integer \*q
Specifies which button must be held down to enable wheel emulation mode.
While this button is down, X and/or Y pointer movement will generate button
press/release events as specified for the
.B XAxisMapping
and
.B YAxisMapping
settings. Default: 4. Property: "Evdev Wheel Emulation Button".
.TP 7
.BI "Option \*qEmulateWheelInertia\*q \*q" integer \*q
Specifies how far (in pixels) the pointer must move to generate button
press/release events in wheel emulation mode. Default: 10. Property: "Evdev
Wheel Emulation Inertia".
.TP 7
.BI "Option \*qEmulateWheelTimeout\*q \*q" integer \*q
Specifies the time in milliseconds the
.BR EmulateWheelButton
must be pressed before wheel emulation is started. If the
.BR EmulateWheelButton
is released before this timeout, the original button press/release event
is sent. Default: 200. Property: "Evdev Wheel Emulation Timeout".
.TP 7
.BI "Option \*qXAxisMapping\*q \*q" "N1 N2" \*q
Specifies which buttons are mapped to motion in the X direction in wheel
emulation mode. Button number
.I N1
is mapped to the negative X axis motion and button number
.I N2
is mapped to the positive X axis motion. Default: no mapping. Property:
"Evdev Wheel Emulation Axes".
.TP 7
.BI "Option \*qYAxisMapping\*q \*q" "N1 N2" \*q
Specifies which buttons are mapped to motion in the Y direction in wheel
emulation mode. Button number
.I N1
is mapped to the negative Y axis motion and button number
.I N2
is mapped to the positive Y axis motion. Default: "4 5". Property:
"Evdev Wheel Emulation Axes".
.TP 7
.BI "Option \*qReopenAttempts\*q \*q" integer \*q
Number of reopen attempts after a read error occurs on the device (e.g. after
waking up from suspend). In between each attempt is a 100ms wait. Default: 10.
.TP 7
.BI "Option \*qInvertX\*q \*q" Bool \*q
.TP 7
.BI "Option \*qInvertY\*q \*q" Bool \*q
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
.SH SUPPORTED PROPERTIES
The following properties are provided by the
.B evdev
driver.
.TP 7
.BI "Evdev Middle Button Emulation"
1 boolean value (8 bit, 0 or 1).
.TP 7
.BI "Evdev Middle Button Timeout"
1 16-bit positive value.
.TP 7
.BI "Evdev Wheel Emulation"
1 boolean value (8 bit, 0 or 1).
.TP 7
.BI "Evdev Wheel Emulation Axes"
4 8-bit values, order X up, X down, Y up, Y down. 0 disables a value.
.TP 7
.BI "Evdev Wheel Emulation Inertia"
1 16-bit positive value.
.TP 7
.BI "Evdev Wheel Emulation Timeout"
1 16-bit positive value.
.TP 7
.BI "Evdev Wheel Emulation Button"
1 8-bit value, allowed range 0-32, 0 disables the button.
.TP 7
.BI "Evdev Drag Lock Buttons"
8-bit. Either 1 value or pairs of values. Value range 0-32, 0 disables a
value.
.TP 7
.BI "Evdev Axis Inversion"
2 boolean values (8 bit, 0 or 1), order X, Y. 1 inverts the axis.
enabled. Default: 50.
.SH AUTHORS
Kristian Høgsberg.
.SH "SEE ALSO"

View File

@@ -28,11 +28,6 @@
@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
@DRIVER_NAME@_drv_ladir = @inputdir@
INCLUDES=-I$(top_srcdir)/include/
@DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \
@DRIVER_NAME@.h \
emuMB.c \
emuWheel.c \
draglock.c
emuMB.c

View File

@@ -1,318 +0,0 @@
/*
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
* Copyright 1993 by David Dawes <dawes@xfree86.org>
* Copyright 2002 by SuSE Linux AG, Author: Egbert Eich
* Copyright 1994-2002 by The XFree86 Project, Inc.
* Copyright 2002 by Paul Elliott
* (Ported from xf86-input-mouse, above copyrights taken from there)
* Copyright © 2008 University of South Australia
* Copyright 2008 by Chris Salch
* Copyright 2008 Red Hat, Inc.
*
* 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 the authors
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. The authors make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS 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.
*
*/
/* Draglock code */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <xf86.h>
#include <xf86Xinput.h>
#include <X11/Xatom.h>
#include <exevents.h>
#include <evdev-properties.h>
#include "evdev.h"
#ifdef HAVE_PROPERTIES
static Atom prop_dlock = 0; /* Drag lock buttons. */
#endif
void EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button);
/* Setup and configuration code */
void
EvdevDragLockPreInit(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
char *option_string = NULL;
int meta_button = 0;
int lock_button = 0;
char *next_num = NULL;
char *end_str = NULL;
BOOL pairs = FALSE;
option_string = xf86CheckStrOption(pInfo->options, "DragLockButtons",NULL);
if (!option_string)
return;
next_num = option_string;
/* Loop until we hit the end of our option string */
while (next_num != NULL) {
lock_button = 0;
meta_button = strtol(next_num, &end_str, 10);
/* check to see if we found anything */
if (next_num != end_str) {
/* setup for the next number */
next_num = end_str;
} else {
/* we have nothing more to parse, drop out of the loop */
next_num = NULL;
}
/* Check for a button to lock if we have a meta button */
if (meta_button != 0 && next_num != NULL ) {
lock_button = strtol(next_num, &end_str, 10);
/* check to see if we found anything */
if (next_num != end_str) {
/* setup for the next number */
next_num = end_str;
} else {
/* we have nothing more to parse, drop out of the loop */
next_num = NULL;
}
}
/* Ok, let the user know what we found on this look */
if (meta_button != 0) {
if (lock_button == 0) {
if (!pairs) {
/* We only have a meta button */
pEvdev->dragLock.meta = meta_button;
xf86Msg(X_CONFIG, "%s: DragLockButtons : "
"%i as meta\n",
pInfo->name, meta_button);
} else {
xf86Msg(X_ERROR, "%s: DragLockButtons : "
"Incomplete pair specifying button pairs %s\n",
pInfo->name, option_string);
}
} else {
/* Do bounds checking to make sure we don't crash */
if ((meta_button <= EVDEV_MAXBUTTONS) && (meta_button >= 0 ) &&
(lock_button <= EVDEV_MAXBUTTONS) && (lock_button >= 0)) {
xf86Msg(X_CONFIG, "%s: DragLockButtons : %i -> %i\n",
pInfo->name, meta_button, lock_button);
pEvdev->dragLock.lock_pair[meta_button - 1] = lock_button;
pairs=TRUE;
} else {
/* Let the user know something was wrong
with this pair of buttons */
xf86Msg(X_CONFIG, "%s: DragLockButtons : "
"Invalid button pair %i -> %i\n",
pInfo->name, meta_button, lock_button);
}
}
} else {
xf86Msg(X_ERROR, "%s: Found DragLockButtons "
"with invalid lock button string : '%s'\n",
pInfo->name, option_string);
/* This should be the case anyhow, just make sure */
next_num = NULL;
}
/* Check for end of string, to avoid annoying error */
if (next_num != NULL && *next_num == '\0')
next_num = NULL;
}
}
/* Updates DragLock button state and firest button event messges */
void
EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
BOOL state=0;
/* update button state */
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
pEvdev->dragLock.lock_state[button - 1] = state;
xf86PostButtonEvent(pInfo->dev, 0, button, state, 0, 0);
}
/* Filter button presses looking for either a meta button or the
* control of a button pair.
*
* @param button button number (1 for left, 3 for right)
* @param value TRUE if button press, FALSE if release
*
* @return TRUE if the event was swallowed here, FALSE otherwise.
*/
BOOL
EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
if (button == 0)
return FALSE;
/* Do we have a single meta key or
several button pairings? */
if (pEvdev->dragLock.meta != 0) {
if (pEvdev->dragLock.meta == button) {
/* setup up for button lock */
if (value)
pEvdev->dragLock.meta_state = TRUE;
return TRUE;
} else if (pEvdev->dragLock.meta_state) { /* waiting to lock */
pEvdev->dragLock.meta_state = FALSE;
EvdevDragLockLockButton(pInfo, button);
return TRUE;
}
} else if (pEvdev->dragLock.lock_pair[button - 1] && value) {
/* A meta button in a meta/lock pair was pressed */
EvdevDragLockLockButton(pInfo, pEvdev->dragLock.lock_pair[button - 1]);
return TRUE;
}
/* Eat events for buttons that are locked */
if (pEvdev->dragLock.lock_state[button - 1])
return TRUE;
return FALSE;
}
#ifdef HAVE_PROPERTIES
/**
* Set the drag lock property.
* If only one value is supplied, then this is used as the meta button.
* If more than one value is supplied, then each value is the drag lock button
* for the pair. 0 disables a pair.
* i.e. to set bt 3 to draglock button 1, supply 0,0,1
*/
int
EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
BOOL checkonly)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (atom == prop_dlock)
{
int i;
if (val->format != 8 || val->type != XA_INTEGER)
return BadMatch;
/* Don't allow changes while a lock is active */
if (pEvdev->dragLock.meta)
{
if (pEvdev->dragLock.meta_state)
return BadAccess;
} else
{
for (i = 0; i < EVDEV_MAXBUTTONS; i++)
if (pEvdev->dragLock.lock_state[i])
return BadValue;
}
if (val->size == 1)
{
int meta = *((CARD8*)val->data);
if (meta > EVDEV_MAXBUTTONS)
return BadValue;
if (!checkonly)
{
pEvdev->dragLock.meta = meta;
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
}
} else
{
CARD8* vals = (CARD8*)val->data;
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
if (vals[i] > EVDEV_MAXBUTTONS)
return BadValue;
if (!checkonly)
{
pEvdev->dragLock.meta = 0;
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
pEvdev->dragLock.lock_pair[i] = vals[i];
}
}
}
return Success;
}
/**
* Initialise property for drag lock buttons setting.
*/
void
EvdevDragLockInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (!dev->button) /* don't init prop for keyboards */
return;
prop_dlock = MakeAtom(EVDEV_PROP_DRAGLOCK, strlen(EVDEV_PROP_DRAGLOCK), TRUE);
if (pEvdev->dragLock.meta)
{
XIChangeDeviceProperty(dev, prop_dlock, XA_INTEGER, 8,
PropModeReplace, 1, &pEvdev->dragLock.meta,
FALSE);
} else {
int highest = 0;
int i;
CARD8 pair[EVDEV_MAXBUTTONS] = {0};
for (i = 0; i < EVDEV_MAXBUTTONS; i++)
{
if (pEvdev->dragLock.lock_pair[i])
highest = i;
pair[i] = pEvdev->dragLock.lock_pair[i];
}
XIChangeDeviceProperty(dev, prop_dlock, XA_INTEGER, 8, PropModeReplace,
highest + 1, pair, FALSE);
}
XISetDevicePropertyDeletable(dev, prop_dlock, FALSE);
XIRegisterPropertyHandler(dev, EvdevDragLockSetProperty, NULL, NULL);
}
#endif

View File

@@ -11,11 +11,11 @@
* 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 the authors
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. The authors make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
@@ -34,12 +34,8 @@
#include "config.h"
#endif
#include <X11/Xatom.h>
#include <xf86.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include <evdev-properties.h>
#include "evdev.h"
enum {
@@ -48,10 +44,6 @@ enum {
MBEMU_AUTO
};
#ifdef HAVE_PROPERTIES
static Atom prop_mbemu = 0; /* Middle button emulation on/off property */
static Atom prop_mbtimeout = 0; /* Middle button timeout property */
#endif
/*
* Lets create a simple finite-state machine for 3 button emulation:
*
@@ -214,14 +206,14 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
/**
* Emulate a middle button on button press.
*
* @param code button number (1 for left, 3 for right)
* @param code Evdev event code (BTN_LEFT or BTN_RIGHT)
* @param press TRUE if press, FALSE if release.
*
* @return TRUE if event was swallowed by middle mouse button emulation, FALSE
* otherwise.
*/
BOOL
EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int code, BOOL press)
{
EvdevPtr pEvdev = pInfo->private;
int id;
@@ -232,14 +224,14 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
return ret;
/* don't care about other buttons */
if (button != 1 && button != 3)
if (code != BTN_LEFT && code != BTN_RIGHT)
return ret;
btstate = &pEvdev->emulateMB.buttonstate;
if (press)
*btstate |= (button == 1) ? 0x1 : 0x2;
*btstate |= (code == BTN_LEFT) ? 0x1 : 0x2;
else
*btstate &= (button == 1) ? ~0x1 : ~0x2;
*btstate &= (code == BTN_LEFT) ? ~0x1 : ~0x2;
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
{
@@ -320,6 +312,7 @@ EvdevMBEmuPreInit(InputInfoPtr pInfo)
RegisterBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
EvdevMBEmuWakeupHandler,
(pointer)pInfo);
}
void
@@ -339,67 +332,3 @@ EvdevMBEmuEnable(InputInfoPtr pInfo, BOOL enable)
if (pEvdev->emulateMB.enabled == MBEMU_AUTO)
pEvdev->emulateMB.enabled = enable;
}
#ifdef HAVE_PROPERTIES
int
EvdevMBEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
BOOL checkonly)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (atom == prop_mbemu)
{
if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
pEvdev->emulateMB.enabled = *((BOOL*)val->data);
} else if (atom == prop_mbtimeout)
{
if (val->format != 16 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
pEvdev->emulateMB.timeout = *((INT16*)val->data);
}
return Success;
}
/**
* Initialise property for MB emulation on/off.
*/
void
EvdevMBEmuInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
int rc;
if (!dev->button) /* don't init prop for keyboards */
return;
prop_mbemu = MakeAtom(EVDEV_PROP_MIDBUTTON, strlen(EVDEV_PROP_MIDBUTTON), TRUE);
rc = XIChangeDeviceProperty(dev, prop_mbemu, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateMB.enabled,
FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_mbemu, FALSE);
prop_mbtimeout = MakeAtom(EVDEV_PROP_MIDBUTTON_TIMEOUT,
strlen(EVDEV_PROP_MIDBUTTON_TIMEOUT),
TRUE);
rc = XIChangeDeviceProperty(dev, prop_mbtimeout, XA_INTEGER, 16, PropModeReplace, 1,
&pEvdev->emulateMB.timeout, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_mbtimeout, FALSE);
XIRegisterPropertyHandler(dev, EvdevMBEmuSetProperty, NULL, NULL);
}
#endif

View File

@@ -1,466 +0,0 @@
/*
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
* Copyright 1993 by David Dawes <dawes@xfree86.org>
* Copyright 2002 by SuSE Linux AG, Author: Egbert Eich
* Copyright 1994-2002 by The XFree86 Project, Inc.
* Copyright 2002 by Paul Elliott
* (Ported from xf86-input-mouse, above copyrights taken from there)
* Copyright 2008 by Chris Salch
* Copyright © 2008 Red Hat, Inc.
*
* 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 the authors
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. The authors make no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS 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.
*
*/
/* Mouse wheel emulation code. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xatom.h>
#include <xf86.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include <evdev-properties.h>
#include "evdev.h"
#define WHEEL_NOT_CONFIGURED 0
#ifdef HAVE_PROPERTIES
static Atom prop_wheel_emu = 0;
static Atom prop_wheel_axismap = 0;
static Atom prop_wheel_inertia = 0;
static Atom prop_wheel_timeout = 0;
static Atom prop_wheel_button = 0;
#endif
/* Local Funciton Prototypes */
static BOOL EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char *axis_name);
static void EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
/* Filter mouse button events */
BOOL
EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
int ms;
/* Has wheel emulation been configured to be enabled? */
if (!pEvdev->emulateWheel.enabled)
return FALSE;
/* Check for EmulateWheelButton */
if (pEvdev->emulateWheel.button == button) {
pEvdev->emulateWheel.button_state = value;
if (value)
/* Start the timer when the button is pressed */
pEvdev->emulateWheel.expires = pEvdev->emulateWheel.timeout +
GetTimeInMillis();
else {
ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
if (ms > 0) {
/*
* If the button is released early enough emit the button
* press/release events
*/
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
}
}
return TRUE;
}
/* Don't care about this event */
return FALSE;
}
/* Filter mouse wheel events */
BOOL
EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
WheelAxisPtr pAxis = NULL;
int value = pEv->value;
int ms;
/* Has wheel emulation been configured to be enabled? */
if (!pEvdev->emulateWheel.enabled)
return FALSE;
/* Handle our motion events if the emuWheel button is pressed*/
if (pEvdev->emulateWheel.button_state) {
/* Just return if the timeout hasn't expired yet */
ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
if (ms > 0)
return TRUE;
/* We don't want to intercept real mouse wheel events */
switch(pEv->code) {
case REL_X:
pAxis = &(pEvdev->emulateWheel.X);
break;
case REL_Y:
pAxis = &(pEvdev->emulateWheel.Y);
break;
default:
break;
}
/* If we found REL_X or REL_Y, emulate a mouse wheel */
if (pAxis)
EvdevWheelEmuInertia(pInfo, pAxis, value);
/* Eat motion events while emulateWheel button pressed. */
return TRUE;
}
return FALSE;
}
/* Simulate inertia for our emulated mouse wheel */
static void
EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
int button;
int inertia;
/* if this axis has not been configured, just eat the motion */
if (!axis->up_button)
return;
axis->traveled_distance += value;
if (axis->traveled_distance < 0) {
button = axis->up_button;
inertia = -pEvdev->emulateWheel.inertia;
} else {
button = axis->down_button;
inertia = pEvdev->emulateWheel.inertia;
}
/* Produce button press events for wheel motion */
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
axis->traveled_distance -= inertia;
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
}
}
/* Handle button mapping here to avoid code duplication,
returns true if a button mapping was found. */
static BOOL
EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char* axis_name)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
char *option_string;
pAxis->up_button = WHEEL_NOT_CONFIGURED;
/* Check to see if there is configuration for this axis */
option_string = xf86SetStrOption(pInfo->options, axis_name, NULL);
if (option_string) {
int up_button = 0;
int down_button = 0;
char *msg = NULL;
if ((sscanf(option_string, "%d %d", &up_button, &down_button) == 2) &&
((up_button > 0) && (up_button <= EVDEV_MAXBUTTONS)) &&
((down_button > 0) && (down_button <= EVDEV_MAXBUTTONS))) {
/* Use xstrdup to allocate a string for us */
msg = xstrdup("buttons XX and YY");
if (msg)
sprintf(msg, "buttons %d and %d", up_button, down_button);
pAxis->up_button = up_button;
pAxis->down_button = down_button;
/* Update the number of buttons if needed */
if (up_button > pEvdev->buttons) pEvdev->buttons = up_button;
if (down_button > pEvdev->buttons) pEvdev->buttons = down_button;
} else {
xf86Msg(X_WARNING, "%s: Invalid %s value:\"%s\"\n",
pInfo->name, axis_name, option_string);
}
/* Clean up and log what happened */
if (msg) {
xf86Msg(X_CONFIG, "%s: %s: %s\n",pInfo->name, axis_name, msg);
xfree(msg);
return TRUE;
}
}
return FALSE;
}
/* Setup the basic configuration options used by mouse wheel emulation */
void
EvdevWheelEmuPreInit(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
char val[4];
int wheelButton;
int inertia;
int timeout;
val[0] = 0;
val[1] = 0;
if (xf86SetBoolOption(pInfo->options, "EmulateWheel", FALSE)) {
pEvdev->emulateWheel.enabled = TRUE;
} else
pEvdev->emulateWheel.enabled = FALSE;
wheelButton = xf86SetIntOption(pInfo->options, "EmulateWheelButton", 4);
if ((wheelButton < 0) || (wheelButton > EVDEV_MAXBUTTONS)) {
xf86Msg(X_WARNING, "%s: Invalid EmulateWheelButton value: %d\n",
pInfo->name, wheelButton);
xf86Msg(X_WARNING, "%s: Wheel emulation disabled.\n", pInfo->name);
pEvdev->emulateWheel.enabled = FALSE;
}
pEvdev->emulateWheel.button = wheelButton;
inertia = xf86SetIntOption(pInfo->options, "EmulateWheelInertia", 10);
if (inertia <= 0) {
xf86Msg(X_WARNING, "%s: Invalid EmulateWheelInertia value: %d\n",
pInfo->name, inertia);
xf86Msg(X_WARNING, "%s: Using built-in inertia value.\n",
pInfo->name);
inertia = 10;
}
pEvdev->emulateWheel.inertia = inertia;
timeout = xf86SetIntOption(pInfo->options, "EmulateWheelTimeout", 200);
if (timeout < 0) {
xf86Msg(X_WARNING, "%s: Invalid EmulateWheelTimeout value: %d\n",
pInfo->name, timeout);
xf86Msg(X_WARNING, "%s: Using built-in timeout value.\n",
pInfo->name);
timeout = 200;
}
pEvdev->emulateWheel.timeout = timeout;
/* Configure the Y axis or default it */
if (!EvdevWheelEmuHandleButtonMap(pInfo, &(pEvdev->emulateWheel.Y),
"YAxisMapping")) {
/* Default the Y axis to sane values */
pEvdev->emulateWheel.Y.up_button = 4;
pEvdev->emulateWheel.Y.down_button = 5;
/* Simpler to check just the largest value in this case */
/* XXX: we should post this to the server */
if (5 > pEvdev->buttons)
pEvdev->buttons = 5;
/* Display default Configuration */
xf86Msg(X_CONFIG, "%s: YAxisMapping: buttons %d and %d\n",
pInfo->name, pEvdev->emulateWheel.Y.up_button,
pEvdev->emulateWheel.Y.down_button);
}
/* This axis should default to an unconfigured state as most people
are not going to expect a Horizontal wheel. */
EvdevWheelEmuHandleButtonMap(pInfo, &(pEvdev->emulateWheel.X),
"XAxisMapping");
/* Used by the inertia code */
pEvdev->emulateWheel.X.traveled_distance = 0;
pEvdev->emulateWheel.Y.traveled_distance = 0;
xf86Msg(X_CONFIG, "%s: EmulateWheelButton: %d, "
"EmulateWheelInertia: %d, "
"EmulateWheelTimeout: %d\n",
pInfo->name, pEvdev->emulateWheel.button, inertia, timeout);
}
#ifdef HAVE_PROPERTIES
int
EvdevWheelEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
BOOL checkonly)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (atom == prop_wheel_emu)
{
if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
{
pEvdev->emulateWheel.enabled = *((BOOL*)val->data);
/* Don't enable with zero inertia, otherwise we may get stuck in an
* infinite loop */
if (pEvdev->emulateWheel.inertia <= 0)
{
pEvdev->emulateWheel.inertia = 10;
/* We may get here before the property is actually enabled */
if (prop_wheel_inertia)
XIChangeDeviceProperty(dev, prop_wheel_inertia, XA_INTEGER,
16, PropModeReplace, 1,
&pEvdev->emulateWheel.inertia, TRUE);
}
/* Don't enable with negative timeout */
if (pEvdev->emulateWheel.timeout < 0)
{
pEvdev->emulateWheel.timeout = 200;
XIChangeDeviceProperty(dev, prop_wheel_timeout, XA_INTEGER, 16,
PropModeReplace, 1,
&pEvdev->emulateWheel.timeout, TRUE);
}
}
}
else if (atom == prop_wheel_button)
{
int bt = *((CARD8*)val->data);
if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (bt < 0 || bt >= EVDEV_MAXBUTTONS)
return BadValue;
if (!checkonly)
pEvdev->emulateWheel.button = bt;
} else if (atom == prop_wheel_axismap)
{
if (val->format != 8 || val->size != 4 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
{
pEvdev->emulateWheel.X.up_button = *((CARD8*)val->data);
pEvdev->emulateWheel.X.down_button = *(((CARD8*)val->data) + 1);
pEvdev->emulateWheel.Y.up_button = *(((CARD8*)val->data) + 2);
pEvdev->emulateWheel.Y.down_button = *(((CARD8*)val->data) + 3);
}
} else if (atom == prop_wheel_inertia)
{
int inertia = *((CARD16*)val->data);
if (val->format != 16 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (inertia < 0)
return BadValue;
if (!checkonly)
pEvdev->emulateWheel.inertia = inertia;
} else if (atom == prop_wheel_timeout)
{
int timeout = *((CARD16*)val->data);
if (val->format != 16 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (timeout < 0)
return BadValue;
if (!checkonly)
pEvdev->emulateWheel.timeout = timeout;
}
return Success;
}
void
EvdevWheelEmuInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
int rc = TRUE;
char vals[4];
if (!dev->button) /* don't init prop for keyboards */
return;
prop_wheel_emu = MakeAtom(EVDEV_PROP_WHEEL, strlen(EVDEV_PROP_WHEEL), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_emu, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateWheel.enabled, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_wheel_emu, FALSE);
vals[0] = pEvdev->emulateWheel.X.up_button;
vals[1] = pEvdev->emulateWheel.X.down_button;
vals[2] = pEvdev->emulateWheel.Y.up_button;
vals[3] = pEvdev->emulateWheel.Y.down_button;
prop_wheel_axismap = MakeAtom(EVDEV_PROP_WHEEL_AXES, strlen(EVDEV_PROP_WHEEL_AXES), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_axismap, XA_INTEGER, 8,
PropModeReplace, 4, vals, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_wheel_axismap, FALSE);
prop_wheel_inertia = MakeAtom(EVDEV_PROP_WHEEL_INERTIA, strlen(EVDEV_PROP_WHEEL_INERTIA), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_inertia, XA_INTEGER, 16,
PropModeReplace, 1,
&pEvdev->emulateWheel.inertia, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_wheel_inertia, FALSE);
prop_wheel_timeout = MakeAtom(EVDEV_PROP_WHEEL_TIMEOUT, strlen(EVDEV_PROP_WHEEL_TIMEOUT), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_timeout, XA_INTEGER, 16,
PropModeReplace, 1,
&pEvdev->emulateWheel.timeout, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_wheel_timeout, FALSE);
prop_wheel_button = MakeAtom(EVDEV_PROP_WHEEL_BUTTON, strlen(EVDEV_PROP_WHEEL_BUTTON), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_button, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateWheel.button, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_wheel_button, FALSE);
XIRegisterPropertyHandler(dev, EvdevWheelEmuSetProperty, NULL, NULL);
}
#endif

View File

@@ -23,7 +23,6 @@
* Authors:
* Kristian Høgsberg (krh@redhat.com)
* Adam Jackson (ajax@redhat.com)
* Peter Hutterer (peter.hutterer@redhat.com)
*/
#ifdef HAVE_CONFIG_H
@@ -31,26 +30,25 @@
#endif
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
#include <X11/extensions/XIproto.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <misc.h>
#include <xf86.h>
#include <xf86str.h>
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
#include <exevents.h>
#include <xorgVersion.h>
#ifdef XKB
#include <xkbsrv.h>
#endif
#include <mipointer.h>
#include "evdev.h"
#ifdef HAVE_PROPERTIES
#include <X11/Xatom.h>
#include <evdev-properties.h>
#endif
#include <xf86Module.h>
#include <errno.h>
#include <fcntl.h>
/* 2.4 compatibility */
#ifndef EVIOCGRAB
@@ -74,7 +72,6 @@
#define EVDEV_RELATIVE_EVENTS (1 << 2)
#define EVDEV_ABSOLUTE_EVENTS (1 << 3)
#define EVDEV_TOUCHPAD (1 << 4)
#define EVDEV_INITIALIZED (1 << 5) /* WheelInit etc. called already? */
#define MIN_KEYCODE 8
#define GLYPHS_PER_KEY 2
@@ -90,25 +87,14 @@
#define MODEFLAG 8
#define COMPOSEFLAG 16
static const char *evdevDefaults[] = {
"XkbRules", "evdev",
"XkbRules", "base",
"XkbModel", "evdev",
"XkbLayout", "us",
NULL
};
static int EvdevOn(DeviceIntPtr);
static int EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare);
#ifdef HAVE_PROPERTIES
static void EvdevInitProperty(DeviceIntPtr dev);
static int EvdevSetProperty(DeviceIntPtr dev, Atom atom,
XIPropertyValuePtr val, BOOL checkonly);
static Atom prop_invert = 0;
static Atom prop_reopen = 0;
#endif
static void
SetXkbOption(InputInfoPtr pInfo, char *name, char **option)
{
@@ -144,9 +130,6 @@ PostButtonClicks(InputInfoPtr pInfo, int button, int count)
static void
PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
{
int code = ev->code + MIN_KEYCODE;
static char warned[KEY_MAX];
/* filter repeat events for chording keys */
if (value == 2 &&
(ev->code == KEY_LEFTCTRL || ev->code == KEY_RIGHTCTRL ||
@@ -157,62 +140,7 @@ PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
ev->code == KEY_SCROLLLOCK)) /* XXX windows keys? */
return;
if (code > 255 && ev->code < KEY_MAX) {
if (!warned[ev->code])
xf86Msg(X_WARNING, "%s: unable to handle keycode %d\n",
pInfo->name, ev->code);
warned[ev->code] = 1;
}
xf86PostKeyboardEvent(pInfo->dev, code, value);
}
/**
* Coming back from resume may leave us with a file descriptor that can be
* opened but fails on the first read (ENODEV).
* In this case, try to open the device until it becomes available or until
* the predefined count expires.
*/
static CARD32
EvdevReopenTimer(OsTimerPtr timer, CARD32 time, pointer arg)
{
InputInfoPtr pInfo = (InputInfoPtr)arg;
EvdevPtr pEvdev = pInfo->private;
do {
pInfo->fd = open(pEvdev->device, O_RDWR, 0);
} while (pInfo->fd < 0 && errno == EINTR);
if (pInfo->fd != -1)
{
if (EvdevCacheCompare(pInfo, TRUE) == Success)
{
xf86Msg(X_INFO, "%s: Device reopened after %d attempts.\n", pInfo->name,
pEvdev->reopen_attempts - pEvdev->reopen_left + 1);
EvdevOn(pInfo->dev);
} else
{
xf86Msg(X_ERROR, "%s: Device has changed - disabling.\n",
pInfo->name);
DisableDevice(pInfo->dev);
close(pInfo->fd);
pInfo->fd = -1;
}
pEvdev->reopen_left = 0;
return 0;
}
pEvdev->reopen_left--;
if (!pEvdev->reopen_left)
{
xf86Msg(X_ERROR, "%s: Failed to reopen device after %d attempts.\n",
pInfo->name, pEvdev->reopen_attempts);
DisableDevice(pInfo->dev);
return 0;
}
return 100; /* come back in 100 ms */
xf86PostKeyboardEvent(pInfo->dev, ev->code + MIN_KEYCODE, value);
}
static void
@@ -222,7 +150,6 @@ EvdevReadInput(InputInfoPtr pInfo)
int len, value;
int dx, dy;
unsigned int abs;
unsigned int button;
EvdevPtr pEvdev = pInfo->private;
dx = 0;
@@ -234,29 +161,15 @@ EvdevReadInput(InputInfoPtr pInfo)
if (len != sizeof ev) {
/* The kernel promises that we always only read a complete
* event, so len != sizeof ev is an error. */
xf86Msg(X_ERROR, "%s: Read error: %s\n", pInfo->name, strerror(errno));
if (errno == ENODEV) /* May happen after resume */
{
xf86RemoveEnabledDevice(pInfo);
close(pInfo->fd);
pInfo->fd = -1;
pEvdev->reopen_left = pEvdev->reopen_attempts;
pEvdev->reopen_timer = TimerSet(NULL, 0, 100, EvdevReopenTimer, pInfo);
}
xf86Msg(X_ERROR, "Read error: %s\n", strerror(errno));
break;
}
/* Get the signed value, earlier kernels had this as unsigned */
value = ev.value;
switch (ev.type) {
case EV_REL:
/* Handle mouse wheel emulation */
if (EvdevWheelEmuFilterMotion(pInfo, &ev))
break;
switch (ev.code) {
case REL_X:
dx += value;
@@ -269,7 +182,7 @@ EvdevReadInput(InputInfoPtr pInfo)
case REL_WHEEL:
if (value > 0)
PostButtonClicks(pInfo, wheel_up_button, value);
else if (value < 0)
if (value < 0)
PostButtonClicks(pInfo, wheel_down_button, -value);
break;
@@ -277,7 +190,7 @@ EvdevReadInput(InputInfoPtr pInfo)
case REL_HWHEEL:
if (value > 0)
PostButtonClicks(pInfo, wheel_right_button, value);
else if (value < 0)
if (value < 0)
PostButtonClicks(pInfo, wheel_left_button, -value);
break;
}
@@ -303,35 +216,53 @@ EvdevReadInput(InputInfoPtr pInfo)
break;
switch (ev.code) {
/* swap here, pretend we're an X-conformant device. */
case BTN_LEFT:
if (!EvdevMBEmuFilterEvent(pInfo, ev.code, value))
xf86PostButtonEvent(pInfo->dev, 0, 1, value, 0, 0);
break;
case BTN_RIGHT:
if (!EvdevMBEmuFilterEvent(pInfo, ev.code, value))
xf86PostButtonEvent(pInfo->dev, 0, 3, value, 0, 0);
break;
case BTN_MIDDLE:
EvdevMBEmuEnable(pInfo, FALSE);
xf86PostButtonEvent(pInfo->dev, 0, 2, value, 0, 0);
break;
case BTN_SIDE:
case BTN_EXTRA:
case BTN_FORWARD:
case BTN_BACK:
case BTN_TASK:
xf86PostButtonEvent(pInfo->dev, 0, ev.code - BTN_LEFT + 5,
value, 0, 0);
break;
case BTN_TOUCH:
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_FINGER:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_FINGER:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
pEvdev->tool = value ? ev.code : 0;
break;
default:
button = EvdevUtilButtonEventToButtonNumber(ev.code);
/* Handle drag lock */
if (EvdevDragLockFilterEvent(pInfo, button, value))
if (ev.code > BTN_TASK && ev.code < KEY_OK) {
/* Some fancy mice with a lot of buttons generate
* button events between BTN_TASK and BTN_JOYSTICK */
if (ev.code < BTN_JOYSTICK)
xf86PostButtonEvent(pInfo->dev, 0,
ev.code - BTN_LEFT + 5,
value, 0, 0);
break;
}
if (EvdevWheelEmuFilterButton(pInfo, button, value))
break;
if (EvdevMBEmuFilterEvent(pInfo, button, value))
break;
if (button)
xf86PostButtonEvent(pInfo->dev, 0, button, value, 0, 0);
else
PostKbdEvent(pInfo, &ev, value);
PostKbdEvent(pInfo, &ev, value);
break;
}
break;
@@ -356,13 +287,8 @@ EvdevReadInput(InputInfoPtr pInfo)
}
}
if (dx != 0 || dy != 0) {
if (pEvdev->invert_x)
dx *= -1;
if (pEvdev->invert_y)
dy *= -1;
if (dx != 0 || dy != 0)
xf86PostMotionEvent(pInfo->dev, FALSE, 0, 2, dx, dy);
}
/*
* Some devices only generate valid abs coords when BTN_DIGI is
@@ -374,19 +300,12 @@ EvdevReadInput(InputInfoPtr pInfo)
* just works.
*/
if (abs && pEvdev->tool) {
int abs_x, abs_y;
abs_x = pEvdev->abs_x;
abs_y = pEvdev->abs_y;
if (pEvdev->invert_x)
abs_x = pEvdev->max_x - abs_x;
if (pEvdev->invert_y)
abs_y = pEvdev->max_y - abs_y;
xf86PostMotionEvent(pInfo->dev, TRUE, 0, 2, abs_x, abs_y);
xf86PostMotionEvent(pInfo->dev, TRUE, 0, 2,
pEvdev->abs_x, pEvdev->abs_y);
}
}
#define TestBit(bit, array) (array[(bit) / LONG_BITS]) & (1 << ((bit) % LONG_BITS))
#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8)))
static void
EvdevPtrCtrlProc(DeviceIntPtr device, PtrCtrl *ctrl)
@@ -687,7 +606,7 @@ EvdevAddKeyClass(DeviceIntPtr device)
static struct { KeySym keysym; CARD8 mask; } modifiers[] = {
{ XK_Shift_L, ShiftMask },
{ XK_Shift_R, ShiftMask },
{ XK_Shift_R, ShiftMask },
{ XK_Control_L, ControlMask },
{ XK_Control_R, ControlMask },
{ XK_Caps_Lock, LockMask },
@@ -700,6 +619,11 @@ EvdevAddKeyClass(DeviceIntPtr device)
{ XK_Mode_switch, AltLangMask }
};
/* TODO:
* Ctrl-Alt-Backspace and other Ctrl-Alt-stuff should work
* Get keyboard repeat under control (right now caps lock repeats!)
*/
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
@@ -731,12 +655,12 @@ EvdevAddKeyClass(DeviceIntPtr device)
#ifdef XKB
else
{
/* sorry, no rules change allowed for you */
xf86ReplaceStrOption(pInfo->options, "xkb_rules", "evdev");
SetXkbOption(pInfo, "xkb_rules", &pEvdev->xkb_rules);
if (!pEvdev->xkb_rules)
SetXkbOption(pInfo, "XkbRules", &pEvdev->xkb_rules);
/* sorry, no model change allowed for you */
xf86ReplaceStrOption(pInfo->options, "xkb_model", "evdev");
SetXkbOption(pInfo, "xkb_model", &pEvdev->xkb_model);
if (!pEvdev->xkb_model)
SetXkbOption(pInfo, "XkbModel", &pEvdev->xkb_rules);
SetXkbOption(pInfo, "xkb_layout", &pEvdev->xkb_layout);
if (!pEvdev->xkb_layout)
SetXkbOption(pInfo, "XkbLayout", &pEvdev->xkb_layout);
@@ -851,71 +775,22 @@ EvdevAddRelClass(DeviceIntPtr device)
static int
EvdevAddButtonClass(DeviceIntPtr device)
{
CARD8 map[32];
InputInfoPtr pInfo;
EvdevPtr pEvdev;
int i;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
/* FIXME: count number of actual buttons */
if (!InitButtonClassDeviceStruct(device, ArrayLength(pEvdev->btnmap),
pEvdev->btnmap))
for (i = 0; i < ArrayLength(map); i++)
map[i] = i;
if (!InitButtonClassDeviceStruct(device, ArrayLength(map), map))
return !Success;
return Success;
}
/**
* Init the button mapping for the device. By default, this is a 1:1 mapping,
* i.e. Button 1 maps to Button 1, Button 2 to 2, etc.
*
* If a mapping has been specified, the mapping is the default, with the
* user-defined ones overwriting the defaults.
* i.e. a user-defined mapping of "3 2 1" results in a mapping of 3 2 1 4 5 6 ...
*
* Invalid button mappings revert to the default.
*
* Note that index 0 is unused, button 0 does not exist.
* This mapping is initialised for all devices, but only applied if the device
* has buttons (in EvdevAddButtonClass).
*/
static void
EvdevInitButtonMapping(InputInfoPtr pInfo)
{
int i, nbuttons = 1;
char *mapping = NULL;
EvdevPtr pEvdev = pInfo->private;
/* Check for user-defined button mapping */
if ((mapping = xf86CheckStrOption(pInfo->options, "ButtonMapping", NULL)))
{
char *s = " ";
int btn = 0;
xf86Msg(X_CONFIG, "%s: ButtonMapping '%s'\n", pInfo->name, mapping);
while (s && *s != '\0' && nbuttons < EVDEV_MAXBUTTONS)
{
btn = strtol(mapping, &s, 10);
if (s == mapping || btn < 0 || btn > EVDEV_MAXBUTTONS)
{
xf86Msg(X_ERROR,
"%s: ... Invalid button mapping. Using defaults\n",
pInfo->name);
nbuttons = 1; /* ensure defaults start at 1 */
break;
}
pEvdev->btnmap[nbuttons++] = btn;
mapping = s;
}
}
for (i = nbuttons; i < ArrayLength(pEvdev->btnmap); i++)
pEvdev->btnmap[i] = i;
}
static int
EvdevInit(DeviceIntPtr device)
{
@@ -945,65 +820,9 @@ EvdevInit(DeviceIntPtr device)
else if (pEvdev->flags & EVDEV_ABSOLUTE_EVENTS)
EvdevAddAbsClass(device);
#ifdef HAVE_PROPERTIES
/* We drop the return value, the only time we ever want the handlers to
* unregister is when the device dies. In which case we don't have to
* unregister anyway */
XIRegisterPropertyHandler(device, EvdevSetProperty, NULL, NULL);
EvdevInitProperty(device);
EvdevMBEmuInitProperty(device);
EvdevWheelEmuInitProperty(device);
EvdevDragLockInitProperty(device);
#endif
return Success;
}
/**
* Init all extras (wheel emulation, etc.) and grab the device.
*
* Coming from a resume, the grab may fail with ENODEV. In this case, we set a
* timer to wake up and try to reopen the device later.
*/
static int
EvdevOn(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
int rc = 0;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
if (pInfo->fd != -1 && !pEvdev->kernel24 &&
(rc = ioctl(pInfo->fd, EVIOCGRAB, (void *)1)))
{
xf86Msg(X_WARNING, "%s: Grab failed (%s)\n", pInfo->name,
strerror(errno));
/* ENODEV - device has disappeared after resume */
if (rc && errno == ENODEV)
{
close(pInfo->fd);
pInfo->fd = -1;
}
}
if (pInfo->fd == -1)
{
pEvdev->reopen_left = pEvdev->reopen_attempts;
pEvdev->reopen_timer = TimerSet(NULL, 0, 100, EvdevReopenTimer, pInfo);
} else
{
xf86AddEnabledDevice(pInfo);
pEvdev->flags |= EVDEV_INITIALIZED;
device->public.on = TRUE;
}
return Success;
}
static int
EvdevProc(DeviceIntPtr device, int what)
{
@@ -1019,160 +838,66 @@ EvdevProc(DeviceIntPtr device, int what)
return EvdevInit(device);
case DEVICE_ON:
return EvdevOn(device);
if (!pEvdev->kernel24 && ioctl(pInfo->fd, EVIOCGRAB, (void *)1))
xf86Msg(X_WARNING, "%s: Grab failed (%s)\n", pInfo->name,
strerror(errno));
if (errno != ENODEV)
{
xf86AddEnabledDevice(pInfo);
if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
EvdevMBEmuPreInit(pInfo);
device->public.on = TRUE;
}
break;
case DEVICE_OFF:
if (pInfo->fd != -1)
{
if (!pEvdev->kernel24 && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
strerror(errno));
xf86RemoveEnabledDevice(pInfo);
close(pInfo->fd);
pInfo->fd = -1;
}
if (pEvdev->flags & EVDEV_INITIALIZED)
EvdevMBEmuFinalize(pInfo);
pEvdev->flags &= ~EVDEV_INITIALIZED;
if (!pEvdev->kernel24 && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
strerror(errno));
xf86RemoveEnabledDevice(pInfo);
EvdevMBEmuFinalize(pInfo);
device->public.on = FALSE;
if (pEvdev->reopen_timer)
{
TimerFree(pEvdev->reopen_timer);
pEvdev->reopen_timer = NULL;
}
break;
case DEVICE_CLOSE:
xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
if (pInfo->fd != -1) {
close(pInfo->fd);
pInfo->fd = -1;
}
break;
}
return Success;
}
/**
* Get as much information as we can from the fd and cache it.
* If compare is True, then the information retrieved will be compared to the
* one already cached. If the information does not match, then this function
* returns an error.
*
* @return Success if the information was cached, or !Success otherwise.
*/
static int
EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare)
static Bool
EvdevConvert(InputInfoPtr pInfo, int first, int num, int v0, int v1, int v2,
int v3, int v4, int v5, int *x, int *y)
{
EvdevPtr pEvdev = pInfo->private;
int i;
int screenWidth = screenInfo.screens[pEvdev->screen]->width;
int screenHeight = screenInfo.screens[pEvdev->screen]->height;
char name[1024] = {0};
long bitmask[NBITS(EV_MAX)] = {0};
long key_bitmask[NBITS(KEY_MAX)] = {0};
long rel_bitmask[NBITS(REL_MAX)] = {0};
long abs_bitmask[NBITS(ABS_MAX)] = {0};
long led_bitmask[NBITS(LED_MAX)] = {0};
struct input_absinfo absinfo[ABS_MAX];
if (first != 0 || num != 2)
return FALSE;
if (ioctl(pInfo->fd,
EVIOCGNAME(sizeof(name) - 1), name) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
goto error;
/* on absolute touchpads, don't warp on initial touch */
if (pEvdev->flags & EVDEV_TOUCHPAD) {
*x = v0;
*y = v0;
return TRUE;
}
if (compare && strcmp(pEvdev->name, name))
goto error;
if (ioctl(pInfo->fd,
EVIOCGBIT(0, sizeof(bitmask)), bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGNAME failed: %s\n", strerror(errno));
goto error;
}
if (compare && memcmp(pEvdev->bitmask, bitmask, sizeof(bitmask)))
goto error;
if (ioctl(pInfo->fd,
EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGBIT failed: %s\n", strerror(errno));
goto error;
}
if (compare && memcmp(pEvdev->rel_bitmask, rel_bitmask, sizeof(rel_bitmask)))
goto error;
if (ioctl(pInfo->fd,
EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGBIT failed: %s\n", strerror(errno));
goto error;
}
if (compare && memcmp(pEvdev->abs_bitmask, abs_bitmask, sizeof(abs_bitmask)))
goto error;
if (ioctl(pInfo->fd,
EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGBIT failed: %s\n", strerror(errno));
goto error;
}
if (compare && memcmp(pEvdev->key_bitmask, key_bitmask, sizeof(key_bitmask)))
goto error;
if (ioctl(pInfo->fd,
EVIOCGBIT(EV_LED, sizeof(led_bitmask)), led_bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGBIT failed: %s\n", strerror(errno));
goto error;
}
if (compare && memcmp(pEvdev->led_bitmask, led_bitmask, sizeof(led_bitmask)))
goto error;
memset(absinfo, 0, sizeof(absinfo));
for (i = 0; i < ABS_MAX; i++)
{
if (TestBit(i, abs_bitmask))
{
if (ioctl(pInfo->fd, EVIOCGABS(i), &absinfo[i]) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGABS failed: %s\n", strerror(errno));
goto error;
}
}
}
if (compare && memcmp(pEvdev->absinfo, absinfo, sizeof(absinfo)))
goto error;
/* cache info */
if (!compare)
{
strcpy(pEvdev->name, name);
memcpy(pEvdev->bitmask, bitmask, sizeof(bitmask));
memcpy(pEvdev->key_bitmask, key_bitmask, sizeof(key_bitmask));
memcpy(pEvdev->rel_bitmask, rel_bitmask, sizeof(rel_bitmask));
memcpy(pEvdev->abs_bitmask, abs_bitmask, sizeof(abs_bitmask));
memcpy(pEvdev->led_bitmask, led_bitmask, sizeof(led_bitmask));
memcpy(pEvdev->absinfo, absinfo, sizeof(absinfo));
}
return Success;
error:
return !Success;
*x = (v0 - pEvdev->min_x) * screenWidth / (pEvdev->max_x - pEvdev->min_x);
*y = (v1 - pEvdev->min_y) * screenHeight / (pEvdev->max_y - pEvdev->min_y);
return TRUE;
}
static int
EvdevProbe(InputInfoPtr pInfo)
{
long key_bitmask[NBITS(KEY_MAX)];
long rel_bitmask[NBITS(REL_MAX)];
long abs_bitmask[NBITS(ABS_MAX)];
int i, has_axes, has_keys, num_buttons;
char key_bitmask[(KEY_MAX + 7) / 8];
char rel_bitmask[(REL_MAX + 7) / 8];
char abs_bitmask[(ABS_MAX + 7) / 8];
int i, has_axes, has_buttons, has_keys;
EvdevPtr pEvdev = pInfo->private;
if (ioctl(pInfo->fd, EVIOCGRAB, (void *)1)) {
@@ -1187,7 +912,7 @@ EvdevProbe(InputInfoPtr pInfo)
ioctl(pInfo->fd, EVIOCGRAB, (void *)0);
}
if (ioctl(pInfo->fd,
if (ioctl(pInfo->fd,
EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) < 0) {
xf86Msg(X_ERROR, "ioctl EVIOCGBIT failed: %s\n", strerror(errno));
return 1;
@@ -1206,15 +931,15 @@ EvdevProbe(InputInfoPtr pInfo)
}
has_axes = FALSE;
has_buttons = FALSE;
has_keys = FALSE;
num_buttons = 0;
if (TestBit(REL_X, rel_bitmask) && TestBit(REL_Y, rel_bitmask)) {
xf86Msg(X_INFO, "%s: Found x and y relative axes\n", pInfo->name);
pEvdev->flags |= EVDEV_RELATIVE_EVENTS;
has_axes = TRUE;
}
if (TestBit(ABS_X, abs_bitmask) && TestBit(ABS_Y, abs_bitmask)) {
xf86Msg(X_INFO, "%s: Found x and y absolute axes\n", pInfo->name);
pEvdev->flags |= EVDEV_ABSOLUTE_EVENTS;
@@ -1226,19 +951,10 @@ EvdevProbe(InputInfoPtr pInfo)
has_axes = TRUE;
}
/* count all buttons */
for (i = BTN_MISC; i < BTN_JOYSTICK; i++)
{
if (TestBit(i, key_bitmask))
num_buttons++;
}
if (num_buttons)
{
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
pEvdev->buttons = num_buttons;
xf86Msg(X_INFO, "%s: Found %d mouse buttons\n", pInfo->name,
num_buttons);
if (TestBit(BTN_LEFT, key_bitmask)) {
xf86Msg(X_INFO, "%s: Found mouse buttons\n", pInfo->name);
pEvdev->flags |= EVDEV_BUTTON_EVENTS;
has_buttons = TRUE;
}
for (i = 0; i < BTN_MISC; i++)
@@ -1251,9 +967,9 @@ EvdevProbe(InputInfoPtr pInfo)
has_keys = TRUE;
}
if (has_axes && num_buttons) {
if (has_axes && has_buttons) {
xf86Msg(X_INFO, "%s: Configuring as mouse\n", pInfo->name);
pInfo->flags |= XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
pInfo->flags |= XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
XI86_CONFIGURED;
pInfo->type_name = XI_MOUSE;
}
@@ -1278,11 +994,11 @@ EvdevProbe(InputInfoPtr pInfo)
return 0;
}
static InputInfoPtr
EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
{
InputInfoPtr pInfo;
MessageType deviceFrom = X_CONFIG;
const char *device;
EvdevPtr pEvdev;
@@ -1299,7 +1015,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
pInfo->control_proc = NULL;
pInfo->close_proc = NULL;
pInfo->switch_mode = NULL;
pInfo->conversion_proc = NULL;
pInfo->conversion_proc = EvdevConvert;
pInfo->reverse_conversion_proc = NULL;
pInfo->dev = NULL;
pInfo->private_flags = 0;
@@ -1312,27 +1028,29 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
pInfo->private = pEvdev;
xf86CollectInputOptions(pInfo, evdevDefaults, NULL);
xf86ProcessCommonOptions(pInfo, pInfo->options);
xf86ProcessCommonOptions(pInfo, pInfo->options);
pEvdev->screen = xf86SetIntOption(pInfo->options, "ScreenNumber", 0);
/*
* We initialize pEvdev->tool to 1 so that device that doesn't use
* proximity will still report events.
*/
pEvdev->tool = 1;
device = xf86CheckStrOption(dev->commonOptions, "Device", NULL);
device = xf86CheckStrOption(dev->commonOptions, "Path", NULL);
if (!device)
device = xf86CheckStrOption(dev->commonOptions, "Device", NULL);
if (!device) {
xf86Msg(X_ERROR, "%s: No device specified.\n", pInfo->name);
xf86DeleteInput(pInfo, 0);
return NULL;
}
pEvdev->device = device;
xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
xf86Msg(deviceFrom, "%s: Device: \"%s\"\n", pInfo->name, device);
do {
pInfo->fd = open(device, O_RDWR, 0);
} while (pInfo->fd < 0 && errno == EINTR);
}
while (pInfo->fd < 0 && errno == EINTR);
if (pInfo->fd < 0) {
xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", device);
@@ -1340,13 +1058,8 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
return NULL;
}
pEvdev->reopen_attempts = xf86SetIntOption(pInfo->options, "ReopenAttempts", 10);
pEvdev->invert_x = xf86SetBoolOption(pInfo->options, "InvertX", FALSE);
pEvdev->invert_y = xf86SetBoolOption(pInfo->options, "InvertY", FALSE);
pEvdev->noXkb = noXkbExtension; /* parse the XKB options during kbd setup */
EvdevInitButtonMapping(pInfo);
pEvdev->noXkb = noXkbExtension;
/* parse the XKB options during kbd setup */
if (EvdevProbe(pInfo)) {
close(pInfo->fd);
@@ -1354,15 +1067,6 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
return NULL;
}
EvdevCacheCompare(pInfo, FALSE); /* cache device data */
if (pEvdev->flags & EVDEV_BUTTON_EVENTS)
{
EvdevMBEmuPreInit(pInfo);
EvdevWheelEmuPreInit(pInfo);
EvdevDragLockPreInit(pInfo);
}
return pInfo;
}
@@ -1397,8 +1101,8 @@ static XF86ModuleVersionInfo EvdevVersionRec =
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
0, /* Missing from SDK: XORG_VERSION_CURRENT, */
1, 0, 0,
ABI_CLASS_XINPUT,
ABI_XINPUT_VERSION,
MOD_CLASS_XINPUT,
@@ -1411,117 +1115,3 @@ _X_EXPORT XF86ModuleData evdevModuleData =
EvdevPlug,
EvdevUnplug
};
/* Return an index value for a given button event code
* returns 0 on non-button event.
*/
unsigned int
EvdevUtilButtonEventToButtonNumber(int code)
{
unsigned int button = 0;
switch(code) {
case BTN_LEFT:
button = 1;
break;
case BTN_RIGHT:
button = 3;
break;
case BTN_MIDDLE:
button = 2;
break;
case BTN_SIDE:
case BTN_EXTRA:
case BTN_FORWARD:
case BTN_BACK:
case BTN_TASK:
button = (code - BTN_LEFT + 5);
break;
default:
if ((code > BTN_TASK) && (code < KEY_OK)) {
if (code < BTN_JOYSTICK)
button = (code - BTN_LEFT + 5);
}
}
if (button > EVDEV_MAXBUTTONS)
return 0;
return button;
}
#ifdef HAVE_PROPERTIES
static void
EvdevInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
int rc;
BOOL invert[2];
char reopen;
if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS))
{
invert[0] = pEvdev->invert_x;
invert[1] = pEvdev->invert_y;
prop_invert = MakeAtom(EVDEV_PROP_INVERT_AXES, strlen(EVDEV_PROP_INVERT_AXES), TRUE);
rc = XIChangeDeviceProperty(dev, prop_invert, XA_INTEGER, 8,
PropModeReplace, 2,
invert, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_invert, FALSE);
}
prop_reopen = MakeAtom(EVDEV_PROP_REOPEN, strlen(EVDEV_PROP_REOPEN),
TRUE);
reopen = pEvdev->reopen_attempts;
rc = XIChangeDeviceProperty(dev, prop_reopen, XA_INTEGER, 8,
PropModeReplace, 1, &reopen, FALSE);
if (rc != Success)
return;
XISetDevicePropertyDeletable(dev, prop_reopen, FALSE);
}
static int
EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
BOOL checkonly)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
if (atom == prop_invert)
{
BOOL* data;
if (val->format != 8 || val->size != 2 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
{
data = (BOOL*)val->data;
pEvdev->invert_x = data[0];
pEvdev->invert_y = data[1];
}
} else if (atom == prop_reopen)
{
if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
return BadMatch;
if (!checkonly)
pEvdev->reopen_attempts = *((CARD8*)val->data);
}
return Success;
}
#endif

View File

@@ -35,37 +35,18 @@
#include <xf86Xinput.h>
#include <xf86_OSproc.h>
#ifdef XKB
#include <xkbstr.h>
#if defined(XKB)
/* XXX VERY WRONG. this is a client side header. */
#include <X11/extensions/XKBstr.h>
#endif
#define EVDEV_MAXBUTTONS 32
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
#define HAVE_PROPERTIES 1
#endif
#define LONG_BITS (sizeof(long) * 8)
#define NBITS(x) (((x) + LONG_BITS - 1) / LONG_BITS)
/* axis specific data for wheel emulation */
typedef struct {
int up_button;
int down_button;
int traveled_distance;
} WheelAxis, *WheelAxisPtr;
typedef struct {
const char *device;
int kernel24;
int screen;
int min_x, min_y, max_x, max_y;
int abs_x, abs_y, old_x, old_y;
int flags;
int tool;
int buttons; /* number of buttons */
BOOL invert_x;
BOOL invert_y;
/* XKB stuff has to be per-device rather than per-driver */
int noXkb;
@@ -86,41 +67,8 @@ typedef struct {
Time expires; /* time of expiry */
Time timeout;
} emulateMB;
struct {
int meta; /* meta key to lock any button */
BOOL meta_state; /* meta_button state */
unsigned int lock_pair[EVDEV_MAXBUTTONS]; /* specify a meta/lock pair */
BOOL lock_state[EVDEV_MAXBUTTONS]; /* state of any locked buttons */
} dragLock;
struct {
BOOL enabled;
int button;
int button_state;
int inertia;
WheelAxis X;
WheelAxis Y;
Time expires; /* time of expiry */
Time timeout;
} emulateWheel;
unsigned char btnmap[32]; /* config-file specified button mapping */
int reopen_attempts; /* max attempts to re-open after read failure */
int reopen_left; /* number of attempts left to re-open the device */
OsTimerPtr reopen_timer;
/* Cached info from device. */
char name[1024];
long bitmask[NBITS(EV_MAX)];
long key_bitmask[NBITS(KEY_MAX)];
long rel_bitmask[NBITS(REL_MAX)];
long abs_bitmask[NBITS(ABS_MAX)];
long led_bitmask[NBITS(LED_MAX)];
struct input_absinfo absinfo[ABS_MAX];
} EvdevRec, *EvdevPtr;
unsigned int EvdevUtilButtonEventToButtonNumber(int code);
/* Middle Button emulation */
int EvdevMBEmuTimer(InputInfoPtr);
BOOL EvdevMBEmuFilterEvent(InputInfoPtr, int, BOOL);
@@ -130,18 +78,4 @@ void EvdevMBEmuPreInit(InputInfoPtr);
void EvdevMBEmuFinalize(InputInfoPtr);
void EvdevMBEmuEnable(InputInfoPtr, BOOL);
/* Mouse Wheel emulation */
void EvdevWheelEmuPreInit(InputInfoPtr pInfo);
BOOL EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value);
BOOL EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv);
/* Draglock code */
void EvdevDragLockPreInit(InputInfoPtr pInfo);
BOOL EvdevDragLockFilterEvent(InputInfoPtr pInfo, unsigned int button, int value);
#ifdef HAVE_PROPERTIES
void EvdevMBEmuInitProperty(DeviceIntPtr);
void EvdevWheelEmuInitProperty(DeviceIntPtr);
void EvdevDragLockInitProperty(DeviceIntPtr);
#endif
#endif

View File

@@ -1,6 +0,0 @@
sdkdir=@sdkdir@
Name: xorg-evdev
Description: X.Org evdev input driver.
Version: @PACKAGE_VERSION@
Cflags: -I${sdkdir}