From d377221e247f67f7b5e6363f81ae2268e16aa32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 8 Jul 2020 19:52:17 +0200 Subject: [PATCH] xcursor: trigger theme reload in pointer-enter event Previously, we triggered a theme reload on output changes. This is completely wrong. We may get a new output with a scale different from the output the pointer is actually on. Now, we store the current scale along with the theme. We then trigger a call to reload the xcursor theme *every* time the pointer enters a surface. When it does, we use the current scale factor of the terminal that owns that surface. If the terminal covers multiple outputs, with different scale factors, we'll use the largest scale factor. This may not be 100% correct. But to fix that, we'd need to track which regions of a surface are mapped on which outputs. Too complicated I say. --- input.c | 3 +++ wayland.c | 20 +++++++++++--------- wayland.h | 3 +++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/input.c b/input.c index a035983a..ea344c99 100644 --- a/input.c +++ b/input.c @@ -846,6 +846,9 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer, LOG_DBG("pointer-enter: pointer=%p, serial=%u, surface = %p, new-moused = %p", wl_pointer, serial, surface, term); + /* Scale may have changed */ + wayl_reload_xcursor_theme(seat, term->scale); + seat->mouse_focus = term; int x = wl_fixed_to_int(surface_x) * term->scale; diff --git a/wayland.c b/wayland.c index 8b4292ae..667ae2da 100644 --- a/wayland.c +++ b/wayland.c @@ -30,8 +30,6 @@ #include "selection.h" #include "util.h" -static bool wayl_reload_cursor_theme(struct seat *seat, struct terminal *term); - static void csd_instantiate(struct wl_window *win) { @@ -212,9 +210,6 @@ update_term_for_output_change(struct terminal *term) render_resize(term, term->width / term->scale, term->height / term->scale); term_font_dpi_changed(term); term_font_subpixel_changed(term); - - tll_foreach(term->wl->seats, it) - wayl_reload_cursor_theme(&it->item, term); } static void @@ -1197,13 +1192,19 @@ wayl_win_destroy(struct wl_window *win) free(win); } -static bool -wayl_reload_cursor_theme(struct seat *seat, struct terminal *term) +bool +wayl_reload_xcursor_theme(struct seat *seat, int new_scale) { if (seat->pointer.size == 0) return true; + if (seat->pointer.theme != NULL && seat->pointer.scale == new_scale) { + /* We already have a theme loaded, and the scale hasn't changed */ + return true; + } + if (seat->pointer.theme != NULL) { + assert(seat->pointer.scale != new_scale); wl_cursor_theme_destroy(seat->pointer.theme); seat->pointer.theme = NULL; seat->pointer.cursor = NULL; @@ -1213,14 +1214,15 @@ wayl_reload_cursor_theme(struct seat *seat, struct terminal *term) seat->pointer.theme_name, seat->pointer.size); seat->pointer.theme = wl_cursor_theme_load( - seat->pointer.theme_name, seat->pointer.size * term->scale, seat->wayl->shm); + seat->pointer.theme_name, seat->pointer.size * new_scale, seat->wayl->shm); if (seat->pointer.theme == NULL) { LOG_ERR("failed to load cursor theme"); return false; } - return render_xcursor_set(seat, term); + seat->pointer.scale = new_scale; + return true; } void diff --git a/wayland.h b/wayland.h index 1232563f..489f485d 100644 --- a/wayland.h +++ b/wayland.h @@ -146,6 +146,7 @@ struct seat { struct wl_cursor_theme *theme; struct wl_cursor *cursor; int size; + int scale; char *theme_name; const char *xcursor; @@ -329,3 +330,5 @@ void wayl_roundtrip(struct wayland *wayl); struct wl_window *wayl_win_init(struct terminal *term); void wayl_win_destroy(struct wl_window *win); + +bool wayl_reload_xcursor_theme(struct seat *seat, int new_scale);