2019-01-11 04:45:52 +11:00
|
|
|
#include <libevdev/libevdev.h>
|
2018-07-12 06:03:06 +10:00
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/commands.h"
|
2019-01-11 04:45:52 +11:00
|
|
|
#include "sway/input/cursor.h"
|
2018-07-12 06:03:06 +10: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 09:56:52 +10:00
|
|
|
struct input_config *ic = config->handler_context.input_config;
|
|
|
|
if (!ic) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_FAILURE, "No input device defined.");
|
2018-07-12 06:03:06 +10:00
|
|
|
}
|
|
|
|
|
2019-01-11 04:45:52 +11:00
|
|
|
if (strcmp(*argv, "disable") == 0) {
|
|
|
|
ic->scroll_button = 0;
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-13 07:50:34 +10:00
|
|
|
}
|
2019-01-11 04:45:52 +11:00
|
|
|
|
|
|
|
char *message = NULL;
|
|
|
|
uint32_t button = get_mouse_button(*argv, &message);
|
|
|
|
if (message) {
|
2019-01-11 10:27:21 +11:00
|
|
|
error = cmd_results_new(CMD_INVALID, message);
|
2019-01-11 04:45:52 +11: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 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID,
|
2019-01-11 04:45:52 +11:00
|
|
|
"X11 axis buttons are not supported for scroll_button");
|
|
|
|
} else if (!button) {
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_INVALID, "Unknown button %s", *argv);
|
2018-07-12 06:03:06 +10:00
|
|
|
}
|
2019-01-11 04:45:52 +11:00
|
|
|
ic->scroll_button = button;
|
2018-07-12 06:03:06 +10:00
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2018-07-12 06:03:06 +10:00
|
|
|
}
|