aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
authorLibravatar Tudor Brindus <me@tbrindus.ca>2020-06-19 14:11:57 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2020-10-12 15:01:37 +0200
commited247c031cb9783deb5c04631b53c5ac6c432eb7 (patch)
tree3b8aa74d49d6e6cb1518cd749854cba13728f259 /sway/commands
parentinput/cursor: default tablet lens tool to relative motion (diff)
downloadsway-ed247c031cb9783deb5c04631b53c5ac6c432eb7.tar.gz
sway-ed247c031cb9783deb5c04631b53c5ac6c432eb7.tar.zst
sway-ed247c031cb9783deb5c04631b53c5ac6c432eb7.zip
input/tablet: add tool_mode option to set tablet tools as relative input
Closes #4139.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/input.c1
-rw-r--r--sway/commands/input/tool_mode.c73
2 files changed, 74 insertions, 0 deletions
diff --git a/sway/commands/input.c b/sway/commands/input.c
index 53db9a16..c9bb8e06 100644
--- a/sway/commands/input.c
+++ b/sway/commands/input.c
@@ -29,6 +29,7 @@ static struct cmd_handler input_handlers[] = {
29 { "scroll_method", input_cmd_scroll_method }, 29 { "scroll_method", input_cmd_scroll_method },
30 { "tap", input_cmd_tap }, 30 { "tap", input_cmd_tap },
31 { "tap_button_map", input_cmd_tap_button_map }, 31 { "tap_button_map", input_cmd_tap_button_map },
32 { "tool_mode", input_cmd_tool_mode },
32 { "xkb_file", input_cmd_xkb_file }, 33 { "xkb_file", input_cmd_xkb_file },
33 { "xkb_layout", input_cmd_xkb_layout }, 34 { "xkb_layout", input_cmd_xkb_layout },
34 { "xkb_model", input_cmd_xkb_model }, 35 { "xkb_model", input_cmd_xkb_model },
diff --git a/sway/commands/input/tool_mode.c b/sway/commands/input/tool_mode.c
new file mode 100644
index 00000000..04316857
--- /dev/null
+++ b/sway/commands/input/tool_mode.c
@@ -0,0 +1,73 @@
1#include <strings.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4
5static void set_tool_mode(struct input_config *ic,
6 enum wlr_tablet_tool_type type, enum sway_tablet_tool_mode mode) {
7 for (int i = 0; i < ic->tools->length; i++) {
8 struct input_config_tool *tool = ic->tools->items[i];
9 if (tool->type == type) {
10 tool->mode = mode;
11 return;
12 }
13 }
14
15 struct input_config_tool *tool = calloc(1, sizeof(*tool));
16 if (tool) {
17 tool->type = type;
18 tool->mode = mode;
19 list_add(ic->tools, tool);
20 }
21}
22
23struct cmd_results *input_cmd_tool_mode(int argc, char **argv) {
24 struct cmd_results *error;
25 if ((error = checkarg(argc, "tool_mode", EXPECTED_AT_LEAST, 2))) {
26 return error;
27 }
28
29 struct input_config *ic = config->handler_context.input_config;
30 if (!ic) {
31 return cmd_results_new(CMD_FAILURE, "No input device defined.");
32 }
33
34 enum sway_tablet_tool_mode tool_mode;
35 if (!strcasecmp(argv[1], "absolute")) {
36 tool_mode = SWAY_TABLET_TOOL_MODE_ABSOLUTE;
37 } else if (!strcasecmp(argv[1], "relative")) {
38 tool_mode = SWAY_TABLET_TOOL_MODE_RELATIVE;
39 } else {
40 goto invalid_command;
41 }
42
43 if (!strcasecmp(argv[0], "*")) {
44 set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_PEN, tool_mode);
45 set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_ERASER, tool_mode);
46 set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_BRUSH, tool_mode);
47 set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_PENCIL, tool_mode);
48 set_tool_mode(ic, WLR_TABLET_TOOL_TYPE_AIRBRUSH, tool_mode);
49 } else {
50 enum wlr_tablet_tool_type tool_type;
51 if (!strcasecmp(argv[0], "pen")) {
52 tool_type = WLR_TABLET_TOOL_TYPE_PEN;
53 } else if (!strcasecmp(argv[0], "eraser")) {
54 tool_type = WLR_TABLET_TOOL_TYPE_ERASER;
55 } else if (!strcasecmp(argv[0], "brush")) {
56 tool_type = WLR_TABLET_TOOL_TYPE_BRUSH;
57 } else if (!strcasecmp(argv[0], "pencil")) {
58 tool_type = WLR_TABLET_TOOL_TYPE_PENCIL;
59 } else if (!strcasecmp(argv[0], "airbrush")) {
60 tool_type = WLR_TABLET_TOOL_TYPE_AIRBRUSH;
61 } else {
62 goto invalid_command;
63 }
64
65 set_tool_mode(ic, tool_type, tool_mode);
66 }
67
68 return cmd_results_new(CMD_SUCCESS, NULL);
69
70invalid_command:
71 return cmd_results_new(CMD_INVALID,
72 "Expected 'tool_mode <tool> <absolute|relative>'");
73}