fix crash when the last monitor is disconnected

This commit is contained in:
Leonardo Hernandez Hernandez 2021-11-04 08:19:13 -06:00 committed by Leonardo Hernández Hernández
parent 3e6d584de1
commit 6e2bb01818
No known key found for this signature in database
GPG Key ID: E538897EE11B9624

9
dwl.c
View File

@ -720,10 +720,11 @@ cleanupmon(struct wl_listener *listener, void *data)
wl_list_remove(&m->link);
wlr_output_layout_remove(output_layout, m->wlr_output);
nmons = wl_list_length(&mons);
do // don't switch to disabled mons
selmon = wl_container_of(mons.prev, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
if ((nmons = wl_list_length(&mons)))
do // don't switch to disabled mons
selmon = wl_container_of(mons.prev, selmon, link);
while (!selmon->wlr_output->enabled && i++ < nmons);
focusclient(focustop(selmon), 1);
closemon(m);
free(m);