oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

Fixed wrapping on next/prev and next_nonempty/prev_nonempty with remainder (rem_euclid), similar to dwms "adjacent_tag" patch.

Commit
b856bdad934654760f47bb271074f36f8fc49258
Parent
183a8e1
Author
tonybtw <tonybtw@tonybtw.com>
Date
2025-12-14 16:01:55

Diff

diff --git a/resources/test-config.lua b/resources/test-config.lua
index 0ff7764..fbe6862 100644
--- a/resources/test-config.lua
+++ b/resources/test-config.lua
@@ -145,6 +145,12 @@ oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
 oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
 oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
 
+oxwm.key.bind({ modkey }, "Tab", oxwm.tag.view_next())
+oxwm.key.bind({ modkey, "Shift" }, "Tab", oxwm.tag.view_previous())
+
+oxwm.key.bind({ modkey, "Control" }, "Tab", oxwm.tag.view_next_nonempty())
+oxwm.key.bind({ modkey, "Control", "Shift" }, "Tab", oxwm.tag.view_previous_nonempty())
+
 oxwm.bar.set_blocks({
     oxwm.bar.block.battery({
         format = "Bat: {}%",
diff --git a/src/window_manager.rs b/src/window_manager.rs
index c5f569a..76af590 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -813,38 +813,40 @@ impl WindowManager {
             }
             KeyAction::ViewNextTag => {
                 let monitor = self.get_selected_monitor();
-                let current_tag_mask = monitor.get_selected_tag();
-
-                let current_tag_index = unmask_tag(current_tag_mask);
-                self.view_tag(current_tag_index.saturating_add(1))?;
+                let current_tag_index = unmask_tag(monitor.get_selected_tag()) as i32;
+                let len = self.config.tags.len() as i32;
+                self.view_tag((current_tag_index + 1).rem_euclid(len) as usize)?;
             }
             KeyAction::ViewPreviousTag => {
                 let monitor = self.get_selected_monitor();
-                let current_tag_mask = monitor.get_selected_tag();
-
-                let current_tag_index = unmask_tag(current_tag_mask);
-                self.view_tag(current_tag_index.saturating_sub(1))?;
+                let current_tag_index = unmask_tag(monitor.get_selected_tag()) as i32;
+                let len = self.config.tags.len() as i32;
+                self.view_tag((current_tag_index - 1).rem_euclid(len) as usize)?;
             }
             KeyAction::ViewNextNonEmptyTag => {
                 let monitor = self.get_selected_monitor();
-                let current_tag_mask = monitor.get_selected_tag();
-                let current_tag_index = unmask_tag(current_tag_mask);
-
-                for next_tag_index in (current_tag_index + 1)..self.config.tags.len() {
-                    if self.has_windows_on_tag(monitor.monitor_number, next_tag_index) {
-                        self.view_tag(next_tag_index)?;
+                let current = unmask_tag(monitor.get_selected_tag()) as i32;
+                let len = self.config.tags.len() as i32;
+                let mon_num = monitor.monitor_number;
+
+                for offset in 1..len {
+                    let next = (current + offset).rem_euclid(len) as usize;
+                    if self.has_windows_on_tag(mon_num, next) {
+                        self.view_tag(next)?;
                         break;
                     }
                 }
             }
             KeyAction::ViewPreviousNonEmptyTag => {
                 let monitor = self.get_selected_monitor();
-                let current_tag_mask = monitor.get_selected_tag();
-                let current_tag_index = unmask_tag(current_tag_mask);
-
-                for prev_tag_index in (0..current_tag_index).rev() {
-                    if self.has_windows_on_tag(monitor.monitor_number, prev_tag_index) {
-                        self.view_tag(prev_tag_index)?;
+                let current = unmask_tag(monitor.get_selected_tag()) as i32;
+                let len = self.config.tags.len() as i32;
+                let mon_num = monitor.monitor_number;
+
+                for offset in 1..len {
+                    let prev = (current - offset).rem_euclid(len) as usize;
+                    if self.has_windows_on_tag(mon_num, prev) {
+                        self.view_tag(prev)?;
                         break;
                     }
                 }