aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/config.h4
-rw-r--r--include/sway/input/cursor.h2
-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/cursor.c28
-rw-r--r--sway/input/seat.c33
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway-input.5.txt20
-rw-r--r--swaybar/render.c39
11 files changed, 120 insertions, 40 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index edb5a213..bc5d5412 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -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;
diff --git a/include/sway/config.h b/include/sway/config.h
index 91f772b5..ed49fbbd 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -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;
};
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h
index 8f907dcd..daf7d4ee 100644
--- a/include/sway/input/cursor.h
+++ b/include/sway/input/cursor.h
@@ -8,7 +8,6 @@ struct sway_cursor {
struct wlr_cursor *cursor;
struct wlr_xcursor_manager *xcursor_manager;
- double x, y;
struct wl_client *image_client;
struct wl_listener motion;
@@ -30,5 +29,6 @@ struct sway_cursor {
void sway_cursor_destroy(struct sway_cursor *cursor);
struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
+void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time);
#endif
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[] = {
{ "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 },
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 @@
+#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);
+}
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) {
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) {
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 4bcf72fc..0df01504 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -14,14 +14,6 @@
#include "sway/tree/view.h"
#include "wlr-layer-shell-unstable-v1-protocol.h"
-static void cursor_update_position(struct sway_cursor *cursor) {
- double x = cursor->cursor->x;
- double y = cursor->cursor->y;
-
- cursor->x = x;
- cursor->y = y;
-}
-
static struct wlr_surface *layer_surface_at(struct sway_output *output,
struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
struct sway_layer_surface *sway_layer;
@@ -53,8 +45,8 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
struct wlr_xwayland_surface *xsurface =
unmanaged_surface->wlr_xwayland_surface;
- double _sx = cursor->x - unmanaged_surface->lx;
- double _sy = cursor->y - unmanaged_surface->ly;
+ double _sx = cursor->cursor->x - unmanaged_surface->lx;
+ double _sy = cursor->cursor->y - unmanaged_surface->ly;
if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) {
*surface = xsurface->surface;
*sx = _sx;
@@ -67,12 +59,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
struct wlr_output_layout *output_layout =
root_container.sway_root->output_layout;
struct wlr_output *wlr_output =
- wlr_output_layout_output_at(output_layout, cursor->x, cursor->y);
+ wlr_output_layout_output_at(output_layout,
+ cursor->cursor->x, cursor->cursor->y);
if (wlr_output == NULL) {
return NULL;
}
struct sway_output *output = wlr_output->data;
- double ox = cursor->x, oy = cursor->y;
+ double ox = cursor->cursor->x, oy = cursor->cursor->y;
wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy);
// find the focused workspace on the output for this seat
@@ -97,7 +90,8 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
}
struct sway_container *c;
- if ((c = container_at(ws, cursor->x, cursor->y, surface, sx, sy))) {
+ if ((c = container_at(ws, cursor->cursor->x, cursor->cursor->y,
+ surface, sx, sy))) {
return c;
}
@@ -124,8 +118,7 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
return output->swayc;
}
-static void cursor_send_pointer_motion(struct sway_cursor *cursor,
- uint32_t time) {
+void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) {
struct wlr_seat *seat = cursor->seat->wlr_seat;
struct wlr_surface *surface = NULL;
double sx, sy;
@@ -161,7 +154,6 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
struct wlr_event_pointer_motion *event = data;
wlr_cursor_move(cursor->cursor, event->device,
event->delta_x, event->delta_y);
- cursor_update_position(cursor);
cursor_send_pointer_motion(cursor, event->time_msec);
}
@@ -171,7 +163,6 @@ static void handle_cursor_motion_absolute(
wl_container_of(listener, cursor, motion_absolute);
struct wlr_event_pointer_motion_absolute *event = data;
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
- cursor_update_position(cursor);
cursor_send_pointer_motion(cursor, event->time_msec);
}
@@ -254,15 +245,12 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
(event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device,
event->x, event->y);
- cursor_update_position(cursor);
cursor_send_pointer_motion(cursor, event->time_msec);
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
- cursor_update_position(cursor);
cursor_send_pointer_motion(cursor, event->time_msec);
} else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
- cursor_update_position(cursor);
cursor_send_pointer_motion(cursor, event->time_msec);
}
}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index fccb739b..467e5087 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -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>
@@ -258,10 +259,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,
@@ -288,6 +317,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,
@@ -486,6 +516,9 @@ void seat_set_focus_warp(struct sway_seat *seat,
wlr_output, seat->cursor->cursor->x,
seat->cursor->cursor->y)) {
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000);
}
}
}
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(
'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',
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
**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
~~~~~~~~~~~~~~~~~~~~~~
diff --git a/swaybar/render.c b/swaybar/render.c
index d2175f0a..28296f31 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -37,8 +37,9 @@ static uint32_t render_status_line_error(cairo_t *cairo,
&text_width, &text_height, output->scale, false, "%s", error);
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
- if (height < ideal_height) {
- return ideal_height / output->scale;
+ uint32_t ideal_surface_height = ideal_height / output->scale;
+ if (surface_height < ideal_surface_height) {
+ return ideal_surface_height;
}
*x -= text_width + margin;
@@ -46,7 +47,7 @@ static uint32_t render_status_line_error(cairo_t *cairo,
cairo_move_to(cairo, *x, (int)floor(text_y));
pango_printf(cairo, config->font, output->scale, false, "%s", error);
*x -= margin;
- return ideal_height / output->scale;
+ return surface_height;
}
static uint32_t render_status_line_text(cairo_t *cairo,
@@ -69,8 +70,9 @@ static uint32_t render_status_line_text(cairo_t *cairo,
int margin = 3 * output->scale;
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
- if (height < ideal_height) {
- return ideal_height / output->scale;
+ uint32_t ideal_surface_height = ideal_height / output->scale;
+ if (surface_height < ideal_surface_height) {
+ return ideal_surface_height;
}
*x -= text_width + margin;
@@ -79,7 +81,7 @@ static uint32_t render_status_line_text(cairo_t *cairo,
pango_printf(cairo, config->font, output->scale,
config->pango_markup, "%s", text);
*x -= margin;
- return ideal_height / output->scale;
+ return surface_height;
}
static void render_sharp_line(cairo_t *cairo, uint32_t color,
@@ -137,8 +139,9 @@ static uint32_t render_status_block(cairo_t *cairo,
double block_width = width;
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
- if (height < ideal_height) {
- return ideal_height / output->scale;
+ uint32_t ideal_surface_height = ideal_height / output->scale;
+ if (surface_height < ideal_surface_height) {
+ return ideal_surface_height;
}
*x -= width;
@@ -249,7 +252,7 @@ static uint32_t render_status_block(cairo_t *cairo,
cairo_stroke(cairo);
}
}
- return ideal_height / output->scale;
+ return surface_height;
}
static uint32_t render_status_line_i3bar(cairo_t *cairo,
@@ -291,7 +294,6 @@ static uint32_t render_status_line(cairo_t *cairo,
static uint32_t render_binding_mode_indicator(cairo_t *cairo,
struct swaybar_output *output, struct swaybar_config *config,
const char *mode, double x, uint32_t surface_height) {
-
uint32_t height = surface_height * output->scale;
int text_width, text_height;
@@ -304,8 +306,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
uint32_t ideal_height = text_height + ws_vertical_padding * 2
+ border_width * 2;
- if (height < ideal_height) {
- return ideal_height / output->scale;
+ uint32_t ideal_surface_height = ideal_height / output->scale;
+ if (surface_height < ideal_surface_height) {
+ return ideal_surface_height;
}
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
@@ -327,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
cairo_set_source_u32(cairo, config->colors.binding_mode.text);
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
pango_printf(cairo, config->font, output->scale, true, "%s", mode);
- return ideal_height / output->scale;
+ return surface_height;
}
static const char *strip_workspace_number(const char *ws_name) {
@@ -379,8 +382,9 @@ static uint32_t render_workspace_button(cairo_t *cairo,
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
+ border_width * 2;
- if (height < ideal_height) {
- return ideal_height / output->scale;
+ uint32_t ideal_surface_height = ideal_height / output->scale;
+ if (surface_height < ideal_surface_height) {
+ return ideal_surface_height;
}
uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
@@ -415,7 +419,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
wl_list_insert(&output->hotspots, &hotspot->link);
*x += width;
- return height / output->scale;
+ return surface_height;
}
static uint32_t render_to_cairo(cairo_t *cairo,
@@ -484,8 +488,7 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
}
if (height != output->height) {
// Reconfigure surface
- zwlr_layer_surface_v1_set_size(
- output->layer_surface, 0, height);
+ zwlr_layer_surface_v1_set_size(output->layer_surface, 0, height);
zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height);
// TODO: this could infinite loop if the compositor assigns us a
// different height than what we asked for