tony / oxwm

Add view next/previous tag actions Browse files
emzywastaken committed 2025-12-13 parent cba2953 commit ddba5cee5e5ba7cd59d00e771eafc808616abc44
Showing 6 changed files with 52 additions and 2 deletions. UnifiedSplit
+10 −0 src/config/lua_api.rs
@@ -303,6 +303,12 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
303 create_action_table(lua, "ViewTag", Value::Integer(idx as i64)) 303 create_action_table(lua, "ViewTag", Value::Integer(idx as i64))
304 })?; 304 })?;
305 305
306 + let view_next =
307 + lua.create_function(|lua, ()| create_action_table(lua, "ViewNextTag", Value::Nil))?;
308 +
309 + let view_previous =
310 + lua.create_function(|lua, ()| create_action_table(lua, "ViewPreviousTag", Value::Nil))?;
311 +
306 let toggleview = lua.create_function(|lua, idx: i32| { 312 let toggleview = lua.create_function(|lua, idx: i32| {
307 create_action_table(lua, "ToggleView", Value::Integer(idx as i64)) 313 create_action_table(lua, "ToggleView", Value::Integer(idx as i64))
308 })?; 314 })?;
@@ -316,6 +322,8 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
316 })?; 322 })?;
317 323
318 tag_table.set("view", view)?; 324 tag_table.set("view", view)?;
325 + tag_table.set("view_next", view_next)?;
326 + tag_table.set("view_previous", view_previous)?;
319 tag_table.set("toggleview", toggleview)?; 327 tag_table.set("toggleview", toggleview)?;
320 tag_table.set("move_to", move_to)?; 328 tag_table.set("move_to", move_to)?;
321 tag_table.set("toggletag", toggletag)?; 329 tag_table.set("toggletag", toggletag)?;
@@ -845,6 +853,8 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
845 "Quit" => Ok(KeyAction::Quit), 853 "Quit" => Ok(KeyAction::Quit),
846 "Restart" => Ok(KeyAction::Restart), 854 "Restart" => Ok(KeyAction::Restart),
847 "ViewTag" => Ok(KeyAction::ViewTag), 855 "ViewTag" => Ok(KeyAction::ViewTag),
856 + "ViewNextTag" => Ok(KeyAction::ViewNextTag),
857 + "ViewPreviousTag" => Ok(KeyAction::ViewPreviousTag),
848 "ToggleView" => Ok(KeyAction::ToggleView), 858 "ToggleView" => Ok(KeyAction::ToggleView),
849 "MoveToTag" => Ok(KeyAction::MoveToTag), 859 "MoveToTag" => Ok(KeyAction::MoveToTag),
850 "ToggleTag" => Ok(KeyAction::ToggleTag), 860 "ToggleTag" => Ok(KeyAction::ToggleTag),
+2 −0 src/keyboard/handlers.rs
@@ -17,6 +17,8 @@ pub enum KeyAction {
17 Quit, 17 Quit,
18 Restart, 18 Restart,
19 ViewTag, 19 ViewTag,
20 + ViewNextTag,
21 + ViewPreviousTag,
20 ToggleView, 22 ToggleView,
21 MoveToTag, 23 MoveToTag,
22 ToggleTag, 24 ToggleTag,
+5 −0 src/monitor.rs
@@ -1,3 +1,4 @@
1 +use crate::client::TagMask;
1 use crate::errors::WmError; 2 use crate::errors::WmError;
2 use x11rb::protocol::xinerama::ConnectionExt as _; 3 use x11rb::protocol::xinerama::ConnectionExt as _;
3 use x11rb::protocol::xproto::{Screen, Window}; 4 use x11rb::protocol::xproto::{Screen, Window};
@@ -75,6 +76,10 @@ impl Monitor {
75 && y >= self.screen_y 76 && y >= self.screen_y
76 && y < self.screen_y + self.screen_height 77 && y < self.screen_y + self.screen_height
77 } 78 }
79 +
80 + pub fn get_selected_tag(&self) -> TagMask {
81 + self.tagset[self.selected_tags_index]
82 + }
78 } 83 }
79 84
80 pub fn detect_monitors( 85 pub fn detect_monitors(
+2 −0 src/overlay/keybind.rs
@@ -220,6 +220,8 @@ impl KeybindOverlay {
220 Arg::Int(n) => format!("View Workspace {}", n), 220 Arg::Int(n) => format!("View Workspace {}", n),
221 _ => "View Workspace".to_string(), 221 _ => "View Workspace".to_string(),
222 }, 222 },
223 + KeyAction::ViewNextTag => "View Next Workspace".to_string(),
224 + KeyAction::ViewPreviousTag => "View Previous Workspace".to_string(),
223 KeyAction::ToggleView => match &binding.arg { 225 KeyAction::ToggleView => match &binding.arg {
224 Arg::Int(n) => format!("Toggle View Workspace {}", n), 226 Arg::Int(n) => format!("Toggle View Workspace {}", n),
225 _ => "Toggle View Workspace".to_string(), 227 _ => "Toggle View Workspace".to_string(),
+25 −2 src/window_manager.rs
@@ -20,6 +20,12 @@ pub fn tag_mask(tag: usize) -> TagMask {
20 1 << tag 20 1 << tag
21 } 21 }
22 22
23 +/// Get back a tag index from a [`TagMask`]
24 +pub fn unmask_tag(mask: TagMask) -> usize {
25 + // mask only has one bit set, so this works.
26 + mask.trailing_zeros() as usize
27 +}
28 +
23 struct AtomCache { 29 struct AtomCache {
24 net_current_desktop: Atom, 30 net_current_desktop: Atom,
25 net_client_info: Atom, 31 net_client_info: Atom,
@@ -805,6 +811,20 @@ impl WindowManager {
805 self.view_tag(*tag_index as usize)?; 811 self.view_tag(*tag_index as usize)?;
806 } 812 }
807 } 813 }
814 + KeyAction::ViewNextTag => {
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))?;
820 + }
821 + KeyAction::ViewPreviousTag => {
822 + 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))?;
827 + }
808 KeyAction::ToggleView => { 828 KeyAction::ToggleView => {
809 if let Arg::Int(tag_index) = arg { 829 if let Arg::Int(tag_index) = arg {
810 self.toggleview(*tag_index as usize)?; 830 self.toggleview(*tag_index as usize)?;
@@ -1455,8 +1475,7 @@ impl WindowManager {
1455 for window in &windows { 1475 for window in &windows {
1456 self.connection.configure_window( 1476 self.connection.configure_window(
1457 *window, 1477 *window,
1458 - &x11rb::protocol::xproto::ConfigureWindowAux::new() 1478 + &x11rb::protocol::xproto::ConfigureWindowAux::new().border_width(0),
1459 - .border_width(0),
1460 )?; 1479 )?;
1461 } 1480 }
1462 1481
@@ -4175,6 +4194,10 @@ impl WindowManager {
4175 Ok(()) 4194 Ok(())
4176 } 4195 }
4177 4196
4197 + fn get_selected_monitor(&self) -> &Monitor {
4198 + &self.monitors[self.selected_monitor]
4199 + }
4200 +
4178 fn run_autostart_commands(&self) { 4201 fn run_autostart_commands(&self) {
4179 for command in &self.config.autostart { 4202 for command in &self.config.autostart {
4180 crate::signal::spawn_detached(command); 4203 crate::signal::spawn_detached(command);
+8 −0 templates/oxwm.lua
@@ -205,6 +205,14 @@ oxwm.tag = {}
205 ---@return table Action table for keybinding 205 ---@return table Action table for keybinding
206 function oxwm.tag.view(index) end 206 function oxwm.tag.view(index) end
207 207
208 +---View/switch to next tag
209 +---@return table Action table for keybinding
210 +function oxwm.tag.view_next() end
211 +
212 +---View/switch to previous tag
213 +---@return table Action table for keybinding
214 +function oxwm.tag.view_previous() end
215 +
208 ---Move focused window to tag 216 ---Move focused window to tag
209 ---@param index integer Tag index (0-based) 217 ---@param index integer Tag index (0-based)
210 ---@return table Action table for keybinding 218 ---@return table Action table for keybinding