mirror of
https://codeberg.org/dwl/dwl-patches.git
synced 2026-03-24 09:51:36 +00:00
shifttag: fix shifting to unoccupied with multiple tags
This commit is contained in:
parent
039be1a6cf
commit
24fa6e04ce
@ -1,13 +1,13 @@
|
|||||||
From 6d3a0506f45243cf11f0f7ba06048f453576567c Mon Sep 17 00:00:00 2001
|
From 8dff34be15664705654e5e4d41f990f8eba8b79d Mon Sep 17 00:00:00 2001
|
||||||
From: nate zhou <gnuunixchad@outlook.com>
|
From: nate zhou <gnuunixchad@outlook.com>
|
||||||
Date: Mon, 23 Mar 2026 01:16:06 +0800
|
Date: Mon, 23 Mar 2026 01:16:06 +0800
|
||||||
Subject: [PATCH] shifttag with filtering occupied/unoccupied tags support for
|
Subject: [PATCH] shifttag with filtering occupied/unoccupied tags support for
|
||||||
bar patch
|
bar patch
|
||||||
|
|
||||||
---
|
---
|
||||||
config.def.h | 8 +++++
|
config.def.h | 8 ++++
|
||||||
shifttag.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
shifttag.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
2 files changed, 107 insertions(+)
|
2 files changed, 123 insertions(+)
|
||||||
create mode 100644 shifttag.c
|
create mode 100644 shifttag.c
|
||||||
|
|
||||||
diff --git a/config.def.h b/config.def.h
|
diff --git a/config.def.h b/config.def.h
|
||||||
@ -38,10 +38,10 @@ index 7da50d2..9fbcf2a 100644
|
|||||||
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
|
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
|
||||||
diff --git a/shifttag.c b/shifttag.c
|
diff --git a/shifttag.c b/shifttag.c
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..2615f4c
|
index 0000000..5f1d5c2
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/shifttag.c
|
+++ b/shifttag.c
|
||||||
@@ -0,0 +1,99 @@
|
@@ -0,0 +1,115 @@
|
||||||
+// "arg->i" stores the number of tags to shift right (positive value)
|
+// "arg->i" stores the number of tags to shift right (positive value)
|
||||||
+// or left (negative value)
|
+// or left (negative value)
|
||||||
+
|
+
|
||||||
@ -61,45 +61,61 @@ index 0000000..2615f4c
|
|||||||
+find_next_tag(uint32_t current_tag, int direction, bool skip_unoccupied, bool skip_occupied)
|
+find_next_tag(uint32_t current_tag, int direction, bool skip_unoccupied, bool skip_occupied)
|
||||||
+{
|
+{
|
||||||
+ uint32_t occupied = get_occupied_tags(selmon);
|
+ uint32_t occupied = get_occupied_tags(selmon);
|
||||||
+ uint32_t start = current_tag;
|
+ uint32_t result = 0;
|
||||||
+ uint32_t test_tag = current_tag;
|
|
||||||
+ uint32_t new_tag = current_tag;
|
|
||||||
+ int count = 0;
|
|
||||||
+
|
+
|
||||||
+ if (!skip_unoccupied && !skip_occupied) {
|
+ for (int i = 0; i < LENGTH(tags); i++) {
|
||||||
+ if (direction > 0) {
|
+ uint32_t bit = 1 << i;
|
||||||
+ new_tag = (current_tag << 1) | (current_tag >> (LENGTH(tags) - 1));
|
+
|
||||||
+ } else {
|
+ if (current_tag & bit) {
|
||||||
+ new_tag = (current_tag >> 1) | (current_tag << (LENGTH(tags) - 1));
|
+ uint32_t new_bit = bit;
|
||||||
|
+
|
||||||
|
+ if (!skip_unoccupied && !skip_occupied) {
|
||||||
|
+ if (direction > 0) {
|
||||||
|
+ if (bit << 1 && (bit << 1) <= TAGMASK)
|
||||||
|
+ new_bit = bit << 1;
|
||||||
|
+ else
|
||||||
|
+ new_bit = 1;
|
||||||
|
+ } else {
|
||||||
|
+ if (bit >> 1)
|
||||||
|
+ new_bit = bit >> 1;
|
||||||
|
+ else
|
||||||
|
+ new_bit = 1 << (LENGTH(tags) - 1);
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ uint32_t test_bit = bit;
|
||||||
|
+ uint32_t start_bit = bit;
|
||||||
|
+ int count = 0;
|
||||||
|
+
|
||||||
|
+ do {
|
||||||
|
+ if (direction > 0) {
|
||||||
|
+ if (test_bit << 1 && (test_bit << 1) <= TAGMASK)
|
||||||
|
+ test_bit = test_bit << 1;
|
||||||
|
+ else
|
||||||
|
+ test_bit = 1;
|
||||||
|
+ } else {
|
||||||
|
+ if (test_bit >> 1)
|
||||||
|
+ test_bit = test_bit >> 1;
|
||||||
|
+ else
|
||||||
|
+ test_bit = 1 << (LENGTH(tags) - 1);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ int is_occupied = (occupied & test_bit) != 0;
|
||||||
|
+ int should_select = (skip_unoccupied && is_occupied) ||
|
||||||
|
+ (skip_occupied && !is_occupied);
|
||||||
|
+
|
||||||
|
+ if (should_select) {
|
||||||
|
+ new_bit = test_bit;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ count++;
|
||||||
|
+ } while (test_bit != start_bit && count < LENGTH(tags));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ result |= new_bit;
|
||||||
+ }
|
+ }
|
||||||
+ return new_tag & TAGMASK;
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ do {
|
+ return result;
|
||||||
+ if (direction > 0) {
|
|
||||||
+ if (test_tag << 1 && (test_tag << 1) <= TAGMASK)
|
|
||||||
+ test_tag = test_tag << 1;
|
|
||||||
+ else
|
|
||||||
+ test_tag = 1;
|
|
||||||
+ } else {
|
|
||||||
+ if (test_tag >> 1)
|
|
||||||
+ test_tag = test_tag >> 1;
|
|
||||||
+ else
|
|
||||||
+ test_tag = 1 << (LENGTH(tags) - 1);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ int is_occupied = (occupied & test_tag) != 0;
|
|
||||||
+ int should_select = (skip_unoccupied && is_occupied) ||
|
|
||||||
+ (skip_occupied && !is_occupied);
|
|
||||||
+
|
|
||||||
+ if (should_select) {
|
|
||||||
+ new_tag = test_tag;
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+ count++;
|
|
||||||
+ } while (test_tag != start && count < LENGTH(tags));
|
|
||||||
+
|
|
||||||
+ return new_tag;
|
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void
|
+static void
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
From 49b0da41f1f28a60cf216f5bffecc0ce1ea1ec9c Mon Sep 17 00:00:00 2001
|
From 2a4417a6344c9d4b83989d63df17d9cdb0f81aea Mon Sep 17 00:00:00 2001
|
||||||
From: nate zhou <gnuunixchad@outlook.com>
|
From: nate zhou <gnuunixchad@outlook.com>
|
||||||
Date: Mon, 23 Mar 2026 00:50:54 +0800
|
Date: Mon, 23 Mar 2026 00:50:54 +0800
|
||||||
Subject: [PATCH] shifttag with filtering occupied/unoccupied tags support
|
Subject: [PATCH] shifttag with filtering occupied/unoccupied tags support
|
||||||
|
|
||||||
---
|
---
|
||||||
config.def.h | 8 +++++
|
config.def.h | 8 ++++
|
||||||
shifttag.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
shifttag.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
2 files changed, 107 insertions(+)
|
2 files changed, 123 insertions(+)
|
||||||
create mode 100644 shifttag.c
|
create mode 100644 shifttag.c
|
||||||
|
|
||||||
diff --git a/config.def.h b/config.def.h
|
diff --git a/config.def.h b/config.def.h
|
||||||
@ -37,10 +37,10 @@ index 8a6eda0..2377fa5 100644
|
|||||||
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
|
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
|
||||||
diff --git a/shifttag.c b/shifttag.c
|
diff --git a/shifttag.c b/shifttag.c
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..5aeee00
|
index 0000000..971216b
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/shifttag.c
|
+++ b/shifttag.c
|
||||||
@@ -0,0 +1,99 @@
|
@@ -0,0 +1,115 @@
|
||||||
+// "arg->i" stores the number of tags to shift right (positive value)
|
+// "arg->i" stores the number of tags to shift right (positive value)
|
||||||
+// or left (negative value)
|
+// or left (negative value)
|
||||||
+
|
+
|
||||||
@ -60,45 +60,61 @@ index 0000000..5aeee00
|
|||||||
+find_next_tag(uint32_t current_tag, int direction, bool skip_unoccupied, bool skip_occupied)
|
+find_next_tag(uint32_t current_tag, int direction, bool skip_unoccupied, bool skip_occupied)
|
||||||
+{
|
+{
|
||||||
+ uint32_t occupied = get_occupied_tags(selmon);
|
+ uint32_t occupied = get_occupied_tags(selmon);
|
||||||
+ uint32_t start = current_tag;
|
+ uint32_t result = 0;
|
||||||
+ uint32_t test_tag = current_tag;
|
|
||||||
+ uint32_t new_tag = current_tag;
|
|
||||||
+ int count = 0;
|
|
||||||
+
|
+
|
||||||
+ if (!skip_unoccupied && !skip_occupied) {
|
+ for (int i = 0; i < TAGCOUNT; i++) {
|
||||||
+ if (direction > 0) {
|
+ uint32_t bit = 1 << i;
|
||||||
+ new_tag = (current_tag << 1) | (current_tag >> (TAGCOUNT - 1));
|
+
|
||||||
+ } else {
|
+ if (current_tag & bit) {
|
||||||
+ new_tag = (current_tag >> 1) | (current_tag << (TAGCOUNT - 1));
|
+ uint32_t new_bit = bit;
|
||||||
|
+
|
||||||
|
+ if (!skip_unoccupied && !skip_occupied) {
|
||||||
|
+ if (direction > 0) {
|
||||||
|
+ if (bit << 1 && (bit << 1) <= TAGMASK)
|
||||||
|
+ new_bit = bit << 1;
|
||||||
|
+ else
|
||||||
|
+ new_bit = 1;
|
||||||
|
+ } else {
|
||||||
|
+ if (bit >> 1)
|
||||||
|
+ new_bit = bit >> 1;
|
||||||
|
+ else
|
||||||
|
+ new_bit = 1 << (TAGCOUNT - 1);
|
||||||
|
+ }
|
||||||
|
+ } else {
|
||||||
|
+ uint32_t test_bit = bit;
|
||||||
|
+ uint32_t start_bit = bit;
|
||||||
|
+ int count = 0;
|
||||||
|
+
|
||||||
|
+ do {
|
||||||
|
+ if (direction > 0) {
|
||||||
|
+ if (test_bit << 1 && (test_bit << 1) <= TAGMASK)
|
||||||
|
+ test_bit = test_bit << 1;
|
||||||
|
+ else
|
||||||
|
+ test_bit = 1;
|
||||||
|
+ } else {
|
||||||
|
+ if (test_bit >> 1)
|
||||||
|
+ test_bit = test_bit >> 1;
|
||||||
|
+ else
|
||||||
|
+ test_bit = 1 << (TAGCOUNT - 1);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ int is_occupied = (occupied & test_bit) != 0;
|
||||||
|
+ int should_select = (skip_unoccupied && is_occupied) ||
|
||||||
|
+ (skip_occupied && !is_occupied);
|
||||||
|
+
|
||||||
|
+ if (should_select) {
|
||||||
|
+ new_bit = test_bit;
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ count++;
|
||||||
|
+ } while (test_bit != start_bit && count < TAGCOUNT);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ result |= new_bit;
|
||||||
+ }
|
+ }
|
||||||
+ return new_tag & TAGMASK;
|
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ do {
|
+ return result;
|
||||||
+ if (direction > 0) {
|
|
||||||
+ if (test_tag << 1 && (test_tag << 1) <= TAGMASK)
|
|
||||||
+ test_tag = test_tag << 1;
|
|
||||||
+ else
|
|
||||||
+ test_tag = 1;
|
|
||||||
+ } else {
|
|
||||||
+ if (test_tag >> 1)
|
|
||||||
+ test_tag = test_tag >> 1;
|
|
||||||
+ else
|
|
||||||
+ test_tag = 1 << (TAGCOUNT - 1);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ int is_occupied = (occupied & test_tag) != 0;
|
|
||||||
+ int should_select = (skip_unoccupied && is_occupied) ||
|
|
||||||
+ (skip_occupied && !is_occupied);
|
|
||||||
+
|
|
||||||
+ if (should_select) {
|
|
||||||
+ new_tag = test_tag;
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+ count++;
|
|
||||||
+ } while (test_tag != start && count < TAGCOUNT);
|
|
||||||
+
|
|
||||||
+ return new_tag;
|
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
+static void
|
+static void
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user