From dcaf19fa916309a9733adb76045521b918cdc19f Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Wed, 26 Jul 2017 08:54:55 +0200 Subject: [PATCH] ratbagd: sync with libratbag --- piper/ratbagd.py | 96 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 11 deletions(-) diff --git a/piper/ratbagd.py b/piper/ratbagd.py index 8005ae7..0d07727 100644 --- a/piper/ratbagd.py +++ b/piper/ratbagd.py @@ -147,7 +147,7 @@ class _RatbagdDBus(GObject.GObject): return p.unpack() return p - def _set_dbus_property(self, property, type, value): + def _set_dbus_property(self, property, type, value, readwrite=True): # Sets a cached property on the bus. # Take our real value and wrap it into a variant. To call @@ -155,10 +155,11 @@ class _RatbagdDBus(GObject.GObject): # into a (ssv), where v is our value's variant. # args to .Set are "interface name", "function name", value-variant val = GLib.Variant("{}".format(type), value) - pval = GLib.Variant("(ssv)".format(type), (self._interface, property, val)) - self._proxy.call_sync("org.freedesktop.DBus.Properties.Set", - pval, Gio.DBusCallFlags.NO_AUTO_START, - 500, None) + if readwrite: + pval = GLib.Variant("(ssv)".format(type), (self._interface, property, val)) + self._proxy.call_sync("org.freedesktop.DBus.Properties.Set", + pval, Gio.DBusCallFlags.NO_AUTO_START, + 500, None) # This is our local copy, so we don't have to wait for the async # update @@ -296,6 +297,18 @@ class RatbagdProfile(_RatbagdDBus): """The index of this profile.""" return self._get_dbus_property("Index") + @GObject.Property + def enabled(self): + """tells if the profile is enabled.""" + return self._get_dbus_property("Enabled") + + @enabled.setter + def enabled(self, enabled): + """Enable/Disable this profile. + + @param enabled The new state, as boolean""" + return self._set_dbus_property("Enabled", "b", enabled) + @GObject.Property def resolutions(self): """A list of RatbagdResolution objects with this profile's resolutions. @@ -413,10 +426,49 @@ class RatbagdResolution(_RatbagdDBus): """Set this resolution to be the default.""" return self._dbus_call("SetDefault", "") + def set_active(self): + """Set this resolution to be the active one.""" + return self._dbus_call("SetActive", "") + class RatbagdButton(_RatbagdDBus): """Represents a ratbagd button.""" + ACTION_TYPE_NONE = 0 + ACTION_TYPE_BUTTON = 1 + ACTION_TYPE_SPECIAL = 2 + ACTION_TYPE_KEY = 3 + ACTION_TYPE_MACRO = 4 + + MACRO_KEY_PRESS = 1 + MACRO_KEY_RELEASE = 2 + MACRO_WAIT = 3 + + TYPE_UNKNOWN = 0 + TYPE_LEFT = 1 + TYPE_MIDDLE = 2 + TYPE_RIGHT = 3 + TYPE_THUMB = 4 + TYPE_THUMB2 = 5 + TYPE_THUMB3 = 6 + TYPE_THUMB4 = 7 + TYPE_WHEEL_LEFT = 8 + TYPE_WHEEL_RIGHT = 9 + TYPE_WHEEL_CLICK = 10 + TYPE_WHEEL_UP = 11 + TYPE_WHEEL_DOWN = 12 + TYPE_WHEEL_RATCHET_MODE_SHIFT = 13 + TYPE_EXTRA = 14 + TYPE_SIDE = 15 + TYPE_PINKIE = 16 + TYPE_PINKIE2 = 17 + TYPE_RESOLUTION_CYCLE_UP = 18 + TYPE_RESOLUTION_UP = 19 + TYPE_RESOLUTION_DOWN = 20 + TYPE_PROFILE_CYCLE_UP = 21 + TYPE_PROFILE_UP = 22 + TYPE_PROFILE_DOWN = 23 + def __init__(self, object_path): _RatbagdDBus.__init__(self, "Button", object_path) @@ -427,7 +479,7 @@ class RatbagdButton(_RatbagdDBus): @GObject.Property def type(self): - """A string describing this button's type.""" + """An enum describing this button's type.""" return self._get_dbus_property("Type") @GObject.Property @@ -442,7 +494,28 @@ class RatbagdButton(_RatbagdDBus): @param button The button to map to, as int """ ret = self._dbus_call("SetButtonMapping", "u", button) - self._set_dbus_property("ButtonMapping", "u", button) + self._set_dbus_property("ButtonMapping", "u", button, readwrite=False) + return ret + + @GObject.Property + def macro(self): + """A list of (type, value) tuples that form the currently set macro, + where type is either RatbagdButton.KEY_PRESS, RatbagdButton.KEY_RELEASE + or RatbagdButton.MACRO_WAIT and the value is the keycode as specified + in linux/input.h for key related types, or the timeout in milliseconds.""" + return self._get_dbus_property("Macro") + + @macro.setter + def macro(self, macro): + """Set the macro to the given macro. Note that the type must be one of + RatbagdButton.KEY_PRESS, RatbagdButton.KEY_RELEASE or + RatbagdButton.MACRO_WAIT and the keycodes must be as specified in + linux/input.h, and the timeout must be in milliseconds. + + @param macro A list of (type, value) tuples to form the new macro. + """ + ret = self._dbus_call("SetMacro", "a(uu)", macro) + self._set_dbus_property("Macro", "a(uu)", macro, readwrite=False) return ret @GObject.Property @@ -457,7 +530,7 @@ class RatbagdButton(_RatbagdDBus): @param special The special entry, as str """ ret = self._dbus_call("SetSpecialMapping", "s", special) - self._set_dbus_property("SpecialMapping", "s", special) + self._set_dbus_property("SpecialMapping", "s", special, readwrite=False) return ret @GObject.Property @@ -474,13 +547,14 @@ class RatbagdButton(_RatbagdDBus): modifiers. """ ret = self._dbus_call("SetKeyMapping", "au", keys) - self._set_dbus_property("KeyMapping", "au", keys) + self._set_dbus_property("KeyMapping", "au", keys, readwrite=False) return ret @GObject.Property def action_type(self): - """A string describing the action type of the button. One of "none", - "button", "key", "special", "macro" or "unknown". This decides which + """An enum describing the action type of the button. One of + ACTION_TYPE_NONE, ACTION_TYPE_BUTTON, ACTION_TYPE_SPECIAL, + ACTION_TYPE_KEY, ACTION_TYPE_MACRO. This decides which *Mapping property has a value. """ return self._get_dbus_property("ActionType")