Skip to content

Commit

Permalink
HID: wacom: retrieve name from HID descriptor for generic devices
Browse files Browse the repository at this point in the history
HID generic devices share the same default name, "Wacom HID". This
causes userland programs to show same device names for different
devices, which would confuse end users with same device names for
different devices too.

This patch uses name retrieved from HID descriptor, if a meaningful
name is reported. Otherwise, affix its product ID to "Wacom HID".

Names from descriptor may contain extra whitespaces. To comfort
readers' eyes, we removed those extra whitespaces too.

Signed-off-by: Ping Cheng <pingc@wacom.com>
Reviewed-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Ping Cheng authored and Jiri Kosina committed Apr 27, 2015
1 parent 007760c commit c24eab4
Showing 1 changed file with 47 additions and 11 deletions.
58 changes: 47 additions & 11 deletions drivers/hid/wacom_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,52 @@ static size_t wacom_compute_pktlen(struct hid_device *hdev)
return size;
}

static void wacom_update_name(struct wacom *wacom)
{
struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct wacom_features *features = &wacom_wac->features;

/* Generic devices name unspecified */
if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) {
if (strstr(wacom->hdev->name, "Wacom") ||
strstr(wacom->hdev->name, "wacom") ||
strstr(wacom->hdev->name, "WACOM")) {
/* name is in HID descriptor, use it */
strlcpy(wacom_wac->name, wacom->hdev->name,
sizeof(wacom_wac->name));

/* strip out excess whitespaces */
while (1) {
char *gap = strstr(wacom_wac->name, " ");
if (gap == NULL)
break;
/* shift everything including the terminator */
memmove(gap, gap+1, strlen(gap));
}
/* get rid of trailing whitespace */
if (wacom_wac->name[strlen(wacom_wac->name)-1] == ' ')
wacom_wac->name[strlen(wacom_wac->name)-1] = '\0';
} else {
/* no meaningful name retrieved. use product ID */
snprintf(wacom_wac->name, sizeof(wacom_wac->name),
"%s %X", features->name, wacom->hdev->product);
}
} else {
strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
}

/* Append the device type to the name */
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
"%s Pad", wacom_wac->name);

if (features->device_type != BTN_TOOL_FINGER)
strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
else if (features->touch_max)
strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
else
strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
}

static int wacom_probe(struct hid_device *hdev,
const struct hid_device_id *id)
{
Expand Down Expand Up @@ -1484,17 +1530,7 @@ static int wacom_probe(struct hid_device *hdev,
wacom_setup_device_quirks(wacom);
wacom_calculate_res(features);

strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
"%s Pad", features->name);

/* Append the device type to the name */
if (features->device_type != BTN_TOOL_FINGER)
strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
else if (features->touch_max)
strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
else
strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
wacom_update_name(wacom);

error = wacom_add_shared_data(hdev);
if (error)
Expand Down

0 comments on commit c24eab4

Please sign in to comment.