aboutsummaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-08 14:15:13 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-08 15:09:12 -0400
commit0e3ddf255ef56b7fe2b868232b80d04ea961120b (patch)
treecd650869ccbeca085a022d7aceb97d5e581ff3bf /sway
parentMerge pull request #1778 from swaywm/fix-cursor (diff)
downloadsway-0e3ddf255ef56b7fe2b868232b80d04ea961120b.tar.gz
sway-0e3ddf255ef56b7fe2b868232b80d04ea961120b.tar.zst
sway-0e3ddf255ef56b7fe2b868232b80d04ea961120b.zip
Add input "identifier" map_to_output "identifier"
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/input/map_to_output.c27
-rw-r--r--sway/config/input.c4
-rw-r--r--sway/input/seat.c30
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.txt20
6 files changed, 83 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 20b8a2aa..55929659 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -187,6 +187,7 @@ static struct cmd_handler input_handlers[] = {
187 { "dwt", input_cmd_dwt }, 187 { "dwt", input_cmd_dwt },
188 { "events", input_cmd_events }, 188 { "events", input_cmd_events },
189 { "left_handed", input_cmd_left_handed }, 189 { "left_handed", input_cmd_left_handed },
190 { "map_to_output", input_cmd_map_to_output },
190 { "middle_emulation", input_cmd_middle_emulation }, 191 { "middle_emulation", input_cmd_middle_emulation },
191 { "natural_scroll", input_cmd_natural_scroll }, 192 { "natural_scroll", input_cmd_natural_scroll },
192 { "pointer_accel", input_cmd_pointer_accel }, 193 { "pointer_accel", input_cmd_pointer_accel },
diff --git a/sway/commands/input/map_to_output.c b/sway/commands/input/map_to_output.c
new file mode 100644
index 00000000..60e4608e
--- /dev/null
+++ b/sway/commands/input/map_to_output.c
@@ -0,0 +1,27 @@
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
9struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {
10 struct cmd_results *error = NULL;
11 if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) {
12 return error;
13 }
14 struct input_config *current_input_config =
15 config->handler_context.input_config;
16 if (!current_input_config) {
17 return cmd_results_new(CMD_FAILURE, "map_to_output",
18 "No input device defined.");
19 }
20 struct input_config *new_config =
21 new_input_config(current_input_config->identifier);
22
23 new_config->mapped_output = strdup(argv[0]);
24 apply_input_config(new_config);
25
26 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
27}
diff --git a/sway/config/input.c b/sway/config/input.c
index c4f6211d..5e657c43 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -88,6 +88,10 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
88 free(dst->xkb_variant); 88 free(dst->xkb_variant);
89 dst->xkb_variant = strdup(src->xkb_variant); 89 dst->xkb_variant = strdup(src->xkb_variant);
90 } 90 }
91 if (src->mapped_output) {
92 free(dst->mapped_output);
93 dst->mapped_output = strdup(src->mapped_output);
94 }
91} 95}
92 96
93struct input_config *copy_input_config(struct input_config *ic) { 97struct input_config *copy_input_config(struct input_config *ic) {
diff --git a/sway/input/seat.c b/sway/input/seat.c
index d9b42828..7b01fe88 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -1,6 +1,7 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#define _POSIX_C_SOURCE 199309L 2#define _POSIX_C_SOURCE 199309L
3#include <assert.h> 3#include <assert.h>
4#include <strings.h>
4#include <time.h> 5#include <time.h>
5#include <wlr/types/wlr_cursor.h> 6#include <wlr/types/wlr_cursor.h>
6#include <wlr/types/wlr_output_layout.h> 7#include <wlr/types/wlr_output_layout.h>
@@ -219,10 +220,38 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
219 return seat; 220 return seat;
220} 221}
221 222
223static void seat_apply_input_config(struct sway_seat *seat,
224 struct sway_seat_device *sway_device) {
225 struct input_config *ic = input_device_get_config(
226 sway_device->input_device);
227 if (!ic) {
228 return;
229 }
230 wlr_log(L_DEBUG, "Applying input config to %s",
231 sway_device->input_device->identifier);
232 if (ic->mapped_output) {
233 struct sway_container *output = NULL;
234 for (int i = 0; i < root_container.children->length; ++i) {
235 struct sway_container *_output = root_container.children->items[i];
236 if (strcasecmp(_output->name, ic->mapped_output) == 0) {
237 output = _output;
238 break;
239 }
240 }
241 if (output) {
242 wlr_cursor_map_input_to_output(seat->cursor->cursor,
243 sway_device->input_device->wlr_device,
244 output->sway_output->wlr_output);
245 wlr_log(L_DEBUG, "Mapped to output %s", output->name);
246 }
247 }
248}
249
222static void seat_configure_pointer(struct sway_seat *seat, 250static void seat_configure_pointer(struct sway_seat *seat,
223 struct sway_seat_device *sway_device) { 251 struct sway_seat_device *sway_device) {
224 wlr_cursor_attach_input_device(seat->cursor->cursor, 252 wlr_cursor_attach_input_device(seat->cursor->cursor,
225 sway_device->input_device->wlr_device); 253 sway_device->input_device->wlr_device);
254 seat_apply_input_config(seat, sway_device);
226} 255}
227 256
228static void seat_configure_keyboard(struct sway_seat *seat, 257static void seat_configure_keyboard(struct sway_seat *seat,
@@ -249,6 +278,7 @@ static void seat_configure_tablet_tool(struct sway_seat *seat,
249 struct sway_seat_device *sway_device) { 278 struct sway_seat_device *sway_device) {
250 wlr_cursor_attach_input_device(seat->cursor->cursor, 279 wlr_cursor_attach_input_device(seat->cursor->cursor,
251 sway_device->input_device->wlr_device); 280 sway_device->input_device->wlr_device);
281 seat_apply_input_config(seat, sway_device);
252} 282}
253 283
254static struct sway_seat_device *seat_get_device(struct sway_seat *seat, 284static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
diff --git a/sway/meson.build b/sway/meson.build
index 2521069f..d0730296 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -85,6 +85,7 @@ sway_sources = files(
85 'commands/input/dwt.c', 85 'commands/input/dwt.c',
86 'commands/input/events.c', 86 'commands/input/events.c',
87 'commands/input/left_handed.c', 87 'commands/input/left_handed.c',
88 'commands/input/map_to_output.c',
88 'commands/input/middle_emulation.c', 89 'commands/input/middle_emulation.c',
89 'commands/input/natural_scroll.c', 90 'commands/input/natural_scroll.c',
90 'commands/input/pointer_accel.c', 91 'commands/input/pointer_accel.c',
diff --git a/sway/sway-input.5.txt b/sway/sway-input.5.txt
index 0603616b..05725360 100644
--- a/sway/sway-input.5.txt
+++ b/sway/sway-input.5.txt
@@ -40,6 +40,26 @@ For more information on these xkb configuration options, see
40**input** <identifier> xkb_variant <variant>:: 40**input** <identifier> xkb_variant <variant>::
41 Sets the variant of the keyboard like _dvorak_ or _colemak_. 41 Sets the variant of the keyboard like _dvorak_ or _colemak_.
42 42
43Mapping Configuration
44---------------------
45
46**input** <identifier> map_to_output <identifier>::
47 Maps inputs from this device to the specified output. Only meaningful if the
48 device is a pointer, touch, or drawing tablet device.
49
50**input** <identifier> map_to_region <WxH\@X,Y>::
51 Maps inputs from this device to the specified region of the global output
52 layout. Only meaningful if the device is a pointer, touch, or drawing tablet
53 device.
54
55**input** <identifier> map_region <WxH\@X,Y>::
56 Ignores inputs from this device that do not occur within the specified region.
57 Can be in millimeters (e.g. 10mmx20mm\@10mm,20mm) or in terms of 0..1 (e.g.
58 0.5x0.5\@0,0). Not all devices support millimeters. Only meaningful if the
59 device is not a keyboard an provides events in absolute terms (such as a
60 drawing tablet or touch screen - most pointers provide events relative to the
61 previous frame).
62
43Libinput Configuration 63Libinput Configuration
44~~~~~~~~~~~~~~~~~~~~~~ 64~~~~~~~~~~~~~~~~~~~~~~
45 65