aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h6
-rw-r--r--sway/commands/input.c1
-rw-r--r--sway/commands/input/calibration_matrix.c40
-rw-r--r--sway/config/input.c5
-rw-r--r--sway/input/input-manager.c13
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.scd3
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;
sway_cmd input_cmd_seat;
sway_cmd input_cmd_accel_profile;
+sway_cmd input_cmd_calibration_matrix;
sway_cmd input_cmd_click_method;
sway_cmd input_cmd_drag;
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 {
bool mm;
};
+struct calibration_matrix {
+ bool configured;
+ float matrix[6];
+};
+
/**
* options for input devices
*/
@@ -109,6 +114,7 @@ struct input_config {
const char *input_type;
int accel_profile;
+ struct calibration_matrix calibration_matrix;
int click_method;
int drag;
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 @@
// 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.