diff options
author | Sergei Dolgov <dolgovs@gmail.com> | 2019-06-17 11:38:41 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-07-05 18:41:56 +0300 |
commit | 01ec18e80228739bbc099ccb35356d198729ab42 (patch) | |
tree | a5a0a701e3ce2168f1278f91984a5ac1c9c555be /sway | |
parent | swaybar-protocol.7: fix block border descriptions (diff) | |
download | sway-01ec18e80228739bbc099ccb35356d198729ab42.tar.gz sway-01ec18e80228739bbc099ccb35356d198729ab42.tar.zst sway-01ec18e80228739bbc099ccb35356d198729ab42.zip |
Add calibration_matrix config option
Can be used to change the orientation of a touchscreen.
Example usage with swaymsg:
# identity
swaymsg input type:touch calibration_matrix '"1 0 0 0 1 0"'
# 90 degree clockwise
swaymsg input type:touch calibration_matrix '"0 -1 1 1 0 0"'
# 180 degree clockwise
swaymsg input type:touch calibration_matrix '"-1 0 1 0 -1 1"'
# 270 degree clockwise
swaymsg input type:touch calibration_matrix '"0 1 0 -1 0 1"'
Documentation:
https://wayland.freedesktop.org/libinput/doc/latest/absolute-axes.html#calibration-of-absolute-devices
Diffstat (limited to 'sway')
-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 |
6 files changed, 63 insertions, 0 deletions
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 | ||