forked from drath/libratbag
ratbagd: switch Profile.Enabled to Profile.Disabled
When a boolean property is optional, the default None value and the False value both represent a boolean false. So let's rename the property so that the boolean values cannot be confused, because None and (Disabled == false) have the same meaning (profile is enabled). This is an API break. Fixes #756 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Yaroslav Chvanov
parent
e32145ecc7
commit
f6bfed4da0
@@ -206,12 +206,12 @@ org.freedesktop.ratbag1.Profile
|
||||
The name of this profile. If the name is the empty string, the
|
||||
profile name cannot be changed.
|
||||
|
||||
.. attribute:: Enabled
|
||||
.. attribute:: Disabled
|
||||
|
||||
:type: b
|
||||
:flags: read-write, mutable
|
||||
|
||||
True if this is the profile is enabled, false otherwise.
|
||||
True if this is the profile is disabled, false otherwise.
|
||||
|
||||
Note that a disabled profile might not have correct bindings, so it's
|
||||
a good thing to rebind everything before calling
|
||||
|
||||
@@ -301,27 +301,27 @@ static int ratbagd_profile_set_active(sd_bus_message *m,
|
||||
}
|
||||
|
||||
static int
|
||||
ratbagd_profile_set_enabled(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
ratbagd_profile_set_disabled(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_profile *profile = userdata;
|
||||
int enabled;
|
||||
int r;
|
||||
bool disabled;
|
||||
|
||||
CHECK_CALL(sd_bus_message_read(m, "b", &enabled));
|
||||
CHECK_CALL(sd_bus_message_read(m, "b", &disabled));
|
||||
|
||||
r = ratbag_profile_set_enabled(profile->lib_profile, enabled);
|
||||
r = ratbag_profile_set_enabled(profile->lib_profile, !disabled);
|
||||
if (r == 0) {
|
||||
sd_bus *bus = sd_bus_message_get_bus(m);
|
||||
sd_bus_emit_properties_changed(bus,
|
||||
profile->path,
|
||||
RATBAGD_NAME_ROOT ".Profile",
|
||||
"Enabled",
|
||||
"Disabled",
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -329,18 +329,18 @@ ratbagd_profile_set_enabled(sd_bus *bus,
|
||||
}
|
||||
|
||||
static int
|
||||
ratbagd_profile_is_enabled(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
ratbagd_profile_is_disabled(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_profile *profile = userdata;
|
||||
int enabled = ratbag_profile_is_enabled(profile->lib_profile) != 0;
|
||||
int disabled = !ratbag_profile_is_enabled(profile->lib_profile);
|
||||
|
||||
CHECK_CALL(sd_bus_message_append(reply, "b", enabled));
|
||||
CHECK_CALL(sd_bus_message_append(reply, "b", disabled));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -529,9 +529,9 @@ const sd_bus_vtable ratbagd_profile_vtable[] = {
|
||||
ratbagd_profile_get_name,
|
||||
ratbagd_profile_set_name, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_WRITABLE_PROPERTY("Enabled", "b",
|
||||
ratbagd_profile_is_enabled,
|
||||
ratbagd_profile_set_enabled, 0,
|
||||
SD_BUS_WRITABLE_PROPERTY("Disabled", "b",
|
||||
ratbagd_profile_is_disabled,
|
||||
ratbagd_profile_set_disabled, 0,
|
||||
SD_BUS_VTABLE_UNPRIVILEGED|SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_profile, index), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Capabilities", "au", ratbagd_profile_get_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
|
||||
@@ -350,16 +350,16 @@ class RatbagdProfile(metaclass=MetaRatbag):
|
||||
return self._dirty
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
"""tells if the profile is enabled."""
|
||||
return libratbag.ratbag_profile_is_enabled(self._profile)
|
||||
def disabled(self):
|
||||
"""tells if the profile is disabled."""
|
||||
return not libratbag.ratbag_profile_is_enabled(self._profile)
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
@disabled.setter
|
||||
def disabled(self, disabled):
|
||||
"""Enable/Disable this profile.
|
||||
|
||||
@param enabled The new state, as boolean"""
|
||||
libratbag.ratbag_profile_set_enabled(self._profile, enabled)
|
||||
@param disabled The new state, as boolean"""
|
||||
libratbag.ratbag_profile_set_enabled(self._profile, not disabled)
|
||||
|
||||
@property
|
||||
def report_rate(self):
|
||||
|
||||
@@ -204,9 +204,10 @@ def print_resolution(d, p, r, level):
|
||||
|
||||
def print_profile(d, p, level):
|
||||
print(" " * (level - 2) + "Profile {}:{}{}".format(p.index,
|
||||
" (disabled)" if not p.enabled else "",
|
||||
" (disabled)" if p.disabled else "",
|
||||
" (active)" if p.is_active else ""))
|
||||
if p.enabled:
|
||||
|
||||
if not p.disabled:
|
||||
print(" " * level + "Name: {}".format(p.name or 'n/a'))
|
||||
if p.report_rate:
|
||||
print(" " * level + "Report Rate: {}Hz".format(p.report_rate))
|
||||
@@ -514,13 +515,13 @@ def func_profile_active_set(r, args):
|
||||
|
||||
def func_profile_enable(r, args):
|
||||
p, d = find_profile(r, args)
|
||||
p.enabled = True
|
||||
p.disabled = False
|
||||
commit(d, args)
|
||||
|
||||
|
||||
def func_profile_disable(r, args):
|
||||
p, d = find_profile(r, args)
|
||||
p.enabled = False
|
||||
p.disabled = True
|
||||
commit(d, args)
|
||||
|
||||
|
||||
|
||||
@@ -463,16 +463,16 @@ class RatbagdProfile(_RatbagdDBus):
|
||||
return self._dirty
|
||||
|
||||
@GObject.Property
|
||||
def enabled(self):
|
||||
"""tells if the profile is enabled."""
|
||||
return self._get_dbus_property("Enabled")
|
||||
def disabled(self):
|
||||
"""tells if the profile is disabled."""
|
||||
return self._get_dbus_property("Disabled")
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, enabled):
|
||||
@disabled.setter
|
||||
def disabled(self, disabled):
|
||||
"""Enable/Disable this profile.
|
||||
|
||||
@param enabled The new state, as boolean"""
|
||||
self._set_dbus_property("Enabled", "b", enabled)
|
||||
@param disabled The new state, as boolean"""
|
||||
self._set_dbus_property("Disabled", "b", disabled)
|
||||
|
||||
@GObject.Property
|
||||
def report_rate(self) -> int:
|
||||
|
||||
Reference in New Issue
Block a user