mirror of
https://github.com/X11Libre/xf86-input-evdev.git
synced 2026-04-14 11:44:16 +00:00
Add support for axes swapping.
New option: SwapAxes (boolean)
New property: EVDEV_PROP_SWAP_AXES.
Actual swapping code written by Donnie Berkholz.
Signed-off-by: Peter Hutterer <peter.hutterer@redhat.com>
(cherry picked from commit 4826969f23)
This commit is contained in:
@@ -62,4 +62,8 @@
|
||||
/* CARD32, 4 values [minx, maxx, miny, maxy], or no values for unset */
|
||||
#define EVDEV_PROP_CALIBRATION "Evdev Axis Calibration"
|
||||
|
||||
/* Swap x and y axis. */
|
||||
/* BOOL */
|
||||
#define EVDEV_PROP_SWAP_AXES "Evdev Axes Swap"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -147,6 +147,9 @@ waking up from suspend). In between each attempt is a 100ms wait. Default: 10.
|
||||
.BI "Option \*qInvertY\*q \*q" Bool \*q
|
||||
Invert the given axis. Default: off. Property: "Evdev Axis Inversion".
|
||||
.TP 7
|
||||
.BI "Option \*qSwapAxes\*q \*q" Bool \*q
|
||||
Swap x/y axes. Default: off. Property: "Evdev Axes Swap".
|
||||
.TP 7
|
||||
.BI "Option \*qGrabDevice\*q \*q" boolean \*q
|
||||
Force a grab on the event device. Doing so will ensure that no other driver
|
||||
can initialise the same device and it will also stop the device from sending
|
||||
@@ -191,6 +194,9 @@ value.
|
||||
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 Swap"
|
||||
1 boolean values (8 bit, 0 or 1). 1 swaps x/y axes.
|
||||
|
||||
.SH AUTHORS
|
||||
Kristian Høgsberg.
|
||||
|
||||
31
src/evdev.c
31
src/evdev.c
@@ -109,6 +109,7 @@ static int EvdevSetProperty(DeviceIntPtr dev, Atom atom,
|
||||
static Atom prop_invert = 0;
|
||||
static Atom prop_reopen = 0;
|
||||
static Atom prop_calibration = 0;
|
||||
static Atom prop_swap = 0;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -227,13 +228,14 @@ EvdevReadInput(InputInfoPtr pInfo)
|
||||
{
|
||||
struct input_event ev;
|
||||
int len, value;
|
||||
int dx, dy;
|
||||
int dx, dy, tmp;
|
||||
unsigned int abs;
|
||||
unsigned int button;
|
||||
EvdevPtr pEvdev = pInfo->private;
|
||||
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
tmp = 0;
|
||||
abs = 0;
|
||||
|
||||
while (xf86WaitForInput (pInfo->fd, 0) > 0) {
|
||||
@@ -369,6 +371,11 @@ EvdevReadInput(InputInfoPtr pInfo)
|
||||
}
|
||||
|
||||
if (dx != 0 || dy != 0) {
|
||||
if (pEvdev->swap_axes) {
|
||||
tmp = dx;
|
||||
dx = dy;
|
||||
dy = tmp;
|
||||
}
|
||||
if (pEvdev->invert_x)
|
||||
dx *= -1;
|
||||
if (pEvdev->invert_y)
|
||||
@@ -387,8 +394,8 @@ EvdevReadInput(InputInfoPtr pInfo)
|
||||
*/
|
||||
if (abs && pEvdev->tool) {
|
||||
int abs_x, abs_y;
|
||||
abs_x = pEvdev->abs_x;
|
||||
abs_y = pEvdev->abs_y;
|
||||
abs_x = (pEvdev->swap_axes) ? pEvdev->abs_y : pEvdev->abs_x;
|
||||
abs_y = (pEvdev->swap_axes) ? pEvdev->abs_x : pEvdev->abs_y;
|
||||
|
||||
if (pEvdev->flags & EVDEV_CALIBRATED)
|
||||
{
|
||||
@@ -1382,6 +1389,7 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
|
||||
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->swap_axes = xf86SetBoolOption(pInfo->options, "SwapAxes", FALSE);
|
||||
|
||||
/* Grabbing the event device stops in-kernel event forwarding. In other
|
||||
words, it disables rfkill and the "Macintosh mouse button emulation".
|
||||
@@ -1565,6 +1573,16 @@ EvdevInitProperty(DeviceIntPtr dev)
|
||||
return;
|
||||
|
||||
XISetDevicePropertyDeletable(dev, prop_calibration, FALSE);
|
||||
|
||||
prop_swap = MakeAtom(EVDEV_PROP_SWAP_AXES,
|
||||
strlen(EVDEV_PROP_SWAP_AXES), TRUE);
|
||||
|
||||
rc = XIChangeDeviceProperty(dev, prop_swap, XA_INTEGER, 8,
|
||||
PropModeReplace, 1, &pEvdev->swap_axes, FALSE);
|
||||
if (rc != Success)
|
||||
return;
|
||||
|
||||
XISetDevicePropertyDeletable(dev, prop_swap, FALSE);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1620,6 +1638,13 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
|
||||
pEvdev->calibration.max_y = vals[3];
|
||||
}
|
||||
}
|
||||
} else if (atom == prop_swap)
|
||||
{
|
||||
if (val->format != 8 || val->type != XA_INTEGER || val->size != 1)
|
||||
return BadMatch;
|
||||
|
||||
if (!checkonly)
|
||||
pEvdev->swap_axes = *((BOOL*)val->data);
|
||||
}
|
||||
|
||||
return Success;
|
||||
|
||||
@@ -64,6 +64,7 @@ typedef struct {
|
||||
int flags;
|
||||
int tool;
|
||||
int buttons; /* number of buttons */
|
||||
BOOL swap_axes;
|
||||
BOOL invert_x;
|
||||
BOOL invert_y;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user