opt: optimize focusmon and tagmon arg

This commit is contained in:
DreamMaoMao 2025-08-16 11:24:09 +08:00
parent bf4b96104e
commit b186437314
2 changed files with 26 additions and 9 deletions

View file

@ -740,7 +740,9 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
} else if (strcmp(func_name, "tagmon") == 0) { } else if (strcmp(func_name, "tagmon") == 0) {
func = tagmon; func = tagmon;
(*arg).i = parse_direction(arg_value); (*arg).i = parse_direction(arg_value);
(*arg).ui = atoi(arg_value2); if ((*arg).i == UNDIR) {
(*arg).v = strdup(arg_value);
};
} else if (strcmp(func_name, "incgaps") == 0) { } else if (strcmp(func_name, "incgaps") == 0) {
func = incgaps; func = incgaps;
(*arg).i = atoi(arg_value); (*arg).i = atoi(arg_value);

View file

@ -102,24 +102,26 @@ void focuslast(const Arg *arg) {
void focusmon(const Arg *arg) { void focusmon(const Arg *arg) {
Client *c; Client *c;
Monitor *m = NULL; Monitor *m = NULL;
int i = 0, nmons = wl_list_length(&mons);
if (nmons && arg->i != UNDIR) { if (arg->i != UNDIR) {
do /* don't switch to disabled mons */ m = dirtomon(arg->i);
selmon = dirtomon(arg->i);
while (!selmon->wlr_output->enabled && i++ < nmons);
} else if (arg->v) { } else if (arg->v) {
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link) {
if (!m->wlr_output->enabled) { if (!m->wlr_output->enabled) {
continue; continue;
} }
if (regex_match(arg->v, m->wlr_output->name)) { if (regex_match(arg->v, m->wlr_output->name)) {
selmon = m;
break; break;
} }
} }
} else { } else {
return; return;
} }
if (!m || !m->wlr_output->enabled)
return;
selmon = m;
warp_cursor_to_selmon(selmon); warp_cursor_to_selmon(selmon);
c = focustop(selmon); c = focustop(selmon);
if (!c) { if (!c) {
@ -836,13 +838,26 @@ void tag(const Arg *arg) {
} }
void tagmon(const Arg *arg) { void tagmon(const Arg *arg) {
Monitor *m; Monitor *m = NULL;
Client *c = focustop(selmon); Client *c = focustop(selmon);
if (!c) if (!c)
return; return;
if (arg->i != UNDIR) {
m = dirtomon(arg->i); m = 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)) {
break;
}
}
} else {
return;
}
if (!m || !m->wlr_output->enabled || m == c->mon) if (!m || !m->wlr_output->enabled || m == c->mon)
return; return;