forked from drath/libratbag
ratbagd: change the special mapping to the enum
This commit is contained in:
committed by
Benjamin Tissoires
parent
5f0ebdead7
commit
b4f451285e
@@ -232,9 +232,9 @@ device.
|
||||
|
||||
uint of the current button mapping (if mapping to button)
|
||||
#### `SpecialMapping`
|
||||
- type: `s`, read-only, mutable
|
||||
- type: `u`, read-only, mutable
|
||||
|
||||
String of the current special mapping (if mapped to special)
|
||||
Enum describing the current special mapping (if mapped to special)
|
||||
#### `KeyMapping`
|
||||
- type: `au`, read-only, mutable
|
||||
|
||||
@@ -254,7 +254,7 @@ on the current device
|
||||
### Methods:
|
||||
#### `SetButtonMapping(u) → ()`
|
||||
Set the button mapping to the given button
|
||||
#### `SetSpecialMapping(s) → ()`
|
||||
#### `SetSpecialMapping(u) → ()`
|
||||
Set the button mapping to the given special entry
|
||||
#### `SetKeyMapping(au) → ()`
|
||||
Set the key mapping, first entry is the keycode, other entries, if any, are
|
||||
|
||||
@@ -114,72 +114,11 @@ static int ratbagd_button_get_special(sd_bus *bus,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_button *button = userdata;
|
||||
const char *type;
|
||||
enum ratbag_button_action_special special;
|
||||
|
||||
special = ratbag_button_get_special(button->lib_button);
|
||||
|
||||
switch(special) {
|
||||
default:
|
||||
log_error("Unknown special type %d\n", special);
|
||||
/* fallthrough */
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_UNKNOWN:
|
||||
type = "unknown";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_INVALID:
|
||||
type = "n/a";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_DOUBLECLICK:
|
||||
type = "doubleclick";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_LEFT:
|
||||
type = "wheel-left";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_RIGHT:
|
||||
type = "wheel-right";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_UP:
|
||||
type = "wheel-up";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_DOWN:
|
||||
type = "wheel-down";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RATCHET_MODE_SWITCH:
|
||||
type = "ratchet-mode-switch";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP:
|
||||
type = "resolution-cycle-up";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_UP:
|
||||
type = "resolution-up";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DOWN:
|
||||
type = "resolution-down";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_ALTERNATE:
|
||||
type = "resolution-alternate";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DEFAULT:
|
||||
type = "resolution-default";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP:
|
||||
type = "profile-cycle-up";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_UP:
|
||||
type = "profile-up";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_DOWN:
|
||||
type = "profile-down";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE:
|
||||
type = "second-mode";
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL:
|
||||
type = "battery-level";
|
||||
break;
|
||||
}
|
||||
|
||||
return sd_bus_message_append(reply, "s", type);
|
||||
return sd_bus_message_append(reply, "u", special);
|
||||
}
|
||||
|
||||
static int ratbagd_button_set_special(sd_bus_message *m,
|
||||
@@ -187,51 +126,13 @@ static int ratbagd_button_set_special(sd_bus_message *m,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_button *button = userdata;
|
||||
const char *s;
|
||||
enum ratbag_button_action_special special;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_read(m, "s", &s);
|
||||
r = sd_bus_message_read(m, "u", &special);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (streq(s, "doubleclick"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_DOUBLECLICK;
|
||||
else if (streq(s, "wheel-left"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_LEFT;
|
||||
else if (streq(s, "wheel-right"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_RIGHT;
|
||||
else if (streq(s, "wheel-up"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_UP;
|
||||
else if (streq(s, "wheel-down"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_WHEEL_DOWN;
|
||||
else if (streq(s, "ratchet-mode-switch"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RATCHET_MODE_SWITCH;
|
||||
else if (streq(s, "resolution-cycle-up"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_CYCLE_UP;
|
||||
else if (streq(s, "resolution-up"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_UP;
|
||||
else if (streq(s, "resolution-down"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DOWN;
|
||||
else if (streq(s, "resolution-alternate"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_ALTERNATE;
|
||||
else if (streq(s, "resolution-default"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_RESOLUTION_DEFAULT;
|
||||
else if (streq(s, "profile-cycle-up"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP;
|
||||
else if (streq(s, "profile-up"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_UP;
|
||||
else if (streq(s, "profile-down"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_DOWN;
|
||||
else if (streq(s, "second-mode"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_SECOND_MODE;
|
||||
else if (streq(s, "battery-level"))
|
||||
special = RATBAG_BUTTON_ACTION_SPECIAL_BATTERY_LEVEL;
|
||||
else {
|
||||
log_error("Unknown button special action %s\n", s);
|
||||
return sd_bus_reply_method_return(m, "u", -1);
|
||||
}
|
||||
|
||||
r = ratbag_button_set_special(button->lib_button, special);
|
||||
|
||||
if (r == 0) {
|
||||
@@ -243,7 +144,7 @@ static int ratbagd_button_set_special(sd_bus_message *m,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return sd_bus_reply_method_return(m, "u", r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int ratbagd_button_get_key(sd_bus *bus,
|
||||
@@ -481,13 +382,13 @@ const sd_bus_vtable ratbagd_button_vtable[] = {
|
||||
SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_button, index), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Type", "u", ratbagd_button_get_type, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("ButtonMapping", "u", ratbagd_button_get_button, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("SpecialMapping", "s", ratbagd_button_get_special, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("SpecialMapping", "u", ratbagd_button_get_special, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("KeyMapping", "au", ratbagd_button_get_key, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("ActionType", "u", ratbagd_button_get_action_type, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("ActionTypes", "au", ratbagd_button_get_action_types, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("Macro", "a(uu)", ratbagd_button_get_macro, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_METHOD("SetButtonMapping", "u", "u", ratbagd_button_set_button, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetSpecialMapping", "s", "u", ratbagd_button_set_special, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetSpecialMapping", "u", "u", ratbagd_button_set_special, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetKeyMapping", "au", "u", ratbagd_button_set_key, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("SetMacro", "a(uu)", "u", ratbagd_button_set_macro, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_METHOD("Disable", "", "u", ratbagd_button_disable, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
|
||||
@@ -269,7 +269,8 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
|
||||
},
|
||||
{
|
||||
.buttons = {
|
||||
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
|
||||
{ .button_type = RATBAG_BUTTON_TYPE_LEFT,
|
||||
.action_type = RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
|
||||
.special = RATBAG_BUTTON_ACTION_SPECIAL_PROFILE_CYCLE_UP },
|
||||
{ .action_type = RATBAG_BUTTON_ACTION_TYPE_MACRO,
|
||||
.macro = {
|
||||
|
||||
@@ -161,10 +161,29 @@ def print_button(d, p, b, level):
|
||||
RatbagdButton.TYPE_PROFILE_UP: "profile-up",
|
||||
RatbagdButton.TYPE_PROFILE_DOWN: "profile-down",
|
||||
}
|
||||
|
||||
specials = {
|
||||
RatbagdButton.ACTION_SPECIAL_UNKNOWN: "unknown",
|
||||
RatbagdButton.ACTION_SPECIAL_DOUBLECLICK: "doubleclick",
|
||||
RatbagdButton.ACTION_SPECIAL_WHEEL_LEFT: "wheel-left",
|
||||
RatbagdButton.ACTION_SPECIAL_WHEEL_RIGHT: "wheel-right",
|
||||
RatbagdButton.ACTION_SPECIAL_WHEEL_UP: "wheel-up",
|
||||
RatbagdButton.ACTION_SPECIAL_WHEEL_DOWN: "wheel-down",
|
||||
RatbagdButton.ACTION_SPECIAL_RATCHET_MODE_SWITCH: "ratchet-mode-switch",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_CYCLE_UP: "resolution-cycle-up",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_CYCLE_DOWN: "resolution-cycle-down",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_UP: "resolution-up",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_DOWN: "resolution-down",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_ALTERNATE: "resolution-alternate",
|
||||
RatbagdButton.ACTION_SPECIAL_RESOLUTION_DEFAULT: "resolution-default",
|
||||
RatbagdButton.ACTION_SPECIAL_PROFILE_CYCLE_UP: "profile-cycle-up",
|
||||
RatbagdButton.ACTION_SPECIAL_PROFILE_CYCLE_DOWN: "profile-cycle-down",
|
||||
RatbagdButton.ACTION_SPECIAL_PROFILE_UP: "profile-up",
|
||||
RatbagdButton.ACTION_SPECIAL_PROFILE_DOWN: "profile-down",
|
||||
RatbagdButton.ACTION_SPECIAL_SECOND_MODE: "second-mode",
|
||||
RatbagdButton.ACTION_SPECIAL_BATTERY_LEVEL: "battery-level",
|
||||
}
|
||||
t = types[b.type]
|
||||
header = " " * level + "Button: {} type {} is mapped to ".format(b.index,
|
||||
t)
|
||||
header = " " * level + "Button: {} type {} is mapped to ".format(b.index, t)
|
||||
|
||||
if b.action_type == RatbagdButton.ACTION_TYPE_BUTTON:
|
||||
print("{}'button {}'".format(header, b.mapping))
|
||||
@@ -176,7 +195,7 @@ def print_button(d, p, b, level):
|
||||
|
||||
print("{}'{}'".format(header, bmap))
|
||||
elif b.action_type == RatbagdButton.ACTION_TYPE_SPECIAL:
|
||||
print("{}'{}'".format(header, b.special))
|
||||
print("{}'{}'".format(header, specials[b.special]))
|
||||
elif b.action_type == RatbagdButton.ACTION_TYPE_MACRO:
|
||||
bmap = ""
|
||||
for t, v in b.macro:
|
||||
@@ -346,6 +365,38 @@ def func_button_action_set_button(r, args):
|
||||
d.commit()
|
||||
|
||||
|
||||
def func_button_action_set_special(r, args):
|
||||
b, p, d = find_button(r, args)
|
||||
try:
|
||||
special = args.target_special
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
specials = {
|
||||
"unknown": RatbagdButton.ACTION_SPECIAL_UNKNOWN,
|
||||
"doubleclick": RatbagdButton.ACTION_SPECIAL_DOUBLECLICK,
|
||||
"wheel-left": RatbagdButton.ACTION_SPECIAL_WHEEL_LEFT,
|
||||
"wheel-right": RatbagdButton.ACTION_SPECIAL_WHEEL_RIGHT,
|
||||
"wheel-up": RatbagdButton.ACTION_SPECIAL_WHEEL_UP,
|
||||
"wheel-down": RatbagdButton.ACTION_SPECIAL_WHEEL_DOWN,
|
||||
"ratchet-mode-switch": RatbagdButton.ACTION_SPECIAL_RATCHET_MODE_SWITCH,
|
||||
"resolution-cycle-up": RatbagdButton.ACTION_SPECIAL_RESOLUTION_CYCLE_UP,
|
||||
"resolution-cycle-down": RatbagdButton.ACTION_SPECIAL_RESOLUTION_CYCLE_DOWN,
|
||||
"resolution-up": RatbagdButton.ACTION_SPECIAL_RESOLUTION_UP,
|
||||
"resolution-down": RatbagdButton.ACTION_SPECIAL_RESOLUTION_DOWN,
|
||||
"resolution-alternate": RatbagdButton.ACTION_SPECIAL_RESOLUTION_ALTERNATE,
|
||||
"resolution-default": RatbagdButton.ACTION_SPECIAL_RESOLUTION_DEFAULT,
|
||||
"profile-cycle-up": RatbagdButton.ACTION_SPECIAL_PROFILE_CYCLE_UP,
|
||||
"profile-cycle-down": RatbagdButton.ACTION_SPECIAL_PROFILE_CYCLE_DOWN,
|
||||
"profile-up": RatbagdButton.ACTION_SPECIAL_PROFILE_UP,
|
||||
"profile-down": RatbagdButton.ACTION_SPECIAL_PROFILE_DOWN,
|
||||
"second-mode": RatbagdButton.ACTION_SPECIAL_SECOND_MODE,
|
||||
"battery-level": RatbagdButton.ACTION_SPECIAL_BATTERY_LEVEL,
|
||||
}
|
||||
b.special = specials[special]
|
||||
d.commit()
|
||||
|
||||
|
||||
def func_button_action_set_macro(r, args):
|
||||
b, p, d = find_button(r, args)
|
||||
macro_keys = args.target_macro
|
||||
@@ -891,11 +942,32 @@ parser_def = [
|
||||
{
|
||||
of_type: argument,
|
||||
name: 'target_special',
|
||||
metavar: 'S',
|
||||
metavar: 'special',
|
||||
help_str: 'The new special value to assign',
|
||||
choices: [
|
||||
"unknown",
|
||||
"doubleclick",
|
||||
"wheel-left",
|
||||
"wheel-right",
|
||||
"wheel-up",
|
||||
"wheel-down",
|
||||
"ratchet-mode-switch",
|
||||
"resolution-cycle-up",
|
||||
"resolution-cycle-down",
|
||||
"resolution-up",
|
||||
"resolution-down",
|
||||
"resolution-alternate",
|
||||
"resolution-default",
|
||||
"profile-cycle-up",
|
||||
"profile-cycle-down",
|
||||
"profile-up",
|
||||
"profile-down",
|
||||
"second-mode",
|
||||
"battery-level",
|
||||
]
|
||||
},
|
||||
],
|
||||
func: func_dummy, # FIXME: func_button_action_set_special,
|
||||
func: func_button_action_set_special,
|
||||
},
|
||||
{
|
||||
of_type: command,
|
||||
|
||||
@@ -404,10 +404,20 @@ class TestRatbgagCtlButton(TestRatbagCtl):
|
||||
self.launch_fail_test(command + " X test_device")
|
||||
self.launch_fail_test(command + " 100 test_device X")
|
||||
|
||||
@unittest.skip("Button action set special not implemented")
|
||||
def test_button_n_action_set_special(self):
|
||||
pass
|
||||
# FIXME
|
||||
self.setProfile(2)
|
||||
command = "button 0 action set special "
|
||||
r = self.launch_good_test("button 0 action get test_device")
|
||||
# FIXME: special maps to UNKNOWN????
|
||||
self.assertEqual(r, "Button: 0 type left is mapped to UNKNOWN")#'profile-cycle-up'")
|
||||
r = self.launch_good_test(command + " second-mode test_device")
|
||||
self.assertEqual(r, '')
|
||||
r = self.launch_good_test("button 0 action get test_device")
|
||||
# FIXME: special maps to UNKNOWN????
|
||||
self.assertEqual(r, "Button: 0 type left is mapped to UNKNOWN")#'second-mode'")
|
||||
self.launch_fail_test(command)
|
||||
self.launch_fail_test(command + " X test_device")
|
||||
self.launch_fail_test(command + " 100 test_device X")
|
||||
|
||||
def test_button_n_action_set_macro(self):
|
||||
command = "button 2 action set macro "
|
||||
|
||||
@@ -440,6 +440,26 @@ class RatbagdButton(_RatbagdDBus):
|
||||
ACTION_TYPE_KEY = 3
|
||||
ACTION_TYPE_MACRO = 4
|
||||
|
||||
ACTION_SPECIAL_UNKNOWN = (1 << 30),
|
||||
ACTION_SPECIAL_DOUBLECLICK = (1 << 30) + 1,
|
||||
ACTION_SPECIAL_WHEEL_LEFT = (1 << 30) + 2,
|
||||
ACTION_SPECIAL_WHEEL_RIGHT = (1 << 30) + 3,
|
||||
ACTION_SPECIAL_WHEEL_UP = (1 << 30) + 4,
|
||||
ACTION_SPECIAL_WHEEL_DOWN = (1 << 30) + 5,
|
||||
ACTION_SPECIAL_RATCHET_MODE_SWITCH = (1 << 30) + 6,
|
||||
ACTION_SPECIAL_RESOLUTION_CYCLE_UP = (1 << 30) + 7,
|
||||
ACTION_SPECIAL_RESOLUTION_CYCLE_DOWN = (1 << 30) + 8,
|
||||
ACTION_SPECIAL_RESOLUTION_UP = (1 << 30) + 9,
|
||||
ACTION_SPECIAL_RESOLUTION_DOWN = (1 << 30) + 10,
|
||||
ACTION_SPECIAL_RESOLUTION_ALTERNATE = (1 << 30) + 11,
|
||||
ACTION_SPECIAL_RESOLUTION_DEFAULT = (1 << 30) + 12,
|
||||
ACTION_SPECIAL_PROFILE_CYCLE_UP = (1 << 30) + 13,
|
||||
ACTION_SPECIAL_PROFILE_CYCLE_DOWN = (1 << 30) + 14,
|
||||
ACTION_SPECIAL_PROFILE_UP = (1 << 30) + 15,
|
||||
ACTION_SPECIAL_PROFILE_DOWN = (1 << 30) + 16,
|
||||
ACTION_SPECIAL_SECOND_MODE = (1 << 30) + 17,
|
||||
ACTION_SPECIAL_BATTERY_LEVEL = (1 << 30) + 18,
|
||||
|
||||
MACRO_KEY_PRESS = 1
|
||||
MACRO_KEY_RELEASE = 2
|
||||
MACRO_WAIT = 3
|
||||
@@ -520,17 +540,17 @@ class RatbagdButton(_RatbagdDBus):
|
||||
|
||||
@GObject.Property
|
||||
def special(self):
|
||||
"""A string of the current special mapping, if mapped to special."""
|
||||
"""An enum describing the current special mapping, if mapped to special."""
|
||||
return self._get_dbus_property("SpecialMapping")
|
||||
|
||||
@special.setter
|
||||
def special(self, special):
|
||||
"""Set the button mapping to the given special entry.
|
||||
|
||||
@param special The special entry, as str
|
||||
@param special The special entry, as one of RatbagdButton.ACTION_SPECIAL_*
|
||||
"""
|
||||
ret = self._dbus_call("SetSpecialMapping", "s", special)
|
||||
self._set_dbus_property("SpecialMapping", "s", special, readwrite=False)
|
||||
ret = self._dbus_call("SetSpecialMapping", "u", special)
|
||||
self._set_dbus_property("SpecialMapping", "u", special, readwrite=False)
|
||||
return ret
|
||||
|
||||
@GObject.Property
|
||||
|
||||
Reference in New Issue
Block a user