diff --git a/README.md b/README.md index 4f5ff694..56550c0d 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,7 @@ The **org.freedesktop.ratbag1.Profile** interface provides: The **org.freedesktop.ratbag1.Resolution** interface provides: - Properties: - Index -> index of the resolution - - CapIndividualReportRate, CapSeparateXYResolution -> booleans to signal - capabilities + - Capabilities -> array of uints with the capabilities enum from libratbag - XResolution -> uint for the x resolution assigned to this entry - YResolution -> uint for the y resolution assigned to this entry - ReportRate -> uint for the report rate in Hz assigned to this entry diff --git a/python/ratbagctl.py b/python/ratbagctl.py index 69a939fd..8adc9f9b 100755 --- a/python/ratbagctl.py +++ b/python/ratbagctl.py @@ -120,12 +120,16 @@ def show_resolution(r, args): d.id, d.description)) print(" Report Rate: {}Hz".format(r.report_rate)) - if "separate-xy-resolution" in r.capabilities: + if RatbagdResolution.CAP_SEPARATE_XY_RESOLUTION in r.capabilities: print(" Resolution: {}x{}dpi".format(*r.resolution)) else: print(" Resolution: {}dpi".format(r.resolution[0])) - print(" Capabilities: {}".format(", ".join(r.capabilities))) + + caps = { RatbagdResolution.CAP_INDIVIDUAL_REPORT_RATE : "individual-report-rate", + RatbagdResolution.CAP_SEPARATE_XY_RESOLUTION : "separate-xy-resolution" } + capabilities = [caps[c] for c in r.capabilities] + print(" Capabilities: {}".format(", ".join(capabilities))) def show_button(r, args): b, p, d = find_button(r, args) diff --git a/python/ratbagd/__init__.py b/python/ratbagd/__init__.py index 726cfebb..2c4dabbf 100644 --- a/python/ratbagd/__init__.py +++ b/python/ratbagd/__init__.py @@ -153,7 +153,8 @@ class RatbagdDevice(_RatbagdDBus): """ Return the capabilities of this device as an array. Capabilities not present on the device are not in the list. Thus use - if "capability" is in device.caps: + e.g. + if RatbagdDevice.CAP_SWITCHABLE_RESOLUTION is in device.caps: do something """ return self._caps @@ -229,6 +230,8 @@ class RatbagdProfile(_RatbagdDBus): return self._objpath == other._objpath class RatbagdResolution(_RatbagdDBus): + CAP_INDIVIDUAL_REPORT_RATE = 1 + CAP_SEPARATE_XY_RESOLUTION = 2 """ Represents a ratbagd resolution. """ @@ -240,13 +243,7 @@ class RatbagdResolution(_RatbagdDBus): self._rate = self.dbus_property("ReportRate") self._objpath = object_path - caps = [ "individual-report-rate", - "separate-xy-resolution" ] - self._caps = [] - for c in caps: - cname = "Cap" + "".join([n.capitalize() for n in c.split("-")]) - if self.dbus_property(cname): - self._caps.append(c) + self._caps = self.dbus_property("Capabilities") @property def resolution(self): @@ -271,13 +268,11 @@ class RatbagdResolution(_RatbagdDBus): @property def capabilities(self): """ - Return the capabilities of this device as a list of identifier strings. + Return the capabilities of this device as a list. Capabilities not present on the device are not in the list. Thus use - if "capability" is in resolution.caps: + e.g. + if RatbagdResolution.CAP_SEPARATE_XY_RESOLUTION is in resolution.caps: do something - - Capabilities supported: "individual-report-rate", - "separate-xy-resolution" """ return self._caps diff --git a/src/ratbagd-resolution.c b/src/ratbagd-resolution.c index cecadabe..356d974c 100644 --- a/src/ratbagd-resolution.c +++ b/src/ratbagd-resolution.c @@ -40,11 +40,6 @@ struct ratbagd_resolution { char *path; unsigned int xres, yres; unsigned int rate; - - struct { - bool individual_report_rate; - bool separate_xy_res; - } capabilities; }; static int ratbagd_resolution_set_report_rate(sd_bus_message *m, @@ -92,15 +87,45 @@ static int ratbagd_resolution_set_resolution(sd_bus_message *m, return sd_bus_reply_method_return(m, "u", r); } +static int +ratbagd_resolution_get_capabilities(sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) +{ + struct ratbagd_resolution *resolution = userdata; + struct ratbag_resolution *lib_resolution = resolution->lib_resolution; + enum ratbag_device_capability cap; + int r; + + r = sd_bus_message_open_container(reply, 'a', "u"); + if (r < 0) + return r; + + cap = RATBAG_RESOLUTION_CAP_INDIVIDUAL_REPORT_RATE; + if (ratbag_resolution_has_capability(lib_resolution, cap)) { + r = sd_bus_message_append(reply, "u", cap); + if (r < 0) + return r; + } + + cap = RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION; + if (ratbag_resolution_has_capability(lib_resolution, cap)) { + r = sd_bus_message_append(reply, "u", cap); + if (r < 0) + return r; + } + + return sd_bus_message_close_container(reply); +} + const sd_bus_vtable ratbagd_resolution_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_resolution, index), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("CapIndividualReportRate", "b", NULL, - offsetof(struct ratbagd_resolution, capabilities.individual_report_rate), - SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("CapSeparateXYResolution", "b", NULL, - offsetof(struct ratbagd_resolution, capabilities.separate_xy_res), - SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("Capabilities", "au", ratbagd_resolution_get_capabilities, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("XResolution", "u", NULL, offsetof(struct ratbagd_resolution, xres), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("YResolution", "u", NULL, offsetof(struct ratbagd_resolution, yres), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("ReportRate", "u", NULL, offsetof(struct ratbagd_resolution, rate), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), @@ -132,12 +157,6 @@ int ratbagd_resolution_new(struct ratbagd_resolution **out, resolution->xres = ratbag_resolution_get_dpi_x(lib_resolution); resolution->yres = ratbag_resolution_get_dpi_y(lib_resolution); resolution->rate = ratbag_resolution_get_report_rate(lib_resolution); - resolution->capabilities.individual_report_rate = - ratbag_resolution_has_capability(lib_resolution, - RATBAG_RESOLUTION_CAP_INDIVIDUAL_REPORT_RATE); - resolution->capabilities.separate_xy_res = - ratbag_resolution_has_capability(lib_resolution, - RATBAG_RESOLUTION_CAP_SEPARATE_XY_RESOLUTION); sprintf(profile_buffer, "p%u", ratbagd_profile_get_index(profile)); sprintf(resolution_buffer, "r%u", index);