tony / oxwm

add configurable back-and-forth tag switching Browse files
Adds the ability to optionally switch back to the previously viewed tag
when trying to view the current tag. Adds `tag_back_and_forth` to
config, configured with `oxwm.tag.set_back_and_forth` in Lua API.

Closes #71.
emzywastaken committed 2025-12-15 parent 46596a9 commit a96e35b6bc98305b9507ed61e3e29a98bbecddc6
Showing 5 changed files with 29 additions and 6 deletions. UnifiedSplit
+1 −0 src/config/lua.rs
@@ -42,6 +42,7 @@ pub fn parse_lua_config(
42 42 tags: builder_data.tags,
43 43 layout_symbols: builder_data.layout_symbols,
44 44 keybindings: builder_data.keybindings,
45 + tag_back_and_forth: builder_data.tag_back_and_forth,
45 46 window_rules: builder_data.window_rules,
46 47 status_blocks: builder_data.status_blocks,
47 48 scheme_normal: builder_data.scheme_normal,
+15 −2 src/config/lua_api.rs
@@ -26,6 +26,7 @@ pub struct ConfigBuilder {
26 26 pub tags: Vec<String>,
27 27 pub layout_symbols: Vec<crate::LayoutSymbolOverride>,
28 28 pub keybindings: Vec<KeyBinding>,
29 + pub tag_back_and_forth: bool,
29 30 pub window_rules: Vec<crate::WindowRule>,
30 31 pub status_blocks: Vec<BlockConfig>,
31 32 pub scheme_normal: ColorScheme,
@@ -53,6 +54,7 @@ impl Default for ConfigBuilder {
53 54 tags: vec!["1".into(), "2".into(), "3".into()],
54 55 layout_symbols: Vec::new(),
55 56 keybindings: Vec::new(),
57 + tag_back_and_forth: false,
56 58 window_rules: Vec::new(),
57 59 status_blocks: Vec::new(),
58 60 scheme_normal: ColorScheme {
@@ -89,7 +91,7 @@ pub fn register_api(lua: &Lua) -> Result<SharedBuilder, ConfigError> {
89 91 register_border_module(&lua, &oxwm_table, builder.clone())?;
90 92 register_client_module(&lua, &oxwm_table)?;
91 93 register_layout_module(&lua, &oxwm_table)?;
92 - register_tag_module(&lua, &oxwm_table)?;
94 + register_tag_module(&lua, &oxwm_table, builder.clone())?;
93 95 register_monitor_module(&lua, &oxwm_table)?;
94 96 register_rule_module(&lua, &oxwm_table, builder.clone())?;
95 97 register_bar_module(&lua, &oxwm_table, builder.clone())?;
@@ -296,7 +298,12 @@ fn register_layout_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
296 298 Ok(())
297 299 }
298 300
299 -fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
301 +fn register_tag_module(
302 + lua: &Lua,
303 + parent: &Table,
304 + builder: SharedBuilder,
305 +) -> Result<(), ConfigError> {
306 + let builder_clone = builder.clone();
300 307 let tag_table = lua.create_table()?;
301 308
302 309 let view = lua.create_function(|lua, idx: i32| {
@@ -328,6 +335,11 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
328 335 create_action_table(lua, "ToggleTag", Value::Integer(idx as i64))
329 336 })?;
330 337
338 + let set_back_and_forth = lua.create_function(move |_, enabled: bool| {
339 + builder_clone.borrow_mut().tag_back_and_forth = enabled;
340 + Ok(())
341 + })?;
342 +
331 343 tag_table.set("view", view)?;
332 344 tag_table.set("view_next", view_next)?;
333 345 tag_table.set("view_previous", view_previous)?;
@@ -336,6 +348,7 @@ fn register_tag_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError> {
336 348 tag_table.set("toggleview", toggleview)?;
337 349 tag_table.set("move_to", move_to)?;
338 350 tag_table.set("toggletag", toggletag)?;
351 + tag_table.set("set_back_and_forth", set_back_and_forth)?;
339 352 parent.set("tag", tag_table)?;
340 353 Ok(())
341 354 }
+2 −0 src/lib.rs
@@ -87,6 +87,7 @@ pub struct Config {
87 87
88 88 // Keybindings
89 89 pub keybindings: Vec<crate::keyboard::handlers::Key>,
90 + pub tag_back_and_forth: bool,
90 91
91 92 // Window rules
92 93 pub window_rules: Vec<WindowRule>,
@@ -320,6 +321,7 @@ impl Default for Config {
320 321 Arg::Int(8),
321 322 ),
322 323 ],
324 + tag_back_and_forth: false,
323 325 window_rules: vec![],
324 326 status_blocks: vec![crate::bar::BlockConfig {
325 327 format: "{}".to_string(),
+7 −4 src/window_manager.rs
@@ -1142,12 +1142,15 @@ impl WindowManager {
1142 1142 let new_tagset = tag_mask(tag_index);
1143 1143
1144 1144 if new_tagset == monitor.tagset[monitor.selected_tags_index] {
1145 - return Ok(());
1145 + if !self.config.tag_back_and_forth {
1146 + return Ok(());
1147 + }
1148 + monitor.tagset.swap(0, 1);
1149 + } else {
1150 + monitor.selected_tags_index ^= 1;
1151 + monitor.tagset[monitor.selected_tags_index] = new_tagset;
1146 1152 }
1147 1153
1148 - monitor.selected_tags_index ^= 1;
1149 - monitor.tagset[monitor.selected_tags_index] = new_tagset;
1150 -
1151 1154 self.save_selected_tags()?;
1152 1155 self.focus(None)?;
1153 1156 self.apply_layout()?;
+4 −0 templates/oxwm.lua
@@ -236,6 +236,10 @@ function oxwm.tag.toggleview(index) end
236 236 ---@return table Action table for keybinding
237 237 function oxwm.tag.toggletag(index) end
238 238
239 +---When enabled an attempt to view the current tag switches back to the previously viewed tag.
240 +---@param enabled boolean Enable or disable tag_back_and_forth
241 +function oxwm.tag.set_back_and_forth(enabled) end
242 +
239 243 ---Status bar configuration module
240 244 ---@class oxwm.bar
241 245 oxwm.bar = {}