mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-08 07:33:53 +01:00
tools: do a cap check before trying to set buttons/macros/..
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -1086,6 +1086,7 @@ ratbag_cmd_button_set_button(const struct ratbag_cmd *cmd,
|
||||
struct ratbag_cmd_options *options,
|
||||
int argc, char **argv)
|
||||
{
|
||||
struct ratbag_device *device;
|
||||
struct ratbag_button *button;
|
||||
char *str, *endptr;
|
||||
int b;
|
||||
@@ -1099,6 +1100,12 @@ ratbag_cmd_button_set_button(const struct ratbag_cmd *cmd,
|
||||
if (*endptr != '\0')
|
||||
return ERR_USAGE;
|
||||
|
||||
device = options->device;
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY))
|
||||
return ERR_UNSUPPORTED;
|
||||
|
||||
|
||||
button = options->button;
|
||||
rc = ratbag_button_set_button(button, b);
|
||||
if (rc != 0)
|
||||
@@ -1122,6 +1129,7 @@ ratbag_cmd_button_set_key(const struct ratbag_cmd *cmd,
|
||||
struct ratbag_cmd_options *options,
|
||||
int argc, char **argv)
|
||||
{
|
||||
struct ratbag_device *device;
|
||||
struct ratbag_button *button;
|
||||
int keycode;
|
||||
char *str;
|
||||
@@ -1137,6 +1145,11 @@ ratbag_cmd_button_set_key(const struct ratbag_cmd *cmd,
|
||||
return ERR_USAGE;
|
||||
}
|
||||
|
||||
device = options->device;
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_DEVICE_CAP_BUTTON_KEY))
|
||||
return ERR_UNSUPPORTED;
|
||||
|
||||
button = options->button;
|
||||
rc = ratbag_button_set_key(button, keycode, NULL, 0);
|
||||
if (rc != 0)
|
||||
@@ -1198,6 +1211,7 @@ ratbag_cmd_button_set_macro(const struct ratbag_cmd *cmd,
|
||||
struct ratbag_cmd_options *options,
|
||||
int argc, char **argv)
|
||||
{
|
||||
struct ratbag_device *device;
|
||||
struct ratbag_button *button;
|
||||
struct macro macro = {0};
|
||||
char *str;
|
||||
@@ -1213,6 +1227,11 @@ ratbag_cmd_button_set_macro(const struct ratbag_cmd *cmd,
|
||||
return ERR_USAGE;
|
||||
}
|
||||
|
||||
device = options->device;
|
||||
if (!ratbag_device_has_capability(device,
|
||||
RATBAG_DEVICE_CAP_BUTTON_MACROS))
|
||||
return ERR_UNSUPPORTED;
|
||||
|
||||
button = options->button;
|
||||
rc = ratbag_button_set_macro(button, macro.name);
|
||||
for (i = 0; i < ARRAY_LENGTH(macro.events); i++) {
|
||||
|
||||
Reference in New Issue
Block a user