forked from drath/libratbag
resolution: switch the capabilities to an enum
Strings can suffer from locale issues, the official recommendation for DBus APIs is to use enums here. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user