summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@redhat.com>2008-08-07 17:34:54 +0930
committerPeter Hutterer <peter.hutterer@redhat.com>2008-08-08 16:04:23 +0930
commit134829d911c698704595014ba402516ae9a2f36c (patch)
treee1251750fa92bfd21a5e6c88acccc401bb75d00d
parent4e121b297ee0a9b179f8188926564fb8b2c3f6c8 (diff)
Simplify the property handler registration.
Instead of having separate handlers for each property, just handle all of them in one handler for emuMB, and one handler for emuWheel.
-rw-r--r--src/emuMB.c34
-rw-r--r--src/emuWheel.c106
-rw-r--r--src/evdev.c47
-rw-r--r--src/evdev.h10
4 files changed, 68 insertions, 129 deletions
diff --git a/src/emuMB.c b/src/emuMB.c
index 1992654..40175bf 100644
--- a/src/emuMB.c
+++ b/src/emuMB.c
@@ -47,6 +47,9 @@ enum {
MBEMU_AUTO
};
+static const char *propname_mbemu = "Middle Button Emulation";
+static const char *propname_mbtimeout = "Middle Button Timeout";
+
static Atom prop_mbemu = 0; /* Middle button emulation on/off property */
static Atom prop_mbtimeout = 0; /* Middle button timeout property */
@@ -349,8 +352,11 @@ EvdevMBEmuEnable(InputInfoPtr pInfo, BOOL enable)
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
-Atom
-EvdevMBEmuInitProperty(DeviceIntPtr dev, char* name)
+/**
+ * Initialise property for MB emulation on/off.
+ */
+void
+EvdevMBEmuInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
@@ -358,38 +364,30 @@ EvdevMBEmuInitProperty(DeviceIntPtr dev, char* name)
INT32 valid_vals[] = { MBEMU_DISABLED, MBEMU_ENABLED, MBEMU_AUTO };
if (!dev->button) /* don't init prop for keyboards */
- return 0;
+ return;
- prop_mbemu = MakeAtom(name, strlen(name), TRUE);
+ prop_mbemu = MakeAtom((char*)propname_mbemu, strlen(propname_mbemu), TRUE);
rc = XIChangeDeviceProperty(dev, prop_mbemu, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateMB.enabled,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_mbemu, FALSE, FALSE, FALSE, 3, valid_vals);
if (rc != Success)
- return 0;
- return prop_mbemu;
-}
-
-Atom
-EvdevMBEmuInitPropertyTimeout(DeviceIntPtr dev, char *name)
-{
- InputInfoPtr pInfo = dev->public.devicePrivate;
- EvdevPtr pEvdev = pInfo->private;
- int rc = TRUE;
+ return;
- prop_mbtimeout = MakeAtom(name, strlen(name), TRUE);
+ prop_mbtimeout = MakeAtom((char*)propname_mbtimeout,
+ strlen(propname_mbtimeout),
+ TRUE);
rc = XIChangeDeviceProperty(dev, prop_mbtimeout, XA_INTEGER, 16, PropModeReplace, 1,
&pEvdev->emulateMB.timeout, FALSE, FALSE,
FALSE);
if (rc != Success)
- return 0;
- return prop_mbtimeout;
+ return;
}
BOOL
diff --git a/src/emuWheel.c b/src/emuWheel.c
index 70ef41c..3c0b066 100644
--- a/src/emuWheel.c
+++ b/src/emuWheel.c
@@ -6,6 +6,7 @@
* Copyright 2002 by Paul Elliott
* (Ported from xf86-input-mouse, above copyrights taken from there)
* Copyright 2008 by Chris Salch
+* 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
@@ -42,6 +43,12 @@
#define WHEEL_NOT_CONFIGURED 0
+static const char *propname_wheel_emu = "Wheel Emulation";
+static const char *propname_wheel_xmap = "Wheel Emulation X Axis";
+static const char *propname_wheel_ymap = "Wheel Emulation Y Axis";
+static const char *propname_wheel_inertia = "Wheel Emulation Inertia";
+static const char *propname_wheel_button = "Wheel Emulation Button";
+
static Atom prop_wheel_emu;
static Atom prop_wheel_xmap;
static Atom prop_wheel_ymap;
@@ -295,8 +302,8 @@ EvdevWheelEmuPreInit(InputInfoPtr pInfo)
}
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
-Atom
-EvdevWheelEmuInitProperty(DeviceIntPtr dev, char* name)
+void
+EvdevWheelEmuInitProperty(DeviceIntPtr dev)
{
InputInfoPtr pInfo = dev->public.devicePrivate;
EvdevPtr pEvdev = pInfo->private;
@@ -304,132 +311,79 @@ EvdevWheelEmuInitProperty(DeviceIntPtr dev, char* name)
INT32 valid_vals[] = { TRUE, FALSE};
if (!dev->button) /* don't init prop for keyboards */
- return 0;
+ return;
- prop_wheel_emu = MakeAtom(name, strlen(name), TRUE);
+ prop_wheel_emu = MakeAtom((char*)propname_wheel_emu, strlen(propname_wheel_emu), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_emu, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateWheel.enabled,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_wheel_emu, FALSE, FALSE,
FALSE, 2, valid_vals);
if (rc != Success)
- return 0;
- return prop_wheel_emu;
-}
-
-Atom
-EvdevWheelEmuInitPropertyXMap(DeviceIntPtr dev, char* name)
-{
- InputInfoPtr pInfo = dev->public.devicePrivate;
- EvdevPtr pEvdev = pInfo->private;
- int rc = TRUE;
- int vals[2];
-
- if (!dev->button) /* don't init prop for keyboards */
- return 0;
+ return;
- vals[0] = pEvdev->emulateWheel.X.up_button;
- vals[1] = pEvdev->emulateWheel.X.down_button;
+ valid_vals[0] = pEvdev->emulateWheel.X.up_button;
+ valid_vals[1] = pEvdev->emulateWheel.X.down_button;
- prop_wheel_xmap = MakeAtom(name, strlen(name), TRUE);
+ prop_wheel_xmap = MakeAtom((char*)propname_wheel_xmap, strlen(propname_wheel_xmap), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_xmap, XA_INTEGER, 8,
- PropModeReplace, 2, vals,
+ PropModeReplace, 2, valid_vals,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_wheel_xmap, FALSE, FALSE,
FALSE, 0, NULL);
if (rc != Success)
- return 0;
- return prop_wheel_xmap;
-}
-
-Atom
-EvdevWheelEmuInitPropertyYMap(DeviceIntPtr dev, char* name)
-{
- InputInfoPtr pInfo = dev->public.devicePrivate;
- EvdevPtr pEvdev = pInfo->private;
- int rc = TRUE;
- int vals[2];
-
- if (!dev->button) /* don't init prop for keyboards */
- return 0;
+ return;
- vals[0] = pEvdev->emulateWheel.Y.up_button;
- vals[1] = pEvdev->emulateWheel.Y.down_button;
+ valid_vals[0] = pEvdev->emulateWheel.Y.up_button;
+ valid_vals[1] = pEvdev->emulateWheel.Y.down_button;
- prop_wheel_ymap = MakeAtom(name, strlen(name), TRUE);
+ prop_wheel_ymap = MakeAtom((char*)propname_wheel_ymap, strlen(propname_wheel_ymap), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_ymap, XA_INTEGER, 8,
- PropModeReplace, 2, vals,
+ PropModeReplace, 2, valid_vals,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_wheel_ymap, FALSE, FALSE,
FALSE, 0, NULL);
- if (rc != Success)
- return 0;
- return prop_wheel_ymap;
-}
-
-Atom
-EvdevWheelEmuInitPropertyInertia(DeviceIntPtr dev, char* name)
-{
- InputInfoPtr pInfo = dev->public.devicePrivate;
- EvdevPtr pEvdev = pInfo->private;
- int rc = TRUE;
-
- if (!dev->button) /* don't init prop for keyboards */
- return 0;
- prop_wheel_inertia = MakeAtom(name, strlen(name), TRUE);
+ prop_wheel_inertia = MakeAtom((char*)propname_wheel_inertia, strlen(propname_wheel_inertia), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_inertia, XA_INTEGER, 16,
PropModeReplace, 1,
&pEvdev->emulateWheel.inertia,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_wheel_inertia, FALSE, FALSE,
FALSE, 0, NULL);
if (rc != Success)
- return 0;
- return prop_wheel_inertia;
-}
-
-Atom
-EvdevWheelEmuInitPropertyButton(DeviceIntPtr dev, char* name)
-{
- InputInfoPtr pInfo = dev->public.devicePrivate;
- EvdevPtr pEvdev = pInfo->private;
- int rc = TRUE;
-
- if (!dev->button) /* don't init prop for keyboards */
- return 0;
+ return;
- prop_wheel_button = MakeAtom(name, strlen(name), TRUE);
+ prop_wheel_button = MakeAtom((char*)propname_wheel_button, strlen(propname_wheel_button), TRUE);
rc = XIChangeDeviceProperty(dev, prop_wheel_button, XA_INTEGER, 8,
PropModeReplace, 1,
&pEvdev->emulateWheel.button,
FALSE, FALSE, FALSE);
if (rc != Success)
- return 0;
+ return;
rc = XIConfigureDeviceProperty(dev, prop_wheel_button, FALSE, FALSE,
FALSE, 0, NULL);
if (rc != Success)
- return 0;
- return prop_wheel_button;
+ return;
}
diff --git a/src/evdev.c b/src/evdev.c
index a383d7b..a80a433 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -96,22 +96,16 @@ static const char *evdevDefaults[] = {
};
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
-typedef struct _PropTable {
- Atom prop;
- char *prop_name;
- Atom (*init)(DeviceIntPtr dev, char* name);
- BOOL (*handler)(DeviceIntPtr dev, Atom prop, XIPropertyValuePtr val);
-} PropTable, *PropTableEntryPtr;
-
-static PropTable evdevPropTable[] = {
- { 0, "Middle Button Emulation", EvdevMBEmuInitProperty, EvdevMBEmuSetProperty },
- { 0, "Middle Button Timeout", EvdevMBEmuInitPropertyTimeout, EvdevMBEmuSetProperty},
- { 0, "Wheel Emulation", EvdevWheelEmuInitProperty, EvdevWheelEmuSetProperty},
- { 0, "Wheel Emulation X Axis", EvdevWheelEmuInitPropertyXMap, EvdevWheelEmuSetProperty},
- { 0, "Wheel Emulation Y Axis", EvdevWheelEmuInitPropertyYMap, EvdevWheelEmuSetProperty},
- { 0, "Wheel Emulation Inertia", EvdevWheelEmuInitPropertyInertia, EvdevWheelEmuSetProperty},
- { 0, "Wheel Emulation Button", EvdevWheelEmuInitPropertyButton, EvdevWheelEmuSetProperty},
- { 0, NULL, NULL, NULL }
+typedef struct _PropHandler {
+ void (*init)(DeviceIntPtr dev);
+ BOOL (*handle)(DeviceIntPtr dev, Atom prop, XIPropertyValuePtr val);
+} PropHandler;
+
+static PropHandler evdevPropHandlers[] =
+{
+ {EvdevMBEmuInitProperty, EvdevMBEmuSetProperty},
+ {EvdevWheelEmuInitProperty, EvdevWheelEmuSetProperty},
+ {NULL, NULL}
};
#endif
@@ -178,13 +172,13 @@ PostKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value)
static Bool
EvdevSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr val)
{
- PropTableEntryPtr entry = evdevPropTable;
+ PropHandler *handler = evdevPropHandlers;
- while (entry && entry->prop_name)
+ while (handler->init || handler->handle)
{
- if (entry->prop == property)
- return entry->handler(dev, property, val);
- entry++;
+ if (handler->handle && !handler->handle(dev, property, val))
+ return FALSE;
+ handler++;
}
/* property not handled, report success */
@@ -882,13 +876,12 @@ EvdevInitButtonMapping(InputInfoPtr pInfo)
static void
EvdevInitProperties(DeviceIntPtr device)
{
- PropTableEntryPtr entry;
-
- entry = evdevPropTable;
- while(entry && entry->prop_name)
+ PropHandler *handler = evdevPropHandlers;
+ while(handler->init || handler->handle)
{
- entry->prop = (*entry->init)(device, entry->prop_name);
- entry++;
+ if (handler->init)
+ (*handler->init)(device);
+ handler++;
}
}
diff --git a/src/evdev.h b/src/evdev.h
index 91e382f..a0a336a 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -101,16 +101,10 @@ void EvdevMBEmuEnable(InputInfoPtr, BOOL);
unsigned int EvdevUtilButtonEventToButtonNumber(int code);
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
-Atom EvdevMBEmuInitProperty(DeviceIntPtr, char*);
-Atom EvdevMBEmuInitPropertyTimeout(DeviceIntPtr, char*);
+void EvdevMBEmuInitProperty(DeviceIntPtr);
BOOL EvdevMBEmuSetProperty(DeviceIntPtr, Atom, XIPropertyValuePtr);
-Atom EvdevWheelEmuInitProperty(DeviceIntPtr, char*);
-Atom EvdevWheelEmuInitPropertyXMap(DeviceIntPtr, char*);
-Atom EvdevWheelEmuInitPropertyYMap(DeviceIntPtr, char*);
-Atom EvdevWheelEmuInitPropertyInertia(DeviceIntPtr, char*);
-Atom EvdevWheelEmuInitPropertyButton(DeviceIntPtr, char*);
-
+void EvdevWheelEmuInitProperty(DeviceIntPtr);
BOOL EvdevWheelEmuSetProperty(DeviceIntPtr, Atom, XIPropertyValuePtr);
#endif