aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Strobach <lalochcz@gmail.com>2016-11-17 20:47:31 +0100
committerPeter Hutterer <peter.hutterer@who-t.net>2016-11-21 15:26:58 +1000
commit425ed6017a42937f69c1e8450ea8f3c6c6c20928 (patch)
tree2748b71a5a8e590c1121f1efaa52f3cf5e63eb7a
parentFix off-by-one error counting axes (diff)
downloadxf86-input-evdev-425ed6017a42937f69c1e8450ea8f3c6c6c20928.tar.gz
xf86-input-evdev-425ed6017a42937f69c1e8450ea8f3c6c6c20928.tar.bz2
xf86-input-evdev-425ed6017a42937f69c1e8450ea8f3c6c6c20928.zip
Middle emulation - make the emulated button number configurable
Sometimes it may be desirable to remap physical middle button to something else and use emulation instead. The emulation is however hardcoded to emulate physical button 2, so the emulated button gets remapped together with the physical one. This patch adds the Emulate3Button configuration option to allow for user selection of the emulated button number and a configuration like this: Section "InputClass" Identifier "Middle button emulation config" MatchProduct ".... some device ..." MatchDriver "evdev" Option "Emulate3Buttons" "on" Option "Emulate3Button" "9" EndSection Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--include/evdev-properties.h2
-rw-r--r--man/evdev.man8
-rw-r--r--src/emuMB.c47
-rw-r--r--src/evdev.h1
4 files changed, 56 insertions, 2 deletions
diff --git a/include/evdev-properties.h b/include/evdev-properties.h
index 8ae5ba3..c61aa49 100644
--- a/include/evdev-properties.h
+++ b/include/evdev-properties.h
@@ -33,6 +33,8 @@
#define EVDEV_PROP_MIDBUTTON "Evdev Middle Button Emulation"
/* CARD32 */
#define EVDEV_PROP_MIDBUTTON_TIMEOUT "Evdev Middle Button Timeout"
+/* CARD8 */
+#define EVDEV_PROP_MIDBUTTON_BUTTON "Evdev Middle Button Button"
/* Wheel emulation */
/* BOOL */
diff --git a/man/evdev.man b/man/evdev.man
index 8d84364..e39736a 100644
--- a/man/evdev.man
+++ b/man/evdev.man
@@ -94,6 +94,11 @@ Sets the timeout (in milliseconds) that the driver waits before deciding
if two buttons where pressed "simultaneously" when 3 button emulation is
enabled. Default: 50. Property: "Evdev Middle Button Timeout".
.TP 7
+.BI "Option \*qEmulate3Button\*q \*q" integer \*q
+Specifies the physical button number to be emitted if middle button emulation
+is triggered.
+Default: 2. Property: "Evdev Middle Button Button".
+.TP 7
.BI "Option \*qEmulateWheel\*q \*q" boolean \*q
Enable/disable "wheel" emulation. Wheel emulation means emulating button
press/release events when the mouse is moved while a specific real button
@@ -283,6 +288,9 @@ value.
.BI "Evdev Middle Button Timeout"
1 16-bit positive value.
.TP 7
+.BI "Evdev Middle Button Button"
+1 8-bit value, allowed range 0-32, 0 disables the button.
+.TP 7
.BI "Evdev Wheel Emulation"
1 boolean value (8 bit, 0 or 1).
.TP 7
diff --git a/src/emuMB.c b/src/emuMB.c
index d1777aa..4f00e0d 100644
--- a/src/emuMB.c
+++ b/src/emuMB.c
@@ -45,6 +45,7 @@
static Atom prop_mbemu = 0; /* Middle button emulation on/off property */
static Atom prop_mbtimeout = 0; /* Middle button timeout property */
+static Atom prop_mbbuton = 0; /* Middle button target button property */
/*
* Lets create a simple finite-state machine for 3 button emulation:
*
@@ -185,6 +186,7 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = pInfo->private;
int id;
+ int mapped_id;
#if HAVE_THREADED_INPUT
input_lock();
@@ -194,7 +196,10 @@ EvdevMBEmuTimer(InputInfoPtr pInfo)
pEvdev->emulateMB.pending = FALSE;
if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) {
- EvdevPostButtonEvent(pInfo, abs(id),
+ mapped_id = abs(id);
+ if (mapped_id == 2)
+ mapped_id = pEvdev->emulateMB.button;
+ EvdevPostButtonEvent(pInfo, mapped_id,
(id >= 0) ? BUTTON_PRESS : BUTTON_RELEASE);
pEvdev->emulateMB.state =
stateTab[pEvdev->emulateMB.state][4][2];
@@ -226,6 +231,7 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
{
EvdevPtr pEvdev = pInfo->private;
int id;
+ int mapped_id;
int *btstate;
int ret = FALSE;
@@ -244,7 +250,10 @@ EvdevMBEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press)
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][0]) != 0)
{
- EvdevQueueButtonEvent(pInfo, abs(id), (id >= 0));
+ mapped_id = abs(id);
+ if (mapped_id == 2)
+ mapped_id = pEvdev->emulateMB.button;
+ EvdevQueueButtonEvent(pInfo, mapped_id, (id >= 0));
ret = TRUE;
}
if ((id = stateTab[pEvdev->emulateMB.state][*btstate][1]) != 0)
@@ -301,12 +310,23 @@ void
EvdevMBEmuPreInit(InputInfoPtr pInfo)
{
EvdevPtr pEvdev = (EvdevPtr)pInfo->private;
+ int bt;
pEvdev->emulateMB.enabled = xf86SetBoolOption(pInfo->options,
"Emulate3Buttons",
FALSE);
pEvdev->emulateMB.timeout = xf86SetIntOption(pInfo->options,
"Emulate3Timeout", 50);
+ bt = xf86SetIntOption(pInfo->options, "Emulate3Button", 2);
+ if (bt < 0 || bt > EVDEV_MAXBUTTONS) {
+ xf86IDrvMsg(pInfo, X_WARNING, "Invalid Emulate3Button value: %d\n",
+ bt);
+ xf86IDrvMsg(pInfo, X_WARNING, "Middle button emulation disabled.\n");
+
+ pEvdev->emulateMB.enabled = FALSE;
+ }
+
+ pEvdev->emulateMB.button = bt;
}
void
@@ -338,6 +358,7 @@ EvdevMBEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
+ int bt;
if (atom == prop_mbemu)
{
@@ -353,6 +374,18 @@ EvdevMBEmuSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
if (!checkonly)
pEvdev->emulateMB.timeout = *((CARD32*)val->data);
+ } else if (atom == prop_mbbuton)
+ {
+ if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER)
+ return BadMatch;
+
+ bt = *((CARD8*)val->data);
+
+ if (bt < 0 || bt > EVDEV_MAXBUTTONS)
+ return BadValue;
+
+ if (!checkonly)
+ pEvdev->emulateMB.button = bt;
}
return Success;
@@ -390,5 +423,15 @@ EvdevMBEmuInitProperty(DeviceIntPtr dev)
return;
XISetDevicePropertyDeletable(dev, prop_mbtimeout, FALSE);
+ prop_mbbuton = MakeAtom(EVDEV_PROP_MIDBUTTON_BUTTON,
+ strlen(EVDEV_PROP_MIDBUTTON_BUTTON),
+ TRUE);
+ rc = XIChangeDeviceProperty(dev, prop_mbbuton, XA_INTEGER, 8, PropModeReplace, 1,
+ &pEvdev->emulateMB.button, FALSE);
+
+ if (rc != Success)
+ return;
+ XISetDevicePropertyDeletable(dev, prop_mbbuton, FALSE);
+
XIRegisterPropertyHandler(dev, EvdevMBEmuSetProperty, NULL, NULL);
}
diff --git a/src/evdev.h b/src/evdev.h
index c506296..7081182 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -196,6 +196,7 @@ typedef struct {
int state; /* state machine (see bt3emu.c) */
Time expires; /* time of expiry */
Time timeout;
+ uint8_t button; /* phys button to emit */
} emulateMB;
/* Third mouse button emulation */
struct emulate3B {