diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 1bd68436..ae4fb4ff 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -1193,7 +1193,7 @@ int32_t tagsilent(const Arg *arg) { return 0; } -int32_t tagtoleft_general(const Arg *arg, bool silent) { +int32_t tagtoside_general(const Arg *arg, bool silent, bool left) { if (!selmon) return 0; @@ -1201,11 +1201,20 @@ int32_t tagtoleft_general(const Arg *arg, bool silent) { __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1) { uint32_t target = selmon->tagset[selmon->seltags]; - if (target & 1) { - // 1 wraps around to 9 - target |= 1 << LENGTH(tags); + + if (left) { + if (target & 1) { + // 1 wraps around to 9 + target |= 1 << LENGTH(tags); + } + target >>= 1; + } else { + target <<= 1; + if (target & 1 << LENGTH(tags)) { + // 9 wraps around to 1 + target |= 1; + } } - target >>= 1; if (silent) tagsilent(&(Arg){.ui = target, .i = arg->i}); @@ -1216,41 +1225,19 @@ int32_t tagtoleft_general(const Arg *arg, bool silent) { } int32_t tagtoleft(const Arg *arg) { - return tagtoleft_general(arg, false); + return tagtoside_general(arg, false, true); } int32_t tagtoleftsilent(const Arg *arg) { - return tagtoleft_general(arg, true); -} - -int32_t tagtoright_general(const Arg *arg, bool silent) { - if (!selmon) - return 0; - - if (selmon->sel != NULL && - __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1) { - - uint32_t target = selmon->tagset[selmon->seltags]; - target <<= 1; - if (target & 1 << LENGTH(tags)) { - // 9 wraps around to 1 - target |= 1; - } - - if (silent) - tagsilent(&(Arg){.ui = target, .i = arg->i}); - else - tag(&(Arg){.ui = target, .i = arg->i}); - } - return 0; + return tagtoside_general(arg, true, true); } int32_t tagtoright(const Arg *arg) { - return tagtoright_general(arg, false); + return tagtoside_general(arg, false, false); } int32_t tagtorightsilent(const Arg *arg) { - return tagtoright_general(arg, true); + return tagtoside_general(arg, true, false); } int32_t toggle_named_scratchpad(const Arg *arg) {