aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStivvo <stivvo01@gmail.com>2020-10-31 17:10:06 +0100
committerStivvo <stivvo01@gmail.com>2020-10-31 17:11:16 +0100
commit80a685ee51da69ae0a7bae11620c5f33c3cd2de2 (patch)
treeeb3b97ceab572d7aabaacf84824e77a580e9ad82
parent5221a329e254627c186ba8e4d68f9595d4e3158a (diff)
Fix crash with no monitors left
When there's no monitors left, prevent the while in cleanupmon() to become an infinite loop Also switch to the left monitors instead of the right
-rw-r--r--dwl.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/dwl.c b/dwl.c
index ca352c4..d875eaa 100644
--- a/dwl.c
+++ b/dwl.c
@@ -696,20 +696,19 @@ cleanupmon(struct wl_listener *listener, void *data)
{
struct wlr_output *wlr_output = data;
Monitor *m = wlr_output->data;
+ int nmons = wl_list_length(&mons), i = 0;
wl_list_remove(&m->destroy.link);
wl_list_remove(&m->frame.link);
wl_list_remove(&m->link);
wlr_output_layout_remove(output_layout, m->wlr_output);
-
updatemons();
do // don't switch to disabled mons
- selmon = wl_container_of(mons.next, selmon, link);
- while (!selmon->wlr_output->enabled);
+ selmon = wl_container_of(mons.prev, selmon, link);
+ while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(selclient(), focustop(selmon), 1);
closemon(m);
-
free(m);
}