From ffcb09dd756532108759a830e545c8e84602c95e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 15 Feb 2020 19:05:33 +0100 Subject: 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(-) (limited to 'wayland.c') 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; } -- cgit v1.3 From 027696e9c6ac0cf4b6a7bd7905358104f9bed6cd Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 15 Feb 2020 19:06:28 +0100 Subject: wayland: calculate DPI from physical size, not logical size xdg_output_handle_logical_size() reports _logical_ output size. That is, it is scaled by the output's scale factor. We want the _actual_ DPI. The _real_ output size is reported by output_mode(), so use that instead. --- wayland.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'wayland.c') diff --git a/wayland.c b/wayland.c index 8b529a9c..8528f987 100644 --- a/wayland.c +++ b/wayland.c @@ -153,6 +153,8 @@ output_mode(void *data, struct wl_output *wl_output, uint32_t flags, struct monitor *mon = data; mon->refresh = (float)refresh / 1000; + mon->width_px = width; + mon->height_px = height; } static void @@ -189,10 +191,6 @@ static void xdg_output_handle_logical_size(void *data, struct zxdg_output_v1 *xdg_output, int32_t width, int32_t height) { - struct monitor *mon = data; - mon->width_px = width; - mon->height_px = height; - output_update_ppi(mon); } static void -- cgit v1.3