mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 16:36:26 +01:00
Add input "identifier" map_to_output "identifier"
This commit is contained in:
parent
26e5974496
commit
0e3ddf255e
8 changed files with 87 additions and 1 deletions
|
@ -192,6 +192,7 @@ sway_cmd input_cmd_drag_lock;
|
|||
sway_cmd input_cmd_dwt;
|
||||
sway_cmd input_cmd_events;
|
||||
sway_cmd input_cmd_left_handed;
|
||||
sway_cmd input_cmd_map_to_output;
|
||||
sway_cmd input_cmd_middle_emulation;
|
||||
sway_cmd input_cmd_natural_scroll;
|
||||
sway_cmd input_cmd_pointer_accel;
|
||||
|
|
|
@ -52,7 +52,7 @@ struct sway_mode {
|
|||
};
|
||||
|
||||
/**
|
||||
* libinput options for input devices
|
||||
* options for input devices
|
||||
*/
|
||||
struct input_config {
|
||||
char *identifier;
|
||||
|
@ -75,6 +75,8 @@ struct input_config {
|
|||
char *xkb_rules;
|
||||
char *xkb_variant;
|
||||
|
||||
char *mapped_output;
|
||||
|
||||
bool capturable;
|
||||
struct wlr_box region;
|
||||
};
|
||||
|
|
|
@ -187,6 +187,7 @@ static struct cmd_handler input_handlers[] = {
|
|||
{ "dwt", input_cmd_dwt },
|
||||
{ "events", input_cmd_events },
|
||||
{ "left_handed", input_cmd_left_handed },
|
||||
{ "map_to_output", input_cmd_map_to_output },
|
||||
{ "middle_emulation", input_cmd_middle_emulation },
|
||||
{ "natural_scroll", input_cmd_natural_scroll },
|
||||
{ "pointer_accel", input_cmd_pointer_accel },
|
||||
|
|
27
sway/commands/input/map_to_output.c
Normal file
27
sway/commands/input/map_to_output.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#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"
|
||||
|
||||
struct cmd_results *input_cmd_map_to_output(int argc, char **argv) {
|
||||
struct cmd_results *error = NULL;
|
||||
if ((error = checkarg(argc, "map_to_output", EXPECTED_EQUAL_TO, 1))) {
|
||||
return error;
|
||||
}
|
||||
struct input_config *current_input_config =
|
||||
config->handler_context.input_config;
|
||||
if (!current_input_config) {
|
||||
return cmd_results_new(CMD_FAILURE, "map_to_output",
|
||||
"No input device defined.");
|
||||
}
|
||||
struct input_config *new_config =
|
||||
new_input_config(current_input_config->identifier);
|
||||
|
||||
new_config->mapped_output = strdup(argv[0]);
|
||||
apply_input_config(new_config);
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
}
|
|
@ -88,6 +88,10 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
|
|||
free(dst->xkb_variant);
|
||||
dst->xkb_variant = strdup(src->xkb_variant);
|
||||
}
|
||||
if (src->mapped_output) {
|
||||
free(dst->mapped_output);
|
||||
dst->mapped_output = strdup(src->mapped_output);
|
||||
}
|
||||
}
|
||||
|
||||
struct input_config *copy_input_config(struct input_config *ic) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#define _XOPEN_SOURCE 700
|
||||
#define _POSIX_C_SOURCE 199309L
|
||||
#include <assert.h>
|
||||
#include <strings.h>
|
||||
#include <time.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
|
@ -219,10 +220,38 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
|
|||
return seat;
|
||||
}
|
||||
|
||||
static void seat_apply_input_config(struct sway_seat *seat,
|
||||
struct sway_seat_device *sway_device) {
|
||||
struct input_config *ic = input_device_get_config(
|
||||
sway_device->input_device);
|
||||
if (!ic) {
|
||||
return;
|
||||
}
|
||||
wlr_log(L_DEBUG, "Applying input config to %s",
|
||||
sway_device->input_device->identifier);
|
||||
if (ic->mapped_output) {
|
||||
struct sway_container *output = NULL;
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *_output = root_container.children->items[i];
|
||||
if (strcasecmp(_output->name, ic->mapped_output) == 0) {
|
||||
output = _output;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (output) {
|
||||
wlr_cursor_map_input_to_output(seat->cursor->cursor,
|
||||
sway_device->input_device->wlr_device,
|
||||
output->sway_output->wlr_output);
|
||||
wlr_log(L_DEBUG, "Mapped to output %s", output->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void seat_configure_pointer(struct sway_seat *seat,
|
||||
struct sway_seat_device *sway_device) {
|
||||
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
||||
sway_device->input_device->wlr_device);
|
||||
seat_apply_input_config(seat, sway_device);
|
||||
}
|
||||
|
||||
static void seat_configure_keyboard(struct sway_seat *seat,
|
||||
|
@ -249,6 +278,7 @@ static void seat_configure_tablet_tool(struct sway_seat *seat,
|
|||
struct sway_seat_device *sway_device) {
|
||||
wlr_cursor_attach_input_device(seat->cursor->cursor,
|
||||
sway_device->input_device->wlr_device);
|
||||
seat_apply_input_config(seat, sway_device);
|
||||
}
|
||||
|
||||
static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
|
||||
|
|
|
@ -85,6 +85,7 @@ sway_sources = files(
|
|||
'commands/input/dwt.c',
|
||||
'commands/input/events.c',
|
||||
'commands/input/left_handed.c',
|
||||
'commands/input/map_to_output.c',
|
||||
'commands/input/middle_emulation.c',
|
||||
'commands/input/natural_scroll.c',
|
||||
'commands/input/pointer_accel.c',
|
||||
|
|
|
@ -40,6 +40,26 @@ For more information on these xkb configuration options, see
|
|||
**input** <identifier> xkb_variant <variant>::
|
||||
Sets the variant of the keyboard like _dvorak_ or _colemak_.
|
||||
|
||||
Mapping Configuration
|
||||
---------------------
|
||||
|
||||
**input** <identifier> map_to_output <identifier>::
|
||||
Maps inputs from this device to the specified output. Only meaningful if the
|
||||
device is a pointer, touch, or drawing tablet device.
|
||||
|
||||
**input** <identifier> map_to_region <WxH\@X,Y>::
|
||||
Maps inputs from this device to the specified region of the global output
|
||||
layout. Only meaningful if the device is a pointer, touch, or drawing tablet
|
||||
device.
|
||||
|
||||
**input** <identifier> map_region <WxH\@X,Y>::
|
||||
Ignores inputs from this device that do not occur within the specified region.
|
||||
Can be in millimeters (e.g. 10mmx20mm\@10mm,20mm) or in terms of 0..1 (e.g.
|
||||
0.5x0.5\@0,0). Not all devices support millimeters. Only meaningful if the
|
||||
device is not a keyboard an provides events in absolute terms (such as a
|
||||
drawing tablet or touch screen - most pointers provide events relative to the
|
||||
previous frame).
|
||||
|
||||
Libinput Configuration
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
Loading…
Reference in a new issue