diff options
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 6 | ||||
-rw-r--r-- | sway/commands/input.c | 1 | ||||
-rw-r--r-- | sway/commands/input/calibration_matrix.c | 40 | ||||
-rw-r--r-- | sway/config/input.c | 5 | ||||
-rw-r--r-- | sway/input/input-manager.c | 13 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-input.5.scd | 3 |
8 files changed, 70 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 641f2504..ddee2994 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -237,6 +237,7 @@ sway_cmd bar_colors_cmd_urgent_workspace; | |||
237 | 237 | ||
238 | sway_cmd input_cmd_seat; | 238 | sway_cmd input_cmd_seat; |
239 | sway_cmd input_cmd_accel_profile; | 239 | sway_cmd input_cmd_accel_profile; |
240 | sway_cmd input_cmd_calibration_matrix; | ||
240 | sway_cmd input_cmd_click_method; | 241 | sway_cmd input_cmd_click_method; |
241 | sway_cmd input_cmd_drag; | 242 | sway_cmd input_cmd_drag; |
242 | sway_cmd input_cmd_drag_lock; | 243 | sway_cmd input_cmd_drag_lock; |
diff --git a/include/sway/config.h b/include/sway/config.h index 9736a665..4adce8ab 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -101,6 +101,11 @@ struct input_config_mapped_from_region { | |||
101 | bool mm; | 101 | bool mm; |
102 | }; | 102 | }; |
103 | 103 | ||
104 | struct calibration_matrix { | ||
105 | bool configured; | ||
106 | float matrix[6]; | ||
107 | }; | ||
108 | |||
104 | /** | 109 | /** |
105 | * options for input devices | 110 | * options for input devices |
106 | */ | 111 | */ |
@@ -109,6 +114,7 @@ struct input_config { | |||
109 | const char *input_type; | 114 | const char *input_type; |
110 | 115 | ||
111 | int accel_profile; | 116 | int accel_profile; |
117 | struct calibration_matrix calibration_matrix; | ||
112 | int click_method; | 118 | int click_method; |
113 | int drag; | 119 | int drag; |
114 | int drag_lock; | 120 | int drag_lock; |
diff --git a/sway/commands/input.c b/sway/commands/input.c index 08af3cb2..588ef2d5 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -9,6 +9,7 @@ | |||
9 | // must be in order for the bsearch | 9 | // must be in order for the bsearch |
10 | static struct cmd_handler input_handlers[] = { | 10 | static struct cmd_handler input_handlers[] = { |
11 | { "accel_profile", input_cmd_accel_profile }, | 11 | { "accel_profile", input_cmd_accel_profile }, |
12 | { "calibration_matrix", input_cmd_calibration_matrix }, | ||
12 | { "click_method", input_cmd_click_method }, | 13 | { "click_method", input_cmd_click_method }, |
13 | { "drag", input_cmd_drag }, | 14 | { "drag", input_cmd_drag }, |
14 | { "drag_lock", input_cmd_drag_lock }, | 15 | { "drag_lock", input_cmd_drag_lock }, |
diff --git a/sway/commands/input/calibration_matrix.c b/sway/commands/input/calibration_matrix.c new file mode 100644 index 00000000..ac15d152 --- /dev/null +++ b/sway/commands/input/calibration_matrix.c | |||
@@ -0,0 +1,40 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
3 | #include <strings.h> | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/input/input-manager.h" | ||
7 | #include "log.h" | ||
8 | #include "stringop.h" | ||
9 | #include "util.h" | ||
10 | |||
11 | struct cmd_results *input_cmd_calibration_matrix(int argc, char **argv) { | ||
12 | struct cmd_results *error = NULL; | ||
13 | if ((error = checkarg(argc, "calibration_matrix", EXPECTED_EQUAL_TO, 1))) { | ||
14 | return error; | ||
15 | } | ||
16 | struct input_config *ic = config->handler_context.input_config; | ||
17 | if (!ic) { | ||
18 | return cmd_results_new(CMD_FAILURE, "No input device defined."); | ||
19 | } | ||
20 | |||
21 | list_t *split = split_string(argv[0], " "); | ||
22 | if (split->length != 6) { | ||
23 | return cmd_results_new(CMD_FAILURE, "calibration_matrix should be a space-separated list of length 6"); | ||
24 | } | ||
25 | |||
26 | float parsed[6]; | ||
27 | for (int i = 0; i < split->length; ++i) { | ||
28 | char *item = split->items[i]; | ||
29 | float x = parse_float(item); | ||
30 | if (x != x) { | ||
31 | return cmd_results_new(CMD_FAILURE, "calibration_matrix: unable to parse float: %s", item); | ||
32 | } | ||
33 | parsed[i] = x; | ||
34 | } | ||
35 | |||
36 | ic->calibration_matrix.configured = true; | ||
37 | memcpy(ic->calibration_matrix.matrix, parsed, sizeof(ic->calibration_matrix.matrix)); | ||
38 | |||
39 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
40 | } | ||
diff --git a/sway/config/input.c b/sway/config/input.c index c4f64eb8..b5be4f26 100644 --- a/sway/config/input.c +++ b/sway/config/input.c | |||
@@ -132,6 +132,11 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { | |||
132 | free(dst->mapped_to_output); | 132 | free(dst->mapped_to_output); |
133 | dst->mapped_to_output = strdup(src->mapped_to_output); | 133 | dst->mapped_to_output = strdup(src->mapped_to_output); |
134 | } | 134 | } |
135 | if (src->calibration_matrix.configured) { | ||
136 | dst->calibration_matrix.configured = src->calibration_matrix.configured; | ||
137 | memcpy(dst->calibration_matrix.matrix, src->calibration_matrix.matrix, | ||
138 | sizeof(src->calibration_matrix.matrix)); | ||
139 | } | ||
135 | } | 140 | } |
136 | 141 | ||
137 | static bool validate_xkb_merge(struct input_config *dest, | 142 | static bool validate_xkb_merge(struct input_config *dest, |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index a2a1e274..195acc6f 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -281,6 +281,13 @@ static void input_manager_libinput_config_touch( | |||
281 | log_libinput_config_status(libinput_device_config_send_events_set_mode( | 281 | log_libinput_config_status(libinput_device_config_send_events_set_mode( |
282 | libinput_device, ic->send_events)); | 282 | libinput_device, ic->send_events)); |
283 | } | 283 | } |
284 | float *m = ic->calibration_matrix.matrix; | ||
285 | if (ic->calibration_matrix.configured) { | ||
286 | sway_log(SWAY_DEBUG, "libinput_config_touch(%s) calibration_set_matrix(%f %f %f %f %f %f)", | ||
287 | ic->identifier, m[0], m[1], m[2], m[3], m[4], m[5]); | ||
288 | log_libinput_config_status(libinput_device_config_calibration_set_matrix( | ||
289 | libinput_device, ic->calibration_matrix.matrix)); | ||
290 | } | ||
284 | } | 291 | } |
285 | 292 | ||
286 | static void input_manager_libinput_reset_touch( | 293 | static void input_manager_libinput_reset_touch( |
@@ -300,6 +307,12 @@ static void input_manager_libinput_reset_touch( | |||
300 | input_device->identifier, send_events); | 307 | input_device->identifier, send_events); |
301 | log_libinput_config_status(libinput_device_config_send_events_set_mode( | 308 | log_libinput_config_status(libinput_device_config_send_events_set_mode( |
302 | libinput_device, send_events)); | 309 | libinput_device, send_events)); |
310 | float m[6]; | ||
311 | libinput_device_config_calibration_get_default_matrix(libinput_device, m); | ||
312 | sway_log(SWAY_DEBUG, "libinput_reset_touch(%s) calibration_set_matrix(%f %f %f %f %f %f)", | ||
313 | input_device->identifier, m[0], m[1], m[2], m[3], m[4], m[5]); | ||
314 | log_libinput_config_status(libinput_device_config_calibration_set_matrix( | ||
315 | libinput_device, m)); | ||
303 | } | 316 | } |
304 | 317 | ||
305 | static void input_manager_libinput_config_pointer( | 318 | static void input_manager_libinput_config_pointer( |
diff --git a/sway/meson.build b/sway/meson.build index 99dab7e7..c60be008 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -140,6 +140,7 @@ sway_sources = files( | |||
140 | 'commands/bar/wrap_scroll.c', | 140 | 'commands/bar/wrap_scroll.c', |
141 | 141 | ||
142 | 'commands/input/accel_profile.c', | 142 | 'commands/input/accel_profile.c', |
143 | 'commands/input/calibration_matrix.c', | ||
143 | 'commands/input/click_method.c', | 144 | 'commands/input/click_method.c', |
144 | 'commands/input/drag.c', | 145 | 'commands/input/drag.c', |
145 | 'commands/input/drag_lock.c', | 146 | 'commands/input/drag_lock.c', |
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index be173c45..4fb14fd2 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd | |||
@@ -97,6 +97,9 @@ The following commands may only be used in the configuration file. | |||
97 | *input* <identifier> accel_profile adaptive|flat | 97 | *input* <identifier> accel_profile adaptive|flat |
98 | Sets the pointer acceleration profile for the specified input device. | 98 | Sets the pointer acceleration profile for the specified input device. |
99 | 99 | ||
100 | *input* <identifier> calibration_matrix <6 space-separated floating point values> | ||
101 | Sets the calibtration matrix. | ||
102 | |||
100 | *input* <identifier> click_method none|button_areas|clickfinger | 103 | *input* <identifier> click_method none|button_areas|clickfinger |
101 | Changes the click method for the specified device. | 104 | Changes the click method for the specified device. |
102 | 105 | ||