aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-10-27 18:36:45 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-10-27 18:36:45 +0000
commit957fb255594d634fdd1c2458546babd2b08114a0 (patch)
tree27eb64fac302f984d4f1ae6f7b8d437ebae738f9
parentmain: remove a couple of includes (diff)
wayland: move reload_cursor_theme() and update_cursor_surface() to wayland
-rw-r--r--input.c2
-rw-r--r--render.c55
-rw-r--r--render.h2
-rw-r--r--wayland.c62
-rw-r--r--wayland.h4
5 files changed, 64 insertions, 61 deletions
diff --git a/input.c b/input.c
index b91fea2f..bee51244 100644
--- a/input.c
+++ b/input.c
@@ -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
diff --git a/render.c b/render.c
index 09e4d7d0..f1eaa9fa 100644
--- a/render.c
+++ b/render.c
@@ -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)
{
diff --git a/render.h b/render.h
index c2fa489e..1c6bbd7f 100644
--- a/render.h
+++ b/render.h
@@ -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;
diff --git a/wayland.c b/wayland.c
index a331190b..2fcf2340 100644
--- a/wayland.c
+++ b/wayland.c
@@ -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)
{
diff --git a/wayland.h b/wayland.h
index 29c30518..a8aba13c 100644
--- a/wayland.h
+++ b/wayland.h
@@ -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);