diff --git a/src/libratbag-private.h b/src/libratbag-private.h index 1187adcb..1d9f2055 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -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)]; diff --git a/src/libratbag.c b/src/libratbag.c index db7b1d02..7e378f7b 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -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; } diff --git a/src/libratbag.h b/src/libratbag.h index 44e93f85..08566380 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -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. * diff --git a/tools/ratbagd.py b/tools/ratbagd.py index 79645813..2ef2aadf 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -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"]