diff --git a/doc/dbus.rst b/doc/dbus.rst index 34753b71..871a726b 100644 --- a/doc/dbus.rst +++ b/doc/dbus.rst @@ -196,7 +196,8 @@ org.freedesktop.ratbag1.Profile :type: s :flags: read-write, mutable - The name of this profile. + The name of this profile. If the name is the empty string, the + profile name cannot be changed. .. attribute:: Enabled diff --git a/ratbagd/ratbagd-profile.c b/ratbagd/ratbagd-profile.c index b9d4eab3..00c09298 100644 --- a/ratbagd/ratbagd-profile.c +++ b/ratbagd/ratbagd-profile.c @@ -384,11 +384,14 @@ ratbagd_profile_get_name(sd_bus *bus, const char *name = ratbag_profile_get_name(profile->lib_profile); _cleanup_free_ char *asciiname; - /* This should really be a UTF8 check and it should really be in - * libratbag, but for now this will do to at least not kick us off - * the bus. https://github.com/libratbag/libratbag/issues/617 - */ - asciiname = strdup_ascii_only(name); + if (!name) + asciiname = strdup(""); + else + /* This should really be a UTF8 check and it should really be in + * libratbag, but for now this will do to at least not kick us off + * the bus. https://github.com/libratbag/libratbag/issues/617 + */ + asciiname = strdup_ascii_only(name); CHECK_CALL(sd_bus_message_append(reply, "s", asciiname)); @@ -408,7 +411,6 @@ ratbagd_profile_get_capabilities(sd_bus *bus, struct ratbag_profile *lib_profile = profile->lib_profile; enum ratbag_profile_capability cap; enum ratbag_profile_capability caps[] = { - RATBAG_PROFILE_CAP_WRITABLE_NAME, RATBAG_PROFILE_CAP_SET_DEFAULT, RATBAG_PROFILE_CAP_DISABLE, }; diff --git a/ratbagd/ratbagd-test.c b/ratbagd/ratbagd-test.c index 2e3aa3c1..5a5e8a88 100644 --- a/ratbagd/ratbagd-test.c +++ b/ratbagd/ratbagd-test.c @@ -42,7 +42,7 @@ static const struct ratbag_test_device ratbagd_test_device_descr = { .svg = "fallback.svg", .profiles = { { - .name = "test profile 1", + .name = NULL, .buttons = { { .button_type = RATBAG_BUTTON_TYPE_LEFT, .action_type = RATBAG_BUTTON_ACTION_TYPE_BUTTON, @@ -115,7 +115,7 @@ static const struct ratbag_test_device ratbagd_test_device_descr = { }, .active = false, .dflt = true, - .caps = { RATBAG_PROFILE_CAP_WRITABLE_NAME }, + .name = "test profile 2", }, { .buttons = { diff --git a/src/driver-hidpp10.c b/src/driver-hidpp10.c index 5d0bf902..3e31064c 100644 --- a/src/driver-hidpp10.c +++ b/src/driver-hidpp10.c @@ -407,7 +407,6 @@ hidpp10drv_read_profile(struct ratbag_profile *profile) if (rc) return; - ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_WRITABLE_NAME); if (hidpp10->profile_type != HIDPP10_PROFILE_UNKNOWN) ratbag_profile_set_cap(profile, RATBAG_PROFILE_CAP_DISABLE); diff --git a/src/libratbag-enums.h b/src/libratbag-enums.h index dd6fc9b4..9b1e6f7e 100644 --- a/src/libratbag-enums.h +++ b/src/libratbag-enums.h @@ -81,15 +81,6 @@ enum ratbag_error_code { enum ratbag_profile_capability { RATBAG_PROFILE_CAP_NONE = 0, - /** - * The device has the capability to write a name to a profile - * and store it in its flash. - * - * Any changes uploaded to the device will be cached in libratbag - * and will be committed to it after a commit only. - */ - RATBAG_PROFILE_CAP_WRITABLE_NAME = 100, - /** * This profile can be assigned as the default profile. A default * profile is the profile that is selected when the device @@ -97,7 +88,7 @@ enum ratbag_profile_capability { * profile, the device either picks last-used profile or a specific * profile (usually the first). */ - RATBAG_PROFILE_CAP_SET_DEFAULT, + RATBAG_PROFILE_CAP_SET_DEFAULT = 101, /** * The profile can be disabled and enabled. Profiles are not diff --git a/src/libratbag.c b/src/libratbag.c index fcc6a90c..00e21215 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -671,7 +671,7 @@ ratbag_create_profile(struct ratbag_device *device, profile->index = index; profile->num_resolutions = 0; profile->is_enabled = true; - profile->name = asprintf_safe("Profile %d", index + 1); + profile->name = NULL; list_insert(&device->profiles, &profile->link); list_init(&profile->buttons); @@ -1589,8 +1589,7 @@ ratbag_profile_set_name(struct ratbag_profile *profile, { char *name_copy; - if (!ratbag_profile_has_capability(profile, - RATBAG_PROFILE_CAP_WRITABLE_NAME)) + if (!profile->name) return RATBAG_ERROR_CAPABILITY; name_copy = strdup_safe(name); diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index ebdb11d9..891f4aa2 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -242,7 +242,7 @@ def print_profile(d, p, level): " (disabled)" if not p.enabled else "", " (active)" if p.is_active else "")) if p.enabled: - print(" " * level + "Name : '{}'".format(p.name)) + print(" " * level + "Name: {}".format(p.name or 'n/a')) print(" " * level + "Resolutions:") for r in p.resolutions: print_resolution(d, p, r, level + 2) @@ -512,7 +512,7 @@ def func_profile_name_get(r, args): def func_profile_name_set(r, args): p, d = find_profile(r, args) - if RatbagdProfile.CAP_WRITABLE_NAME not in p.capabilities: + if not p.name: raise RatbagErrorCapability("assigning a profile name is not supported on this profile") p.name = args.name commit(d, args) diff --git a/tools/ratbagctl.test.in b/tools/ratbagctl.test.in index c2e28c5f..1f5aa9c5 100755 --- a/tools/ratbagctl.test.in +++ b/tools/ratbagctl.test.in @@ -139,16 +139,16 @@ class TestRatbagCtlProfile(TestRatbagCtl): cls.setProfile(0) def test_profile_name_get(self): - command = "profile 0 name get" + command = "profile 1 name get" r = self.launch_good_test(command + " test_device") - self.assertEqual(r, 'test profile 1') + self.assertEqual(r, 'test profile 2') self.launch_fail_test(command) self.launch_fail_test(command + " X test_device") self.launch_fail_test("profile name get test_device") def test_profile_name_set(self): r = self.launch_good_test("profile 1 name get test_device") - self.assertEqual(r, 'Profile 2') + self.assertEqual(r, 'test profile 2') self.launch_good_test("profile 1 name set banana test_device") r = self.launch_good_test("profile 1 name get test_device") self.assertEqual(r, 'banana')