diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-25 21:24:07 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-12-20 15:01:56 +1000 |
commit | 91cbc367947556420e546a5c48107aa62da6231f (patch) | |
tree | e37b3d8e551801228a1fa757890afe78bb04abb2 /src | |
parent | 36392bb42a9f34e9b9b4f4045d1db7616f57c059 (diff) | |
download | xf86-input-wacom-91cbc367947556420e546a5c48107aa62da6231f.tar.gz |
Move the device initialization bits into the core driver layer
What remains in the X driver layer is how specifically the classes are
initialized in the server, but *what* gets initialized is now handled by
the driver layer.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/wcmConfig.c | 172 | ||||
-rw-r--r-- | src/xf86Wacom.c | 192 | ||||
-rw-r--r-- | src/xf86Wacom.h | 9 |
3 files changed, 187 insertions, 186 deletions
diff --git a/src/wcmConfig.c b/src/wcmConfig.c index 7772d5e..7b85b8f 100644 --- a/src/wcmConfig.c +++ b/src/wcmConfig.c @@ -860,6 +860,178 @@ int wcmDevOpen(WacomDevicePtr priv) return TRUE; } +/** + * Initialize the device axes with their proper attributes. + * + * For each axis on the device, we need to provide X with its attributes + * so that its values can be interpreted properly. To support older X + * servers without axis labels, each axis index has a de-facto meaning. + * Any de-facto defined axis index left unused is initialized with default + * attributes. + */ +static int wcmInitAxes(WacomDevicePtr priv) +{ + WacomCommonPtr common = priv->common; + int min, max, res; + + /* first valuator: x */ + min = priv->topX; + max = priv->bottomX; + res = priv->resolX; + wcmInitAxis(priv, WACOM_AXIS_X, min, max, res); + + + /* second valuator: y */ + min = priv->topY; + max = priv->bottomY; + res = priv->resolY; + wcmInitAxis(priv, WACOM_AXIS_Y, min, max, res); + + /* third valuator: pressure */ + if (!IsPad(priv)) + { + res = 0; + min = 0; + max = priv->maxCurve; + wcmInitAxis(priv, WACOM_AXIS_PRESSURE, min, max, res); + } + /* FIXME: how to set up this axis on the pad? */ + + /* fourth valuator: tilt-x, cursor:z-rotation, pad:strip-x */ + res = 0; + if (IsPen(priv)) + { + res = round(TILT_RES); + min = TILT_MIN; + max = TILT_MAX; + wcmInitAxis(priv, WACOM_AXIS_TILT_X, min, max, res); + } + else if (IsCursor(priv)) + { + min = MIN_ROTATION; + max = MIN_ROTATION + MAX_ROTATION_RANGE - 1; + wcmInitAxis(priv, WACOM_AXIS_ROTATION, min, max, res); + } + else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP)) + { + min = 0; + max = common->wcmMaxStripX; + wcmInitAxis(priv, WACOM_AXIS_STRIP_X, min, max, res); + } + + /* fifth valuator: tilt-y, cursor:throttle, pad:strip-y */ + res = 0; + if (IsPen(priv)) + { + res = round(TILT_RES); + min = TILT_MIN; + max = TILT_MAX; + wcmInitAxis(priv, WACOM_AXIS_TILT_Y, min, max, res); + } + else if (IsCursor(priv)) + { + min = -1023; + max = 1023; + wcmInitAxis(priv, WACOM_AXIS_THROTTLE, min, max, res); + } + else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP)) + { + min = 0; + max = common->wcmMaxStripY; + wcmInitAxis(priv, WACOM_AXIS_STRIP_Y, min, max, res); + } + + /* sixth valuator: airbrush: abs-wheel, artpen: rotation, pad:abs-wheel */ + res = 0; + if (IsStylus(priv)) + { + max = MAX_ROTATION_RANGE + MIN_ROTATION - 1; + min = MIN_ROTATION; + wcmInitAxis(priv, WACOM_AXIS_WHEEL, min, max, res); + } + else if ((TabletHasFeature(common, WCM_RING)) && IsPad(priv)) + { + /* Touch ring */ + min = common->wcmMinRing; + max = common->wcmMaxRing; + wcmInitAxis(priv, WACOM_AXIS_RING, min, max, res); + } + + /* seventh valuator: abswheel2 */ + if ((TabletHasFeature(common, WCM_DUALRING)) && IsPad(priv)) + { + res = 0; + min = common->wcmMinRing; + max = common->wcmMaxRing; + wcmInitAxis(priv, WACOM_AXIS_RING2, min, max, res); + } + + return TRUE; +} + +int wcmDevInit(WacomDevicePtr priv) +{ + InputInfoPtr pInfo = priv->pInfo; + WacomCommonPtr common = priv->common; + int nbaxes, nbbuttons, nbkeys; + + /* Detect tablet configuration, if possible */ + if (priv->common->wcmModel->DetectConfig) + priv->common->wcmModel->DetectConfig (priv); + + nbaxes = priv->naxes; /* X, Y, Pressure, Tilt-X, Tilt-Y, Wheel */ + if (!nbaxes || nbaxes > 7) + nbaxes = priv->naxes = 7; + nbbuttons = priv->nbuttons; /* Use actual number of buttons, if possible */ + + if (IsPad(priv) && TabletHasFeature(priv->common, WCM_DUALRING)) + nbaxes = priv->naxes = nbaxes + 1; /* ABS wheel 2 */ + + /* if more than 3 buttons, offset by the four scroll buttons, + * otherwise, alloc 7 buttons for scroll wheel. */ + nbbuttons = min(max(nbbuttons + 4, 7), WCM_MAX_BUTTONS); + nbkeys = nbbuttons; /* Same number of keys since any button may be + * configured as an either mouse button or key */ + + DBG(10, priv, + "(%s) %d buttons, %d keys, %d axes\n", + pInfo->type_name, + nbbuttons, nbkeys, nbaxes); + + if (!wcmInitButtons(priv, nbbuttons)) + { + wcmLog(priv, W_ERROR, "unable to allocate Button class device\n"); + return FALSE; + } + + if (!wcmInitKeyboard(priv)) + { + wcmLog(priv, W_ERROR, "unable to init Focus class device\n"); + return FALSE; + } + + if (!wcmInitPointer(priv, nbaxes, is_absolute(priv) ? Absolute : Relative)) + { + wcmLog(priv, W_ERROR, "unable to init Pointer class device\n"); + return FALSE; + } + + if (IsTouch(priv)) { + if (!wcmInitTouch(priv, common->wcmMaxContacts, + TabletHasFeature(common, WCM_LCD))) + { + wcmLog(priv, W_ERROR, "Unable to init touch class device struct!\n"); + return FALSE; + } + priv->common->touch_mask = valuator_mask_new(2); + } + + if (!wcmInitAxes(priv)) + return FALSE; + + return TRUE; +} + Bool wcmDevStart(WacomDevicePtr priv) { WacomCommonPtr common = priv->common; diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c index 7425736..68987ea 100644 --- a/src/xf86Wacom.c +++ b/src/xf86Wacom.c @@ -161,7 +161,7 @@ void wcmEmitTouch(WacomDevicePtr priv, int type, unsigned int touchid, int x, in } -static void wcmInitAxis(WacomDevicePtr priv, enum WacomAxisType type, +void wcmInitAxis(WacomDevicePtr priv, enum WacomAxisType type, int min, int max, int res) { @@ -230,7 +230,7 @@ static void wcmInitAxis(WacomDevicePtr priv, enum WacomAxisType type, Absolute); } -static Bool wcmInitButtons(WacomDevicePtr priv, unsigned int nbuttons) +Bool wcmInitButtons(WacomDevicePtr priv, unsigned int nbuttons) { InputInfoPtr pInfo = priv->pInfo; unsigned char butmap[WCM_MAX_BUTTONS+1]; @@ -248,7 +248,7 @@ static Bool wcmInitButtons(WacomDevicePtr priv, unsigned int nbuttons) static void wcmKbdLedCallback(DeviceIntPtr di, LedCtrl * lcp) { } static void wcmKbdCtrlCallback(DeviceIntPtr di, KeybdCtrl* ctrl) { } -static Bool wcmInitKeyboard(WacomDevicePtr priv) +Bool wcmInitKeyboard(WacomDevicePtr priv) { InputInfoPtr pInfo = priv->pInfo; return InitFocusClassDeviceStruct(pInfo->dev) && @@ -258,7 +258,7 @@ static Bool wcmInitKeyboard(WacomDevicePtr priv) static void wcmDevControlProc(DeviceIntPtr device, PtrCtrl* ctrl) { } -static Bool wcmInitPointer(WacomDevicePtr priv, int naxes, Bool is_absolute) +Bool wcmInitPointer(WacomDevicePtr priv, int naxes, Bool is_absolute) { InputInfoPtr pInfo = priv->pInfo; Atom axis_labels[MAX_VALUATORS] = {0}; @@ -275,7 +275,7 @@ static Bool wcmInitPointer(WacomDevicePtr priv, int naxes, Bool is_absolute) mode | OutOfProximity); } -static Bool wcmInitTouch(WacomDevicePtr priv, int ntouches, Bool is_direct_touch) +Bool wcmInitTouch(WacomDevicePtr priv, int ntouches, Bool is_direct_touch) { InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; @@ -284,185 +284,6 @@ static Bool wcmInitTouch(WacomDevicePtr priv, int ntouches, Bool is_direct_touch 2); } -/** - * Initialize the device axes with their proper attributes. - * - * For each axis on the device, we need to provide X with its attributes - * so that its values can be interpreted properly. To support older X - * servers without axis labels, each axis index has a de-facto meaning. - * Any de-facto defined axis index left unused is initialized with default - * attributes. - */ -static int wcmInitAxes(WacomDevicePtr priv) -{ - WacomCommonPtr common = priv->common; - int min, max, res; - - /* first valuator: x */ - min = priv->topX; - max = priv->bottomX; - res = priv->resolX; - wcmInitAxis(priv, WACOM_AXIS_X, min, max, res); - - - /* second valuator: y */ - min = priv->topY; - max = priv->bottomY; - res = priv->resolY; - wcmInitAxis(priv, WACOM_AXIS_Y, min, max, res); - - /* third valuator: pressure */ - if (!IsPad(priv)) - { - res = 0; - min = 0; - max = priv->maxCurve; - wcmInitAxis(priv, WACOM_AXIS_PRESSURE, min, max, res); - } - /* FIXME: how to set up this axis on the pad? */ - - /* fourth valuator: tilt-x, cursor:z-rotation, pad:strip-x */ - res = 0; - if (IsPen(priv)) - { - res = round(TILT_RES); - min = TILT_MIN; - max = TILT_MAX; - wcmInitAxis(priv, WACOM_AXIS_TILT_X, min, max, res); - } - else if (IsCursor(priv)) - { - min = MIN_ROTATION; - max = MIN_ROTATION + MAX_ROTATION_RANGE - 1; - wcmInitAxis(priv, WACOM_AXIS_ROTATION, min, max, res); - } - else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP)) - { - min = 0; - max = common->wcmMaxStripX; - wcmInitAxis(priv, WACOM_AXIS_STRIP_X, min, max, res); - } - - /* fifth valuator: tilt-y, cursor:throttle, pad:strip-y */ - res = 0; - if (IsPen(priv)) - { - res = round(TILT_RES); - min = TILT_MIN; - max = TILT_MAX; - wcmInitAxis(priv, WACOM_AXIS_TILT_Y, min, max, res); - } - else if (IsCursor(priv)) - { - min = -1023; - max = 1023; - wcmInitAxis(priv, WACOM_AXIS_THROTTLE, min, max, res); - } - else if (IsPad(priv) && TabletHasFeature(common, WCM_STRIP)) - { - min = 0; - max = common->wcmMaxStripY; - wcmInitAxis(priv, WACOM_AXIS_STRIP_Y, min, max, res); - } - - /* sixth valuator: airbrush: abs-wheel, artpen: rotation, pad:abs-wheel */ - res = 0; - if (IsStylus(priv)) - { - max = MAX_ROTATION_RANGE + MIN_ROTATION - 1; - min = MIN_ROTATION; - wcmInitAxis(priv, WACOM_AXIS_WHEEL, min, max, res); - } - else if ((TabletHasFeature(common, WCM_RING)) && IsPad(priv)) - { - /* Touch ring */ - min = common->wcmMinRing; - max = common->wcmMaxRing; - wcmInitAxis(priv, WACOM_AXIS_RING, min, max, res); - } - - /* seventh valuator: abswheel2 */ - if ((TabletHasFeature(common, WCM_DUALRING)) && IsPad(priv)) - { - res = 0; - min = common->wcmMinRing; - max = common->wcmMaxRing; - wcmInitAxis(priv, WACOM_AXIS_RING2, min, max, res); - } - - return TRUE; -} - -/***************************************************************************** - * wcmDevInit -- - * Set up the device's buttons, axes and keys - ****************************************************************************/ - -static int wcmDevInit(DeviceIntPtr pWcm) -{ - InputInfoPtr pInfo = (InputInfoPtr)pWcm->public.devicePrivate; - WacomDevicePtr priv = (WacomDevicePtr)pInfo->private; - WacomCommonPtr common = priv->common; - int nbaxes, nbbuttons, nbkeys; - - /* Detect tablet configuration, if possible */ - if (priv->common->wcmModel->DetectConfig) - priv->common->wcmModel->DetectConfig (priv); - - nbaxes = priv->naxes; /* X, Y, Pressure, Tilt-X, Tilt-Y, Wheel */ - if (!nbaxes || nbaxes > 7) - nbaxes = priv->naxes = 7; - nbbuttons = priv->nbuttons; /* Use actual number of buttons, if possible */ - - if (IsPad(priv) && TabletHasFeature(priv->common, WCM_DUALRING)) - nbaxes = priv->naxes = nbaxes + 1; /* ABS wheel 2 */ - - /* if more than 3 buttons, offset by the four scroll buttons, - * otherwise, alloc 7 buttons for scroll wheel. */ - nbbuttons = min(max(nbbuttons + 4, 7), WCM_MAX_BUTTONS); - nbkeys = nbbuttons; /* Same number of keys since any button may be - * configured as an either mouse button or key */ - - DBG(10, priv, - "(%s) %d buttons, %d keys, %d axes\n", - pInfo->type_name, - nbbuttons, nbkeys, nbaxes); - - if (!wcmInitButtons(priv, nbbuttons)) - { - wcmLog(priv, W_ERROR, "unable to allocate Button class device\n"); - return FALSE; - } - - if (!wcmInitKeyboard(priv)) - { - wcmLog(priv, W_ERROR, "unable to init Focus class device\n"); - return FALSE; - } - - if (!wcmInitPointer(priv, nbaxes, is_absolute(priv) ? Absolute : Relative)) - { - wcmLog(priv, W_ERROR, "unable to init Pointer class device\n"); - return FALSE; - } - - if (IsTouch(priv)) { - if (!wcmInitTouch(priv, common->wcmMaxContacts, - TabletHasFeature(common, WCM_LCD))) - { - wcmLog(priv, W_ERROR, "Unable to init touch class device struct!\n"); - return FALSE; - } - priv->common->touch_mask = valuator_mask_new(2); - } - - if (!wcmInitAxes(priv)) - return FALSE; - - InitWcmDeviceProperties(priv); - - return TRUE; -} /***************************************************************************** * wcmOpen -- @@ -598,8 +419,9 @@ static int wcmDevProc(DeviceIntPtr pWcm, int what) switch (what) { case DEVICE_INIT: - if (!wcmDevInit(pWcm)) + if (!wcmDevInit(priv)) goto out; + InitWcmDeviceProperties(priv); break; case DEVICE_ON: diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h index 9598347..2603470 100644 --- a/src/xf86Wacom.h +++ b/src/xf86Wacom.h @@ -119,12 +119,12 @@ int wcmPreInit(WacomDevicePtr priv); void wcmUnInit(WacomDevicePtr priv); /* Open the **shared** fd, if necessary */ int wcmDevOpen(WacomDevicePtr priv); +int wcmDevInit(WacomDevicePtr priv); /* Close the **shared** fd, if necessary */ void wcmDevClose(WacomDevicePtr priv); Bool wcmDevStart(WacomDevicePtr priv); void wcmDevStop(WacomDevicePtr priv); - /* Open the device with the right serial parmeters */ extern Bool wcmOpen(WacomDevicePtr priv); @@ -297,6 +297,13 @@ static inline Bool wcmAxisGet(const WacomAxisData *data, return TRUE; } +void wcmInitAxis(WacomDevicePtr priv, enum WacomAxisType type, int min, int max, int res); +Bool wcmInitButtons(WacomDevicePtr priv, unsigned int nbuttons); +Bool wcmInitKeyboard(WacomDevicePtr priv); +Bool wcmInitPointer(WacomDevicePtr priv, int naxes, Bool is_absolute); +Bool wcmInitTouch(WacomDevicePtr priv, int ntouches, Bool is_direct_touch); + + void wcmEmitKeycode(WacomDevicePtr priv, int keycode, int state); void wcmEmitMotion(WacomDevicePtr priv, Bool is_absolute, const WacomAxisData *axes); void wcmEmitButton(WacomDevicePtr priv, Bool is_absolute, int button, Bool is_press, |