forked from drath/libratbag
Move the disable-profile capability into the profile caps
This is a profile-specific capability, not a device-specific one so let's move it there. Arguably, the DBus API should not expose SetEnabled() where not available, but that's a separate issue. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -250,7 +250,6 @@ ratbagd_device_get_capabilities(sd_bus *bus,
|
||||
RATBAG_DEVICE_CAP_RESOLUTION_SWITCHABLE,
|
||||
RATBAG_DEVICE_CAP_PROFILE,
|
||||
RATBAG_DEVICE_CAP_PROFILE_SWITCHABLE,
|
||||
RATBAG_DEVICE_CAP_PROFILE_DISABLE,
|
||||
RATBAG_DEVICE_CAP_BUTTON,
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY,
|
||||
RATBAG_DEVICE_CAP_BUTTON_MACROS,
|
||||
|
||||
@@ -410,6 +410,7 @@ ratbagd_profile_get_capabilities(sd_bus *bus,
|
||||
enum ratbag_profile_capability caps[] = {
|
||||
RATBAG_PROFILE_CAP_WRITABLE_NAME,
|
||||
RATBAG_PROFILE_CAP_SET_DEFAULT,
|
||||
RATBAG_PROFILE_CAP_DISABLE,
|
||||
};
|
||||
size_t i;
|
||||
|
||||
|
||||
@@ -1410,7 +1410,6 @@ gskill_probe(struct ratbag_device *device)
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_KEY);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE_DISABLE);
|
||||
|
||||
ret = gskill_get_active_profile_idx(device);
|
||||
if (ret < 0)
|
||||
@@ -1425,6 +1424,8 @@ gskill_probe(struct ratbag_device *device)
|
||||
ratbag_profile_for_each_button(profile, button)
|
||||
gskill_read_button(button);
|
||||
|
||||
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE);
|
||||
|
||||
if (profile->index == active_idx)
|
||||
profile->is_active = true;
|
||||
}
|
||||
|
||||
@@ -408,6 +408,8 @@ hidpp10drv_read_profile(struct ratbag_profile *profile)
|
||||
return;
|
||||
|
||||
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_WRITABLE_NAME);
|
||||
if (hidpp10->profile_type != HIDPP10_PROFILE_UNKNOWN)
|
||||
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE);
|
||||
|
||||
profile->is_enabled = p.enabled;
|
||||
|
||||
@@ -504,7 +506,6 @@ hidpp10drv_fill_from_profile(struct ratbag_device *device, struct hidpp10_device
|
||||
if (dev->profile_type != HIDPP10_PROFILE_UNKNOWN) {
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE_SWITCHABLE);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE_DISABLE);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_KEY);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);
|
||||
|
||||
@@ -1048,6 +1048,7 @@ hidpp20drv_read_profile(struct ratbag_profile *profile)
|
||||
|
||||
if (drv_data->capabilities & HIDPP_CAP_ONBOARD_PROFILES_8100) {
|
||||
hidpp20drv_read_profile_8100(profile);
|
||||
ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE);
|
||||
} else {
|
||||
hidpp20drv_read_resolution_dpi(profile);
|
||||
hidpp20drv_read_special_key_mouse(device);
|
||||
@@ -1178,7 +1179,6 @@ hidpp20drv_init_feature(struct ratbag_device *device, uint16_t feature)
|
||||
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_PROFILE_DISABLE);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_KEY);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);
|
||||
|
||||
@@ -269,10 +269,8 @@ test_probe(struct ratbag_device *device, const void *data)
|
||||
test_device->num_buttons,
|
||||
test_device->num_leds);
|
||||
|
||||
if (test_device->num_profiles > 1) {
|
||||
if (test_device->num_profiles > 1)
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_BUTTON_MACROS);
|
||||
ratbag_device_set_capability(device, RATBAG_DEVICE_CAP_PROFILE_DISABLE);
|
||||
}
|
||||
|
||||
ratbag_device_for_each_profile(device, profile)
|
||||
test_read_profile(profile);
|
||||
|
||||
@@ -129,16 +129,6 @@ enum ratbag_device_capability {
|
||||
*/
|
||||
RATBAG_DEVICE_CAP_PROFILE_SWITCHABLE,
|
||||
|
||||
/**
|
||||
* The device has the capability to disable and enable profiles. While
|
||||
* profiles are not immediately deleted after being disabled, it is not
|
||||
* guaranteed that the device will remember any disabled profiles the
|
||||
* next time ratbag runs. Furthermore, the order of profiles may get
|
||||
* changed the next time ratbag runs if profiles are disabled.
|
||||
*/
|
||||
RATBAG_DEVICE_CAP_PROFILE_DISABLE,
|
||||
|
||||
|
||||
/**
|
||||
* The device provides read and/or write access to one or more
|
||||
* buttons.
|
||||
@@ -185,6 +175,21 @@ enum ratbag_profile_capability {
|
||||
* profile (usually the first).
|
||||
*/
|
||||
RATBAG_PROFILE_CAP_SET_DEFAULT,
|
||||
|
||||
/**
|
||||
* The profile can be disabled and enabled. Profiles are not
|
||||
* immediately deleted after being disabled, it is not guaranteed
|
||||
* that the device will remember any disabled profiles the next time
|
||||
* ratbag runs. Furthermore, the order of profiles may get changed
|
||||
* the next time ratbag runs if profiles are disabled.
|
||||
*
|
||||
* Note that this capability only notes the general capability. A
|
||||
* specific profile may still fail to be disabled, e.g. when it is
|
||||
* the last enabled profile on the device.
|
||||
*/
|
||||
RATBAG_PROFILE_CAP_DISABLE,
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -811,8 +811,7 @@ ratbag_device_get_profile(struct ratbag_device *device, unsigned int index)
|
||||
LIBRATBAG_EXPORT enum ratbag_error_code
|
||||
ratbag_profile_set_enabled(struct ratbag_profile *profile, bool enabled)
|
||||
{
|
||||
if (!ratbag_device_has_capability(profile->device,
|
||||
RATBAG_DEVICE_CAP_PROFILE_DISABLE))
|
||||
if (!ratbag_profile_has_capability(profile, RATBAG_PROFILE_CAP_DISABLE))
|
||||
return RATBAG_ERROR_CAPABILITY;
|
||||
|
||||
profile->is_enabled = enabled;
|
||||
|
||||
@@ -572,8 +572,8 @@ ratbag_profile_set_name(struct ratbag_profile *profile,
|
||||
/**
|
||||
* @ingroup profile
|
||||
*
|
||||
* Enable/disable the ratbag profile. For this to work, the device must support
|
||||
* @ref RATBAG_DEVICE_CAP_PROFILE_DISABLE.
|
||||
* Enable/disable the ratbag profile. For this to work, the profile must support
|
||||
* @ref RATBAG_PROFILE_CAP_DISABLE.
|
||||
*
|
||||
* @param profile A previously initialized ratbag profile
|
||||
* @param enabled Whether to enable or disable the profile
|
||||
@@ -587,7 +587,7 @@ ratbag_profile_set_enabled(struct ratbag_profile *profile, bool enabled);
|
||||
* @ingroup profile
|
||||
*
|
||||
* Check whether the ratbag profile is enabled or not. For devices that don't
|
||||
* support @ref RATBAG_DEVICE_CAP_PROFILE_DISABLE the profile will always be
|
||||
* support @ref RATBAG_PROFILE_CAP_DISABLE the profile will always be
|
||||
* set to enabled.
|
||||
*
|
||||
* @param profile A previously initialized ratbag profile
|
||||
|
||||
@@ -263,7 +263,6 @@ def print_device(d, level):
|
||||
RatbagdDevice.CAP_BUTTON_KEY: "button-keys",
|
||||
RatbagdDevice.CAP_BUTTON_MACROS: "button-macros",
|
||||
RatbagdDevice.CAP_QUERY_CONFIGURATION: "query-configuration",
|
||||
RatbagdDevice.CAP_PROFILE_DISABLE: "disable-profile",
|
||||
RatbagdDevice.CAP_LED: "led"}
|
||||
capabilities = [caps[c] for c in d.capabilities]
|
||||
|
||||
|
||||
@@ -323,7 +323,6 @@ class RatbagdDevice(_RatbagdDBus):
|
||||
CAP_RESOLUTION_SWITCHABLE = 101
|
||||
CAP_PROFILE = 200
|
||||
CAP_PROFILE_SWITCHABLE = 201
|
||||
CAP_PROFILE_DISABLE = 202
|
||||
CAP_BUTTON = 300
|
||||
CAP_BUTTON_KEY = 301
|
||||
CAP_BUTTON_MACROS = 302
|
||||
@@ -424,6 +423,7 @@ class RatbagdProfile(_RatbagdDBus):
|
||||
|
||||
CAP_WRITABLE_NAME = 100
|
||||
CAP_SET_DEFAULT = 101
|
||||
CAP_DISABLE = 102
|
||||
|
||||
def __init__(self, object_path):
|
||||
_RatbagdDBus.__init__(self, "Profile", object_path)
|
||||
|
||||
Reference in New Issue
Block a user