tony / oxwm

Fixed wrapping on next/prev and next_nonempty/prev_nonempty with remainder (rem_euclid), similar to dwms "adjacent_tag" patch. Browse files
tonybtw committed 2025-12-14 parent 183a8e1 commit b856bdad934654760f47bb271074f36f8fc49258
Showing 2 changed files with 28 additions and 20 deletions. UnifiedSplit
+6 −0 resources/test-config.lua
@@ -145,6 +145,12 @@ oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
145 145 oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
146 146 oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
147 147
148 +oxwm.key.bind({ modkey }, "Tab", oxwm.tag.view_next())
149 +oxwm.key.bind({ modkey, "Shift" }, "Tab", oxwm.tag.view_previous())
150 +
151 +oxwm.key.bind({ modkey, "Control" }, "Tab", oxwm.tag.view_next_nonempty())
152 +oxwm.key.bind({ modkey, "Control", "Shift" }, "Tab", oxwm.tag.view_previous_nonempty())
153 +
148 154 oxwm.bar.set_blocks({
149 155 oxwm.bar.block.battery({
150 156 format = "Bat: {}%",
+22 −20 src/window_manager.rs
@@ -813,38 +813,40 @@ impl WindowManager {
813 813 }
814 814 KeyAction::ViewNextTag => {
815 815 let monitor = self.get_selected_monitor();
816 - let current_tag_mask = monitor.get_selected_tag();
817 -
818 - let current_tag_index = unmask_tag(current_tag_mask);
819 - self.view_tag(current_tag_index.saturating_add(1))?;
816 + let current_tag_index = unmask_tag(monitor.get_selected_tag()) as i32;
817 + let len = self.config.tags.len() as i32;
818 + self.view_tag((current_tag_index + 1).rem_euclid(len) as usize)?;
820 819 }
821 820 KeyAction::ViewPreviousTag => {
822 821 let monitor = self.get_selected_monitor();
823 - let current_tag_mask = monitor.get_selected_tag();
824 -
825 - let current_tag_index = unmask_tag(current_tag_mask);
826 - self.view_tag(current_tag_index.saturating_sub(1))?;
822 + let current_tag_index = unmask_tag(monitor.get_selected_tag()) as i32;
823 + let len = self.config.tags.len() as i32;
824 + self.view_tag((current_tag_index - 1).rem_euclid(len) as usize)?;
827 825 }
828 826 KeyAction::ViewNextNonEmptyTag => {
829 827 let monitor = self.get_selected_monitor();
830 - let current_tag_mask = monitor.get_selected_tag();
831 - let current_tag_index = unmask_tag(current_tag_mask);
832 -
833 - for next_tag_index in (current_tag_index + 1)..self.config.tags.len() {
834 - if self.has_windows_on_tag(monitor.monitor_number, next_tag_index) {
835 - self.view_tag(next_tag_index)?;
828 + let current = unmask_tag(monitor.get_selected_tag()) as i32;
829 + let len = self.config.tags.len() as i32;
830 + let mon_num = monitor.monitor_number;
831 +
832 + for offset in 1..len {
833 + let next = (current + offset).rem_euclid(len) as usize;
834 + if self.has_windows_on_tag(mon_num, next) {
835 + self.view_tag(next)?;
836 836 break;
837 837 }
838 838 }
839 839 }
840 840 KeyAction::ViewPreviousNonEmptyTag => {
841 841 let monitor = self.get_selected_monitor();
842 - let current_tag_mask = monitor.get_selected_tag();
843 - let current_tag_index = unmask_tag(current_tag_mask);
844 -
845 - for prev_tag_index in (0..current_tag_index).rev() {
846 - if self.has_windows_on_tag(monitor.monitor_number, prev_tag_index) {
847 - self.view_tag(prev_tag_index)?;
842 + let current = unmask_tag(monitor.get_selected_tag()) as i32;
843 + let len = self.config.tags.len() as i32;
844 + let mon_num = monitor.monitor_number;
845 +
846 + for offset in 1..len {
847 + let prev = (current - offset).rem_euclid(len) as usize;
848 + if self.has_windows_on_tag(mon_num, prev) {
849 + self.view_tag(prev)?;
848 850 break;
849 851 }
850 852 }