fix: crash when focusmon to invalid monitor

This commit is contained in:
DreamMaoMao
2025-12-16 11:34:52 +08:00
parent acb3fc2a2a
commit db2151af64

View File

@@ -173,15 +173,17 @@ int toggle_trackpad_enable(const Arg *arg) {
int focusmon(const Arg *arg) {
Client *c = NULL;
Monitor *m = NULL;
Monitor *tm = NULL;
if (arg->i != UNDIR) {
m = dirtomon(arg->i);
tm = dirtomon(arg->i);
} else if (arg->v) {
wl_list_for_each(m, &mons, link) {
if (!m->wlr_output->enabled) {
continue;
}
if (regex_match(arg->v, m->wlr_output->name)) {
tm = m;
break;
}
}
@@ -189,10 +191,10 @@ int focusmon(const Arg *arg) {
return 0;
}
if (!m || !m->wlr_output->enabled || m == selmon)
if (!tm || !tm->wlr_output->enabled || tm == selmon)
return 0;
selmon = m;
selmon = tm;
if (warpcursor) {
warp_cursor_to_selmon(selmon);
}