summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2010-05-19 15:37:01 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2010-05-28 09:24:28 +1000
commit7c01cff1faede468efddf2c66c9ca85022585244 (patch)
tree57eef8dde336aafb9de8ac7cae818d7711384a69 /src
parente6e20c1b3e5977830a2b78046c0a8c49e38746fd (diff)
Move EVIOCGRAB into a static func.
This is in preparation of some major rework, there are no functional changes. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r--src/evdev.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/src/evdev.c b/src/evdev.c
index fd8e68c..e09c203 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -93,6 +93,7 @@ static int EvdevOn(DeviceIntPtr);
static int EvdevCacheCompare(InputInfoPtr pInfo, BOOL compare);
static void EvdevKbdCtrl(DeviceIntPtr device, KeybdCtrl *ctrl);
static int EvdevSwitchMode(ClientPtr client, DeviceIntPtr device, int mode);
+static BOOL EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab);
#ifdef HAVE_PROPERTIES
static void EvdevInitAxesLabels(EvdevPtr pEvdev, int natoms, Atom *atoms);
@@ -1529,7 +1530,6 @@ EvdevOn(DeviceIntPtr device)
{
InputInfoPtr pInfo;
EvdevPtr pEvdev;
- int rc = 0;
pInfo = device->public.devicePrivate;
pEvdev = pInfo->private;
@@ -1547,9 +1547,7 @@ EvdevOn(DeviceIntPtr device)
}
}
- if (pEvdev->grabDevice && (rc = ioctl(pInfo->fd, EVIOCGRAB, (void *)1)))
- xf86Msg(X_WARNING, "%s: Grab failed (%s)\n", pInfo->name,
- strerror(errno));
+ EvdevGrabDevice(pInfo, 1, 0);
pEvdev->min_maj = EvdevGetMajorMinor(pInfo);
if (EvdevIsDuplicate(pInfo))
@@ -1591,9 +1589,7 @@ EvdevProc(DeviceIntPtr device, int what)
EvdevMBEmuFinalize(pInfo);
if (pInfo->fd != -1)
{
- if (pEvdev->grabDevice && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
- xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
- strerror(errno));
+ EvdevGrabDevice(pInfo, 0, 1);
xf86RemoveEnabledDevice(pInfo);
close(pInfo->fd);
pInfo->fd = -1;
@@ -1760,27 +1756,39 @@ error:
}
-static int
-EvdevProbe(InputInfoPtr pInfo)
+/**
+ * Issue an EVIOCGRAB on the device file, either as a grab or to ungrab, or
+ * both. Return TRUE on success, otherwise FALSE. Failing the release is a
+ * still considered a success, because it's not as if you could do anything
+ * about it.
+ */
+static BOOL
+EvdevGrabDevice(InputInfoPtr pInfo, int grab, int ungrab)
{
- int i, has_rel_axes, has_abs_axes, has_keys, num_buttons, has_scroll;
- int has_lmr; /* left middle right */
- int ignore_abs = 0, ignore_rel = 0;
EvdevPtr pEvdev = pInfo->private;
- /* If grabDevice is set, ungrab immediately since we only want to grab
- * between DEVICE_ON and DEVICE_OFF. If we never get DEVICE_ON, don't
- * hold a grab. */
if (pEvdev->grabDevice)
{
- if (ioctl(pInfo->fd, EVIOCGRAB, (void *)1)) {
- xf86Msg(X_ERROR, "Grab failed. Device already configured?\n");
- return 1;
- } else if (ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
+ if (grab && ioctl(pInfo->fd, EVIOCGRAB, (void *)1)) {
+ xf86Msg(X_WARNING, "%s: Grab failed (%s)\n", pInfo->name,
+ strerror(errno));
+ return FALSE;
+ } else if (ungrab && ioctl(pInfo->fd, EVIOCGRAB, (void *)0))
xf86Msg(X_WARNING, "%s: Release failed (%s)\n", pInfo->name,
strerror(errno));
}
+ return TRUE;
+}
+
+static int
+EvdevProbe(InputInfoPtr pInfo)
+{
+ int i, has_rel_axes, has_abs_axes, has_keys, num_buttons, has_scroll;
+ int has_lmr; /* left middle right */
+ int ignore_abs = 0, ignore_rel = 0;
+ EvdevPtr pEvdev = pInfo->private;
+
/* Trinary state for ignoring axes:
- unset: do the normal thing.
- TRUE: explicitly ignore them.
@@ -2075,6 +2083,16 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
Note that this needs a server that sets the console to RAW mode. */
pEvdev->grabDevice = xf86CheckBoolOption(dev->commonOptions, "GrabDevice", 0);
+ /* If grabDevice is set, ungrab immediately since we only want to grab
+ * between DEVICE_ON and DEVICE_OFF. If we never get DEVICE_ON, don't
+ * hold a grab. */
+ if (!EvdevGrabDevice(pInfo, 1, 1))
+ {
+ xf86Msg(X_WARNING, "%s: Device may already be configured.\n",
+ pInfo->name);
+ goto error;
+ }
+
EvdevInitButtonMapping(pInfo);
if (EvdevCacheCompare(pInfo, FALSE) ||