diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-11-29 14:36:24 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-12-20 15:01:56 +1000 |
commit | 6bd9b920a40bc22c45cfdb5318d9354a7d12a470 (patch) | |
tree | 12d415843ea8a293d7da9fa176ab1d54c83b1a27 | |
parent | 1be51900620cb1f55262efb475fa11e5519f509d (diff) | |
download | xf86-input-wacom-6bd9b920a40bc22c45cfdb5318d9354a7d12a470.tar.gz |
Decide on the hotplugged device's name in the driver
For devices hotplugged by the driver, we use the basename and then
append the tool type and serial (if any). No point having this in the X
driver layer, let's make this generic.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | src/WacomInterface.h | 4 | ||||
-rw-r--r-- | src/wcmValidateDevice.c | 26 | ||||
-rw-r--r-- | src/xf86Wacom.c | 25 |
3 files changed, 29 insertions, 26 deletions
diff --git a/src/WacomInterface.h b/src/WacomInterface.h index d5cabd7..1c1db0b 100644 --- a/src/WacomInterface.h +++ b/src/WacomInterface.h @@ -175,13 +175,13 @@ void wcmEmitProximity(WacomDevicePtr priv, bool is_proximity_in, void wcmEmitTouch(WacomDevicePtr priv, int type, unsigned int touchid, int x, int y); /** - * Queue the addition of a new device with the given basename (sans type) and + * Queue the addition of a new device with the device's name, type and * the serial, if any. Otherwise the device should be a copy of priv. * * This is a **queuing** function, the device must be hotplugged when the * frontend is idle later. */ -void wcmQueueHotplug(WacomDevicePtr priv, const char *basename, +void wcmQueueHotplug(WacomDevicePtr priv, const char *name, const char *type, int serial); /* X server interface emulations */ diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c index 4487bb1..10b2c7f 100644 --- a/src/wcmValidateDevice.c +++ b/src/wcmValidateDevice.c @@ -429,6 +429,28 @@ int wcmDeviceTypeKeys(WacomDevicePtr priv) return ret; } +static void +wcmAddHotpluggedDevice(WacomDevicePtr priv, const char *basename, const char *type, + WacomToolPtr ser) +{ + char *name; + int rc; + + if (ser == NULL) + rc = asprintf(&name, "%s %s", basename, type); + else if (strlen(ser->name) > 0) + rc = asprintf(&name, "%s %s %s", basename, ser->name, type); + else + rc = asprintf(&name, "%s %d %s", basename, ser->serial, type); + + if (rc == -1) + return; + + wcmQueueHotplug(priv, name, type, ser ? ser->serial : -1); + + free(name); +} + /** * Attempt to hotplug a tool with a given type. * @@ -455,7 +477,7 @@ static void wcmTryHotplugSerialType(WacomDevicePtr priv, WacomToolPtr ser, const return; } - wcmQueueHotplug(priv, basename, type, ser->serial); + wcmAddHotpluggedDevice(priv, basename, type, ser); } /** @@ -495,7 +517,7 @@ void wcmHotplugOthers(WacomDevicePtr priv, const char *basename) if (skip) skip = 0; else - wcmQueueHotplug(priv, basename, wcmType[i].type, -1); + wcmAddHotpluggedDevice(priv, basename, wcmType[i].type, NULL); } } diff --git a/src/xf86Wacom.c b/src/xf86Wacom.c index 91406be..ee8e34d 100644 --- a/src/xf86Wacom.c +++ b/src/xf86Wacom.c @@ -183,42 +183,23 @@ void wcmTimerSet(WacomTimerPtr timer, uint32_t millis, WacomTimerCallback func, * @param type Tool type (cursor, eraser, etc.) * @param serial Serial number this device should be bound to (-1 for "any") */ -static InputOption *wcmOptionDupConvert(WacomDevicePtr priv, const char* basename, const char *type, int serial) +static InputOption *wcmOptionDupConvert(WacomDevicePtr priv, const char* name, const char *type, int serial) { WacomCommonPtr common = priv->common; InputInfoPtr pInfo = priv->frontend; pointer original = pInfo->options; WacomToolPtr ser = common->serials; InputOption *iopts = NULL; - char *name; pointer options, o; int rc; options = xf86OptionListDuplicate(original); - if (serial > -1) - { - while (ser->serial && ser->serial != serial) - ser = ser->next; - - if (strlen(ser->name) > 0) - rc = asprintf(&name, "%s %s %s", basename, ser->name, type); - else - rc = asprintf(&name, "%s %d %s", basename, ser->serial, type); - } - else - rc = asprintf(&name, "%s %s", basename, type); - - if (rc == -1) /* if asprintf fails, strdup will probably too... */ - name = strdup("unknown"); - options = xf86ReplaceStrOption(options, "Type", type); options = xf86ReplaceStrOption(options, "Name", name); if (serial > -1) options = xf86ReplaceIntOption(options, "Serial", ser->serial); - free(name); - o = options; while(o) { @@ -310,7 +291,7 @@ wcmHotplugDevice(ClientPtr client, pointer closure ) * @param type Type name for this tool * @param serial Serial number this device should be bound to (-1 for "any") */ -void wcmQueueHotplug(WacomDevicePtr priv, const char* basename, const char *type, int serial) +void wcmQueueHotplug(WacomDevicePtr priv, const char* name, const char *type, int serial) { WacomHotplugInfo *hotplug_info; @@ -322,7 +303,7 @@ void wcmQueueHotplug(WacomDevicePtr priv, const char* basename, const char *type return; } - hotplug_info->input_options = wcmOptionDupConvert(priv, basename, type, serial); + hotplug_info->input_options = wcmOptionDupConvert(priv, name, type, serial); hotplug_info->attrs = wcmDuplicateAttributes(priv, type); QueueWorkProc(wcmHotplugDevice, serverClient, hotplug_info); } |