mirror of
https://github.com/swaywm/sway.git
synced 2025-11-27 06:59:53 -05:00
input/tablet: add tool_mode option to set tablet tools as relative input
Closes #4139.
This commit is contained in:
parent
136add4e12
commit
ed247c031c
10 changed files with 149 additions and 6 deletions
|
|
@ -29,6 +29,7 @@ static struct cmd_handler input_handlers[] = {
|
|||
{ "scroll_method", input_cmd_scroll_method },
|
||||
{ "tap", input_cmd_tap },
|
||||
{ "tap_button_map", input_cmd_tap_button_map },
|
||||
{ "tool_mode", input_cmd_tool_mode },
|
||||
{ "xkb_file", input_cmd_xkb_file },
|
||||
{ "xkb_layout", input_cmd_xkb_layout },
|
||||
{ "xkb_model", input_cmd_xkb_model },
|
||||
|
|
|
|||
73
sway/commands/input/tool_mode.c
Normal file
73
sway/commands/input/tool_mode.c
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include <strings.h>
|
||||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
|
||||
static void set_tool_mode(struct input_config *ic,
|
||||
enum wlr_tablet_tool_type type, enum sway_tablet_tool_mode mode) {
|
||||
for (int i = 0; i < ic->tools->length; i++) {
|
||||
struct input_config_tool *tool = ic->tools->items[i];
|
||||
if (tool->type == type) {
|
||||
tool->mode = mode;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
struct input_config_tool *tool = calloc(1, sizeof(*tool));
|
||||
if (tool) {
|
||||
tool->type = type;
|
||||
tool->mode = mode;
|
||||
list_add(ic->tools, tool);
|
||||
}
|
||||
}
|
||||
|
||||
struct cmd_results *input_cmd_tool_mode(int argc, char **argv) {
|
||||
struct cmd_results *error;
|
||||
if ((error = checkarg(argc, "tool_mode", EXPECTED_AT_LEAST, 2))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
struct input_config *ic = config->handler_context.input_config;
|
||||
if (!ic) {
|
||||
return cmd_results_new(CMD_FAILURE, "No input device defined.");
|
||||
}
|
||||
|
||||
enum sway_tablet_tool_mode tool_mode;
|
||||
if (!strcasecmp(argv[1], "absolute")) {
|
||||
tool_mode = SWAY_TABLET_TOOL_MODE_ABSOLUTE;
|
||||
} else if (!strcasecmp(argv[1], "relative")) {
|
||||
tool_mode = SWAY_TABLET_TOOL_MODE_RELATIVE;
|
||||
} else {
|
||||
goto invalid_command;
|
||||
}
|
||||
|
||||
if (!strcasecmp(argv[0], "*")) {
|
||||
set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_PEN, tool_mode);
|
||||
set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_ERASER, tool_mode);
|
||||
set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_BRUSH, tool_mode);
|
||||
set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_PENCIL, tool_mode);
|
||||
set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_AIRBRUSH, tool_mode);
|
||||
} else {
|
||||
enum wlr_tablet_tool_type tool_type;
|
||||
if (!strcasecmp(argv[0], "pen")) {
|
||||
tool_type = WLR_TABLET_TOOL_TYPE_PEN;
|
||||
} else if (!strcasecmp(argv[0], "eraser")) {
|
||||
tool_type = WLR_TABLET_TOOL_TYPE_ERASER;
|
||||
} else if (!strcasecmp(argv[0], "brush")) {
|
||||
tool_type = WLR_TABLET_TOOL_TYPE_BRUSH;
|
||||
} else if (!strcasecmp(argv[0], "pencil")) {
|
||||
tool_type = WLR_TABLET_TOOL_TYPE_PENCIL;
|
||||
} else if (!strcasecmp(argv[0], "airbrush")) {
|
||||
tool_type = WLR_TABLET_TOOL_TYPE_AIRBRUSH;
|
||||
} else {
|
||||
goto invalid_command;
|
||||
}
|
||||
|
||||
set_tool_mode(ic, tool_type, tool_mode);
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
|
||||
invalid_command:
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Expected 'tool_mode <tool> <absolute|relative>'");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue