From 568d047595d08beda5f486d43db8b240361d838d Mon Sep 17 00:00:00 2001 From: dvh Date: Wed, 11 Nov 2026 10:09:02 +0100 Subject: [PATCH] don't keep outputs unplugged while off in offmons When an output was unplugged while turned off (e.g. by swayidle), only the remaining ones were turned on again, and the unplugged one stayed in offmons, so it stayed off when plugged in again. Forget the outputs that are no longer connected whenever one is turned on. --- dwl.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/dwl.c b/dwl.c index ce1f746..8db7fc7 100644 --- a/dwl.c +++ b/dwl.c @@ -320,6 +320,7 @@ static void focusclient(Client *c, LayerSurface *l, int lift); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); static Client *focustop(Monitor *m); +static void forgetoffmons(void); static void fullscreennotify(struct wl_listener *listener, void *data); static void gpureset(struct wl_listener *listener, void *data); static void handlesig(int signo); @@ -1760,6 +1761,26 @@ focustop(Monitor *m) return NULL; } +void +forgetoffmons(void) +{ + /* Forget the outputs that were unplugged while off, or they would stay + * off when plugged in again */ + char **name, **kept = offmons.data; + Monitor *m; + + wl_array_for_each(name, &offmons) { + wl_list_for_each(m, &mons, link) + if (!strcmp(*name, m->wlr_output->name)) + break; + if (&m->link != &mons) + *kept++ = *name; + else + free(*name); + } + offmons.size = (char *)kept - (char *)offmons.data; +} + void fullscreennotify(struct wl_listener *listener, void *data) { @@ -2451,6 +2472,8 @@ powermgrsetmode(struct wl_listener *listener, void *data) if (!m) return; + if (event->mode) + forgetoffmons(); m->gamma_lut_changed = 1; /* Reapply gamma LUT when re-enabling the output */ wlr_output_state_set_enabled(&state, event->mode); /* The output was reconnected while off and was never modeset */