diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-26 09:55:30 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-12-20 15:01:56 +1000 |
commit | bff714f45b48b551c0662658578c5e4080738670 (patch) | |
tree | fd615dc447abf9aaf0549141b85a53e6fa68cf3f | |
parent | 6e10faec5fcd09bd1390a0d59f436f14e5555e77 (diff) | |
download | xf86-input-wacom-bff714f45b48b551c0662658578c5e4080738670.tar.gz |
Switch the type handling to an enum
The init code remains largely as-is but as soon as sensible, change this
to an enum value and keep it in the device. The X driver layer can
convert that into the type_name as required.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/wcmConfig.c | 77 | ||||
-rw-r--r-- | src/xf86Wacom.c | 19 | ||||
-rw-r--r-- | src/xf86Wacom.h | 2 | ||||
-rw-r--r-- | src/xf86WacomDefs.h | 10 | ||||
-rw-r--r-- | test/wacom-tests.c | 16 |
5 files changed, 72 insertions, 52 deletions
diff --git a/src/wcmConfig.c b/src/wcmConfig.c index 0409229..8d04767 100644 --- a/src/wcmConfig.c +++ b/src/wcmConfig.c @@ -126,33 +126,34 @@ static void wcmFree(WacomDevicePtr priv) } TEST_NON_STATIC Bool -wcmSetFlags(WacomDevicePtr priv, const char *type) +wcmSetFlags(WacomDevicePtr priv, WacomType type) { - if (!type) - goto invalid; + int flags = 0; - if (strcasecmp(type, "stylus") == 0) - { - priv->flags = ABSOLUTE_FLAG|STYLUS_ID; - } else if (strcasecmp(type, "touch") == 0) + switch (type) { - int flags = TOUCH_ID; - - if (TabletHasFeature(priv->common, WCM_LCD)) - flags |= ABSOLUTE_FLAG; + case WTYPE_STYLUS: + flags = ABSOLUTE_FLAG|STYLUS_ID; + break; + case WTYPE_TOUCH: + flags = TOUCH_ID; + if (TabletHasFeature(priv->common, WCM_LCD)) + flags |= ABSOLUTE_FLAG; + break; + case WTYPE_CURSOR: + flags = CURSOR_ID; + break; + case WTYPE_ERASER: + flags = ABSOLUTE_FLAG|ERASER_ID; + break; + case WTYPE_PAD: + flags = ABSOLUTE_FLAG|PAD_ID; + break; + default: + goto invalid; + } - priv->flags = flags; - } else if (strcasecmp(type, "cursor") == 0) - { - priv->flags = CURSOR_ID; - } else if (strcasecmp(type, "eraser") == 0) - { - priv->flags = ABSOLUTE_FLAG|ERASER_ID; - } else if (strcasecmp(type, "pad") == 0) - { - priv->flags = ABSOLUTE_FLAG|PAD_ID; - } else - goto invalid; + priv->flags = flags; /* Set the device id of the "last seen" device on this tool */ priv->oldState.device_id = wcmGetPhyDeviceID(priv); @@ -160,7 +161,7 @@ wcmSetFlags(WacomDevicePtr priv, const char *type) if (!priv->tool) return FALSE; - priv->tool->typeid = DEVICE_ID(priv->flags); /* tool type (stylus/touch/eraser/cursor/pad) */ + priv->tool->typeid = DEVICE_ID(flags); /* tool type (stylus/touch/eraser/cursor/pad) */ return TRUE; @@ -670,6 +671,24 @@ static void wcmInitActions(WacomDevicePtr priv) } } +static inline WacomType getType(const char *type) +{ + WacomType wtype = WTYPE_INVALID; + + if (strcasecmp(type, "stylus") == 0) + wtype = WTYPE_STYLUS; + else if (strcasecmp(type, "touch") == 0) + wtype = WTYPE_TOUCH; + else if (strcasecmp(type, "cursor") == 0) + wtype = WTYPE_CURSOR; + else if (strcasecmp(type, "eraser") == 0) + wtype = WTYPE_ERASER; + else if (strcasecmp(type, "pad") == 0) + wtype = WTYPE_PAD; + + return wtype; +} + /* wcmPreInit - called for each input devices with the driver set to * "wacom" */ int wcmPreInit(WacomDevicePtr priv) @@ -743,7 +762,9 @@ int wcmPreInit(WacomDevicePtr priv) goto SetupProc_fail; } - if (!wcmSetFlags(priv, type)) + priv->type = getType(type); + + if (!wcmSetFlags(priv, priv->type)) goto SetupProc_fail; if (!wcmPreInitParseOptions(priv, need_hotplug, is_dependent)) @@ -952,7 +973,6 @@ static int wcmInitAxes(WacomDevicePtr priv) int wcmDevInit(WacomDevicePtr priv) { - InputInfoPtr pInfo = priv->pInfo; WacomCommonPtr common = priv->common; int nbaxes, nbbuttons, nbkeys; @@ -975,9 +995,8 @@ int wcmDevInit(WacomDevicePtr priv) * 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); + "(type %d) %d buttons, %d keys, %d axes\n", + priv->type, nbbuttons, nbkeys, nbaxes); if (!wcmInitButtons(priv, nbbuttons)) { diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c index e098032..2302379 100644 --- a/src/xf86Wacom.c +++ b/src/xf86Wacom.c @@ -772,7 +772,6 @@ static int wcmDevSwitchMode(ClientPtr client, DeviceIntPtr dev, int mode) static int preInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) { WacomDevicePtr priv = NULL; - const char *type = NULL; Status status; pInfo->device_control = wcmDevProc; @@ -789,17 +788,13 @@ static int preInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) if ((status = wcmPreInit(priv)) != Success) return status; - if (strcasecmp(type, "stylus") == 0) - pInfo->type_name = WACOM_PROP_XI_TYPE_STYLUS; - else if (strcasecmp(type, "touch") == 0) - pInfo->type_name = WACOM_PROP_XI_TYPE_TOUCH; - else if (strcasecmp(type, "cursor") == 0) - pInfo->type_name = WACOM_PROP_XI_TYPE_CURSOR; - else if (strcasecmp(type, "eraser") == 0) - pInfo->type_name = WACOM_PROP_XI_TYPE_ERASER; - else if (strcasecmp(type, "pad") == 0) - pInfo->type_name = WACOM_PROP_XI_TYPE_PAD; - else { + switch (priv->type) { + case WTYPE_STYLUS: pInfo->type_name = WACOM_PROP_XI_TYPE_STYLUS; break; + case WTYPE_ERASER: pInfo->type_name = WACOM_PROP_XI_TYPE_ERASER; break; + case WTYPE_CURSOR: pInfo->type_name = WACOM_PROP_XI_TYPE_CURSOR; break; + case WTYPE_PAD: pInfo->type_name = WACOM_PROP_XI_TYPE_PAD; break; + case WTYPE_TOUCH: pInfo->type_name = WACOM_PROP_XI_TYPE_TOUCH; break; + default: xf86IDrvMsg(pInfo, X_ERROR, "No type or invalid type specified.\n" "Must be one of stylus, touch, cursor, eraser, or pad\n"); diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h index f3dc677..a99da21 100644 --- a/src/xf86Wacom.h +++ b/src/xf86Wacom.h @@ -201,7 +201,7 @@ enum WacomSuppressMode { extern void wcmInitialToolSize(WacomDevicePtr priv); /* wcmConfig.c */ -extern int wcmSetFlags(WacomDevicePtr priv, const char *type); +extern int wcmSetFlags(WacomDevicePtr priv, WacomType type); /* wcmCommon.c */ extern int getScrollDelta(int current, int old, int wrap, int flags); diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h index d526822..6c57a8b 100644 --- a/src/xf86WacomDefs.h +++ b/src/xf86WacomDefs.h @@ -218,9 +218,19 @@ typedef struct { size_t nactions; } WacomAction; +typedef enum { + WTYPE_INVALID = 0, + WTYPE_STYLUS, + WTYPE_ERASER, + WTYPE_CURSOR, + WTYPE_PAD, + WTYPE_TOUCH, +} WacomType; + struct _WacomDeviceRec { char *name; /* Do not move, same offset as common->device_path. Used by DBG macro */ + WacomType type; /* configuration fields */ struct _WacomDeviceRec *next; InputInfoPtr pInfo; diff --git a/test/wacom-tests.c b/test/wacom-tests.c index 2cb291a..7a1aad5 100644 --- a/test/wacom-tests.c +++ b/test/wacom-tests.c @@ -541,11 +541,7 @@ static void test_set_type(void) reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, NULL); - assert(rc == 0); - - reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "stylus"); + rc = wcmSetFlags(&priv, WTYPE_STYLUS); assert(rc == 1); assert(is_absolute(&priv)); assert(IsStylus(&priv)); @@ -555,7 +551,7 @@ static void test_set_type(void) assert(!IsPad(&priv)); reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "touch"); + rc = wcmSetFlags(&priv, WTYPE_TOUCH); assert(rc == 1); /* only some touch screens are absolute */ assert(!is_absolute(&priv)); @@ -566,7 +562,7 @@ static void test_set_type(void) assert(!IsPad(&priv)); reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "eraser"); + rc = wcmSetFlags(&priv, WTYPE_ERASER); assert(rc == 1); assert(is_absolute(&priv)); assert(!IsStylus(&priv)); @@ -576,7 +572,7 @@ static void test_set_type(void) assert(!IsPad(&priv)); reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "cursor"); + rc = wcmSetFlags(&priv, WTYPE_CURSOR); assert(rc == 1); assert(!is_absolute(&priv)); assert(!IsStylus(&priv)); @@ -586,7 +582,7 @@ static void test_set_type(void) assert(!IsPad(&priv)); reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "pad"); + rc = wcmSetFlags(&priv, WTYPE_PAD); assert(rc == 1); assert(is_absolute(&priv)); assert(!IsStylus(&priv)); @@ -596,7 +592,7 @@ static void test_set_type(void) assert(IsPad(&priv)); reset(info, priv, tool, common); - rc = wcmSetFlags(&priv, "foobar"); + rc = wcmSetFlags(&priv, WTYPE_INVALID); assert(rc == 0); #undef reset |