mirror of
https://github.com/NickHu/sway
synced 2024-12-28 22:23:30 +01:00
4e6bd53abf
This modifies `input_cmd_scroll_button` to utilize the mouse button helper `get_mouse_button` when parsing the button. x11 axis buttons are not supported with this command and `CMD_INVALID` will be returned, but all other x11 buttons, button event names, and button event codes should be working
39 lines
1.2 KiB
C
39 lines
1.2 KiB
C
#include <libevdev/libevdev.h>
|
|
#include "sway/config.h"
|
|
#include "sway/commands.h"
|
|
#include "sway/input/cursor.h"
|
|
|
|
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;
|
|
}
|
|
struct input_config *ic = config->handler_context.input_config;
|
|
if (!ic) {
|
|
return cmd_results_new(CMD_FAILURE, "scroll_button",
|
|
"No input device defined.");
|
|
}
|
|
|
|
if (strcmp(*argv, "disable") == 0) {
|
|
ic->scroll_button = 0;
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
}
|
|
|
|
char *message = NULL;
|
|
uint32_t button = get_mouse_button(*argv, &message);
|
|
if (message) {
|
|
error = cmd_results_new(CMD_INVALID, "scroll_button", message);
|
|
free(message);
|
|
return error;
|
|
} else if (button == SWAY_SCROLL_UP || button == SWAY_SCROLL_DOWN
|
|
|| button == SWAY_SCROLL_LEFT || button == SWAY_SCROLL_RIGHT) {
|
|
return cmd_results_new(CMD_INVALID, "scroll_button",
|
|
"X11 axis buttons are not supported for scroll_button");
|
|
} else if (!button) {
|
|
return cmd_results_new(CMD_INVALID, "scroll_button",
|
|
"Unknown button %s", *argv);
|
|
}
|
|
ic->scroll_button = button;
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
}
|