From cdee55afed6eee4e2618926d096d1322b58e2962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 3 Jan 2024 15:39:04 +0100 Subject: [PATCH] bar: wayland: update bar size + refresh in output_done() This ensures the bar's size (width) is updated when the screen resolution (and/or scale) is changed. Note that we already handled scale changes. This logic has been moved from output_scale() to output_done(). Closes #330 --- CHANGELOG.md | 3 +++ bar/wayland.c | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a7469..01bd423 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,9 +31,12 @@ * map: conditions failing to match when they contain multiple, quoted tag values ([#302][302]). * Crash when hidden by an opaque window. +* Bar not resizing itself when the screen resolution is changed + ([#330][330]). [311]: https://codeberg.org/dnkl/yambar/issues/311 [302]: https://codeberg.org/dnkl/yambar/issues/302 +[330]: https://codeberg.org/dnkl/yambar/issues/330 ### Security diff --git a/bar/wayland.c b/bar/wayland.c index 2b1e0a5..22ca3e2 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -475,13 +475,24 @@ output_mode(void *data, struct wl_output *wl_output, uint32_t flags, { } +static bool update_size(struct wayland_backend *backend); +static void refresh(const struct bar *_bar); + static void output_done(void *data, struct wl_output *wl_output) { -} + struct monitor *mon = data; -static bool update_size(struct wayland_backend *backend); -static void refresh(const struct bar *_bar); + if (mon->backend->monitor == mon) { + int old_scale = mon->backend->scale; + int old_width = mon->backend->width; + + update_size(mon->backend); + + if (mon->backend->scale != old_scale || mon->backend->width != old_width) + refresh(mon->backend->bar); + } +} static void output_scale(void *data, struct wl_output *wl_output, int32_t factor) @@ -491,14 +502,6 @@ output_scale(void *data, struct wl_output *wl_output, int32_t factor) return; mon->scale = factor; - - if (mon->backend->monitor == mon) { - int old_scale = mon->backend->scale; - update_size(mon->backend); - - if (mon->backend->scale != old_scale) - refresh(mon->backend->bar); - } } #if defined(WL_OUTPUT_NAME_SINCE_VERSION) @@ -1058,9 +1061,6 @@ update_size(struct wayland_backend *backend) assert(backend->surface != NULL); - if (backend->scale == scale) - return true; - backend->scale = scale; int height = bar->height_with_border;