From 3fcf13b58e831f078bf7a799a4530e98d6def17e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 20 Feb 2019 12:56:59 +1000 Subject: [PATCH] Drop the superflous device capabilities If we have a profiles/resolution/button/led, we can write to it. That is the default assumption and where we don't have write-access to those, we should simply not expose them. Signed-off-by: Peter Hutterer --- ratbagd/ratbagd-device.c | 4 ---- src/driver-etekcity.c | 2 -- src/driver-gskill.c | 1 - src/driver-hidpp10.c | 7 ------- src/driver-hidpp20.c | 7 ------- src/driver-logitech-g300.c | 4 ---- src/driver-logitech-g600.c | 4 ---- src/driver-roccat.c | 2 -- src/driver-steelseries.c | 6 ------ src/libratbag-enums.h | 23 ----------------------- src/libratbag.c | 38 -------------------------------------- tools/ratbagctl.in | 11 +---------- tools/ratbagd.py | 4 ---- 13 files changed, 1 insertion(+), 112 deletions(-) diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index 66c9bf0e..58252774 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -246,10 +246,6 @@ ratbagd_device_get_capabilities(sd_bus *bus, enum ratbag_device_capability cap; enum ratbag_device_capability caps[] = { RATBAG_DEVICE_CAP_QUERY_CONFIGURATION, - RATBAG_DEVICE_CAP_RESOLUTION, - RATBAG_DEVICE_CAP_PROFILE, - RATBAG_DEVICE_CAP_BUTTON, - RATBAG_DEVICE_CAP_LED, }; size_t i; diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index 8ce3aa3e..d40b0aa8 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -668,8 +668,6 @@ etekcity_probe(struct ratbag_device *device) ratbag_device_for_each_profile(device, profile) etekcity_read_profile(profile); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - active_idx = etekcity_current_profile(device); if (active_idx < 0) { log_error(device->ratbag, diff --git a/src/driver-gskill.c b/src/driver-gskill.c index 76a592ef..0427d3dc 100644 --- a/src/driver-gskill.c +++ b/src/driver-gskill.c @@ -1407,7 +1407,6 @@ gskill_probe(struct ratbag_device *device) GSKILL_BUTTON_MAX, GSKILL_NUM_LED); ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_QUERY_CONFIGURATION); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); ret = gskill_get_active_profile_idx(device); if (ret < 0) diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 5c67d71c..5d0bf902 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -425,8 +425,6 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) if (rc) xres = 0xffff; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); - ratbag_profile_for_each_resolution(profile, res) { unsigned int dpis[hidpp10->dpi_count]; @@ -502,11 +500,6 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device profile.num_buttons, profile.num_leds); - if (dev->profile_type != HIDPP10_PROFILE_UNKNOWN) { - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - } - return 0; } diff --git a/src/driver-hidpp20.c b/src/driver-hidpp20.c index c51ceb19..bf5b03a8 100644 --- a/src/driver-hidpp20.c +++ b/src/driver-hidpp20.c @@ -1086,7 +1086,6 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) break; case HIDPP_PAGE_MOUSE_POINTER_BASIC: { drv_data->capabilities |= HIDPP_CAP_RESOLUTION_2200; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); break; } case HIDPP_PAGE_ADJUSTABLE_DPI: { @@ -1096,14 +1095,12 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) rc = hidpp20drv_read_resolution_dpi_2201(device); if (rc < 0) return 0; /* this is not a hard failure */ - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); drv_data->capabilities |= HIDPP_CAP_SWITCHABLE_RESOLUTION_2201; break; } case HIDPP_PAGE_SPECIAL_KEYS_BUTTONS: { log_debug(ratbag, "device has programmable keys/buttons\n"); drv_data->capabilities |= HIDPP_CAP_BUTTON_KEY_1b04; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); /* we read the profile once to get the correct number of * supported buttons. */ if (!hidpp20drv_read_special_key_mouse(device)) @@ -1156,7 +1153,6 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) if (hidpp20drv_read_color_leds(device)) return 0; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_LED); device->num_leds = drv_data->num_leds; break; } @@ -1170,14 +1166,11 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature) if (hidpp20drv_read_leds(device)) return 0; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_LED); break; } case HIDPP_PAGE_ONBOARD_PROFILES: { log_debug(ratbag, "device has onboard profiles\n"); drv_data->capabilities |= HIDPP_CAP_ONBOARD_PROFILES_8100; - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); rc = hidpp20_onboard_profiles_allocate(drv_data->dev, &drv_data->profiles); if (rc < 0) diff --git a/src/driver-logitech-g300.c b/src/driver-logitech-g300.c index 7bd83afa..98f91174 100644 --- a/src/driver-logitech-g300.c +++ b/src/driver-logitech-g300.c @@ -498,10 +498,6 @@ logitech_g300_probe(struct ratbag_device *device) ratbag_device_for_each_profile(device, profile) logitech_g300_read_profile(profile); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - active_idx = logitech_g300_get_active_profile_and_resolution(device); if (active_idx < 0) { diff --git a/src/driver-logitech-g600.c b/src/driver-logitech-g600.c index ce8ef00c..22b916cc 100644 --- a/src/driver-logitech-g600.c +++ b/src/driver-logitech-g600.c @@ -495,10 +495,6 @@ logitech_g600_probe(struct ratbag_device *device) ratbag_device_for_each_profile(device, profile) logitech_g600_read_profile(profile); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - rc = logitech_g600_get_active_profile_and_resolution(device); if (rc < 0) { diff --git a/src/driver-roccat.c b/src/driver-roccat.c index b4075db8..539af2e5 100644 --- a/src/driver-roccat.c +++ b/src/driver-roccat.c @@ -805,8 +805,6 @@ roccat_probe(struct ratbag_device *device) ratbag_device_for_each_profile(device, profile) roccat_read_profile(profile); - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - active_idx = roccat_current_profile(device); if (active_idx < 0) { log_error(device->ratbag, diff --git a/src/driver-steelseries.c b/src/driver-steelseries.c index 47920a21..bcc4fa68 100644 --- a/src/driver-steelseries.c +++ b/src/driver-steelseries.c @@ -300,12 +300,6 @@ steelseries_probe(struct ratbag_device *device) button_count, led_count); - /* only later models allow setting buttons on the device */ - if (ratbag_device_data_steelseries_get_macro_length(device->data) > 0) { - /* set these caps manually as they are not assumed with only 1 profile */ - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - } - ratbag_device_unset_capability(device, RATBAG_DEVICE_CAP_QUERY_CONFIGURATION); /* The device does not support reading the current settings. Fall back diff --git a/src/libratbag-enums.h b/src/libratbag-enums.h index 1d4c287a..e96af27c 100644 --- a/src/libratbag-enums.h +++ b/src/libratbag-enums.h @@ -97,29 +97,6 @@ enum ratbag_device_capability { * libratbag can be used to query the device as normal. */ RATBAG_DEVICE_CAP_QUERY_CONFIGURATION, - - /** - * The device provides read and/or write access to one or more - * resolutions. - */ - RATBAG_DEVICE_CAP_RESOLUTION = 100, - - /** - * The device provides read and/or write access to one or more - * profiles. - */ - RATBAG_DEVICE_CAP_PROFILE = 200, - - /** - * The device provides read and/or write access to one or more - * buttons. - */ - RATBAG_DEVICE_CAP_BUTTON = 300, - - /** - * The device supports assigning LED colors and effects - */ - RATBAG_DEVICE_CAP_LED = 400, }; /** diff --git a/src/libratbag.c b/src/libratbag.c index 85dc65cd..bc03a56d 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -273,9 +273,6 @@ ratbag_sanity_check_device(struct ratbag_device *device) unsigned int vals[300]; unsigned int nvals = ARRAY_LENGTH(vals); - if (!ratbag_device_has_capability(device, RATBAG_DEVICE_CAP_RESOLUTION)) - break; - nvals = ratbag_resolution_get_dpi_list(resolution, vals, nvals); if (nvals == 0) { log_bug_libratbag(ratbag, @@ -718,20 +715,6 @@ ratbag_device_init_profiles(struct ratbag_device *device, device->num_profiles = num_profiles; - if (num_profiles > 1) { - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE); - - /* having more than one profile means we can remap the buttons - * at least */ - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON); - } - - if (num_resolutions > 1) - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_RESOLUTION); - - if (num_leds > 0) - ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_LED); - return 0; } @@ -1580,11 +1563,6 @@ ratbag_led_get_brightness(struct ratbag_led *led) LIBRATBAG_EXPORT enum ratbag_error_code ratbag_led_set_mode(struct ratbag_led *led, enum ratbag_led_mode mode) { - - if (!ratbag_device_has_capability(led->profile->device, - RATBAG_DEVICE_CAP_LED)) - return RATBAG_ERROR_CAPABILITY; - led->mode = mode; led->dirty = true; led->profile->dirty = true; @@ -1594,10 +1572,6 @@ ratbag_led_set_mode(struct ratbag_led *led, enum ratbag_led_mode mode) LIBRATBAG_EXPORT enum ratbag_error_code ratbag_led_set_color(struct ratbag_led *led, struct ratbag_color color) { - if (!ratbag_device_has_capability(led->profile->device, - RATBAG_DEVICE_CAP_LED)) - return RATBAG_ERROR_CAPABILITY; - led->color = color; led->dirty = true; led->profile->dirty = true; @@ -1607,20 +1581,12 @@ ratbag_led_set_color(struct ratbag_led *led, struct ratbag_color color) LIBRATBAG_EXPORT enum ratbag_led_colordepth ratbag_led_get_colordepth(struct ratbag_led *led) { - if (!ratbag_device_has_capability(led->profile->device, - RATBAG_DEVICE_CAP_LED)) - return RATBAG_ERROR_CAPABILITY; - return led->colordepth; } LIBRATBAG_EXPORT enum ratbag_error_code ratbag_led_set_effect_duration(struct ratbag_led *led, unsigned int ms) { - if (!ratbag_device_has_capability(led->profile->device, - RATBAG_DEVICE_CAP_LED)) - return RATBAG_ERROR_CAPABILITY; - led->ms = ms; led->dirty = true; led->profile->dirty = true; @@ -1630,10 +1596,6 @@ ratbag_led_set_effect_duration(struct ratbag_led *led, unsigned int ms) LIBRATBAG_EXPORT enum ratbag_error_code ratbag_led_set_brightness(struct ratbag_led *led, unsigned int brightness) { - if (!ratbag_device_has_capability(led->profile->device, - RATBAG_DEVICE_CAP_LED)) - return RATBAG_ERROR_CAPABILITY; - led->brightness = brightness; led->dirty = true; led->profile->dirty = true; diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index 226064f0..1a610b58 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -255,11 +255,7 @@ def print_profile(d, p, level): def print_device(d, level): p = d.profiles[0] # there should be always one - caps = {RatbagdDevice.CAP_RESOLUTION: "resolution", - RatbagdDevice.CAP_PROFILE: "profile", - RatbagdDevice.CAP_BUTTON: "button", - RatbagdDevice.CAP_QUERY_CONFIGURATION: "query-configuration", - RatbagdDevice.CAP_LED: "led"} + caps = {RatbagdDevice.CAP_QUERY_CONFIGURATION: "query-configuration"} capabilities = [caps[c] for c in d.capabilities] svg_name = 'unknown' @@ -373,17 +369,12 @@ def func_button_get(r, args): def func_button_action_set_button(r, args): b, p, d = find_button(r, args) - if not d.CAP_BUTTON in d.capabilities: - raise RatbagErrorCapability("assigning a button is not supported on this device") b.mapping = args.target_button commit(d, args) def func_button_action_set_special(r, args): b, p, d = find_button(r, args) - if not d.CAP_BUTTON in d.capabilities: - raise RatbagErrorCapability("assigning a button is not supported on this device") - try: special = args.target_special except AttributeError: diff --git a/tools/ratbagd.py b/tools/ratbagd.py index d08d7fba..d7994b5f 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -319,10 +319,6 @@ class RatbagdDevice(_RatbagdDBus): CAP_NONE = 0 CAP_QUERY_CONFIGURATION = 1 - CAP_RESOLUTION = 100 - CAP_PROFILE = 200 - CAP_BUTTON = 300 - CAP_LED = 400 __gsignals__ = { "active-profile-changed":