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
This commit is contained in:
Stivvo 2020-10-31 17:10:06 +01:00
parent 5221a329e2
commit 80a685ee51

7
dwl.c
View file

@ -696,20 +696,19 @@ cleanupmon(struct wl_listener *listener, void *data)
{ {
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
Monitor *m = 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->destroy.link);
wl_list_remove(&m->frame.link); wl_list_remove(&m->frame.link);
wl_list_remove(&m->link); wl_list_remove(&m->link);
wlr_output_layout_remove(output_layout, m->wlr_output); wlr_output_layout_remove(output_layout, m->wlr_output);
updatemons(); updatemons();
do // don't switch to disabled mons do // don't switch to disabled mons
selmon = wl_container_of(mons.next, selmon, link); selmon = wl_container_of(mons.prev, selmon, link);
while (!selmon->wlr_output->enabled); while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(selclient(), focustop(selmon), 1); focusclient(selclient(), focustop(selmon), 1);
closemon(m); closemon(m);
free(m); free(m);
} }