From ffcb09dd756532108759a830e545c8e84602c95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 19:05:33 +0100 Subject: [PATCH] wayland: break out scale/resize updating to a new function And call this function once from output_done(), rather than from each output_*() callback. --- wayland.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/wayland.c b/wayland.c index 8a9b8012..8b529a9c 100644 --- a/wayland.c +++ b/wayland.c @@ -95,6 +95,31 @@ static const struct wl_seat_listener seat_listener = { .name = seat_handle_name, }; +static void +update_term_for_output_change(struct terminal *term) +{ + render_resize(term, term->width / term->scale, term->height / term->scale); + term_font_dpi_changed(term); + wayl_reload_cursor_theme(term->wl, term); +} + +static void +update_terms_on_monitor(struct monitor *mon) +{ + struct wayland *wayl = mon->wayl; + + tll_foreach(wayl->terms, it) { + struct terminal *term = it->item; + + tll_foreach(term->window->on_outputs, it2) { + if (it2->item == mon) { + update_term_for_output_change(term); + break; + } + } + } +} + static void output_update_ppi(struct monitor *mon) { @@ -133,22 +158,15 @@ output_mode(void *data, struct wl_output *wl_output, uint32_t flags, static void output_done(void *data, struct wl_output *wl_output) { + struct monitor *mon = data; + update_terms_on_monitor(mon); } static void output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct monitor *mon = data; - mon->scale = factor; - - tll_foreach(mon->wayl->terms, it) { - struct terminal *term = it->item; - int scale = term->scale; - - render_resize(term, term->width / scale, term->height / scale); - wayl_reload_cursor_theme(mon->wayl, term); - } } static const struct wl_output_listener output_listener = { @@ -370,11 +388,7 @@ surface_enter(void *data, struct wl_surface *wl_surface, if (it->item.output == wl_output) { LOG_DBG("mapped on %s", it->item.name); tll_push_back(term->window->on_outputs, &it->item); - - /* Resize, since scale-to-use may have changed */ - int scale = term->scale; - render_resize(term, term->width / scale, term->height / scale); - wayl_reload_cursor_theme(term->wl, term); + update_term_for_output_change(term); return; } } @@ -395,11 +409,7 @@ surface_leave(void *data, struct wl_surface *wl_surface, LOG_DBG("unmapped from %s", it->item->name); tll_remove(term->window->on_outputs, it); - - /* Resize, since scale-to-use may have changed */ - int scale = term->scale; - render_resize(term, term->width / scale, term->height / scale); - wayl_reload_cursor_theme(term->wl, term); + update_term_for_output_change(term); return; }