summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shiftview.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/shiftview.c b/shiftview.c
index fa53db0..ddd81ef 100644
--- a/shiftview.c
+++ b/shiftview.c
@@ -1,34 +1,30 @@
-// "arg->i" stores the number of tags to shift right (positive value)
-// or left (negative value)
+// shiftview all tags regardless of tags having open windows
void
shiftview(const Arg *arg)
{
- Arg a;
- Client *c;
- bool visible = false;
- int i = arg->i;
- int count = 0;
- int nextseltags, curseltags = selmon->tagset[selmon->seltags];
+ Arg view_argument;
+ uint32_t destination_tag;
- do {
- if (i > 0) // left circular shift
- nextseltags = (curseltags << i) | (curseltags >> (TAGCOUNT - i));
- else // right circular shift
- nextseltags = curseltags >> (-i) | (curseltags << (TAGCOUNT + i));
+ // arg->i represents the direction and distance passed from config.def.h (usually -1 and +1)
+ if(arg->i > 0){
+ // shift right (increase tag index), move the active tag bit to the left (0001) to (0010)
+ destination_tag = selmon->tagset[selmon->seltags] << arg->i;
+ }else{
+ // shift to the left
+ destination_tag = selmon->tagset[selmon->seltags] >> (-arg->i);
+ }
- // Check if the tag is visible
- wl_list_for_each(c, &clients, link) {
- if (c->mon == selmon && nextseltags & c->tags) {
- visible = true;
- break;
- }
- }
+ // TAGMASK defines the valid boundary for tags (111111111) for 9 tags
+ // if the shift pushed the active bit outside the bounds, destination_tag will become 0
+ if(!(destination_tag & TAGMASK)){
+ // If we went off to the right edge, wrap around to the first tag (000000001)
+ // If we went off to the left, wrap around to the last tag (bit 1 shifted left by TAGCOUNT - 1)
+ destination_tag = arg->i > 0 ? 1 : 1 << (TAGCOUNT - 1);
+ }
- i += arg->i;
- } while (!visible && ++count <= TAGCOUNT);
-
- if (count <= TAGCOUNT) {
- a.i = nextseltags;
- view(&a);
- }
+ // pack the destination tag bitmask into the required dwl argument struct
+ view_argument.ui = destination_tag;
+
+ // pass the destination tag to dwl's view function
+ view(&view_argument);
}