opt: Re-implement view left and view right logic

This commit is contained in:
DreamMaoMao 2025-09-10 11:38:39 +08:00
parent 258550fa0a
commit b8f3bec0be
2 changed files with 32 additions and 107 deletions

View file

@ -1177,7 +1177,6 @@ void toggleview(const Arg *arg) {
printstatus(); printstatus();
} }
void viewtoleft(const Arg *arg) { void viewtoleft(const Arg *arg) {
unsigned int tmptag;
unsigned int target = selmon->tagset[selmon->seltags]; unsigned int target = selmon->tagset[selmon->seltags];
if (selmon->isoverview || selmon->pertag->curtag == 0) { if (selmon->isoverview || selmon->pertag->curtag == 0) {
@ -1192,26 +1191,13 @@ void viewtoleft(const Arg *arg) {
if (!selmon || (target) == selmon->tagset[selmon->seltags]) if (!selmon || (target) == selmon->tagset[selmon->seltags])
return; return;
selmon->seltags ^= 1; /* toggle sel tagset */
if (target) {
selmon->tagset[selmon->seltags] = target;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = selmon->pertag->curtag - 1;
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
focusclient(focustop(selmon), 1); view(&(Arg){.ui = target & TAGMASK}, true);
arrange(selmon, true);
printstatus();
} }
void viewtoright(const Arg *arg) { void viewtoright(const Arg *arg) {
if (selmon->isoverview || selmon->pertag->curtag == 0) { if (selmon->isoverview || selmon->pertag->curtag == 0) {
return; return;
} }
unsigned int tmptag;
unsigned int target = selmon->tagset[selmon->seltags]; unsigned int target = selmon->tagset[selmon->seltags];
target <<= 1; target <<= 1;
@ -1220,120 +1206,58 @@ void viewtoright(const Arg *arg) {
if (!(target & TAGMASK)) { if (!(target & TAGMASK)) {
return; return;
} }
selmon->seltags ^= 1; /* toggle sel tagset */
if (target) {
selmon->tagset[selmon->seltags] = target;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = selmon->pertag->curtag + 1;
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
focusclient(focustop(selmon), 1); view(&(Arg){.ui = target & TAGMASK}, true);
arrange(selmon, true);
printstatus();
} }
void viewtoleft_have_client(const Arg *arg) { void viewtoleft_have_client(const Arg *arg) {
unsigned int tmptag; unsigned int n;
Client *c; unsigned int current =
unsigned int found = 0; get_tags_first_tag_num(selmon->tagset[selmon->seltags]);
unsigned int n = 1; bool found = false;
unsigned int target = selmon->tagset[selmon->seltags];
if (selmon->isoverview || selmon->pertag->curtag == 0) { if (selmon->isoverview) {
return; return;
} }
for (target >>= 1; target > 0 && n <= LENGTH(tags); target >>= 1, n++) { if (current <= 1)
wl_list_for_each(c, &clients, link) { return;
if (c->mon == selmon && target & c->tags) {
found = 1; for (n = current - 1; n >= 1; n--) {
break; if (get_tag_status(n, selmon)) {
} found = true;
}
if (found) {
break; break;
} }
} }
if (target == 0) { if (found)
return; view(&(Arg){.ui = (1 << (n - 1)) & TAGMASK}, true);
}
if (!selmon || (target) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
int new_tag = selmon->pertag->curtag - n;
if (new_tag < 1)
new_tag = 1;
if (target) {
selmon->tagset[selmon->seltags] = target;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = new_tag;
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
focusclient(focustop(selmon), 1);
arrange(selmon, true);
printstatus();
} }
void viewtoright_have_client(const Arg *arg) { void viewtoright_have_client(const Arg *arg) {
unsigned int tmptag; unsigned int n;
Client *c; unsigned int current =
unsigned int found = 0; get_tags_first_tag_num(selmon->tagset[selmon->seltags]);
unsigned int n = 1; bool found = false;
unsigned int target = selmon->tagset[selmon->seltags];
if (selmon->isoverview || selmon->pertag->curtag == 0) { if (selmon->isoverview) {
return; return;
} }
for (target <<= 1; target & TAGMASK && n <= LENGTH(tags); if (current >= LENGTH(tags))
target <<= 1, n++) { return;
wl_list_for_each(c, &clients, link) {
if (c->mon == selmon && target & c->tags) { for (n = current + 1; n <= LENGTH(tags); n++) {
found = 1; if (get_tag_status(n, selmon)) {
break; found = true;
}
}
if (found) {
break; break;
} }
} }
if (!(target & TAGMASK)) { if (found)
return; view(&(Arg){.ui = (1 << (n - 1)) & TAGMASK}, true);
}
if (!selmon || (target) == selmon->tagset[selmon->seltags])
return;
selmon->seltags ^= 1; /* toggle sel tagset */
int new_tag = selmon->pertag->curtag + n;
if (new_tag > LENGTH(tags))
new_tag = LENGTH(tags);
if (target) {
selmon->tagset[selmon->seltags] = target;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = new_tag;
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
}
focusclient(focustop(selmon), 1);
arrange(selmon, true);
printstatus();
} }
void zoom(const Arg *arg) { void zoom(const Arg *arg) {
Client *c, *sel = focustop(selmon); Client *c, *sel = focustop(selmon);

View file

@ -694,6 +694,7 @@ void apply_named_scratchpad(Client *target_client);
Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title); Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title);
bool switch_scratchpad_client_state(Client *c); bool switch_scratchpad_client_state(Client *c);
bool check_trackpad_disabled(struct wlr_pointer *pointer); bool check_trackpad_disabled(struct wlr_pointer *pointer);
unsigned int get_tag_status(unsigned int tag, Monitor *m);
#include "data/static_keymap.h" #include "data/static_keymap.h"
#include "dispatch/bind_declare.h" #include "dispatch/bind_declare.h"