diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2010-05-20 14:24:05 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2010-05-28 09:24:28 +1000 |
commit | e7c301563a4b1718d2fc0066c1b3125404e3060f (patch) | |
tree | 08895676311e48678650f2ed8974b50b0ed6b1f8 | |
parent | ffc2c9961f5fb099b85a97550a30a854420ee773 (diff) |
Move opening the device into a separate function.
Re-use from EvdevOn and PreInit.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/evdev.c | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/src/evdev.c b/src/evdev.c index e54a8ed..624f431 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -95,6 +95,7 @@ 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); static void EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4]); +static BOOL EvdevOpenDevice(InputInfoPtr pInfo); #ifdef HAVE_PROPERTIES static void EvdevInitAxesLabels(EvdevPtr pEvdev, int natoms, Atom *atoms); @@ -1534,30 +1535,12 @@ EvdevOn(DeviceIntPtr device) pInfo = device->public.devicePrivate; pEvdev = pInfo->private; - - if (pInfo->fd == -1) /* after PreInit fd is still open */ - { - do { - pInfo->fd = open(pEvdev->device, O_RDWR | O_NONBLOCK, 0); - } while (pInfo->fd < 0 && errno == EINTR); - - if (pInfo->fd < 0) { - xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", - pEvdev->device); - return !Success; - } - } + /* after PreInit fd is still open */ + if (!EvdevOpenDevice(pInfo)) + return !Success; EvdevGrabDevice(pInfo, 1, 0); - pEvdev->min_maj = EvdevGetMajorMinor(pInfo); - if (EvdevIsDuplicate(pInfo)) - { - xf86Msg(X_WARNING, "%s: Refusing to enable duplicate device.\n", - pInfo->name); - return !Success; - } - xf86FlushInput(pInfo->fd); xf86AddEnabledDevice(pInfo); EvdevMBEmuOn(pInfo); @@ -2014,11 +1997,53 @@ EvdevSetCalibration(InputInfoPtr pInfo, int num_calibration, int calibration[4]) } } +static BOOL +EvdevOpenDevice(InputInfoPtr pInfo) +{ + EvdevPtr pEvdev = pInfo->private; + char *device = (char*)pEvdev->device; + + if (!device) + { + device = xf86CheckStrOption(pInfo->options, "Device", NULL); + if (!device) { + xf86Msg(X_ERROR, "%s: No device specified.\n", pInfo->name); + return FALSE; + } + + pEvdev->device = device; + xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device); + } + + if (pInfo->fd < 0) + { + do { + pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0); + } while (pInfo->fd < 0 && errno == EINTR); + + if (pInfo->fd < 0) { + xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", device); + return FALSE; + } + } + + /* Check major/minor of device node to avoid adding duplicate devices. */ + pEvdev->min_maj = EvdevGetMajorMinor(pInfo); + if (EvdevIsDuplicate(pInfo)) + { + xf86Msg(X_WARNING, "%s: device file is duplicate. Ignoring.\n", + pInfo->name); + close(pInfo->fd); + return FALSE; + } + + return TRUE; +} + static InputInfoPtr EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags) { InputInfoPtr pInfo; - const char *device; EvdevPtr pEvdev; if (!(pInfo = xf86AllocateInput(drv, 0))) @@ -2051,39 +2076,15 @@ EvdevPreInit(InputDriverPtr drv, IDevPtr dev, int flags) xf86CollectInputOptions(pInfo, evdevDefaults, NULL); xf86ProcessCommonOptions(pInfo, pInfo->options); + if (!EvdevOpenDevice(pInfo)) + goto error; + /* * We initialize pEvdev->tool to 1 so that device that doesn't use * proximity will still report events. */ pEvdev->tool = 1; - device = xf86CheckStrOption(dev->commonOptions, "Device", NULL); - if (!device) { - xf86Msg(X_ERROR, "%s: No device specified.\n", pInfo->name); - goto error; - } - - pEvdev->device = device; - - xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device); - do { - pInfo->fd = open(device, O_RDWR | O_NONBLOCK, 0); - } while (pInfo->fd < 0 && errno == EINTR); - - if (pInfo->fd < 0) { - xf86Msg(X_ERROR, "Unable to open evdev device \"%s\".\n", device); - goto error; - } - - /* Check major/minor of device node to avoid adding duplicate devices. */ - pEvdev->min_maj = EvdevGetMajorMinor(pInfo); - if (EvdevIsDuplicate(pInfo)) - { - xf86Msg(X_WARNING, "%s: device file already in use. Ignoring.\n", - pInfo->name); - goto error; - } - /* Grabbing the event device stops in-kernel event forwarding. In other words, it disables rfkill and the "Macintosh mouse button emulation". Note that this needs a server that sets the console to RAW mode. */ |