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).
This commit is contained in:
Daniel Eklöf 2019-11-30 12:09:57 +01:00
parent 841e20b75b
commit a87b39f6eb
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 11 additions and 0 deletions

View file

@ -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];

View file

@ -132,6 +132,7 @@ struct wayland {
struct wl_cursor *cursor;
int size;
char *theme_name;
const char *xcursor;
} pointer;
struct {