Probe for the model during PreInit and get the important bits off the device
here.
During DEVICE_INIT, just register the X server bits required for the device
to be a device.
DEVICE_OPEN actually opens the device, but by then we already know
everything about it anyway.

A large hunk of this patch is just whitespace change due to a indentation
level change in wcmRegisterX11Devices.

This also removes the need for wcmDevOpenCount and wcmInitKeyClassCount.

Signed-off-by: Peter Hutterer <[email protected]>
---
 src/wcmCommon.c     |    4 --
 src/wcmConfig.c     |   45 +++++++++++++++++++++
 src/xf86Wacom.c     |  109 ++++++++++++++++-----------------------------------
 src/xf86WacomDefs.h |    2 -
 4 files changed, 79 insertions(+), 81 deletions(-)

diff --git a/src/wcmCommon.c b/src/wcmCommon.c
index ced4773..6e485be 100644
--- a/src/wcmCommon.c
+++ b/src/wcmCommon.c
@@ -1638,10 +1638,6 @@ int wcmInitTablet(LocalDevicePtr local, const char* id, 
float version)
                        common->wcmResolX, common->wcmResolY,
                        HANDLE_TILT(common) ? "enabled" : "disabled");
 
-       /* start the tablet data */
-       if (model->Start && (model->Start(local) != Success))
-               return !Success;
-
        return Success;
 }
 
diff --git a/src/wcmConfig.c b/src/wcmConfig.c
index f7c1c09..3a459eb 100644
--- a/src/wcmConfig.c
+++ b/src/wcmConfig.c
@@ -26,6 +26,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <linux/serial.h>
 
 /*****************************************************************************
  * wcmAllocate --
@@ -376,6 +377,47 @@ static Bool wcmMatchDevice(LocalDevicePtr pLocal)
        return 0;
 }
 
+static Bool
+wcmInitModel(LocalDevicePtr local)
+{
+       WacomDevicePtr priv = (WacomDevicePtr)local->private;
+       WacomCommonPtr common = priv->common;
+       struct serial_struct ser;
+       int rc;
+       char id[BUFFER_SIZE];
+       float version;
+
+       rc = ioctl(local->fd, TIOCGSERIAL, &ser);
+
+       /* we initialized wcmDeviceClasses to USB
+        * Bluetooth is also considered as USB */
+       if (rc == 0) /* serial device */
+       {
+               /* only ISDV4 are supported on X server 1.7 and later */
+               common->wcmForceDevice = DEVICE_ISDV4;
+               common->wcmDevCls = &gWacomISDV4Device;
+       }
+       else
+       {
+               /* Detect USB device class */
+               if ((&gWacomUSBDevice)->Detect(local))
+                       common->wcmDevCls = &gWacomUSBDevice;
+               else
+               {
+                       xf86Msg(X_ERROR, "%s: wcmInitModel found undetectable "
+                               " %s \n", local->name, common->wcmDevice);
+                       return FALSE;
+               }
+       }
+
+       /* Initialize the tablet */
+       if(common->wcmDevCls->Init(local, id, &version) != Success ||
+               wcmInitTablet(local, id, version) != Success)
+               return FALSE;
+
+       return TRUE;
+}
+
 /* wcmPreInit - called for each input devices with the driver set to
  * "wacom" */
 static LocalDevicePtr wcmPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
@@ -475,6 +517,9 @@ static LocalDevicePtr wcmPreInit(InputDriverPtr drv, 
IDevPtr dev, int flags)
        if (!wcmParseOptions(local, need_hotplug))
                goto SetupProc_fail;
 
+       if (!wcmInitModel(local))
+               goto SetupProc_fail;
+
        /* mark the device configured */
        local->flags |= XI86_POINTER_CAPABLE | XI86_CONFIGURED;
 
diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c
index f8bc54f..472eaa9 100644
--- a/src/xf86Wacom.c
+++ b/src/xf86Wacom.c
@@ -42,7 +42,6 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <linux/serial.h>
 
 #include "xf86Wacom.h"
 #include <xf86_OSproc.h>
@@ -631,35 +630,31 @@ static int wcmRegisterX11Devices (LocalDevicePtr local)
        }
 
 
-       /* only initial KeyClass and LedFeedbackClass once */
-       if (!priv->wcmInitKeyClassCount)
-       {
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
-               if (InitKeyboardDeviceStruct(local->dev, NULL, NULL, 
wcmKbdCtrlCallback)) {
+       if (InitKeyboardDeviceStruct(local->dev, NULL, NULL, 
wcmKbdCtrlCallback)) {
 #define SYMS_PER_KEY 2
-                       KeySymsRec syms;
-                       CARD8 modmap[MAP_LENGTH];
-                       int num_keys = XkbMaxLegalKeyCode - XkbMinLegalKeyCode 
+ 1;
-
-                       syms.map = keymap;
-                       syms.mapWidth = SYMS_PER_KEY;
-                       syms.minKeyCode = XkbMinLegalKeyCode;
-                       syms.maxKeyCode = XkbMaxLegalKeyCode;
-
-                       memset(modmap, 0, sizeof(modmap));
-                       modmap[XkbMinLegalKeyCode + 2] = ShiftMask;
-                       XkbApplyMappingChange(local->dev, &syms, 
syms.minKeyCode, num_keys, NULL, // modmap,
-                                       serverClient);
-               } else
-               {
-                       xf86Msg(X_ERROR, "%s: unable to init kbd device 
struct\n", local->name);
-                       return FALSE;
-               }
+               KeySymsRec syms;
+               CARD8 modmap[MAP_LENGTH];
+               int num_keys = XkbMaxLegalKeyCode - XkbMinLegalKeyCode + 1;
+
+               syms.map = keymap;
+               syms.mapWidth = SYMS_PER_KEY;
+               syms.minKeyCode = XkbMinLegalKeyCode;
+               syms.maxKeyCode = XkbMaxLegalKeyCode;
+
+               memset(modmap, 0, sizeof(modmap));
+               modmap[XkbMinLegalKeyCode + 2] = ShiftMask;
+               XkbApplyMappingChange(local->dev, &syms, syms.minKeyCode, 
num_keys, NULL, // modmap,
+                               serverClient);
+       } else
+       {
+               xf86Msg(X_ERROR, "%s: unable to init kbd device struct\n", 
local->name);
+               return FALSE;
+       }
 #endif
-               if(InitLedFeedbackClassDeviceStruct (local->dev, 
wcmKbdLedCallback) == FALSE) {
-                       xf86Msg(X_ERROR, "%s: unable to init led feedback 
device struct\n", local->name);
-                       return FALSE;
-               }
+       if(InitLedFeedbackClassDeviceStruct (local->dev, wcmKbdLedCallback) == 
FALSE) {
+               xf86Msg(X_ERROR, "%s: unable to init led feedback device 
struct\n", local->name);
+               return FALSE;
        }
 
        wcmInitialToolSize(local);
@@ -837,10 +832,6 @@ static Bool wcmOpen(LocalDevicePtr local)
 {
        WacomDevicePtr priv = (WacomDevicePtr)local->private;
        WacomCommonPtr common = priv->common;
-       char id[BUFFER_SIZE];
-       float version;
-       int rc;
-       struct serial_struct ser;
 
        DBG(1, priv, "opening device file\n");
 
@@ -852,38 +843,14 @@ static Bool wcmOpen(LocalDevicePtr local)
                return !Success;
        }
 
-       rc = ioctl(local->fd, TIOCGSERIAL, &ser);
+       return Success;
+}
 
-       /* we initialized wcmDeviceClasses to USB
-        * Bluetooth is also considered as USB */
-       if (rc == 0) /* serial device */
-       {
-               /* only ISDV4 are supported on X server 1.7 and later */
-               common->wcmForceDevice=DEVICE_ISDV4;
-               common->wcmDevCls = &gWacomISDV4Device;
-       }
-       else
-       {
-               /* Detect USB device class */
-               if ((&gWacomUSBDevice)->Detect(local))
-                       common->wcmDevCls = &gWacomUSBDevice;
-               else
-               {
-                       xf86Msg(X_ERROR, "%s: wcmOpen found undetectable "
-                               " %s \n", local->name, common->wcmDevice);
-                       return !Success;
-               }
-       }
+static int wcmDevInit(DeviceIntPtr pWcm)
+{
+       LocalDevicePtr local = (LocalDevicePtr)pWcm->public.devicePrivate;
 
-       /* Initialize the tablet */
-       if(common->wcmDevCls->Init(local, id, &version) != Success ||
-               wcmInitTablet(local, id, version) != Success)
-       {
-               xf86CloseSerial(local->fd);
-               local->fd = -1;
-               return !Success;
-       }
-       return Success;
+       return wcmRegisterX11Devices (local);
 }
 
 /*****************************************************************************
@@ -896,14 +863,11 @@ static int wcmDevOpen(DeviceIntPtr pWcm)
        LocalDevicePtr local = (LocalDevicePtr)pWcm->public.devicePrivate;
        WacomDevicePtr priv = (WacomDevicePtr)local->private;
        WacomCommonPtr common = priv->common;
+       WacomModelPtr model = common->wcmModel;
        struct stat st;
 
        DBG(10, priv, "\n");
 
-       /* Device has been open and not autoprobed */
-       if (priv->wcmDevOpenCount)
-               return TRUE;
-
        /* open file, if not already open */
        if (common->fd_refs == 0)
        {
@@ -943,8 +907,9 @@ static int wcmDevOpen(DeviceIntPtr pWcm)
                common->fd_refs++;
        }
 
-       if (!wcmRegisterX11Devices (local))
-               return FALSE;
+       /* start the tablet data */
+       if (model->Start && (model->Start(local) != Success))
+               return !Success;
 
        return TRUE;
 }
@@ -1134,18 +1099,13 @@ static int wcmDevProc(DeviceIntPtr pWcm, int what)
        switch (what)
        {
                case DEVICE_INIT:
-                       priv->wcmDevOpenCount = 0;
-                       priv->wcmInitKeyClassCount = 0;
-                       if (!wcmDevOpen(pWcm))
+                       if (!wcmDevInit(pWcm))
                                goto out;
-                       priv->wcmInitKeyClassCount++;
-                       priv->wcmDevOpenCount++;
-                       break; 
+                       break;
 
                case DEVICE_ON:
                        if (!wcmDevOpen(pWcm))
                                goto out;
-                       priv->wcmDevOpenCount++;
                        xf86AddEnabledDevice(local);
                        pWcm->public.on = TRUE;
                        break;
@@ -1158,7 +1118,6 @@ static int wcmDevProc(DeviceIntPtr pWcm, int what)
                                wcmDevClose(local);
                        }
                        pWcm->public.on = FALSE;
-                       priv->wcmDevOpenCount = 0;
                        break;
 
                default:
diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
index 6884ec2..f4481a8 100644
--- a/src/xf86WacomDefs.h
+++ b/src/xf86WacomDefs.h
@@ -243,8 +243,6 @@ struct _WacomDeviceRec
        int tvoffsetY;          /* Y edge offset for TwinView setup */
        int tvResolution[4];    /* twinview screens' resultion */
        int wcmMMonitor;        /* disable/enable moving across screens in 
multi-monitor desktop */
-       int wcmDevOpenCount;    /* Device open count */
-       int wcmInitKeyClassCount;    /* Device InitKeyClassDeviceStruct count */
 
        /* JEJ - throttle */
        int throttleStart;      /* time in ticks for last wheel movement */
-- 
1.7.0.1


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to