mirror of
https://github.com/X11Libre/xf86-input-evdev.git
synced 2026-04-14 11:44:16 +00:00
Compare commits
69 Commits
xf86-input
...
xf86-input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7850a4042 | ||
|
|
bd4102af6e | ||
|
|
22e816eb32 | ||
|
|
b6b377fe9a | ||
|
|
3772676fd6 | ||
|
|
4f05afd495 | ||
|
|
c6964dd28a | ||
|
|
175af93bdb | ||
|
|
7c3c7f83d0 | ||
|
|
aa6399fdb9 | ||
|
|
1d86f5dec1 | ||
|
|
fbd86e2530 | ||
|
|
9ea1f9a695 | ||
|
|
57b54ee399 | ||
|
|
f2dc0681fe | ||
|
|
3fa49dfcab | ||
|
|
941391ca34 | ||
|
|
2144f7d834 | ||
|
|
61b4e88e01 | ||
|
|
9ee70943ec | ||
|
|
415b6ffa95 | ||
|
|
f4ba2bd785 | ||
|
|
2e5f68754f | ||
|
|
8fdb2abb6f | ||
|
|
ca0fb396f1 | ||
|
|
7967677789 | ||
|
|
36064dca90 | ||
|
|
8bf93709cb | ||
|
|
37373a223b | ||
|
|
d764dded18 | ||
|
|
f352598e45 | ||
|
|
69d6ff3e01 | ||
|
|
6f4634111a | ||
|
|
1f641d75ed | ||
|
|
2994825665 | ||
|
|
9bfd9e8a36 | ||
|
|
dcca28a59c | ||
|
|
db8b1ca5cf | ||
|
|
8cc0d0f285 | ||
|
|
aa1609285d | ||
|
|
b07ab6ea97 | ||
|
|
7bc48c666d | ||
|
|
880ad1e19a | ||
|
|
6ab23e4519 | ||
|
|
88eedea281 | ||
|
|
9a5a4fed3a | ||
|
|
0a3657d2ee | ||
|
|
dc2191285e | ||
|
|
255b9f6bbf | ||
|
|
aa117d49a5 | ||
|
|
b358f1eb3a | ||
|
|
33cc112ca1 | ||
|
|
3c43d880f1 | ||
|
|
5462898935 | ||
|
|
9243d338d1 | ||
|
|
71e9a69ed6 | ||
|
|
220e2dfb8f | ||
|
|
ddc1266374 | ||
|
|
98ecb5233b | ||
|
|
92ca3dc2e7 | ||
|
|
3fa28c8acd | ||
|
|
d9809d7edd | ||
|
|
b11439a176 | ||
|
|
740dc202f7 | ||
|
|
7ac0c4456d | ||
|
|
b4f6ab126d | ||
|
|
a3ea979c2b | ||
|
|
a7fb654a68 | ||
|
|
3f06825a44 |
@@ -23,11 +23,7 @@ AUTOMAKE_OPTIONS = foreign
|
|||||||
# Ensure headers are installed below $(prefix) for distcheck
|
# Ensure headers are installed below $(prefix) for distcheck
|
||||||
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
|
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
|
||||||
|
|
||||||
if BUILD_TEST
|
SUBDIRS = src man include
|
||||||
test_dir=test
|
|
||||||
endif
|
|
||||||
|
|
||||||
SUBDIRS = src man include $(test_dir)
|
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = xorg-evdev.pc
|
pkgconfig_DATA = xorg-evdev.pc
|
||||||
|
|||||||
33
configure.ac
33
configure.ac
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
AC_PREREQ(2.57)
|
AC_PREREQ(2.57)
|
||||||
AC_INIT([xf86-input-evdev],
|
AC_INIT([xf86-input-evdev],
|
||||||
2.1.99.1,
|
2.3.2,
|
||||||
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
|
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
|
||||||
xf86-input-evdev)
|
xf86-input-evdev)
|
||||||
|
|
||||||
@@ -32,16 +32,16 @@ AM_INIT_AUTOMAKE([dist-bzip2])
|
|||||||
|
|
||||||
AM_MAINTAINER_MODE
|
AM_MAINTAINER_MODE
|
||||||
|
|
||||||
# Require xorg-macros: XORG_CWARNFLAGS, XORG_CHANGELOG
|
# Require xorg-macros: XORG_DEFAULT_OPTIONS
|
||||||
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.2 or later before running autoconf/autogen])])
|
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.3 or later before running autoconf/autogen])])
|
||||||
XORG_MACROS_VERSION(1.2)
|
XORG_MACROS_VERSION(1.3)
|
||||||
AM_CONFIG_HEADER([config.h])
|
AM_CONFIG_HEADER([config.h])
|
||||||
|
|
||||||
# Checks for programs.
|
# Checks for programs.
|
||||||
AC_DISABLE_STATIC
|
AC_DISABLE_STATIC
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
XORG_CWARNFLAGS
|
XORG_DEFAULT_OPTIONS
|
||||||
|
|
||||||
AH_TOP([#include "xorg-server.h"])
|
AH_TOP([#include "xorg-server.h"])
|
||||||
|
|
||||||
@@ -53,24 +53,6 @@ AC_ARG_WITH(xorg-module-dir,
|
|||||||
inputdir=${moduledir}/input
|
inputdir=${moduledir}/input
|
||||||
AC_SUBST(inputdir)
|
AC_SUBST(inputdir)
|
||||||
|
|
||||||
# Enable building everything in the test/ directory. These are uinput-based
|
|
||||||
# devices that resemble random hardware that may or may not look like a mouse,
|
|
||||||
# keyboard, etc.
|
|
||||||
AC_ARG_ENABLE(testdevices,
|
|
||||||
AC_HELP_STRING([--enable-testdevices], [Build uinput-based test devices]),
|
|
||||||
[BUILD_TEST="yes"],
|
|
||||||
[BUILD_TEST="no"])
|
|
||||||
AM_CONDITIONAL([BUILD_TEST], [test "x$BUILD_TEST" = "xyes"])
|
|
||||||
|
|
||||||
if test "x$BUILD_TEST" = "xyes"; then
|
|
||||||
AC_CHECK_FUNC([dlopen], [],
|
|
||||||
AC_CHECK_LIB([dl], [dlopen], DLOPEN_LIBS="-ldl"))
|
|
||||||
AC_SUBST([DLOPEN_LIBS])
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Checks for extensions
|
|
||||||
XORG_DRIVER_CHECK_EXT(XINPUT, inputproto)
|
|
||||||
|
|
||||||
# Checks for pkg-config packages. We need to be able to override sdkdir
|
# Checks for pkg-config packages. We need to be able to override sdkdir
|
||||||
# to satisfy silly distcheck requirements.
|
# to satisfy silly distcheck requirements.
|
||||||
PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES)
|
PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES)
|
||||||
@@ -88,13 +70,8 @@ AC_HEADER_STDC
|
|||||||
DRIVER_NAME=evdev
|
DRIVER_NAME=evdev
|
||||||
AC_SUBST([DRIVER_NAME])
|
AC_SUBST([DRIVER_NAME])
|
||||||
|
|
||||||
XORG_MANPAGE_SECTIONS
|
|
||||||
XORG_RELEASE_VERSION
|
|
||||||
XORG_CHANGELOG
|
|
||||||
|
|
||||||
AC_OUTPUT([Makefile
|
AC_OUTPUT([Makefile
|
||||||
src/Makefile
|
src/Makefile
|
||||||
man/Makefile
|
man/Makefile
|
||||||
include/Makefile
|
include/Makefile
|
||||||
test/Makefile
|
|
||||||
xorg-evdev.pc])
|
xorg-evdev.pc])
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
#define EVDEV_PROP_WHEEL_INERTIA "Evdev Wheel Emulation Inertia"
|
#define EVDEV_PROP_WHEEL_INERTIA "Evdev Wheel Emulation Inertia"
|
||||||
/* CARD16 */
|
/* CARD16 */
|
||||||
#define EVDEV_PROP_WHEEL_TIMEOUT "Evdev Wheel Emulation Timeout"
|
#define EVDEV_PROP_WHEEL_TIMEOUT "Evdev Wheel Emulation Timeout"
|
||||||
/* CARD8, value range 0-32, 0 to disable a value */
|
/* CARD8, value range 0-32, 0 to always scroll */
|
||||||
#define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
|
#define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
|
||||||
|
|
||||||
/* Drag lock */
|
/* Drag lock */
|
||||||
|
|||||||
@@ -105,7 +105,10 @@ press/release events as specified for the
|
|||||||
.B XAxisMapping
|
.B XAxisMapping
|
||||||
and
|
and
|
||||||
.B YAxisMapping
|
.B YAxisMapping
|
||||||
settings. Default: 4. Property: "Evdev Wheel Emulation Button".
|
settings. If the button is 0 and
|
||||||
|
.BR EmulateWheel
|
||||||
|
is on, any motion of the device is converted into wheel events. Default: 4.
|
||||||
|
Property: "Evdev Wheel Emulation Button".
|
||||||
.TP 7
|
.TP 7
|
||||||
.BI "Option \*qEmulateWheelInertia\*q \*q" integer \*q
|
.BI "Option \*qEmulateWheelInertia\*q \*q" integer \*q
|
||||||
Specifies how far (in pixels) the pointer must move to generate button
|
Specifies how far (in pixels) the pointer must move to generate button
|
||||||
@@ -132,10 +135,34 @@ Default: disabled.
|
|||||||
.BI "Option \*qInvertY\*q \*q" Bool \*q
|
.BI "Option \*qInvertY\*q \*q" Bool \*q
|
||||||
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
|
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
|
||||||
.TP 7
|
.TP 7
|
||||||
|
.BI "Option \*qIgnoreRelativeAxes\*q \*q" Bool \*q
|
||||||
|
.TP 7
|
||||||
|
.BI "Option \*qIgnoreAbsoluteAxes\*q \*q" Bool \*q
|
||||||
|
Ignore the specified type of axis. Default: unset. The X server cannot deal
|
||||||
|
with devices that have both relative and absolute axes. Evdev tries to guess
|
||||||
|
wich axes to ignore given the device type and disables absolute axes for
|
||||||
|
mice and relative axes for tablets, touchscreens and touchpad. These options
|
||||||
|
allow to forcibly disable an axis type. Mouse wheel axes are exempt and will
|
||||||
|
work even if relative axes are ignored. No property, this configuration must
|
||||||
|
be set in the configuration.
|
||||||
|
.br
|
||||||
|
If either option is set to False, the driver will not ignore the specified
|
||||||
|
axes regardless of the presence of other axes. This may trigger buggy
|
||||||
|
behavior and events from this axis are always forwarded. Users are
|
||||||
|
discouraged from setting this option.
|
||||||
|
.TP 7
|
||||||
.BI "Option \*qReopenAttempts\*q \*q" integer \*q
|
.BI "Option \*qReopenAttempts\*q \*q" integer \*q
|
||||||
Number of reopen attempts after a read error occurs on the device (e.g. after
|
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.
|
waking up from suspend). In between each attempt is a 100ms wait. Default: 10.
|
||||||
.TP 7
|
.TP 7
|
||||||
|
.BI "Option \*qCalibration\*q \*q" "min-x max-x min-y max-y" \*q
|
||||||
|
Calibrates the X and Y axes for devices that need to scale to a different
|
||||||
|
coordinate system than reported to the X server. This feature is required
|
||||||
|
for devices that need to scale to a different coordinate system than
|
||||||
|
originally reported by the kernel (e.g. touchscreens). The scaling to the
|
||||||
|
custom coordinate system is done in-driver and the X server is unaware of
|
||||||
|
the transformation. Property: "Evdev Axis Calibration".
|
||||||
|
.TP 7
|
||||||
.BI "Option \*qSwapAxes\*q \*q" Bool \*q
|
.BI "Option \*qSwapAxes\*q \*q" Bool \*q
|
||||||
Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
|
Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
|
||||||
.TP 7
|
.TP 7
|
||||||
@@ -164,14 +191,12 @@ driver.
|
|||||||
.TP 7
|
.TP 7
|
||||||
.BI "Evdev Axis Calibration"
|
.BI "Evdev Axis Calibration"
|
||||||
4 32-bit values, order min-x, max-x, min-y, max-y or 0 values to disable
|
4 32-bit values, order min-x, max-x, min-y, max-y or 0 values to disable
|
||||||
run-time axis calibration. This feature is required for devices that need to
|
in-driver axis calibration.
|
||||||
scale to a different coordinate system than originally reported to the X
|
|
||||||
server, such as touchscreens that require run-time calibration.
|
|
||||||
.TP 7
|
.TP 7
|
||||||
.BI "Evdev Axis Inversion"
|
.BI "Evdev Axis Inversion"
|
||||||
2 boolean values (8 bit, 0 or 1), order X, Y. 1 inverts the axis.
|
2 boolean values (8 bit, 0 or 1), order X, Y. 1 inverts the axis.
|
||||||
.TP 7
|
.TP 7
|
||||||
.BI "Evdev Axis Swap"
|
.BI "Evdev Axes Swap"
|
||||||
1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
|
1 boolean value (8 bit, 0 or 1). 1 swaps x/y axes.
|
||||||
.TP 7
|
.TP 7
|
||||||
.BI "Evdev Drag Lock Buttons"
|
.BI "Evdev Drag Lock Buttons"
|
||||||
|
|||||||
@@ -147,18 +147,18 @@ EvdevDragLockPreInit(InputInfoPtr pInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Updates DragLock button state and firest button event messges */
|
/* Updates DragLock button state and fires button event messges */
|
||||||
void
|
void
|
||||||
EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
|
EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
|
||||||
{
|
{
|
||||||
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
||||||
BOOL state=0;
|
BOOL state = 0;
|
||||||
|
|
||||||
/* update button state */
|
/* update button state */
|
||||||
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
|
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
|
||||||
pEvdev->dragLock.lock_state[button - 1] = state;
|
pEvdev->dragLock.lock_state[button - 1] = state;
|
||||||
|
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, button, state, 0, 0);
|
EvdevQueueButtonEvent(pInfo, button, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Filter button presses looking for either a meta button or the
|
/* Filter button presses looking for either a meta button or the
|
||||||
@@ -256,7 +256,7 @@ EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
|
|||||||
pEvdev->dragLock.meta = meta;
|
pEvdev->dragLock.meta = meta;
|
||||||
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
|
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
|
||||||
}
|
}
|
||||||
} else
|
} else if ((val->size % 2) == 0)
|
||||||
{
|
{
|
||||||
CARD8* vals = (CARD8*)val->data;
|
CARD8* vals = (CARD8*)val->data;
|
||||||
|
|
||||||
@@ -269,10 +269,11 @@ EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
|
|||||||
pEvdev->dragLock.meta = 0;
|
pEvdev->dragLock.meta = 0;
|
||||||
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
|
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
|
||||||
|
|
||||||
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
|
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i += 2)
|
||||||
pEvdev->dragLock.lock_pair[i] = vals[i];
|
pEvdev->dragLock.lock_pair[vals[i] - 1] = vals[i + 1];
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
return BadMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
|
|||||||
12
src/emuMB.c
12
src/emuMB.c
@@ -198,7 +198,7 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
|
|||||||
|
|
||||||
pEvdev->emulateMB.pending = FALSE;
|
pEvdev->emulateMB.pending = FALSE;
|
||||||
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
|
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
|
||||||
pEvdev->emulateMB.state =
|
pEvdev->emulateMB.state =
|
||||||
stateTab[pEvdev->emulateMB.state][4][2];
|
stateTab[pEvdev->emulateMB.state][4][2];
|
||||||
} else {
|
} else {
|
||||||
@@ -248,12 +248,12 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
|
|||||||
|
|
||||||
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
|
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
|
||||||
{
|
{
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
|
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
|
||||||
{
|
{
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,6 +327,9 @@ EvdevMBEmuPreInit(InputInfoPtr pInfo)
|
|||||||
void
|
void
|
||||||
EvdevMBEmuOn(InputInfoPtr pInfo)
|
EvdevMBEmuOn(InputInfoPtr pInfo)
|
||||||
{
|
{
|
||||||
|
if (!pInfo->dev->button) /* don't init for keyboards */
|
||||||
|
return;
|
||||||
|
|
||||||
RegisterBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
|
RegisterBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
|
||||||
EvdevMBEmuWakeupHandler,
|
EvdevMBEmuWakeupHandler,
|
||||||
(pointer)pInfo);
|
(pointer)pInfo);
|
||||||
@@ -335,6 +338,9 @@ EvdevMBEmuOn(InputInfoPtr pInfo)
|
|||||||
void
|
void
|
||||||
EvdevMBEmuFinalize(InputInfoPtr pInfo)
|
EvdevMBEmuFinalize(InputInfoPtr pInfo)
|
||||||
{
|
{
|
||||||
|
if (!pInfo->dev->button) /* don't cleanup for keyboards */
|
||||||
|
return;
|
||||||
|
|
||||||
RemoveBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
|
RemoveBlockAndWakeupHandlers (EvdevMBEmuBlockHandler,
|
||||||
EvdevMBEmuWakeupHandler,
|
EvdevMBEmuWakeupHandler,
|
||||||
(pointer)pInfo);
|
(pointer)pInfo);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ static Atom prop_wheel_button = 0;
|
|||||||
|
|
||||||
/* Local Funciton Prototypes */
|
/* Local Funciton Prototypes */
|
||||||
static BOOL EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char *axis_name);
|
static BOOL EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char *axis_name);
|
||||||
static void EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
|
static int EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
|
||||||
|
|
||||||
/* Filter mouse button events */
|
/* Filter mouse button events */
|
||||||
BOOL
|
BOOL
|
||||||
@@ -82,8 +82,7 @@ EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
|
|||||||
* If the button is released early enough emit the button
|
* If the button is released early enough emit the button
|
||||||
* press/release events
|
* press/release events
|
||||||
*/
|
*/
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
|
EvdevQueueButtonClicks(pInfo, button, 1);
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,38 +98,51 @@ BOOL
|
|||||||
EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
|
EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
|
||||||
{
|
{
|
||||||
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
||||||
WheelAxisPtr pAxis = NULL;
|
WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
|
||||||
int value = pEv->value;
|
int value = pEv->value;
|
||||||
int ms;
|
|
||||||
|
|
||||||
/* Has wheel emulation been configured to be enabled? */
|
/* Has wheel emulation been configured to be enabled? */
|
||||||
if (!pEvdev->emulateWheel.enabled)
|
if (!pEvdev->emulateWheel.enabled)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Handle our motion events if the emuWheel button is pressed*/
|
/* Handle our motion events if the emuWheel button is pressed
|
||||||
if (pEvdev->emulateWheel.button_state) {
|
* wheel button of 0 means always emulate wheel.
|
||||||
|
*/
|
||||||
|
if (pEvdev->emulateWheel.button_state || !pEvdev->emulateWheel.button) {
|
||||||
/* Just return if the timeout hasn't expired yet */
|
/* Just return if the timeout hasn't expired yet */
|
||||||
ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
|
if (pEvdev->emulateWheel.button)
|
||||||
if (ms > 0)
|
{
|
||||||
return TRUE;
|
int ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
|
||||||
|
if (ms > 0)
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* We don't want to intercept real mouse wheel events */
|
/* We don't want to intercept real mouse wheel events */
|
||||||
switch(pEv->code) {
|
switch(pEv->code) {
|
||||||
case REL_X:
|
case REL_X:
|
||||||
pAxis = &(pEvdev->emulateWheel.X);
|
pAxis = &(pEvdev->emulateWheel.X);
|
||||||
|
pOtherAxis = &(pEvdev->emulateWheel.Y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REL_Y:
|
case REL_Y:
|
||||||
pAxis = &(pEvdev->emulateWheel.Y);
|
pAxis = &(pEvdev->emulateWheel.Y);
|
||||||
|
pOtherAxis = &(pEvdev->emulateWheel.X);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we found REL_X or REL_Y, emulate a mouse wheel */
|
/* If we found REL_X or REL_Y, emulate a mouse wheel.
|
||||||
|
Reset the inertia of the other axis when a scroll event was sent
|
||||||
|
to avoid the buildup of erroneous scroll events if the user
|
||||||
|
doesn't move in a perfectly straight line.
|
||||||
|
*/
|
||||||
if (pAxis)
|
if (pAxis)
|
||||||
EvdevWheelEmuInertia(pInfo, pAxis, value);
|
{
|
||||||
|
if (EvdevWheelEmuInertia(pInfo, pAxis, value))
|
||||||
|
pOtherAxis->traveled_distance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Eat motion events while emulateWheel button pressed. */
|
/* Eat motion events while emulateWheel button pressed. */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@@ -139,17 +151,20 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simulate inertia for our emulated mouse wheel */
|
/* Simulate inertia for our emulated mouse wheel.
|
||||||
static void
|
Returns the number of wheel events generated.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
|
EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
|
||||||
{
|
{
|
||||||
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
||||||
int button;
|
int button;
|
||||||
int inertia;
|
int inertia;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
/* if this axis has not been configured, just eat the motion */
|
/* if this axis has not been configured, just eat the motion */
|
||||||
if (!axis->up_button)
|
if (!axis->up_button)
|
||||||
return;
|
return rc;
|
||||||
|
|
||||||
axis->traveled_distance += value;
|
axis->traveled_distance += value;
|
||||||
|
|
||||||
@@ -163,11 +178,11 @@ EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
|
|||||||
|
|
||||||
/* Produce button press events for wheel motion */
|
/* Produce button press events for wheel motion */
|
||||||
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
|
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
|
||||||
|
|
||||||
axis->traveled_distance -= inertia;
|
axis->traveled_distance -= inertia;
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
|
EvdevQueueButtonClicks(pInfo, button, 1);
|
||||||
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
|
rc++;
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Handle button mapping here to avoid code duplication,
|
/* Handle button mapping here to avoid code duplication,
|
||||||
@@ -201,8 +216,8 @@ EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char* axis_
|
|||||||
pAxis->down_button = down_button;
|
pAxis->down_button = down_button;
|
||||||
|
|
||||||
/* Update the number of buttons if needed */
|
/* Update the number of buttons if needed */
|
||||||
if (up_button > pEvdev->buttons) pEvdev->buttons = up_button;
|
if (up_button > pEvdev->num_buttons) pEvdev->num_buttons = up_button;
|
||||||
if (down_button > pEvdev->buttons) pEvdev->buttons = down_button;
|
if (down_button > pEvdev->num_buttons) pEvdev->num_buttons = down_button;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
xf86Msg(X_WARNING, "%s: Invalid %s value:\"%s\"\n",
|
xf86Msg(X_WARNING, "%s: Invalid %s value:\"%s\"\n",
|
||||||
@@ -285,8 +300,8 @@ EvdevWheelEmuPreInit(InputInfoPtr pInfo)
|
|||||||
|
|
||||||
/* Simpler to check just the largest value in this case */
|
/* Simpler to check just the largest value in this case */
|
||||||
/* XXX: we should post this to the server */
|
/* XXX: we should post this to the server */
|
||||||
if (5 > pEvdev->buttons)
|
if (5 > pEvdev->num_buttons)
|
||||||
pEvdev->buttons = 5;
|
pEvdev->num_buttons = 5;
|
||||||
|
|
||||||
/* Display default Configuration */
|
/* Display default Configuration */
|
||||||
xf86Msg(X_CONFIG, "%s: YAxisMapping: buttons %d and %d\n",
|
xf86Msg(X_CONFIG, "%s: YAxisMapping: buttons %d and %d\n",
|
||||||
@@ -337,15 +352,6 @@ EvdevWheelEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
|
|||||||
16, PropModeReplace, 1,
|
16, PropModeReplace, 1,
|
||||||
&pEvdev->emulateWheel.inertia, TRUE);
|
&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)
|
else if (atom == prop_wheel_button)
|
||||||
|
|||||||
1488
src/evdev.c
1488
src/evdev.c
File diff suppressed because it is too large
Load Diff
30
src/evdev.h
30
src/evdev.h
@@ -25,6 +25,7 @@
|
|||||||
* Kristian Høgsberg (krh@redhat.com)
|
* Kristian Høgsberg (krh@redhat.com)
|
||||||
* Adam Jackson (ajax@redhat.com)
|
* Adam Jackson (ajax@redhat.com)
|
||||||
* Peter Hutterer (peter@cs.unisa.edu.au)
|
* Peter Hutterer (peter@cs.unisa.edu.au)
|
||||||
|
* Oliver McFadden (oliver.mcfadden@nokia.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef EVDEV_H
|
#ifndef EVDEV_H
|
||||||
@@ -54,6 +55,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define EVDEV_MAXBUTTONS 32
|
#define EVDEV_MAXBUTTONS 32
|
||||||
|
#define EVDEV_MAXQUEUE 32
|
||||||
|
|
||||||
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
|
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
|
||||||
#define HAVE_PROPERTIES 1
|
#define HAVE_PROPERTIES 1
|
||||||
@@ -87,6 +89,16 @@ typedef struct {
|
|||||||
int traveled_distance;
|
int traveled_distance;
|
||||||
} WheelAxis, *WheelAxisPtr;
|
} WheelAxis, *WheelAxisPtr;
|
||||||
|
|
||||||
|
/* Event queue used to defer keyboard/button events until EV_SYN time. */
|
||||||
|
typedef struct {
|
||||||
|
enum {
|
||||||
|
EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */
|
||||||
|
EV_QUEUE_BTN, /* xf86PostButtonEvent() */
|
||||||
|
} type;
|
||||||
|
int key; /* May be either a key code or button number. */
|
||||||
|
int val; /* State of the key/button; pressed or released. */
|
||||||
|
} EventQueueRec, *EventQueuePtr;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *device;
|
const char *device;
|
||||||
int grabDevice; /* grab the event device? */
|
int grabDevice; /* grab the event device? */
|
||||||
@@ -98,11 +110,14 @@ typedef struct {
|
|||||||
|
|
||||||
int flags;
|
int flags;
|
||||||
int tool;
|
int tool;
|
||||||
int buttons; /* number of buttons */
|
int num_buttons; /* number of buttons */
|
||||||
BOOL swap_axes;
|
BOOL swap_axes;
|
||||||
BOOL invert_x;
|
BOOL invert_x;
|
||||||
BOOL invert_y;
|
BOOL invert_y;
|
||||||
|
|
||||||
|
int delta[REL_CNT];
|
||||||
|
unsigned int abs, rel;
|
||||||
|
|
||||||
/* XKB stuff has to be per-device rather than per-driver */
|
/* XKB stuff has to be per-device rather than per-driver */
|
||||||
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
|
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
|
||||||
XkbComponentNamesRec xkbnames;
|
XkbComponentNamesRec xkbnames;
|
||||||
@@ -159,8 +174,21 @@ typedef struct {
|
|||||||
|
|
||||||
/* minor/major number */
|
/* minor/major number */
|
||||||
dev_t min_maj;
|
dev_t min_maj;
|
||||||
|
|
||||||
|
/* Event queue used to defer keyboard/button events until EV_SYN time. */
|
||||||
|
int num_queue;
|
||||||
|
EventQueueRec queue[EVDEV_MAXQUEUE];
|
||||||
} EvdevRec, *EvdevPtr;
|
} EvdevRec, *EvdevPtr;
|
||||||
|
|
||||||
|
/* Event posting functions */
|
||||||
|
void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value);
|
||||||
|
void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value);
|
||||||
|
void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value);
|
||||||
|
void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count);
|
||||||
|
void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
|
||||||
|
int v[MAX_VALUATORS]);
|
||||||
|
void EvdevPostAbsoluteMotionEvents(InputInfoPtr pInfo, int *num_v, int *first_v,
|
||||||
|
int v[MAX_VALUATORS]);
|
||||||
unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
|
unsigned int EvdevUtilButtonEventToButtonNumber(EvdevPtr pEvdev, int code);
|
||||||
|
|
||||||
/* Middle Button emulation */
|
/* Middle Button emulation */
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
# Copyright 2008 Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
# THE AUTHORS 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.
|
|
||||||
AM_CFLAGS = $(XORG_CFLAGS)
|
|
||||||
|
|
||||||
noinst_PROGRAMS=fakedev btn0 absrel abs dummy
|
|
||||||
|
|
||||||
fakedev_SOURCES=fakedev.c fakedev.h
|
|
||||||
fakedev_LDFLAGS=$(DLOPEN_LIBS) -rdynamic
|
|
||||||
|
|
||||||
LFLAGS=-shared -fPIC
|
|
||||||
|
|
||||||
btn0_SOURCES=btn0.c
|
|
||||||
btn0_LDFLAGS=$(LFLAGS)
|
|
||||||
|
|
||||||
absrel_SOURCES=absrel.c
|
|
||||||
absrel_LDFLAGS=$(LFLAGS)
|
|
||||||
|
|
||||||
abs_SOURCES=abs.c
|
|
||||||
abs_LDFLAGS=$(LFLAGS)
|
|
||||||
|
|
||||||
dummy_SOURCES=dummy.c
|
|
||||||
dummy_LDFLAGS=$(LFLAGS)
|
|
||||||
84
test/abs.c
84
test/abs.c
@@ -1,84 +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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* creates a device with ABS_X, ABS_Y, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT. */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/input.h>
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
|
|
||||||
#include "fakedev.h"
|
|
||||||
|
|
||||||
int abs_setup(struct uinput_user_dev* dev, int fd)
|
|
||||||
{
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
|
|
||||||
|
|
||||||
/* buttons */
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
|
|
||||||
|
|
||||||
/* axes */
|
|
||||||
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
|
|
||||||
|
|
||||||
|
|
||||||
dev->absmin[ABS_X] = 0;
|
|
||||||
dev->absmax[ABS_X] = 120;
|
|
||||||
|
|
||||||
dev->absmin[ABS_Y] = 0;
|
|
||||||
dev->absmax[ABS_Y] = 120;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
perror("ioctl failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int abs_run(int fd)
|
|
||||||
{
|
|
||||||
absmove(fd, 100, 100);
|
|
||||||
sleep(1);
|
|
||||||
absmove(fd, 120, 120);
|
|
||||||
sleep(1);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct test_device abs_dev = {
|
|
||||||
.name = "Abs test device",
|
|
||||||
.setup = abs_setup,
|
|
||||||
.run = abs_run,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct test_device* get_device()
|
|
||||||
{
|
|
||||||
return &abs_dev;
|
|
||||||
}
|
|
||||||
@@ -1,91 +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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* creates a device with ABS_X, ABS_Y, REL_X, REL_Y, BTN_LEFT, BTN_MIDDLE,
|
|
||||||
BTN_RIGHT. */
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/input.h>
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
|
|
||||||
#include "fakedev.h"
|
|
||||||
|
|
||||||
int absrel_setup(struct uinput_user_dev* dev, int fd)
|
|
||||||
{
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
|
|
||||||
|
|
||||||
/* buttons */
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
|
|
||||||
|
|
||||||
/* axes */
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
|
|
||||||
|
|
||||||
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
|
|
||||||
|
|
||||||
|
|
||||||
dev->absmin[ABS_X] = 0;
|
|
||||||
dev->absmax[ABS_X] = 1000;
|
|
||||||
|
|
||||||
dev->absmin[ABS_Y] = 0;
|
|
||||||
dev->absmax[ABS_Y] = 1000;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
perror("ioctl failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int absrel_run(int fd)
|
|
||||||
{
|
|
||||||
absmove(fd, 100, 100);
|
|
||||||
sleep(1);
|
|
||||||
absmove(fd, 120, 120);
|
|
||||||
sleep(1);
|
|
||||||
move(fd, 10, 10);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct test_device absrel_dev = {
|
|
||||||
.name = "Abs/Rel test device",
|
|
||||||
.setup = absrel_setup,
|
|
||||||
.run = absrel_run,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct test_device* get_device()
|
|
||||||
{
|
|
||||||
return &absrel_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
87
test/btn0.c
87
test/btn0.c
@@ -1,87 +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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Creates a device that has REL_X REL_Y BTN_0 BTN_1 BTN_2
|
|
||||||
*
|
|
||||||
* Moves the device around in a 10px square and clicks after each completed
|
|
||||||
* circle.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/input.h>
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
|
|
||||||
#include "fakedev.h"
|
|
||||||
|
|
||||||
int btn0_setup(struct uinput_user_dev *dev, int fd)
|
|
||||||
{
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
|
|
||||||
|
|
||||||
/* buttons */
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_0) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_1) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_2) == -1) goto error;
|
|
||||||
|
|
||||||
/* axes */
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
error:
|
|
||||||
perror("ioctl failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int btn0_run(int fd)
|
|
||||||
{
|
|
||||||
move(fd, -10, 0);
|
|
||||||
usleep(1000);
|
|
||||||
move(fd, 0, -10);
|
|
||||||
usleep(1000);
|
|
||||||
move(fd, 10, 0);
|
|
||||||
usleep(1000);
|
|
||||||
move(fd, 0, 10);
|
|
||||||
usleep(1000);
|
|
||||||
click(fd, BTN_0, 1);
|
|
||||||
usleep(1000);
|
|
||||||
click(fd, BTN_0, 0);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct test_device btn0_dev = {
|
|
||||||
.name = "BTN_0 test device",
|
|
||||||
.setup = btn0_setup,
|
|
||||||
.run = btn0_run,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct test_device* get_device()
|
|
||||||
{
|
|
||||||
return &btn0_dev;
|
|
||||||
}
|
|
||||||
77
test/dummy.c
77
test/dummy.c
@@ -1,77 +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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* dummy device, looks like a mouse but doesn't do anything.
|
|
||||||
* Good for filling up the device list.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/input.h>
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
|
|
||||||
#include "fakedev.h"
|
|
||||||
|
|
||||||
int dummy_setup(struct uinput_user_dev *dev, int fd)
|
|
||||||
{
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_KEY) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
|
|
||||||
|
|
||||||
/* buttons */
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
|
|
||||||
|
|
||||||
/* axes */
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
|
|
||||||
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
error:
|
|
||||||
perror("ioctl failed.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int dummy_run(int fd)
|
|
||||||
{
|
|
||||||
usleep(1000);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct test_device dummy_dev = {
|
|
||||||
.name = "dummy_ test device",
|
|
||||||
.setup = dummy_setup,
|
|
||||||
.run = dummy_run,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct test_device* get_device()
|
|
||||||
{
|
|
||||||
return &dummy_dev;
|
|
||||||
}
|
|
||||||
|
|
||||||
199
test/fakedev.c
199
test/fakedev.c
@@ -1,199 +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)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <linux/input.h>
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
#include "fakedev.h"
|
|
||||||
|
|
||||||
/* "public interfaces" */
|
|
||||||
|
|
||||||
void send_event(int fd, int type, int code, int value)
|
|
||||||
{
|
|
||||||
struct input_event event;
|
|
||||||
|
|
||||||
event.type = type;
|
|
||||||
event.code = code;
|
|
||||||
event.value = value;
|
|
||||||
gettimeofday(&event.time, NULL);
|
|
||||||
|
|
||||||
if (write(fd, &event, sizeof(event)) < sizeof(event))
|
|
||||||
perror("Send event failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void move(int fd, int x, int y)
|
|
||||||
{
|
|
||||||
if (!x && !y)
|
|
||||||
return;
|
|
||||||
|
|
||||||
send_event(fd, EV_REL, REL_X, x);
|
|
||||||
send_event(fd, EV_REL, REL_Y, y);
|
|
||||||
send_event(fd, EV_SYN, SYN_REPORT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void absmove(int fd, int x, int y)
|
|
||||||
{
|
|
||||||
send_event(fd, EV_ABS, ABS_X, x);
|
|
||||||
send_event(fd, EV_ABS, ABS_Y, y);
|
|
||||||
send_event(fd, EV_SYN, SYN_REPORT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void click(int fd, int btn, int down)
|
|
||||||
{
|
|
||||||
send_event(fd, EV_KEY, btn, down);
|
|
||||||
send_event(fd, EV_SYN, SYN_REPORT, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* end public interfaces */
|
|
||||||
|
|
||||||
static int fd = -1;
|
|
||||||
static int stop = 0;
|
|
||||||
|
|
||||||
static void sighandler(int signum)
|
|
||||||
{
|
|
||||||
printf("Stopping.\n");
|
|
||||||
stop = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void init_signal(void)
|
|
||||||
{
|
|
||||||
struct sigaction action;
|
|
||||||
sigset_t mask;
|
|
||||||
|
|
||||||
sigfillset(&mask);
|
|
||||||
|
|
||||||
action.sa_handler = sighandler;
|
|
||||||
action.sa_mask = mask;
|
|
||||||
action.sa_flags = 0;
|
|
||||||
|
|
||||||
sigaction(SIGTERM, &action, NULL);
|
|
||||||
sigaction(SIGINT, &action, NULL);
|
|
||||||
sigprocmask(SIG_UNBLOCK, &mask, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int init_uinput(struct test_device* test_dev)
|
|
||||||
{
|
|
||||||
struct uinput_user_dev dev;
|
|
||||||
|
|
||||||
fd = open("/dev/input/uinput", O_RDWR);
|
|
||||||
if (fd < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
memset(&dev, 0, sizeof(dev));
|
|
||||||
strcpy(dev.name, test_dev->name);
|
|
||||||
dev.id.bustype = 0;
|
|
||||||
dev.id.vendor = 0x1F;
|
|
||||||
dev.id.product = 0x1F;
|
|
||||||
dev.id.version = 0;
|
|
||||||
|
|
||||||
|
|
||||||
test_dev->setup(&dev, fd);
|
|
||||||
|
|
||||||
if (write(fd, &dev, sizeof(dev)) < sizeof(dev))
|
|
||||||
goto error;
|
|
||||||
if (ioctl(fd, UI_DEV_CREATE, NULL) == -1) goto error;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
fprintf(stderr, "Error: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
if (fd != -1)
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cleanup_uinput(void)
|
|
||||||
{
|
|
||||||
if (fd == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ioctl(fd, UI_DEV_DESTROY, NULL);
|
|
||||||
close(fd);
|
|
||||||
fd = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main (int argc, char **argv)
|
|
||||||
{
|
|
||||||
struct test_device *dev;
|
|
||||||
void *dlhandle = NULL;
|
|
||||||
struct test_device* (*get_device)(void);
|
|
||||||
|
|
||||||
if (argc <= 1)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Usage: %s test_dev\n", argv[0]);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Loading %s.\n", argv[1]);
|
|
||||||
|
|
||||||
dlhandle = dlopen(argv[1], RTLD_NOW | RTLD_GLOBAL);
|
|
||||||
if (!dlhandle)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error: %s\n", dlerror());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*(void**)(&get_device) = dlsym(dlhandle, "get_device");
|
|
||||||
if (!get_device)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error getting the symbol: %s.\n", dlerror());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = (*get_device)();
|
|
||||||
|
|
||||||
if (init_uinput(dev) < 0) {
|
|
||||||
fprintf(stderr, "Failed to initialize /dev/uinput. Exiting.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_signal();
|
|
||||||
|
|
||||||
printf("Device created. Press CTRL+C to terminate.\n");
|
|
||||||
while (!stop) {
|
|
||||||
if (dev->run(fd))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup_uinput();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,51 +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_TEST_H
|
|
||||||
#define _EVDEV_TEST_H
|
|
||||||
#include <linux/uinput.h>
|
|
||||||
|
|
||||||
struct test_device {
|
|
||||||
char *name; /* device name */
|
|
||||||
/**
|
|
||||||
* Called to setup the device. Call ioctls to set your EVBITs, KEYBITs,
|
|
||||||
* etc. here. Return 0 on success or non-zero to exit.
|
|
||||||
*/
|
|
||||||
int (*setup)(struct uinput_user_dev* dev, int fd);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called during each run of the main loop. Generate events by calling
|
|
||||||
* move(), click(), etc.
|
|
||||||
* Return 0 on success, or non-zero to stop the main loop.
|
|
||||||
*/
|
|
||||||
int (*run)(int fd);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern void move (int fd, int x, int y);
|
|
||||||
extern void absmove (int fd, int x, int y);
|
|
||||||
extern void click (int fd, int btn, int down);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user