aboutsummaryrefslogtreecommitdiffstats
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;
192sway_cmd input_cmd_dwt; 192sway_cmd input_cmd_dwt;
193sway_cmd input_cmd_events; 193sway_cmd input_cmd_events;
194sway_cmd input_cmd_left_handed; 194sway_cmd input_cmd_left_handed;
195sway_cmd input_cmd_map_to_output;
195sway_cmd input_cmd_middle_emulation; 196sway_cmd input_cmd_middle_emulation;
196sway_cmd input_cmd_natural_scroll; 197sway_cmd input_cmd_natural_scroll;
197sway_cmd input_cmd_pointer_accel; 198sway_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 {
52}; 52};
53 53
54/** 54/**
55 * libinput options for input devices 55 * options for input devices
56 */ 56 */
57struct input_config { 57struct input_config {
58 char *identifier; 58 char *identifier;
@@ -75,6 +75,8 @@ struct input_config {
75 char *xkb_rules; 75 char *xkb_rules;
76 char *xkb_variant; 76 char *xkb_variant;
77 77
78 char *mapped_output;
79
78 bool capturable; 80 bool capturable;
79 struct wlr_box region; 81 struct wlr_box region;
80}; 82};
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 {
8 struct wlr_cursor *cursor; 8 struct wlr_cursor *cursor;
9 struct wlr_xcursor_manager *xcursor_manager; 9 struct wlr_xcursor_manager *xcursor_manager;
10 10
11 double x, y;
12 struct wl_client *image_client; 11 struct wl_client *image_client;
13 12
14 struct wl_listener motion; 13 struct wl_listener motion;
@@ -30,5 +29,6 @@ struct sway_cursor {
30 29
31void sway_cursor_destroy(struct sway_cursor *cursor); 30void sway_cursor_destroy(struct sway_cursor *cursor);
32struct sway_cursor *sway_cursor_create(struct sway_seat *seat); 31struct sway_cursor *sway_cursor_create(struct sway_seat *seat);
32void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time);
33 33
34#endif 34#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[] = {
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/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 @@
14#include "sway/tree/view.h" 14#include "sway/tree/view.h"
15#include "wlr-layer-shell-unstable-v1-protocol.h" 15#include "wlr-layer-shell-unstable-v1-protocol.h"
16 16
17static void cursor_update_position(struct sway_cursor *cursor) {
18 double x = cursor->cursor->x;
19 double y = cursor->cursor->y;
20
21 cursor->x = x;
22 cursor->y = y;
23}
24
25static struct wlr_surface *layer_surface_at(struct sway_output *output, 17static struct wlr_surface *layer_surface_at(struct sway_output *output,
26 struct wl_list *layer, double ox, double oy, double *sx, double *sy) { 18 struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
27 struct sway_layer_surface *sway_layer; 19 struct sway_layer_surface *sway_layer;
@@ -53,8 +45,8 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
53 struct wlr_xwayland_surface *xsurface = 45 struct wlr_xwayland_surface *xsurface =
54 unmanaged_surface->wlr_xwayland_surface; 46 unmanaged_surface->wlr_xwayland_surface;
55 47
56 double _sx = cursor->x - unmanaged_surface->lx; 48 double _sx = cursor->cursor->x - unmanaged_surface->lx;
57 double _sy = cursor->y - unmanaged_surface->ly; 49 double _sy = cursor->cursor->y - unmanaged_surface->ly;
58 if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) { 50 if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) {
59 *surface = xsurface->surface; 51 *surface = xsurface->surface;
60 *sx = _sx; 52 *sx = _sx;
@@ -67,12 +59,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
67 struct wlr_output_layout *output_layout = 59 struct wlr_output_layout *output_layout =
68 root_container.sway_root->output_layout; 60 root_container.sway_root->output_layout;
69 struct wlr_output *wlr_output = 61 struct wlr_output *wlr_output =
70 wlr_output_layout_output_at(output_layout, cursor->x, cursor->y); 62 wlr_output_layout_output_at(output_layout,
63 cursor->cursor->x, cursor->cursor->y);
71 if (wlr_output == NULL) { 64 if (wlr_output == NULL) {
72 return NULL; 65 return NULL;
73 } 66 }
74 struct sway_output *output = wlr_output->data; 67 struct sway_output *output = wlr_output->data;
75 double ox = cursor->x, oy = cursor->y; 68 double ox = cursor->cursor->x, oy = cursor->cursor->y;
76 wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy); 69 wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy);
77 70
78 // find the focused workspace on the output for this seat 71 // 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,
97 } 90 }
98 91
99 struct sway_container *c; 92 struct sway_container *c;
100 if ((c = container_at(ws, cursor->x, cursor->y, surface, sx, sy))) { 93 if ((c = container_at(ws, cursor->cursor->x, cursor->cursor->y,
94 surface, sx, sy))) {
101 return c; 95 return c;
102 } 96 }
103 97
@@ -124,8 +118,7 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor,
124 return output->swayc; 118 return output->swayc;
125} 119}
126 120
127static void cursor_send_pointer_motion(struct sway_cursor *cursor, 121void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time) {
128 uint32_t time) {
129 struct wlr_seat *seat = cursor->seat->wlr_seat; 122 struct wlr_seat *seat = cursor->seat->wlr_seat;
130 struct wlr_surface *surface = NULL; 123 struct wlr_surface *surface = NULL;
131 double sx, sy; 124 double sx, sy;
@@ -161,7 +154,6 @@ static void handle_cursor_motion(struct wl_listener *listener, void *data) {
161 struct wlr_event_pointer_motion *event = data; 154 struct wlr_event_pointer_motion *event = data;
162 wlr_cursor_move(cursor->cursor, event->device, 155 wlr_cursor_move(cursor->cursor, event->device,
163 event->delta_x, event->delta_y); 156 event->delta_x, event->delta_y);
164 cursor_update_position(cursor);
165 cursor_send_pointer_motion(cursor, event->time_msec); 157 cursor_send_pointer_motion(cursor, event->time_msec);
166} 158}
167 159
@@ -171,7 +163,6 @@ static void handle_cursor_motion_absolute(
171 wl_container_of(listener, cursor, motion_absolute); 163 wl_container_of(listener, cursor, motion_absolute);
172 struct wlr_event_pointer_motion_absolute *event = data; 164 struct wlr_event_pointer_motion_absolute *event = data;
173 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y); 165 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
174 cursor_update_position(cursor);
175 cursor_send_pointer_motion(cursor, event->time_msec); 166 cursor_send_pointer_motion(cursor, event->time_msec);
176} 167}
177 168
@@ -254,15 +245,12 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
254 (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { 245 (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
255 wlr_cursor_warp_absolute(cursor->cursor, event->device, 246 wlr_cursor_warp_absolute(cursor->cursor, event->device,
256 event->x, event->y); 247 event->x, event->y);
257 cursor_update_position(cursor);
258 cursor_send_pointer_motion(cursor, event->time_msec); 248 cursor_send_pointer_motion(cursor, event->time_msec);
259 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { 249 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
260 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1); 250 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
261 cursor_update_position(cursor);
262 cursor_send_pointer_motion(cursor, event->time_msec); 251 cursor_send_pointer_motion(cursor, event->time_msec);
263 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { 252 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
264 wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y); 253 wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
265 cursor_update_position(cursor);
266 cursor_send_pointer_motion(cursor, event->time_msec); 254 cursor_send_pointer_motion(cursor, event->time_msec);
267 } 255 }
268} 256}
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 @@
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>
@@ -258,10 +259,38 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
258 return seat; 259 return seat;
259} 260}
260 261
262static void seat_apply_input_config(struct sway_seat *seat,
263 struct sway_seat_device *sway_device) {
264 struct input_config *ic = input_device_get_config(
265 sway_device->input_device);
266 if (!ic) {
267 return;
268 }
269 wlr_log(L_DEBUG, "Applying input config to %s",
270 sway_device->input_device->identifier);
271 if (ic->mapped_output) {
272 struct sway_container *output = NULL;
273 for (int i = 0; i < root_container.children->length; ++i) {
274 struct sway_container *_output = root_container.children->items[i];
275 if (strcasecmp(_output->name, ic->mapped_output) == 0) {
276 output = _output;
277 break;
278 }
279 }
280 if (output) {
281 wlr_cursor_map_input_to_output(seat->cursor->cursor,
282 sway_device->input_device->wlr_device,
283 output->sway_output->wlr_output);
284 wlr_log(L_DEBUG, "Mapped to output %s", output->name);
285 }
286 }
287}
288
261static void seat_configure_pointer(struct sway_seat *seat, 289static void seat_configure_pointer(struct sway_seat *seat,
262 struct sway_seat_device *sway_device) { 290 struct sway_seat_device *sway_device) {
263 wlr_cursor_attach_input_device(seat->cursor->cursor, 291 wlr_cursor_attach_input_device(seat->cursor->cursor,
264 sway_device->input_device->wlr_device); 292 sway_device->input_device->wlr_device);
293 seat_apply_input_config(seat, sway_device);
265} 294}
266 295
267static void seat_configure_keyboard(struct sway_seat *seat, 296static void seat_configure_keyboard(struct sway_seat *seat,
@@ -288,6 +317,7 @@ static void seat_configure_tablet_tool(struct sway_seat *seat,
288 struct sway_seat_device *sway_device) { 317 struct sway_seat_device *sway_device) {
289 wlr_cursor_attach_input_device(seat->cursor->cursor, 318 wlr_cursor_attach_input_device(seat->cursor->cursor,
290 sway_device->input_device->wlr_device); 319 sway_device->input_device->wlr_device);
320 seat_apply_input_config(seat, sway_device);
291} 321}
292 322
293static struct sway_seat_device *seat_get_device(struct sway_seat *seat, 323static struct sway_seat_device *seat_get_device(struct sway_seat *seat,
@@ -486,6 +516,9 @@ void seat_set_focus_warp(struct sway_seat *seat,
486 wlr_output, seat->cursor->cursor->x, 516 wlr_output, seat->cursor->cursor->x,
487 seat->cursor->cursor->y)) { 517 seat->cursor->cursor->y)) {
488 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); 518 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
519 struct timespec now;
520 clock_gettime(CLOCK_MONOTONIC, &now);
521 cursor_send_pointer_motion(seat->cursor, now.tv_nsec / 1000);
489 } 522 }
490 } 523 }
491 } 524 }
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
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,
37 &text_width, &text_height, output->scale, false, "%s", error); 37 &text_width, &text_height, output->scale, false, "%s", error);
38 38
39 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 39 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
40 if (height < ideal_height) { 40 uint32_t ideal_surface_height = ideal_height / output->scale;
41 return ideal_height / output->scale; 41 if (surface_height < ideal_surface_height) {
42 return ideal_surface_height;
42 } 43 }
43 *x -= text_width + margin; 44 *x -= text_width + margin;
44 45
@@ -46,7 +47,7 @@ static uint32_t render_status_line_error(cairo_t *cairo,
46 cairo_move_to(cairo, *x, (int)floor(text_y)); 47 cairo_move_to(cairo, *x, (int)floor(text_y));
47 pango_printf(cairo, config->font, output->scale, false, "%s", error); 48 pango_printf(cairo, config->font, output->scale, false, "%s", error);
48 *x -= margin; 49 *x -= margin;
49 return ideal_height / output->scale; 50 return surface_height;
50} 51}
51 52
52static uint32_t render_status_line_text(cairo_t *cairo, 53static uint32_t render_status_line_text(cairo_t *cairo,
@@ -69,8 +70,9 @@ static uint32_t render_status_line_text(cairo_t *cairo,
69 int margin = 3 * output->scale; 70 int margin = 3 * output->scale;
70 71
71 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 72 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
72 if (height < ideal_height) { 73 uint32_t ideal_surface_height = ideal_height / output->scale;
73 return ideal_height / output->scale; 74 if (surface_height < ideal_surface_height) {
75 return ideal_surface_height;
74 } 76 }
75 77
76 *x -= text_width + margin; 78 *x -= text_width + margin;
@@ -79,7 +81,7 @@ static uint32_t render_status_line_text(cairo_t *cairo,
79 pango_printf(cairo, config->font, output->scale, 81 pango_printf(cairo, config->font, output->scale,
80 config->pango_markup, "%s", text); 82 config->pango_markup, "%s", text);
81 *x -= margin; 83 *x -= margin;
82 return ideal_height / output->scale; 84 return surface_height;
83} 85}
84 86
85static void render_sharp_line(cairo_t *cairo, uint32_t color, 87static void render_sharp_line(cairo_t *cairo, uint32_t color,
@@ -137,8 +139,9 @@ static uint32_t render_status_block(cairo_t *cairo,
137 139
138 double block_width = width; 140 double block_width = width;
139 uint32_t ideal_height = text_height + ws_vertical_padding * 2; 141 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
140 if (height < ideal_height) { 142 uint32_t ideal_surface_height = ideal_height / output->scale;
141 return ideal_height / output->scale; 143 if (surface_height < ideal_surface_height) {
144 return ideal_surface_height;
142 } 145 }
143 146
144 *x -= width; 147 *x -= width;
@@ -249,7 +252,7 @@ static uint32_t render_status_block(cairo_t *cairo,
249 cairo_stroke(cairo); 252 cairo_stroke(cairo);
250 } 253 }
251 } 254 }
252 return ideal_height / output->scale; 255 return surface_height;
253} 256}
254 257
255static uint32_t render_status_line_i3bar(cairo_t *cairo, 258static uint32_t render_status_line_i3bar(cairo_t *cairo,
@@ -291,7 +294,6 @@ static uint32_t render_status_line(cairo_t *cairo,
291static uint32_t render_binding_mode_indicator(cairo_t *cairo, 294static uint32_t render_binding_mode_indicator(cairo_t *cairo,
292 struct swaybar_output *output, struct swaybar_config *config, 295 struct swaybar_output *output, struct swaybar_config *config,
293 const char *mode, double x, uint32_t surface_height) { 296 const char *mode, double x, uint32_t surface_height) {
294
295 uint32_t height = surface_height * output->scale; 297 uint32_t height = surface_height * output->scale;
296 298
297 int text_width, text_height; 299 int text_width, text_height;
@@ -304,8 +306,9 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
304 306
305 uint32_t ideal_height = text_height + ws_vertical_padding * 2 307 uint32_t ideal_height = text_height + ws_vertical_padding * 2
306 + border_width * 2; 308 + border_width * 2;
307 if (height < ideal_height) { 309 uint32_t ideal_surface_height = ideal_height / output->scale;
308 return ideal_height / output->scale; 310 if (surface_height < ideal_surface_height) {
311 return ideal_surface_height;
309 } 312 }
310 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2; 313 uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
311 314
@@ -327,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
327 cairo_set_source_u32(cairo, config->colors.binding_mode.text); 330 cairo_set_source_u32(cairo, config->colors.binding_mode.text);
328 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); 331 cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
329 pango_printf(cairo, config->font, output->scale, true, "%s", mode); 332 pango_printf(cairo, config->font, output->scale, true, "%s", mode);
330 return ideal_height / output->scale; 333 return surface_height;
331} 334}
332 335
333static const char *strip_workspace_number(const char *ws_name) { 336static const char *strip_workspace_number(const char *ws_name) {
@@ -379,8 +382,9 @@ static uint32_t render_workspace_button(cairo_t *cairo,
379 382
380 uint32_t ideal_height = ws_vertical_padding * 2 + text_height 383 uint32_t ideal_height = ws_vertical_padding * 2 + text_height
381 + border_width * 2; 384 + border_width * 2;
382 if (height < ideal_height) { 385 uint32_t ideal_surface_height = ideal_height / output->scale;
383 return ideal_height / output->scale; 386 if (surface_height < ideal_surface_height) {
387 return ideal_surface_height;
384 } 388 }
385 389
386 uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2; 390 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,
415 wl_list_insert(&output->hotspots, &hotspot->link); 419 wl_list_insert(&output->hotspots, &hotspot->link);
416 420
417 *x += width; 421 *x += width;
418 return height / output->scale; 422 return surface_height;
419} 423}
420 424
421static uint32_t render_to_cairo(cairo_t *cairo, 425static uint32_t render_to_cairo(cairo_t *cairo,
@@ -484,8 +488,7 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
484 } 488 }
485 if (height != output->height) { 489 if (height != output->height) {
486 // Reconfigure surface 490 // Reconfigure surface
487 zwlr_layer_surface_v1_set_size( 491 zwlr_layer_surface_v1_set_size(output->layer_surface, 0, height);
488 output->layer_surface, 0, height);
489 zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height); 492 zwlr_layer_surface_v1_set_exclusive_zone(output->layer_surface, height);
490 // TODO: this could infinite loop if the compositor assigns us a 493 // TODO: this could infinite loop if the compositor assigns us a
491 // different height than what we asked for 494 // different height than what we asked for