summaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-15 03:21:08 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-15 09:26:50 +0100
commit35a82a869328ecf387f1490ca6ecfca8bdc1ab39 (patch)
tree64984913256a543417b5932e0863ac02d9de1be8 /swaybar
parentMerge pull request #3291 from RedSoxFan/fix-focus-nonvis (diff)
downloadsway-35a82a869328ecf387f1490ca6ecfca8bdc1ab39.tar.gz
sway-35a82a869328ecf387f1490ca6ecfca8bdc1ab39.tar.zst
sway-35a82a869328ecf387f1490ca6ecfca8bdc1ab39.zip
swaybar: fix cursor scale
This fixes a few issues with swaybar's cursor scaling: 1. The cursor scale is now changed when the output scale changes 2. The cursor scale is no longer bound by the max output scale when swaybar is launched 3. Related to the previous item, the cursor is no longer tiny on low scale outputs after the max output scale has changed This also bumps up `wl_compositor` to version 4 to allow usage of `wl_surface_damage_buffer`.
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c22
-rw-r--r--swaybar/input.c38
2 files changed, 29 insertions, 31 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 47c89a39..53e798bc 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -196,6 +196,10 @@ static void output_scale(void *data, struct wl_output *wl_output,
196 int32_t factor) { 196 int32_t factor) {
197 struct swaybar_output *output = data; 197 struct swaybar_output *output = data;
198 output->scale = factor; 198 output->scale = factor;
199 if (output == output->bar->pointer.current) {
200 update_cursor(output->bar);
201 render_frame(output);
202 }
199} 203}
200 204
201struct wl_output_listener output_listener = { 205struct wl_output_listener output_listener = {
@@ -273,7 +277,7 @@ static void handle_global(void *data, struct wl_registry *registry,
273 struct swaybar *bar = data; 277 struct swaybar *bar = data;
274 if (strcmp(interface, wl_compositor_interface.name) == 0) { 278 if (strcmp(interface, wl_compositor_interface.name) == 0) {
275 bar->compositor = wl_registry_bind(registry, name, 279 bar->compositor = wl_registry_bind(registry, name,
276 &wl_compositor_interface, 3); 280 &wl_compositor_interface, 4);
277 } else if (strcmp(interface, wl_seat_interface.name) == 0) { 281 } else if (strcmp(interface, wl_seat_interface.name) == 0) {
278 bar->seat = wl_registry_bind(registry, name, 282 bar->seat = wl_registry_bind(registry, name,
279 &wl_seat_interface, 3); 283 &wl_seat_interface, 3);
@@ -355,22 +359,6 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) {
355 wl_display_roundtrip(bar->display); 359 wl_display_roundtrip(bar->display);
356 360
357 struct swaybar_pointer *pointer = &bar->pointer; 361 struct swaybar_pointer *pointer = &bar->pointer;
358
359 int max_scale = 1;
360 struct swaybar_output *output;
361 wl_list_for_each(output, &bar->outputs, link) {
362 if (output->scale > max_scale) {
363 max_scale = output->scale;
364 }
365 }
366
367 pointer->cursor_theme =
368 wl_cursor_theme_load(NULL, 24 * max_scale, bar->shm);
369 assert(pointer->cursor_theme);
370 struct wl_cursor *cursor;
371 cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
372 assert(cursor);
373 pointer->cursor_image = cursor->images[0];
374 pointer->cursor_surface = wl_compositor_create_surface(bar->compositor); 362 pointer->cursor_surface = wl_compositor_create_surface(bar->compositor);
375 assert(pointer->cursor_surface); 363 assert(pointer->cursor_surface);
376 364
diff --git a/swaybar/input.c b/swaybar/input.c
index 1f8491f6..7d219be3 100644
--- a/swaybar/input.c
+++ b/swaybar/input.c
@@ -55,11 +55,34 @@ static enum x11_button wl_axis_to_x11_button(uint32_t axis, wl_fixed_t value) {
55 } 55 }
56} 56}
57 57
58void update_cursor(struct swaybar *bar) {
59 struct swaybar_pointer *pointer = &bar->pointer;
60 if (pointer->cursor_theme) {
61 wl_cursor_theme_destroy(pointer->cursor_theme);
62 }
63 int scale = pointer->current ? pointer->current->scale : 1;
64 pointer->cursor_theme = wl_cursor_theme_load(NULL, 24 * scale, bar->shm);
65 struct wl_cursor *cursor;
66 cursor = wl_cursor_theme_get_cursor(pointer->cursor_theme, "left_ptr");
67 pointer->cursor_image = cursor->images[0];
68 wl_surface_set_buffer_scale(pointer->cursor_surface, scale);
69 wl_surface_attach(pointer->cursor_surface,
70 wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
71 wl_pointer_set_cursor(pointer->pointer, pointer->serial,
72 pointer->cursor_surface,
73 pointer->cursor_image->hotspot_x / scale,
74 pointer->cursor_image->hotspot_y / scale);
75 wl_surface_damage_buffer(pointer->cursor_surface, 0, 0,
76 INT32_MAX, INT32_MAX);
77 wl_surface_commit(pointer->cursor_surface);
78}
79
58static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, 80static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
59 uint32_t serial, struct wl_surface *surface, 81 uint32_t serial, struct wl_surface *surface,
60 wl_fixed_t surface_x, wl_fixed_t surface_y) { 82 wl_fixed_t surface_x, wl_fixed_t surface_y) {
61 struct swaybar *bar = data; 83 struct swaybar *bar = data;
62 struct swaybar_pointer *pointer = &bar->pointer; 84 struct swaybar_pointer *pointer = &bar->pointer;
85 pointer->serial = serial;
63 struct swaybar_output *output; 86 struct swaybar_output *output;
64 wl_list_for_each(output, &bar->outputs, link) { 87 wl_list_for_each(output, &bar->outputs, link) {
65 if (output->surface == surface) { 88 if (output->surface == surface) {
@@ -67,20 +90,7 @@ static void wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
67 break; 90 break;
68 } 91 }
69 } 92 }
70 int max_scale = 1; 93 update_cursor(bar);
71 struct swaybar_output *_output;
72 wl_list_for_each(_output, &bar->outputs, link) {
73 if (_output->scale > max_scale) {
74 max_scale = _output->scale;
75 }
76 }
77 wl_surface_set_buffer_scale(pointer->cursor_surface, max_scale);
78 wl_surface_attach(pointer->cursor_surface,
79 wl_cursor_image_get_buffer(pointer->cursor_image), 0, 0);
80 wl_pointer_set_cursor(wl_pointer, serial, pointer->cursor_surface,
81 pointer->cursor_image->hotspot_x / max_scale,
82 pointer->cursor_image->hotspot_y / max_scale);
83 wl_surface_commit(pointer->cursor_surface);
84} 94}
85 95
86static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer, 96static void wl_pointer_leave(void *data, struct wl_pointer *wl_pointer,