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 | f5d1c27226a74a234664af9b35ab226a67386e8e (diff) |
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 @@ // must be in order for the bsearch static struct cmd_handler input_handlers[] = { { "accel_profile", input_cmd_accel_profile }, + { "calibration_matrix", input_cmd_calibration_matrix }, { "click_method", input_cmd_click_method }, { "drag", input_cmd_drag }, { "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 @@ +#define _POSIX_C_SOURCE 200809L +#include <string.h> +#include <strings.h> +#include "sway/config.h" +#include "sway/commands.h" +#include "sway/input/input-manager.h" +#include "log.h" +#include "stringop.h" +#include "util.h" + +struct cmd_results *input_cmd_calibration_matrix(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "calibration_matrix", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct input_config *ic = config->handler_context.input_config; + if (!ic) { + return cmd_results_new(CMD_FAILURE, "No input device defined."); + } + + list_t *split = split_string(argv[0], " "); + if (split->length != 6) { + return cmd_results_new(CMD_FAILURE, "calibration_matrix should be a space-separated list of length 6"); + } + + float parsed[6]; + for (int i = 0; i < split->length; ++i) { + char *item = split->items[i]; + float x = parse_float(item); + if (x != x) { + return cmd_results_new(CMD_FAILURE, "calibration_matrix: unable to parse float: %s", item); + } + parsed[i] = x; + } + + ic->calibration_matrix.configured = true; + memcpy(ic->calibration_matrix.matrix, parsed, sizeof(ic->calibration_matrix.matrix)); + + return cmd_results_new(CMD_SUCCESS, NULL); +} 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) { free(dst->mapped_to_output); dst->mapped_to_output = strdup(src->mapped_to_output); } + if (src->calibration_matrix.configured) { + dst->calibration_matrix.configured = src->calibration_matrix.configured; + memcpy(dst->calibration_matrix.matrix, src->calibration_matrix.matrix, + sizeof(src->calibration_matrix.matrix)); + } } 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( log_libinput_config_status(libinput_device_config_send_events_set_mode( libinput_device, ic->send_events)); } + float *m = ic->calibration_matrix.matrix; + if (ic->calibration_matrix.configured) { + sway_log(SWAY_DEBUG, "libinput_config_touch(%s) calibration_set_matrix(%f %f %f %f %f %f)", + ic->identifier, m[0], m[1], m[2], m[3], m[4], m[5]); + log_libinput_config_status(libinput_device_config_calibration_set_matrix( + libinput_device, ic->calibration_matrix.matrix)); + } } static void input_manager_libinput_reset_touch( @@ -300,6 +307,12 @@ static void input_manager_libinput_reset_touch( input_device->identifier, send_events); log_libinput_config_status(libinput_device_config_send_events_set_mode( libinput_device, send_events)); + float m[6]; + libinput_device_config_calibration_get_default_matrix(libinput_device, m); + sway_log(SWAY_DEBUG, "libinput_reset_touch(%s) calibration_set_matrix(%f %f %f %f %f %f)", + input_device->identifier, m[0], m[1], m[2], m[3], m[4], m[5]); + log_libinput_config_status(libinput_device_config_calibration_set_matrix( + libinput_device, m)); } 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( 'commands/bar/wrap_scroll.c', 'commands/input/accel_profile.c', + 'commands/input/calibration_matrix.c', 'commands/input/click_method.c', 'commands/input/drag.c', '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. *input* <identifier> accel_profile adaptive|flat Sets the pointer acceleration profile for the specified input device. +*input* <identifier> calibration_matrix <6 space-separated floating point values> + Sets the calibtration matrix. + *input* <identifier> click_method none|button_areas|clickfinger Changes the click method for the specified device. |