From a87b39f6eb18b5b3674afcb3f24816d933eab319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 30 Nov 2019 12:09:57 +0100 Subject: [PATCH] wayland: track current xcursor, and don't update if same We may have many windows open, which tries to update/change the xcursor at various points. Track which cursor is currently loaded, regardless of which window it was set by. If someone tries to load that very same xcursor again, simply skip it. One example is when we've moused over a window that does *not* have keyboard focus, and then the user clicks, or by some other mean gives that window keyboard focus. In many cases it will then try to set the same cursor again (most of the times, the cursor is the same regardless of keyboard focus, but not always). --- wayland.c | 10 ++++++++++ wayland.h | 1 + 2 files changed, 11 insertions(+) diff --git a/wayland.c b/wayland.c index 3cc86429..938056ac 100644 --- a/wayland.c +++ b/wayland.c @@ -801,11 +801,19 @@ wayl_cursor_set(struct wayland *wayl, const struct terminal *term) if (wayl->pointer.theme == NULL) return false; + if (wayl->moused == NULL) { + wayl->pointer.xcursor = NULL; + return true; + } + if (wayl->moused != term) { /* This terminal doesn't have mouse focus */ return true; } + if (wayl->pointer.xcursor == term->xcursor) + return true; + wayl->pointer.cursor = wl_cursor_theme_get_cursor(wayl->pointer.theme, term->xcursor); if (wayl->pointer.cursor == NULL) { LOG_ERR("%s: failed to load xcursor pointer '%s'", @@ -813,6 +821,8 @@ wayl_cursor_set(struct wayland *wayl, const struct terminal *term) return false; } + wayl->pointer.xcursor = term->xcursor; + const int scale = term->scale; struct wl_cursor_image *image = wayl->pointer.cursor->images[0]; diff --git a/wayland.h b/wayland.h index a5084d83..fb681dd6 100644 --- a/wayland.h +++ b/wayland.h @@ -132,6 +132,7 @@ struct wayland { struct wl_cursor *cursor; int size; char *theme_name; + const char *xcursor; } pointer; struct {