From f04b1e806c05d45f9e985fa8d1494e9f16febb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 9 Jul 2020 19:02:02 +0200 Subject: [PATCH] bar: let backend check if xcursor should be updated or not This allows the backend to support multi-seat "properly", by checking against the correct seat. Before this, when we used a single, global xcursor value, a seat whose pointer needed to be updated would not be updated. --- bar/bar.c | 7 ------- bar/private.h | 3 --- bar/wayland.c | 47 ++++++++++++++++++++--------------------------- bar/xcb.c | 7 ++++--- 4 files changed, 24 insertions(+), 40 deletions(-) diff --git a/bar/bar.c b/bar/bar.c index c9ca8cd..d3abd14 100644 --- a/bar/bar.c +++ b/bar/bar.c @@ -154,13 +154,6 @@ static void set_cursor(struct bar *bar, const char *cursor) { struct private *b = bar->private; - - if (b->cursor_name != NULL && strcmp(b->cursor_name, cursor) == 0) - return; - - free(b->cursor_name); - b->cursor_name = strdup(cursor); - b->backend.iface->set_cursor(bar, cursor); } diff --git a/bar/private.h b/bar/private.h index 5b9aa2f..b5d888f 100644 --- a/bar/private.h +++ b/bar/private.h @@ -40,9 +40,6 @@ struct private { int width; int height_with_border; - /* Name of currently active cursor */ - char *cursor_name; - pixman_image_t *pix; struct { diff --git a/bar/wayland.c b/bar/wayland.c index 2d2fb97..af2e7f4 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -72,6 +72,7 @@ struct seat { struct wl_surface *surface; struct wl_cursor_theme *theme; struct wl_cursor *cursor; + const char *xcursor; int scale; } pointer; }; @@ -89,7 +90,6 @@ struct wayland_backend { tll(struct seat) seats; struct seat *active_seat; - const char *xcursor; tll(struct monitor) monitors; const struct monitor *monitor; @@ -178,28 +178,6 @@ update_cursor_surface(struct wayland_backend *backend, struct seat *seat) wl_display_flush(backend->display); } -static void -set_cursor(struct bar *_bar, const char *_cursor) -{ - struct private *bar = _bar->private; - struct wayland_backend *backend = bar->backend.data; - - const char *cursor = _cursor != NULL ? _cursor : backend->xcursor; - if (cursor == NULL) - return; - - backend->xcursor = cursor; - - struct seat *seat = backend->active_seat; - if (seat == NULL || seat->pointer.theme == NULL) - return; - - seat->pointer.cursor = wl_cursor_theme_get_cursor( - seat->pointer.theme, cursor); - - update_cursor_surface(backend, seat); -} - static void reload_cursor_theme(struct seat *seat, int new_scale) { @@ -252,7 +230,6 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, backend->active_seat = seat; reload_cursor_theme(seat, backend->monitor->scale); - set_cursor(backend->bar, NULL); } static void @@ -981,9 +958,6 @@ cleanup(struct bar *_bar) if (backend->xdg_output_manager != NULL) zxdg_output_manager_v1_destroy(backend->xdg_output_manager); - /* TODO: move to bar */ - free(bar->cursor_name); - tll_foreach(backend->seats, it) seat_destroy(&it->item); tll_free(backend->seats); @@ -1202,6 +1176,25 @@ refresh(const struct bar *_bar) } } +static void +set_cursor(struct bar *_bar, const char *cursor) +{ + struct private *bar = _bar->private; + struct wayland_backend *backend = bar->backend.data; + + struct seat *seat = backend->active_seat; + if (seat == NULL || seat->pointer.theme == NULL) + return; + + if (seat->pointer.xcursor != NULL && strcmp(seat->pointer.xcursor, cursor) == 0) + return; + + seat->pointer.cursor = wl_cursor_theme_get_cursor( + seat->pointer.theme, cursor); + + update_cursor_surface(backend, seat); +} + const struct backend wayland_backend_iface = { .setup = &setup, .cleanup = &cleanup, diff --git a/bar/xcb.c b/bar/xcb.c index 038da8d..f95c445 100644 --- a/bar/xcb.c +++ b/bar/xcb.c @@ -32,6 +32,7 @@ struct xcb_backend { xcb_gc_t gc; xcb_cursor_context_t *cursor_ctx; xcb_cursor_t cursor; + const char *xcursor; uint8_t depth; void *client_pixmap; @@ -280,9 +281,6 @@ cleanup(struct bar *_bar) if (backend->cursor_ctx != NULL) xcb_cursor_context_free(backend->cursor_ctx); - /* TODO: move to bar.c */ - free(bar->cursor_name); - if (backend->pix != NULL) pixman_image_unref(backend->pix); free(backend->client_pixmap); @@ -432,6 +430,9 @@ set_cursor(struct bar *_bar, const char *cursor) if (backend->cursor_ctx == NULL) return; + if (backend->xcursor != NULL && strcmp(backend->xcursor, cursor) == 0) + return; + if (backend->cursor != 0) xcb_free_cursor(backend->conn, backend->cursor);