aboutsummaryrefslogtreecommitdiffstats
path: root/sway
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
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')
-rw-r--r--sway/commands/input.c1
-rw-r--r--sway/commands/input/tool_mode.c73
-rw-r--r--sway/config/input.c18
-rw-r--r--sway/input/cursor.c12
-rw-r--r--sway/input/tablet.c23
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.scd11
7 files changed, 133 insertions, 6 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}
diff --git a/sway/config/input.c b/sway/config/input.c
index 2ed9c016..a998e170 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -40,6 +40,7 @@ struct input_config *new_input_config(const char* identifier) {
40 input->xkb_numlock = INT_MIN; 40 input->xkb_numlock = INT_MIN;
41 input->xkb_capslock = INT_MIN; 41 input->xkb_capslock = INT_MIN;
42 input->xkb_file_is_set = false; 42 input->xkb_file_is_set = false;
43 input->tools = create_list();
43 44
44 return input; 45 return input;
45} 46}
@@ -153,6 +154,22 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
153 memcpy(dst->calibration_matrix.matrix, src->calibration_matrix.matrix, 154 memcpy(dst->calibration_matrix.matrix, src->calibration_matrix.matrix,
154 sizeof(src->calibration_matrix.matrix)); 155 sizeof(src->calibration_matrix.matrix));
155 } 156 }
157 for (int i = 0; i < src->tools->length; i++) {
158 struct input_config_tool *src_tool = src->tools->items[i];
159 for (int j = 0; j < dst->tools->length; j++) {
160 struct input_config_tool *dst_tool = dst->tools->items[j];
161 if (src_tool->type == dst_tool->type) {
162 dst_tool->mode = src_tool->mode;
163 goto tool_merge_outer;
164 }
165 }
166
167 struct input_config_tool *dst_tool = malloc(sizeof(*dst_tool));
168 memcpy(dst_tool, src_tool, sizeof(*dst_tool));
169 list_add(dst->tools, dst_tool);
170
171 tool_merge_outer:;
172 }
156} 173}
157 174
158static bool validate_xkb_merge(struct input_config *dest, 175static bool validate_xkb_merge(struct input_config *dest,
@@ -358,6 +375,7 @@ void free_input_config(struct input_config *ic) {
358 free(ic->mapped_from_region); 375 free(ic->mapped_from_region);
359 free(ic->mapped_to_output); 376 free(ic->mapped_to_output);
360 free(ic->mapped_to_region); 377 free(ic->mapped_to_region);
378 list_free_items_and_destroy(ic->tools);
361 free(ic); 379 free(ic);
362} 380}
363 381
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 61d75b8a..e47410a5 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -567,14 +567,14 @@ static void handle_tablet_tool_position(struct sway_cursor *cursor,
567 ic->mapped_from_region, &x, &y); 567 ic->mapped_from_region, &x, &y);
568 } 568 }
569 569
570 switch (tool->tablet_v2_tool->wlr_tool->type) { 570 switch (tool->mode) {
571 case WLR_TABLET_TOOL_TYPE_LENS: 571 case SWAY_TABLET_TOOL_MODE_ABSOLUTE:
572 case WLR_TABLET_TOOL_TYPE_MOUSE:
573 wlr_cursor_move(cursor->cursor, input_device->wlr_device, dx, dy);
574 break;
575 default:
576 wlr_cursor_warp_absolute(cursor->cursor, input_device->wlr_device, 572 wlr_cursor_warp_absolute(cursor->cursor, input_device->wlr_device,
577 change_x ? x : NAN, change_y ? y : NAN); 573 change_x ? x : NAN, change_y ? y : NAN);
574 break;
575 case SWAY_TABLET_TOOL_MODE_RELATIVE:
576 wlr_cursor_move(cursor->cursor, input_device->wlr_device, dx, dy);
577 break;
578 } 578 }
579 579
580 double sx, sy; 580 double sx, sy;
diff --git a/sway/input/tablet.c b/sway/input/tablet.c
index b74347aa..5f81f772 100644
--- a/sway/input/tablet.c
+++ b/sway/input/tablet.c
@@ -140,6 +140,29 @@ void sway_tablet_tool_configure(struct sway_tablet *tablet,
140 return; 140 return;
141 } 141 }
142 142
143 switch (wlr_tool->type) {
144 case WLR_TABLET_TOOL_TYPE_LENS:
145 case WLR_TABLET_TOOL_TYPE_MOUSE:
146 tool->mode = SWAY_TABLET_TOOL_MODE_RELATIVE;
147 break;
148 default:
149 tool->mode = SWAY_TABLET_TOOL_MODE_ABSOLUTE;
150
151 struct input_config *ic = input_device_get_config(
152 tablet->seat_device->input_device);
153 if (!ic) {
154 break;
155 }
156
157 for (int i = 0; i < ic->tools->length; i++) {
158 struct input_config_tool *tool_config = ic->tools->items[i];
159 if (tool_config->type == wlr_tool->type) {
160 tool->mode = tool_config->mode;
161 break;
162 }
163 }
164 }
165
143 tool->seat = tablet->seat_device->sway_seat; 166 tool->seat = tablet->seat_device->sway_seat;
144 tool->tablet = tablet; 167 tool->tablet = tablet;
145 tool->tablet_v2_tool = 168 tool->tablet_v2_tool =
diff --git a/sway/meson.build b/sway/meson.build
index b65a5211..6e138101 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -168,6 +168,7 @@ sway_sources = files(
168 'commands/input/scroll_method.c', 168 'commands/input/scroll_method.c',
169 'commands/input/tap.c', 169 'commands/input/tap.c',
170 'commands/input/tap_button_map.c', 170 'commands/input/tap_button_map.c',
171 'commands/input/tool_mode.c',
171 'commands/input/xkb_capslock.c', 172 'commands/input/xkb_capslock.c',
172 'commands/input/xkb_file.c', 173 'commands/input/xkb_file.c',
173 'commands/input/xkb_layout.c', 174 'commands/input/xkb_layout.c',
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd
index 9ec5eeae..d8180c1c 100644
--- a/sway/sway-input.5.scd
+++ b/sway/sway-input.5.scd
@@ -94,6 +94,17 @@ The following commands may only be used in the configuration file.
94*input* <identifier> xkb_numlock enabled|disabled 94*input* <identifier> xkb_numlock enabled|disabled
95 Initially enables or disables NumLock on startup, the default is disabled. 95 Initially enables or disables NumLock on startup, the default is disabled.
96 96
97## TABLET CONFIGURATION
98
99*input* <identifier> tool_mode <tool> <absolute|relative>
100 Sets whether movement of a tablet tool should be treated as absolute or
101 relative; the default is absolute.
102
103 Valid values for _\<tool\>_ are currently "pen", "eraser", "brush",
104 "pencil", "airbrush", and the wildcard _\*_, which matches all tools.
105
106 Mouse and lens tools ignore this setting and are always treated as relative.
107
97## MAPPING CONFIGURATION 108## MAPPING CONFIGURATION
98 109
99*input* <identifier> map_to_output <identifier> 110*input* <identifier> map_to_output <identifier>