summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@redhat.com>2008-11-03 13:25:06 +1030
committerPeter Hutterer <peter.hutterer@redhat.com>2008-11-03 13:46:40 +1030
commitdd0eeacc24a80893209f24d9ad028a6bc7e3a390 (patch)
tree27f1781cefb7869704425e039854b0759584034c
parent67c0ea6c9421a5226c1b8bc3a198b1cb01f6b355 (diff)
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 4826969f23a0b298da2750c2e23a92b9d91819dd)
-rw-r--r--include/evdev-properties.h4
-rw-r--r--man/evdev.man6
-rw-r--r--src/evdev.c31
-rw-r--r--src/evdev.h1
4 files changed, 39 insertions, 3 deletions
diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index be4307b..31f6c66 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -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
diff --git a/man/evdev.man b/man/evdev.man
index fc8a96a..cf087e8 100644
--- a/man/evdev.man
+++ b/man/evdev.man
@@ -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.
diff --git a/src/evdev.c b/src/evdev.c
index aa8a10d..638831d 100644
--- a/src/evdev.c
+++ b/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;
diff --git a/src/evdev.h b/src/evdev.h
index 5696978..32da81c 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -64,6 +64,7 @@ typedef struct {
int flags;
int tool;
int buttons; /* number of buttons */
+ BOOL swap_axes;
BOOL invert_x;
BOOL invert_y;