Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special case for volume key devices in capabilities check #832

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static uint8_t resolve_device_capabilities(int fd, uint32_t *num_keys, uint8_t *
size_t i;
uint32_t mask[BTN_LEFT/32+1] = {0};
uint8_t capabilities = 0;
int has_brightness_key;
int has_brightness_key, has_volume_key;

if (ioctl(fd, EVIOCGBIT(EV_KEY, (BTN_LEFT/32+1)*4), mask) < 0) {
perror("ioctl: ev_key");
Expand Down Expand Up @@ -92,7 +92,19 @@ static uint8_t resolve_device_capabilities(int fd, uint32_t *num_keys, uint8_t *
*/
has_brightness_key = mask[KEY_BRIGHTNESSUP/32] & (1 << (KEY_BRIGHTNESSUP % 32));

if (((mask[0] & keyboard_mask) == keyboard_mask) || has_brightness_key)
/*
* If the device can emit KEY_VOLUMEUP we treat it as a keyboard.
*
* This is to accomodate for example laptops that have dedicated volume
* up/down buttons separate from the regular keyboard.
*
* NOTE: This will subsume anything that can emit a volume key and may
* produce false positives which need to be explcitly excluded by the user
* if they use the wildcard id.
*/
has_volume_key = mask[KEY_VOLUMEUP/32] & (1 << (KEY_VOLUMEUP % 32));

if (((mask[0] & keyboard_mask) == keyboard_mask) || has_brightness_key || has_volume_key)
capabilities |= CAP_KEYBOARD;

return capabilities;
Expand Down