mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
Namespace the ratbag capabilities to the ratbag device
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -246,15 +246,16 @@ etekcity_button_action_to_raw(const struct ratbag_button_action *action)
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_has_capability(const struct ratbag_device *device, enum ratbag_capability cap)
|
||||
etekcity_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_device_capability cap)
|
||||
{
|
||||
switch (cap) {
|
||||
case RATBAG_CAP_NONE:
|
||||
case RATBAG_DEVICE_CAP_NONE:
|
||||
return 0;
|
||||
case RATBAG_CAP_SWITCHABLE_RESOLUTION:
|
||||
case RATBAG_CAP_SWITCHABLE_PROFILE:
|
||||
case RATBAG_CAP_BUTTON_KEY:
|
||||
case RATBAG_CAP_BUTTON_MACROS:
|
||||
case RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION:
|
||||
case RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE:
|
||||
case RATBAG_DEVICE_CAP_BUTTON_KEY:
|
||||
case RATBAG_DEVICE_CAP_BUTTON_MACROS:
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -89,16 +89,17 @@ hidpp10drv_write_button(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp10drv_has_capability(const struct ratbag_device *device, enum ratbag_capability cap)
|
||||
hidpp10drv_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_device_capability cap)
|
||||
{
|
||||
switch (cap) {
|
||||
case RATBAG_CAP_NONE:
|
||||
case RATBAG_DEVICE_CAP_NONE:
|
||||
abort();
|
||||
break;
|
||||
case RATBAG_CAP_SWITCHABLE_PROFILE:
|
||||
case RATBAG_CAP_SWITCHABLE_RESOLUTION:
|
||||
case RATBAG_CAP_BUTTON_KEY:
|
||||
case RATBAG_CAP_BUTTON_MACROS:
|
||||
case RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE:
|
||||
case RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION:
|
||||
case RATBAG_DEVICE_CAP_BUTTON_KEY:
|
||||
case RATBAG_DEVICE_CAP_BUTTON_MACROS:
|
||||
return (device->num_profiles > 1);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -127,7 +127,8 @@ hidpp20drv_write_button(struct ratbag_button *button,
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_has_capability(const struct ratbag_device *device, enum ratbag_capability cap)
|
||||
hidpp20drv_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_device_capability cap)
|
||||
{
|
||||
/*
|
||||
* We need to force the non const, but we will not change anything,
|
||||
@@ -136,9 +137,9 @@ hidpp20drv_has_capability(const struct ratbag_device *device, enum ratbag_capabi
|
||||
struct hidpp20drv_data *drv_data = ratbag_get_drv_data((struct ratbag_device *)device);
|
||||
|
||||
switch (cap) {
|
||||
case RATBAG_CAP_SWITCHABLE_RESOLUTION:
|
||||
case RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION:
|
||||
return !!(drv_data->capabilities & HIDPP_CAP_SWITCHABLE_RESOLUTION_2201);
|
||||
case RATBAG_CAP_BUTTON_KEY:
|
||||
case RATBAG_DEVICE_CAP_BUTTON_KEY:
|
||||
return !!(drv_data->capabilities & HIDPP_CAP_BUTTON_KEY_1b04);
|
||||
default:
|
||||
return 0;
|
||||
|
||||
@@ -133,7 +133,8 @@ struct ratbag_driver {
|
||||
* for each device, but most of the time, it can be statically
|
||||
* stored.
|
||||
*/
|
||||
int (*has_capability)(const struct ratbag_device *device, enum ratbag_capability cap);
|
||||
int (*has_capability)(const struct ratbag_device *device,
|
||||
enum ratbag_device_capability cap);
|
||||
|
||||
/** For the given button, fill in the struct ratbag_button
|
||||
* with the available information.
|
||||
@@ -164,7 +165,7 @@ struct ratbag_driver {
|
||||
/** For the given profile, overwrite the current resolution
|
||||
* of the sensor expressed in DPI, and commit it to the hardware.
|
||||
*
|
||||
* Mandatory if the driver exports RATBAG_CAP_SWITCHABLE_RESOLUTION.
|
||||
* Mandatory if the driver exports RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION.
|
||||
*/
|
||||
int (*write_resolution_dpi)(struct ratbag_resolution *resolution, int dpi);
|
||||
|
||||
|
||||
@@ -678,7 +678,7 @@ ratbag_device_get_num_buttons(struct ratbag_device *device)
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_device_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_capability cap)
|
||||
enum ratbag_device_capability cap)
|
||||
{
|
||||
assert(device->driver->has_capability);
|
||||
return device->driver->has_capability(device, cap);
|
||||
@@ -696,7 +696,7 @@ ratbag_profile_set_active(struct ratbag_profile *profile)
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (ratbag_device_has_capability(device, RATBAG_CAP_SWITCHABLE_PROFILE)) {
|
||||
if (ratbag_device_has_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE)) {
|
||||
assert(device->driver->set_active_profile);
|
||||
rc = device->driver->set_active_profile(device, profile->index);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ struct ratbag_device;
|
||||
* @struct ratbag_profile
|
||||
*
|
||||
* A handle to a profile context on devices with the @ref
|
||||
* RATBAG_CAP_SWITCHABLE_PROFILE capability.
|
||||
* RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE capability.
|
||||
* This struct is refcounted, use ratbag_profile_ref() and
|
||||
* ratbag_profile_unref().
|
||||
*/
|
||||
@@ -308,8 +308,8 @@ ratbag_device_get_name(const struct ratbag_device* device);
|
||||
/**
|
||||
* @ingroup device
|
||||
*/
|
||||
enum ratbag_capability {
|
||||
RATBAG_CAP_NONE = 0,
|
||||
enum ratbag_device_capability {
|
||||
RATBAG_DEVICE_CAP_NONE = 0,
|
||||
/**
|
||||
* The device can change resolution, either software-controlled or
|
||||
* by a hardware button.
|
||||
@@ -318,7 +318,7 @@ enum ratbag_capability {
|
||||
* query that, even if we can't switch it ourselves? Maybe better to
|
||||
* have a separate cap for that then.
|
||||
*/
|
||||
RATBAG_CAP_SWITCHABLE_RESOLUTION,
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION,
|
||||
/**
|
||||
* The device can switch between hardware profiles.
|
||||
* A device with this capability can store multiple profiles in the
|
||||
@@ -326,18 +326,18 @@ enum ratbag_capability {
|
||||
* possibly with a button.
|
||||
* Devices without this capability will only have a single profile.
|
||||
*/
|
||||
RATBAG_CAP_SWITCHABLE_PROFILE,
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE,
|
||||
|
||||
/**
|
||||
* The device supports assigning button numbers, key events or key +
|
||||
* modifier combinations.
|
||||
*/
|
||||
RATBAG_CAP_BUTTON_KEY,
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY,
|
||||
|
||||
/**
|
||||
* The device supports user-defined key or button sequences.
|
||||
*/
|
||||
RATBAG_CAP_BUTTON_MACROS,
|
||||
RATBAG_DEVICE_CAP_BUTTON_MACROS,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -353,7 +353,8 @@ enum ratbag_capability {
|
||||
* @retval 0 The device does not have the capability
|
||||
*/
|
||||
int
|
||||
ratbag_device_has_capability(const struct ratbag_device *device, enum ratbag_capability cap);
|
||||
ratbag_device_has_capability(const struct ratbag_device *device,
|
||||
enum ratbag_device_capability cap);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
|
||||
@@ -298,16 +298,16 @@ ratbag_cmd_info(struct ratbag *ratbag, uint32_t flags, int argc, char **argv)
|
||||
|
||||
printf("Capabilities:");
|
||||
if (ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_SWITCHABLE_RESOLUTION))
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION))
|
||||
printf(" res");
|
||||
if (ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_SWITCHABLE_PROFILE))
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE))
|
||||
printf(" profile");
|
||||
if (ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_BUTTON_KEY))
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY))
|
||||
printf(" btn-key");
|
||||
if (ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_BUTTON_MACROS))
|
||||
RATBAG_DEVICE_CAP_BUTTON_MACROS))
|
||||
printf(" btn-macros");
|
||||
printf("\n");
|
||||
|
||||
@@ -394,7 +394,7 @@ ratbag_cmd_switch_profile(struct ratbag *ratbag, uint32_t flags, int argc, char
|
||||
}
|
||||
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_SWITCHABLE_PROFILE)) {
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE)) {
|
||||
error("Looks like '%s' has no switchable profiles\n", path);
|
||||
goto out;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ ratbag_cmd_switch_etekcity(struct ratbag *ratbag, uint32_t flags, int argc, char
|
||||
}
|
||||
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_SWITCHABLE_PROFILE)) {
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE)) {
|
||||
error("Looks like '%s' has no switchable profiles\n", path);
|
||||
goto out;
|
||||
}
|
||||
@@ -615,7 +615,7 @@ ratbag_cmd_change_button(struct ratbag *ratbag, uint32_t flags, int argc, char *
|
||||
}
|
||||
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_BUTTON_KEY)) {
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY)) {
|
||||
error("Looks like '%s' has no programmable buttons\n", path);
|
||||
goto out;
|
||||
}
|
||||
@@ -760,7 +760,7 @@ ratbag_cmd_switch_dpi(struct ratbag *ratbag, uint32_t flags, int argc, char **ar
|
||||
}
|
||||
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_CAP_SWITCHABLE_RESOLUTION)) {
|
||||
RATBAG_DEVICE_CAP_SWITCHABLE_RESOLUTION)) {
|
||||
error("Looks like '%s' has no switchable resolution\n", path);
|
||||
goto out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user