2019-01-10 18:45:52 +01:00
|
|
|
#include <libevdev/libevdev.h>
|
2018-07-11 22:03:06 +02:00
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/commands.h"
|
2019-01-10 18:45:52 +01:00
|
|
|
#include "sway/input/cursor.h"
|
2018-07-11 22:03:06 +02:00
|
|
|
|
|
|
|
struct cmd_results *input_cmd_scroll_button(int argc, char **argv) {
|
|
|
|
struct cmd_results *error = NULL;
|
|
|
|
if ((error = checkarg(argc, "scroll_button", EXPECTED_AT_LEAST, 1))) {
|
|
|
|
return error;
|
|
|
|
}
|
2018-09-24 01:56:52 +02:00
|
|
|
struct input_config *ic = config->handler_context.input_config;
|
|
|
|
if (!ic) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_FAILURE, "No input device defined.");
|
2018-07-11 22:03:06 +02:00
|
|
|
}
|
|
|
|
|
2019-01-10 18:45:52 +01:00
|
|
|
if (strcmp(*argv, "disable") == 0) {
|
|
|
|
ic->scroll_button = 0;
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-12 23:50:34 +02:00
|
|
|
}
|
2019-01-10 18:45:52 +01:00
|
|
|
|
|
|
|
char *message = NULL;
|
|
|
|
uint32_t button = get_mouse_button(*argv, &message);
|
|
|
|
if (message) {
|
2023-02-28 16:24:03 +01:00
|
|
|
error = cmd_results_new(CMD_INVALID, "%s", message);
|
2019-01-10 18:45:52 +01:00
|
|
|
free(message);
|
|
|
|
return error;
|
|
|
|
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN
|
|
|
|
|| button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2019-01-10 18:45:52 +01:00
|
|
|
"X11 axis buttons are not supported for scroll_button");
|
|
|
|
} else if (!button) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID, "Unknown button %s", *argv);
|
2018-07-11 22:03:06 +02:00
|
|
|
}
|
2019-01-10 18:45:52 +01:00
|
|
|
ic->scroll_button = button;
|
2018-07-11 22:03:06 +02:00
|
|
|
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-11 22:03:06 +02:00
|
|
|
}
|