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
This commit is contained in:
Sergei Dolgov 2019-06-17 11:38:41 +02:00 committed by Simon Ser
parent f5d1c27226
commit 01ec18e802
8 changed files with 70 additions and 0 deletions

View file

@ -237,6 +237,7 @@ sway_cmd bar_colors_cmd_urgent_workspace;
sway_cmd input_cmd_seat; sway_cmd input_cmd_seat;
sway_cmd input_cmd_accel_profile; sway_cmd input_cmd_accel_profile;
sway_cmd input_cmd_calibration_matrix;
sway_cmd input_cmd_click_method; sway_cmd input_cmd_click_method;
sway_cmd input_cmd_drag; sway_cmd input_cmd_drag;
sway_cmd input_cmd_drag_lock; sway_cmd input_cmd_drag_lock;

View file

@ -101,6 +101,11 @@ struct input_config_mapped_from_region {
bool mm; bool mm;
}; };
struct calibration_matrix {
bool configured;
float matrix[6];
};
/** /**
* options for input devices * options for input devices
*/ */
@ -109,6 +114,7 @@ struct input_config {
const char *input_type; const char *input_type;
int accel_profile; int accel_profile;
struct calibration_matrix calibration_matrix;
int click_method; int click_method;
int drag; int drag;
int drag_lock; int drag_lock;

View file

@ -9,6 +9,7 @@
// must be in order for the bsearch // must be in order for the bsearch
static struct cmd_handler input_handlers[] = { static struct cmd_handler input_handlers[] = {
{ "accel_profile", input_cmd_accel_profile }, { "accel_profile", input_cmd_accel_profile },
{ "calibration_matrix", input_cmd_calibration_matrix },
{ "click_method", input_cmd_click_method }, { "click_method", input_cmd_click_method },
{ "drag", input_cmd_drag }, { "drag", input_cmd_drag },
{ "drag_lock", input_cmd_drag_lock }, { "drag_lock", input_cmd_drag_lock },

View file

@ -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);
}

View file

@ -132,6 +132,11 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
free(dst->mapped_to_output); free(dst->mapped_to_output);
dst->mapped_to_output = strdup(src->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, static bool validate_xkb_merge(struct input_config *dest,

View file

@ -281,6 +281,13 @@ static void input_manager_libinput_config_touch(
log_libinput_config_status(libinput_device_config_send_events_set_mode( log_libinput_config_status(libinput_device_config_send_events_set_mode(
libinput_device, ic->send_events)); 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( static void input_manager_libinput_reset_touch(
@ -300,6 +307,12 @@ static void input_manager_libinput_reset_touch(
input_device->identifier, send_events); input_device->identifier, send_events);
log_libinput_config_status(libinput_device_config_send_events_set_mode( log_libinput_config_status(libinput_device_config_send_events_set_mode(
libinput_device, send_events)); 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( static void input_manager_libinput_config_pointer(

View file

@ -140,6 +140,7 @@ sway_sources = files(
'commands/bar/wrap_scroll.c', 'commands/bar/wrap_scroll.c',
'commands/input/accel_profile.c', 'commands/input/accel_profile.c',
'commands/input/calibration_matrix.c',
'commands/input/click_method.c', 'commands/input/click_method.c',
'commands/input/drag.c', 'commands/input/drag.c',
'commands/input/drag_lock.c', 'commands/input/drag_lock.c',

View file

@ -97,6 +97,9 @@ The following commands may only be used in the configuration file.
*input* <identifier> accel_profile adaptive|flat *input* <identifier> accel_profile adaptive|flat
Sets the pointer acceleration profile for the specified input device. 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 *input* <identifier> click_method none|button_areas|clickfinger
Changes the click method for the specified device. Changes the click method for the specified device.