[PATCH evdev 4/8] Move EVIOCGRAB into a static func.

Peter Hutterer peter.hutterer at who-t.net
Sun May 23 17:57:44 PDT 2010


This is in preparation of some major rework, there are no functional
changes.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c |   56 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index fd8e68c..c5b6e5f 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 EVICGRAB 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) ||
-- 
1.7.0.1



More information about the xorg-devel mailing list