forked from drath/libratbag
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 <peter.hutterer@who-t.net>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user