mirror of
https://github.com/X11Libre/xf86-input-evdev.git
synced 2026-04-14 11:44:16 +00:00
Compare commits
30 Commits
xf86-input
...
xf86-input
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5969caabe | ||
|
|
5a4b0ba33d | ||
|
|
cd24c2cc18 | ||
|
|
c8a0f1cf36 | ||
|
|
bf356d9399 | ||
|
|
4c1c4f2c83 | ||
|
|
c0bee1b4d6 | ||
|
|
8acc999d40 | ||
|
|
3cce7fa38a | ||
|
|
c793aa2738 | ||
|
|
9f3632c0b6 | ||
|
|
06b303f26d | ||
|
|
4dda242d56 | ||
|
|
4efe0d272e | ||
|
|
1432b5153e | ||
|
|
b8519930e4 | ||
|
|
6d43a45b99 | ||
|
|
40d3ad3ac0 | ||
|
|
cf887a2b7c | ||
|
|
1cc0651e1b | ||
|
|
48a747ea86 | ||
|
|
aa58eb6096 | ||
|
|
aff7228d97 | ||
|
|
c695234c5c | ||
|
|
79d4956add | ||
|
|
7e9809837c | ||
|
|
d07692a4af | ||
|
|
1073cd4fdc | ||
|
|
486bbdc481 | ||
|
|
73e5eba8cd |
@@ -23,7 +23,11 @@ AUTOMAKE_OPTIONS = foreign
|
||||
# Ensure headers are installed below $(prefix) for distcheck
|
||||
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
|
||||
|
||||
SUBDIRS = src man include
|
||||
if BUILD_TEST
|
||||
test_dir=test
|
||||
endif
|
||||
|
||||
SUBDIRS = src man include $(test_dir)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = xorg-evdev.pc
|
||||
|
||||
30
configure.ac
30
configure.ac
@@ -22,7 +22,7 @@
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([xf86-input-evdev],
|
||||
2.3.2,
|
||||
2.2.6,
|
||||
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
|
||||
xf86-input-evdev)
|
||||
|
||||
@@ -32,16 +32,16 @@ AM_INIT_AUTOMAKE([dist-bzip2])
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
# Require xorg-macros: XORG_DEFAULT_OPTIONS
|
||||
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.3 or later before running autoconf/autogen])])
|
||||
XORG_MACROS_VERSION(1.3)
|
||||
# Require xorg-macros: XORG_CWARNFLAGS, XORG_CHANGELOG
|
||||
m4_ifndef([XORG_MACROS_VERSION], [AC_FATAL([must install xorg-macros 1.2 or later before running autoconf/autogen])])
|
||||
XORG_MACROS_VERSION(1.2)
|
||||
AM_CONFIG_HEADER([config.h])
|
||||
|
||||
# Checks for programs.
|
||||
AC_DISABLE_STATIC
|
||||
AC_PROG_LIBTOOL
|
||||
AC_PROG_CC
|
||||
XORG_DEFAULT_OPTIONS
|
||||
XORG_CWARNFLAGS
|
||||
|
||||
AH_TOP([#include "xorg-server.h"])
|
||||
|
||||
@@ -53,6 +53,21 @@ AC_ARG_WITH(xorg-module-dir,
|
||||
inputdir=${moduledir}/input
|
||||
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 pkg-config packages. We need to be able to override sdkdir
|
||||
# to satisfy silly distcheck requirements.
|
||||
PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES)
|
||||
@@ -70,8 +85,13 @@ AC_HEADER_STDC
|
||||
DRIVER_NAME=evdev
|
||||
AC_SUBST([DRIVER_NAME])
|
||||
|
||||
XORG_MANPAGE_SECTIONS
|
||||
XORG_RELEASE_VERSION
|
||||
XORG_CHANGELOG
|
||||
|
||||
AC_OUTPUT([Makefile
|
||||
src/Makefile
|
||||
man/Makefile
|
||||
include/Makefile
|
||||
test/Makefile
|
||||
xorg-evdev.pc])
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#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 always scroll */
|
||||
/* CARD8, value range 0-32, 0 to disable a value */
|
||||
#define EVDEV_PROP_WHEEL_BUTTON "Evdev Wheel Emulation Button"
|
||||
|
||||
/* Drag lock */
|
||||
|
||||
@@ -105,10 +105,7 @@ press/release events as specified for the
|
||||
.B XAxisMapping
|
||||
and
|
||||
.B YAxisMapping
|
||||
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".
|
||||
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
|
||||
@@ -135,34 +132,10 @@ Default: disabled.
|
||||
.BI "Option \*qInvertY\*q \*q" Bool \*q
|
||||
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
|
||||
.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
|
||||
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 \*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
|
||||
Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
|
||||
.TP 7
|
||||
@@ -191,7 +164,9 @@ driver.
|
||||
.TP 7
|
||||
.BI "Evdev Axis Calibration"
|
||||
4 32-bit values, order min-x, max-x, min-y, max-y or 0 values to disable
|
||||
in-driver axis calibration.
|
||||
run-time axis calibration. This feature is required for devices that need to
|
||||
scale to a different coordinate system than originally reported to the X
|
||||
server, such as touchscreens that require run-time calibration.
|
||||
.TP 7
|
||||
.BI "Evdev Axis Inversion"
|
||||
2 boolean values (8 bit, 0 or 1), order X, Y. 1 inverts the axis.
|
||||
|
||||
@@ -147,18 +147,18 @@ EvdevDragLockPreInit(InputInfoPtr pInfo)
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates DragLock button state and fires button event messges */
|
||||
/* Updates DragLock button state and firest button event messges */
|
||||
void
|
||||
EvdevDragLockLockButton(InputInfoPtr pInfo, unsigned int button)
|
||||
{
|
||||
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
||||
BOOL state = 0;
|
||||
BOOL state=0;
|
||||
|
||||
/* update button state */
|
||||
state = pEvdev->dragLock.lock_state[button - 1] ? FALSE : TRUE;
|
||||
pEvdev->dragLock.lock_state[button - 1] = state;
|
||||
|
||||
EvdevQueueButtonEvent(pInfo, button, state);
|
||||
xf86PostButtonEvent(pInfo->dev, 0, button, state, 0, 0);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
memset(pEvdev->dragLock.lock_pair, 0, sizeof(pEvdev->dragLock.lock_pair));
|
||||
}
|
||||
} else if ((val->size % 2) == 0)
|
||||
} else
|
||||
{
|
||||
CARD8* vals = (CARD8*)val->data;
|
||||
|
||||
@@ -269,11 +269,10 @@ EvdevDragLockSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
|
||||
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 += 2)
|
||||
pEvdev->dragLock.lock_pair[vals[i] - 1] = vals[i + 1];
|
||||
for (i = 0; i < val->size && i < EVDEV_MAXBUTTONS; i++)
|
||||
pEvdev->dragLock.lock_pair[i] = vals[i];
|
||||
}
|
||||
} else
|
||||
return BadMatch;
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
|
||||
@@ -198,7 +198,7 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
|
||||
|
||||
pEvdev->emulateMB.pending = FALSE;
|
||||
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
|
||||
EvdevPostButtonEvent(pInfo, abs(id), (id >= 0));
|
||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
||||
pEvdev->emulateMB.state =
|
||||
stateTab[pEvdev->emulateMB.state][4][2];
|
||||
} else {
|
||||
@@ -248,12 +248,12 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
|
||||
|
||||
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
|
||||
{
|
||||
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
|
||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
||||
ret = TRUE;
|
||||
}
|
||||
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
|
||||
{
|
||||
EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
|
||||
xf86PostButtonEvent(pInfo->dev, 0, abs(id), (id >= 0), 0, 0);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ static Atom prop_wheel_button = 0;
|
||||
|
||||
/* Local Funciton Prototypes */
|
||||
static BOOL EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char *axis_name);
|
||||
static int EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
|
||||
static void EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value);
|
||||
|
||||
/* Filter mouse button events */
|
||||
BOOL
|
||||
@@ -82,7 +82,8 @@ EvdevWheelEmuFilterButton(InputInfoPtr pInfo, unsigned int button, int value)
|
||||
* If the button is released early enough emit the button
|
||||
* press/release events
|
||||
*/
|
||||
EvdevQueueButtonClicks(pInfo, button, 1);
|
||||
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
|
||||
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,51 +99,38 @@ BOOL
|
||||
EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
|
||||
{
|
||||
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
|
||||
WheelAxisPtr pAxis = NULL, pOtherAxis = NULL;
|
||||
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
|
||||
* wheel button of 0 means always emulate wheel.
|
||||
*/
|
||||
if (pEvdev->emulateWheel.button_state || !pEvdev->emulateWheel.button) {
|
||||
/* Handle our motion events if the emuWheel button is pressed*/
|
||||
if (pEvdev->emulateWheel.button_state) {
|
||||
/* Just return if the timeout hasn't expired yet */
|
||||
if (pEvdev->emulateWheel.button)
|
||||
{
|
||||
int ms = pEvdev->emulateWheel.expires - GetTimeInMillis();
|
||||
if (ms > 0)
|
||||
return TRUE;
|
||||
}
|
||||
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);
|
||||
pOtherAxis = &(pEvdev->emulateWheel.Y);
|
||||
break;
|
||||
|
||||
case REL_Y:
|
||||
pAxis = &(pEvdev->emulateWheel.Y);
|
||||
pOtherAxis = &(pEvdev->emulateWheel.X);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* 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 we found REL_X or REL_Y, emulate a mouse wheel */
|
||||
if (pAxis)
|
||||
{
|
||||
if (EvdevWheelEmuInertia(pInfo, pAxis, value))
|
||||
pOtherAxis->traveled_distance = 0;
|
||||
}
|
||||
EvdevWheelEmuInertia(pInfo, pAxis, value);
|
||||
|
||||
/* Eat motion events while emulateWheel button pressed. */
|
||||
return TRUE;
|
||||
@@ -151,20 +139,17 @@ EvdevWheelEmuFilterMotion(InputInfoPtr pInfo, struct input_event *pEv)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Simulate inertia for our emulated mouse wheel.
|
||||
Returns the number of wheel events generated.
|
||||
*/
|
||||
static int
|
||||
/* 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;
|
||||
int rc = 0;
|
||||
|
||||
/* if this axis has not been configured, just eat the motion */
|
||||
if (!axis->up_button)
|
||||
return rc;
|
||||
return;
|
||||
|
||||
axis->traveled_distance += value;
|
||||
|
||||
@@ -178,11 +163,11 @@ EvdevWheelEmuInertia(InputInfoPtr pInfo, WheelAxisPtr axis, int value)
|
||||
|
||||
/* Produce button press events for wheel motion */
|
||||
while(abs(axis->traveled_distance) > pEvdev->emulateWheel.inertia) {
|
||||
|
||||
axis->traveled_distance -= inertia;
|
||||
EvdevQueueButtonClicks(pInfo, button, 1);
|
||||
rc++;
|
||||
xf86PostButtonEvent(pInfo->dev, 0, button, 1, 0, 0);
|
||||
xf86PostButtonEvent(pInfo->dev, 0, button, 0, 0, 0);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Handle button mapping here to avoid code duplication,
|
||||
@@ -216,8 +201,8 @@ EvdevWheelEmuHandleButtonMap(InputInfoPtr pInfo, WheelAxisPtr pAxis, char* axis_
|
||||
pAxis->down_button = down_button;
|
||||
|
||||
/* Update the number of buttons if needed */
|
||||
if (up_button > pEvdev->num_buttons) pEvdev->num_buttons = up_button;
|
||||
if (down_button > pEvdev->num_buttons) pEvdev->num_buttons = down_button;
|
||||
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",
|
||||
@@ -300,8 +285,8 @@ EvdevWheelEmuPreInit(InputInfoPtr pInfo)
|
||||
|
||||
/* Simpler to check just the largest value in this case */
|
||||
/* XXX: we should post this to the server */
|
||||
if (5 > pEvdev->num_buttons)
|
||||
pEvdev->num_buttons = 5;
|
||||
if (5 > pEvdev->buttons)
|
||||
pEvdev->buttons = 5;
|
||||
|
||||
/* Display default Configuration */
|
||||
xf86Msg(X_CONFIG, "%s: YAxisMapping: buttons %d and %d\n",
|
||||
|
||||
1333
src/evdev.c
1333
src/evdev.c
File diff suppressed because it is too large
Load Diff
30
src/evdev.h
30
src/evdev.h
@@ -25,7 +25,6 @@
|
||||
* Kristian Høgsberg (krh@redhat.com)
|
||||
* Adam Jackson (ajax@redhat.com)
|
||||
* Peter Hutterer (peter@cs.unisa.edu.au)
|
||||
* Oliver McFadden (oliver.mcfadden@nokia.com)
|
||||
*/
|
||||
|
||||
#ifndef EVDEV_H
|
||||
@@ -55,7 +54,6 @@
|
||||
#endif
|
||||
|
||||
#define EVDEV_MAXBUTTONS 32
|
||||
#define EVDEV_MAXQUEUE 32
|
||||
|
||||
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
|
||||
#define HAVE_PROPERTIES 1
|
||||
@@ -89,16 +87,6 @@ typedef struct {
|
||||
int traveled_distance;
|
||||
} 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 {
|
||||
const char *device;
|
||||
int grabDevice; /* grab the event device? */
|
||||
@@ -110,14 +98,11 @@ typedef struct {
|
||||
|
||||
int flags;
|
||||
int tool;
|
||||
int num_buttons; /* number of buttons */
|
||||
int buttons; /* number of buttons */
|
||||
BOOL swap_axes;
|
||||
BOOL invert_x;
|
||||
BOOL invert_y;
|
||||
|
||||
int delta[REL_CNT];
|
||||
unsigned int abs, rel;
|
||||
|
||||
/* XKB stuff has to be per-device rather than per-driver */
|
||||
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 5
|
||||
XkbComponentNamesRec xkbnames;
|
||||
@@ -174,21 +159,8 @@ typedef struct {
|
||||
|
||||
/* minor/major number */
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Middle Button emulation */
|
||||
|
||||
39
test/Makefile.am
Normal file
39
test/Makefile.am
Normal file
@@ -0,0 +1,39 @@
|
||||
# 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
Normal file
84
test/abs.c
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
91
test/absrel.c
Normal file
91
test/absrel.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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
Normal file
87
test/btn0.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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
Normal file
77
test/dummy.c
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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
Normal file
199
test/fakedev.c
Normal file
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
51
test/fakedev.h
Normal file
51
test/fakedev.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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