mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
Add hooks for getting/setting the default profile
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -295,6 +295,12 @@ etekcity_set_current_profile(struct ratbag_device *device, unsigned int index)
|
||||
return ret == sizeof(buf) ? 0 : ret;
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_default_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int
|
||||
etekcity_set_config_profile(struct ratbag_device *device, uint8_t profile, uint8_t type)
|
||||
{
|
||||
@@ -743,6 +749,7 @@ struct ratbag_driver etekcity_driver = {
|
||||
.read_profile = etekcity_read_profile,
|
||||
.write_profile = etekcity_write_profile,
|
||||
.set_active_profile = etekcity_set_current_profile,
|
||||
.set_default_profile = etekcity_set_default_profile,
|
||||
.has_capability = etekcity_has_capability,
|
||||
.read_button = etekcity_read_button,
|
||||
.write_button = etekcity_write_button,
|
||||
|
||||
@@ -115,6 +115,12 @@ hidpp10drv_set_current_profile(struct ratbag_device *device, unsigned int index)
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp10drv_set_default_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static void
|
||||
hidpp10drv_read_profile(struct ratbag_profile *profile, unsigned int index)
|
||||
{
|
||||
@@ -280,6 +286,7 @@ struct ratbag_driver hidpp10_driver = {
|
||||
.read_profile = hidpp10drv_read_profile,
|
||||
.write_profile = hidpp10drv_write_profile,
|
||||
.set_active_profile = hidpp10drv_set_current_profile,
|
||||
.set_default_profile = hidpp10drv_set_default_profile,
|
||||
.has_capability = hidpp10drv_has_capability,
|
||||
.read_button = hidpp10drv_read_button,
|
||||
.write_button = hidpp10drv_write_button,
|
||||
|
||||
@@ -163,6 +163,12 @@ hidpp20drv_set_current_profile(struct ratbag_device *device, unsigned int index)
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_set_default_profile(struct ratbag_device *device, unsigned int index)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static int
|
||||
hidpp20drv_read_resolution_dpi(struct ratbag_profile *profile)
|
||||
{
|
||||
@@ -510,6 +516,7 @@ struct ratbag_driver hidpp20_driver = {
|
||||
.read_profile = hidpp20drv_read_profile,
|
||||
.write_profile = hidpp20drv_write_profile,
|
||||
.set_active_profile = hidpp20drv_set_current_profile,
|
||||
.set_default_profile = hidpp20drv_set_default_profile,
|
||||
.has_capability = hidpp20drv_has_capability,
|
||||
.read_button = hidpp20drv_read_button,
|
||||
.write_button = hidpp20drv_write_button,
|
||||
|
||||
@@ -134,6 +134,14 @@ struct ratbag_driver {
|
||||
*/
|
||||
int (*set_active_profile)(struct ratbag_device *device, unsigned int index);
|
||||
|
||||
/**
|
||||
* Called to mark a previously writen profile as the default.
|
||||
*
|
||||
* There should be no need to write the profile here, a
|
||||
* .write_profile() call is issued before calling this.
|
||||
*/
|
||||
int (*set_default_profile)(struct ratbag_device *device, unsigned int index);
|
||||
|
||||
/**
|
||||
* This should return a boolean whether or not the device
|
||||
* supports the given capability.
|
||||
@@ -215,6 +223,7 @@ struct ratbag_profile {
|
||||
} resolution;
|
||||
|
||||
bool is_active; /**< profile is the currently active one */
|
||||
bool is_default; /**< profile is the default one */
|
||||
};
|
||||
|
||||
#define BUTTON_ACTION_NONE \
|
||||
|
||||
@@ -663,6 +663,12 @@ ratbag_profile_is_active(struct ratbag_profile *profile)
|
||||
#endif
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_profile_is_default(struct ratbag_profile *profile)
|
||||
{
|
||||
return profile->is_default;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT unsigned int
|
||||
ratbag_device_get_num_profiles(struct ratbag_device *device)
|
||||
{
|
||||
@@ -710,6 +716,32 @@ ratbag_profile_set_active(struct ratbag_profile *profile)
|
||||
return rc;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_profile_set_default(struct ratbag_profile *profile)
|
||||
{
|
||||
struct ratbag_device *device = profile->device;
|
||||
struct ratbag_profile *p;
|
||||
int rc;
|
||||
|
||||
assert(device->driver->write_profile);
|
||||
rc = device->driver->write_profile(profile);
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
if (ratbag_device_has_capability(device, RATBAG_DEVICE_CAP_SWITCHABLE_PROFILE)) {
|
||||
assert(device->driver->set_active_profile);
|
||||
rc = device->driver->set_default_profile(device, profile->index);
|
||||
}
|
||||
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
list_for_each(p, &device->profiles, link) {
|
||||
p->is_default = false;
|
||||
}
|
||||
profile->is_default = true;
|
||||
return rc;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT int
|
||||
ratbag_profile_get_num_resolutions(struct ratbag_profile *profile)
|
||||
|
||||
@@ -564,6 +564,31 @@ ratbag_profile_is_active(struct ratbag_profile *profile);
|
||||
int
|
||||
ratbag_profile_set_active(struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* @ingroup profile
|
||||
*
|
||||
* Check if the given profile is the default one. The default profile is the
|
||||
* one selected by the device when it is plugged in.
|
||||
*
|
||||
* @param profile A previously initialized ratbag profile
|
||||
*
|
||||
* @return non-zero if the profile is the default, zero otherwise
|
||||
*/
|
||||
int
|
||||
ratbag_profile_is_default(struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* @ingroup profile
|
||||
*
|
||||
* Make the given profile the default profile
|
||||
*
|
||||
* @param profile The profile to make the default profile.
|
||||
*
|
||||
* @return 0 on success or nonzero otherwise.
|
||||
*/
|
||||
int
|
||||
ratbag_profile_set_default(struct ratbag_profile *profile);
|
||||
|
||||
/**
|
||||
* @ingroup profile
|
||||
*
|
||||
|
||||
@@ -36,9 +36,11 @@ global:
|
||||
ratbag_profile_get_resolution;
|
||||
ratbag_profile_get_user_data;
|
||||
ratbag_profile_is_active;
|
||||
ratbag_profile_is_default;
|
||||
ratbag_profile_ref;
|
||||
ratbag_profile_set_user_data;
|
||||
ratbag_profile_set_active;
|
||||
ratbag_profile_set_default;
|
||||
ratbag_profile_unref;
|
||||
ratbag_resolution_get_dpi;
|
||||
ratbag_resolution_get_dpi_x;
|
||||
|
||||
@@ -323,8 +323,9 @@ ratbag_cmd_info(struct ratbag *ratbag, uint32_t flags, int argc, char **argv)
|
||||
if (!profile)
|
||||
continue;
|
||||
|
||||
printf(" Profile %d%s\n", i,
|
||||
ratbag_profile_is_active(profile) ? " (active)" : "");
|
||||
printf(" Profile %d%s%s\n", i,
|
||||
ratbag_profile_is_active(profile) ? " (active)" : "",
|
||||
ratbag_profile_is_default(profile) ? " (default)" : "");
|
||||
printf(" Resolutions:\n");
|
||||
for (j = 0; j < ratbag_profile_get_num_resolutions(profile); j++) {
|
||||
struct ratbag_resolution *res;
|
||||
|
||||
Reference in New Issue
Block a user