wayland: break out scale/resize updating to a new function

And call this function once from output_done(), rather than from each
output_*() callback.
This commit is contained in:
Daniel Eklöf 2020-02-15 19:05:33 +01:00
parent e5253ca737
commit ffcb09dd75
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

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