libratbag: don't apply active profile change until committing

This commit is contained in:
Yaroslav Chvanov
2023-03-04 04:07:32 +03:00
parent a3f0ea9a52
commit 84e8e63752
4 changed files with 19 additions and 8 deletions

View File

@@ -278,6 +278,8 @@ struct ratbag_profile {
unsigned int num_resolutions;
bool is_active; /**< profile is the currently active one */
bool is_active_dirty;
bool is_enabled;
bool dirty; /**< profile changed since last commit */
unsigned long capabilities[NLONGS(MAX_CAP)];

View File

@@ -878,6 +878,16 @@ ratbag_device_commit(struct ratbag_device *device)
list_for_each(resolution, &profile->resolutions, link)
resolution->dirty = false;
/* TODO: think if this should be moved into `driver-commit`. */
if (profile->is_active_dirty && profile->is_active) {
if (device->driver->set_active_profile == NULL)
return RATBAG_ERROR_IMPLEMENTATION;
rc = device->driver->set_active_profile(device, profile->index);
if (rc)
return RATBAG_ERROR_DEVICE;
}
profile->is_active_dirty = false;
}
return RATBAG_SUCCESS;
@@ -888,20 +898,17 @@ ratbag_profile_set_active(struct ratbag_profile *profile)
{
struct ratbag_device *device = profile->device;
struct ratbag_profile *p;
int rc;
if (device->num_profiles == 1)
return RATBAG_SUCCESS;
assert(device->driver->set_active_profile);
rc = device->driver->set_active_profile(device, profile->index);
if (rc)
return RATBAG_ERROR_DEVICE;
list_for_each(p, &device->profiles, link)
list_for_each(p, &device->profiles, link) {
p->is_active = false;
p->is_active_dirty = true;
}
profile->is_active = true;
profile->is_active_dirty = true;
return RATBAG_SUCCESS;
}

View File

@@ -705,7 +705,8 @@ ratbag_profile_is_active(struct ratbag_profile *profile);
/**
* @ingroup profile
*
* Make the given profile the currently active profile
* Make the given profile the currently active profile. Note that you have to
* commit the device before this gets applied.
*
* @param profile The profile to make the active profile.
*

View File

@@ -456,6 +456,7 @@ class RatbagdProfile(_RatbagdDBus):
if active != self._active:
self._active = active
self.notify("is-active")
self._on_obj_notify(None, None)
if "ReportRate" in changed_props.keys():
report_rate = changed_props["ReportRate"]