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.
This commit is contained in:
Daniel Eklöf 2020-07-09 19:02:02 +02:00
parent 5884e665a4
commit f04b1e806c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 24 additions and 40 deletions

View file

@ -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);
}

View file

@ -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 {

View file

@ -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,

View file

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