wayland: move reload_cursor_theme() and update_cursor_surface() to wayland

This commit is contained in:
Daniel Eklöf 2019-10-27 19:36:45 +01:00
parent 664641104c
commit 957fb25559
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 64 additions and 61 deletions

View file

@ -397,7 +397,7 @@ wl_pointer_enter(void *data, struct wl_pointer *wl_pointer,
wayl->mouse.col = x / term->cell_width;
wayl->mouse.row = y / term->cell_height;
render_update_cursor_surface(term);
wayl_update_cursor_surface(wayl, term);
}
static void

View file

@ -942,61 +942,6 @@ render_set_title(struct terminal *term, const char *title)
xdg_toplevel_set_title(term->window->xdg_toplevel, title);
}
bool
render_reload_cursor_theme(struct terminal *term)
{
if (term->wl->pointer.size == 0)
return true;
if (term->wl->pointer.theme != NULL) {
wl_cursor_theme_destroy(term->wl->pointer.theme);
term->wl->pointer.theme = NULL;
term->wl->pointer.cursor = NULL;
}
LOG_DBG("reloading cursor theme: %s@%d",
term->wl->pointer.theme_name, term->wl->pointer.size);
term->wl->pointer.theme = wl_cursor_theme_load(
term->wl->pointer.theme_name, term->wl->pointer.size * term->scale, term->wl->shm);
if (term->wl->pointer.theme == NULL) {
LOG_ERR("failed to load cursor theme");
return false;
}
term->wl->pointer.cursor = wl_cursor_theme_get_cursor(
term->wl->pointer.theme, "left_ptr");
assert(term->wl->pointer.cursor != NULL);
render_update_cursor_surface(term);
return true;
}
void
render_update_cursor_surface(struct terminal *term)
{
if (term->wl->pointer.cursor == NULL)
return;
const int scale = term->scale;
wl_surface_set_buffer_scale(term->wl->pointer.surface, scale);
struct wl_cursor_image *image = term->wl->pointer.cursor->images[0];
wl_surface_attach(
term->wl->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0);
wl_pointer_set_cursor(
term->wl->pointer.pointer, term->wl->pointer.serial,
term->wl->pointer.surface,
image->hotspot_x / scale, image->hotspot_y / scale);
wl_surface_damage_buffer(
term->wl->pointer.surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(term->wl->pointer.surface);
}
void
render_refresh(struct terminal *term)
{

View file

@ -11,8 +11,6 @@ void render_set_title(struct terminal *term, const char *title);
void render_refresh(struct terminal *term);
void render_search_box(struct terminal *term);
bool render_reload_cursor_theme(struct terminal *term);
void render_update_cursor_surface(struct terminal *term);
struct render_worker_context {
int my_id;

View file

@ -126,7 +126,7 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor)
struct terminal *term = mon->wayl->term;
if (term != NULL) {
render_resize(term, term->width / term->scale, term->height / term->scale);
render_reload_cursor_theme(term);
wayl_reload_cursor_theme(mon->wayl, term);
}
}
@ -269,7 +269,7 @@ surface_enter(void *data, struct wl_surface *wl_surface,
/* Resize, since scale-to-use may have changed */
render_resize(term, term->width / term->scale, term->height / term->scale);
render_reload_cursor_theme(term);
wayl_reload_cursor_theme(wayl, term);
return;
}
}
@ -293,7 +293,7 @@ surface_leave(void *data, struct wl_surface *wl_surface,
/* Resize, since scale-to-use may have changed */
render_resize(term, term->width / term->scale, term->height / term->scale);
render_reload_cursor_theme(term);
wayl_reload_cursor_theme(wayl, term);
return;
}
@ -704,6 +704,62 @@ wayl_win_destroy(struct wl_window *win)
free(win);
}
bool
wayl_reload_cursor_theme(struct wayland *wayl, struct terminal *term)
{
if (wayl->pointer.size == 0)
return true;
if (wayl->pointer.theme != NULL) {
wl_cursor_theme_destroy(wayl->pointer.theme);
wayl->pointer.theme = NULL;
wayl->pointer.cursor = NULL;
}
LOG_DBG("reloading cursor theme: %s@%d",
wayl->pointer.theme_name, wayl->pointer.size);
wayl->pointer.theme = wl_cursor_theme_load(
wayl->pointer.theme_name, wayl->pointer.size * term->scale, wayl->shm);
if (wayl->pointer.theme == NULL) {
LOG_ERR("failed to load cursor theme");
return false;
}
wayl->pointer.cursor = wl_cursor_theme_get_cursor(
wayl->pointer.theme, "left_ptr");
assert(wayl->pointer.cursor != NULL);
wayl_update_cursor_surface(wayl, term);
return true;
}
void
wayl_update_cursor_surface(struct wayland *wayl, struct terminal *term)
{
if (wayl->pointer.cursor == NULL)
return;
const int scale = term->scale;
wl_surface_set_buffer_scale(wayl->pointer.surface, scale);
struct wl_cursor_image *image = wayl->pointer.cursor->images[0];
wl_surface_attach(
wayl->pointer.surface, wl_cursor_image_get_buffer(image), 0, 0);
wl_pointer_set_cursor(
wayl->pointer.pointer, wayl->pointer.serial,
wayl->pointer.surface,
image->hotspot_x / scale, image->hotspot_y / scale);
wl_surface_damage_buffer(
wayl->pointer.surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(wayl->pointer.surface);
}
struct terminal *
wayl_terminal_from_surface(struct wayland *wayl, struct wl_surface *surface)
{

View file

@ -161,5 +161,9 @@ struct terminal *wayl_terminal_from_xdg_surface(
struct terminal *wayl_terminal_from_xdg_toplevel(
struct wayland *wayl, struct xdg_toplevel *toplevel);
/* TODO: pass something other than 'term'? Need scale... */
bool wayl_reload_cursor_theme(struct wayland *wayl, struct terminal *term);
void wayl_update_cursor_surface(struct wayland *wayl, struct terminal *term);
struct wl_window *wayl_win_init(struct wayland *wayl);
void wayl_win_destroy(struct wl_window *win);