From 16076ec5a40ed708b99f27100036a4a92b4fdd59 Mon Sep 17 00:00:00 2001
From: Rutherther <rutherther@proton.me>
Date: Sat, 4 May 2024 20:59:51 +0200
Subject: fix: make sure selmon doesn't get set to disabled mon

---
 dwl.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/dwl.c b/dwl.c
index 79ccb34..83bdbe4 100644
--- a/dwl.c
+++ b/dwl.c
@@ -727,6 +727,9 @@ closemon(Monitor *m)
 		do /* don't switch to disabled mons */
 			selmon = wl_container_of(mons.next, selmon, link);
 		while (!selmon->wlr_output->enabled && i++ < nmons);
+
+		if (!selmon->wlr_output->enabled)
+			selmon = NULL;
 	}
 
 	wl_list_for_each(c, &clients, link) {
@@ -2789,6 +2792,10 @@ updatemons(struct wl_listener *listener, void *data)
 
 		config_head->state.x = m->m.x;
 		config_head->state.y = m->m.y;
+
+		if (!selmon) {
+			selmon = m;
+		}
 	}
 
 	if (selmon && selmon->wlr_output->enabled) {
-- 
cgit v1.2.3