forked from drath/libratbag
ratbagd: map disabling a button to the existing action type None
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Yaroslav Chvanov
parent
cdf19a904e
commit
39b8f2bce2
@@ -396,6 +396,9 @@ org.freedesktop.ratbag1.Button
|
||||
| 1 | Key press event |
|
||||
+---------+--------------------------------------+
|
||||
|
||||
If the ActionType is *None*, the variant is an unsigned integer
|
||||
(``u``) of value 0.
|
||||
|
||||
If the ActionType is *Unknown*, the variant is an unsigned integer
|
||||
(``u``) of value 0.
|
||||
|
||||
@@ -423,10 +426,6 @@ org.freedesktop.ratbag1.Button
|
||||
|
||||
Clients must ignore :attr:`ActionTypes` unknown to them.
|
||||
|
||||
.. function:: Disable() → ()
|
||||
|
||||
Disable this button
|
||||
|
||||
.. _led:
|
||||
|
||||
org.freedesktop.ratbag1.Led
|
||||
|
||||
@@ -310,6 +310,48 @@ static int ratbagd_button_set_macro(sd_bus *bus,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ratbagd_button_get_none(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *reply,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
CHECK_CALL(sd_bus_message_append(reply, "(uv)",
|
||||
RATBAG_BUTTON_ACTION_TYPE_NONE,
|
||||
"u",
|
||||
0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ratbagd_button_set_none(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
const char *property,
|
||||
sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_button *button = userdata;
|
||||
int r;
|
||||
_unused_ unsigned int zero;
|
||||
|
||||
CHECK_CALL(sd_bus_message_read(m, "v", "u", &zero));
|
||||
|
||||
r = ratbag_button_disable(button->lib_button);
|
||||
if (r < 0) {
|
||||
sd_bus_emit_properties_changed(bus,
|
||||
button->path,
|
||||
RATBAGD_NAME_ROOT ".Button",
|
||||
"Mapping",
|
||||
NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ratbagd_button_get_mapping(sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
@@ -325,6 +367,9 @@ static int ratbagd_button_get_mapping(sd_bus *bus,
|
||||
verify_unsigned_int(type);
|
||||
|
||||
switch (type) {
|
||||
case RATBAG_BUTTON_ACTION_TYPE_NONE:
|
||||
return ratbagd_button_get_none(bus, path, interface, property,
|
||||
reply, userdata, error);
|
||||
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
|
||||
return ratbagd_button_get_button(bus, path, interface, property,
|
||||
reply, userdata, error);
|
||||
@@ -360,6 +405,10 @@ static int ratbagd_button_set_mapping(sd_bus *bus,
|
||||
CHECK_CALL(sd_bus_message_read(m, "u", &type));
|
||||
|
||||
switch (type) {
|
||||
case RATBAG_BUTTON_ACTION_TYPE_NONE:
|
||||
CHECK_CALL(ratbagd_button_set_none(bus, path, interface, property,
|
||||
m, userdata, error));
|
||||
break;
|
||||
case RATBAG_BUTTON_ACTION_TYPE_BUTTON:
|
||||
CHECK_CALL(ratbagd_button_set_button(bus, path, interface, property,
|
||||
m, userdata, error));
|
||||
@@ -397,6 +446,7 @@ static int ratbagd_button_get_action_types(sd_bus *bus,
|
||||
{
|
||||
struct ratbagd_button *button = userdata;
|
||||
enum ratbag_button_action_type types[] = {
|
||||
RATBAG_BUTTON_ACTION_TYPE_NONE,
|
||||
RATBAG_BUTTON_ACTION_TYPE_BUTTON,
|
||||
RATBAG_BUTTON_ACTION_TYPE_SPECIAL,
|
||||
RATBAG_BUTTON_ACTION_TYPE_KEY,
|
||||
@@ -420,28 +470,6 @@ static int ratbagd_button_get_action_types(sd_bus *bus,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ratbagd_button_disable(sd_bus_message *m,
|
||||
void *userdata,
|
||||
sd_bus_error *error)
|
||||
{
|
||||
struct ratbagd_button *button = userdata;
|
||||
int r;
|
||||
|
||||
CHECK_CALL(sd_bus_message_read(m, ""));
|
||||
|
||||
r = ratbag_button_disable(button->lib_button);
|
||||
if (r < 0) {
|
||||
sd_bus *bus = sd_bus_message_get_bus(m);
|
||||
r = ratbagd_device_resync(button->device, bus);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
CHECK_CALL(sd_bus_reply_method_return(m, "u", 0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const sd_bus_vtable ratbagd_button_vtable[] = {
|
||||
SD_BUS_VTABLE_START(0),
|
||||
SD_BUS_PROPERTY("Index", "u", NULL, offsetof(struct ratbagd_button, index), SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
@@ -450,7 +478,6 @@ const sd_bus_vtable ratbagd_button_vtable[] = {
|
||||
ratbagd_button_set_mapping,
|
||||
0, SD_BUS_VTABLE_UNPRIVILEGED | SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("ActionTypes", "au", ratbagd_button_get_action_types, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_METHOD("Disable", "", "u", ratbagd_button_disable, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||
SD_BUS_VTABLE_END,
|
||||
};
|
||||
|
||||
|
||||
@@ -323,6 +323,12 @@ def func_button_get(r, args):
|
||||
print_button(b, p, b, 0)
|
||||
|
||||
|
||||
def func_button_action_set_none(r, args):
|
||||
b, p, d = find_button(r, args)
|
||||
b.disable()
|
||||
commit(d, args)
|
||||
|
||||
|
||||
def func_button_action_set_button(r, args):
|
||||
b, p, d = find_button(r, args)
|
||||
b.mapping = args.target_button
|
||||
@@ -1026,6 +1032,13 @@ active profile if none is given.""",
|
||||
],
|
||||
func: func_button_action_set_macro,
|
||||
},
|
||||
{
|
||||
of_type: command,
|
||||
name: 'disabled',
|
||||
help_str: 'Disable this button',
|
||||
pos_args: [],
|
||||
func: func_button_action_set_none,
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
|
||||
@@ -569,7 +569,7 @@ class TestRatbagCtlButton(TestRatbagCtl):
|
||||
r = self.launch_good_test("test_device button 0 get")
|
||||
self.assertEqual(r, "Button: 0 is mapped to 'button 0'")
|
||||
r = self.launch_good_test("test_device button 1 get")
|
||||
self.assertEqual(r, "Button: 1 is mapped to UNKNOWN")
|
||||
self.assertEqual(r, "Button: 1 is mapped to none")
|
||||
r = self.launch_good_test("test_device button 2 get")
|
||||
self.assertEqual(r, "Button: 2 is mapped to 'profile-cycle-up'")
|
||||
r = self.launch_good_test("test_device button 3 get")
|
||||
|
||||
@@ -784,9 +784,16 @@ class RatbagdButton(_RatbagdDBus):
|
||||
"""An array of possible values for ActionType."""
|
||||
return self._get_dbus_property("ActionTypes")
|
||||
|
||||
@GObject.Property
|
||||
def disabled(self):
|
||||
type, unused = self._mapping()
|
||||
return type == RatbagdButton.ActionType.NONE
|
||||
|
||||
def disable(self):
|
||||
"""Disables this button."""
|
||||
return self._dbus_call("Disable", "")
|
||||
zero = GLib.Variant('u', 0)
|
||||
self._set_dbus_property("Mapping", "(uv)",
|
||||
(RatbagdButton.ActionType.NONE, zero))
|
||||
|
||||
|
||||
class RatbagdMacro(GObject.Object):
|
||||
|
||||
Reference in New Issue
Block a user