From 05e91fa9df2fb0b34eea1a82a521b5544580f3f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 12 Aug 2019 21:32:38 +0200 Subject: [PATCH] output: resize on scale changes --- main.c | 9 ++++++--- render.c | 10 ++++++++-- render.h | 2 +- terminal.h | 1 + 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 93e91c54..fc1505f7 100644 --- a/main.c +++ b/main.c @@ -128,6 +128,7 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct monitor *mon = data; mon->scale = factor; + render_resize(mon->term, mon->term->width, mon->term->height, factor); } static const struct wl_output_listener output_listener = { @@ -224,7 +225,8 @@ handle_global(void *data, struct wl_registry *registry, term->wl.registry, name, &wl_output_interface, 3); tll_push_back( - term->wl.monitors, ((struct monitor){.output = output})); + term->wl.monitors, ((struct monitor){ + .term = term, .output = output})); struct monitor *mon = &tll_back(term->wl.monitors); wl_output_add_listener(output, &output_listener, mon); @@ -255,7 +257,8 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, if (width <= 0 || height <= 0) return; - render_resize(data, width, height); + struct terminal *term = data; + render_resize(term, width, height, term->scale); } static void @@ -674,7 +677,7 @@ main(int argc, char *const *argv) /* TODO: use font metrics to calculate initial size from ROWS x COLS */ const int default_width = 300; const int default_height = 300; - render_resize(&term, default_width, default_height); + render_resize(&term, default_width, default_height, term.scale); wl_display_dispatch_pending(term.wl.display); diff --git a/render.c b/render.c index ee45b96b..d6f4a5de 100644 --- a/render.c +++ b/render.c @@ -675,16 +675,22 @@ reflow(struct row **new_grid, int new_cols, int new_rows, /* Move to terminal.c? */ void -render_resize(struct terminal *term, int width, int height) +render_resize(struct terminal *term, int width, int height, int scale) { width *= term->scale; height *= term->scale; - if (width == term->width && height == term->height) + if (width == 0 && height == 0) { + /* Assume we're not fully up and running yet */ + return; + } + + if (width == term->width && height == term->height && scale == term->scale) return; term->width = width; term->height = height; + term->scale = scale; const int scrollback_lines = term->render.scrollback_lines; diff --git a/render.h b/render.h index 0b7a40ca..059e03d0 100644 --- a/render.h +++ b/render.h @@ -6,7 +6,7 @@ struct font *attrs_to_font( struct terminal *term, const struct attributes *attrs); void grid_render(struct terminal *term); -void render_resize(struct terminal *term, int width, int height); +void render_resize(struct terminal *term, int width, int height, int scale); void render_set_title(struct terminal *term, const char *title); void render_update_cursor_surface(struct terminal *term); void render_refresh(struct terminal *term); diff --git a/terminal.h b/terminal.h index 03e1584f..27265796 100644 --- a/terminal.h +++ b/terminal.h @@ -21,6 +21,7 @@ #define unlikely(c) __builtin_expect(!!(c), 0) struct monitor { + struct terminal *term; struct wl_output *output; struct zxdg_output_v1 *xdg; char *name;