tony / oxwm

Added hide_vacant_tags() feature from dwm patch into oxwm as optional flag. Browse files
tonybtw committed 2025-12-29 parent d47da56 commit f8f0c96eac32d76234e9a0a5a9fb84d4233b8c87
Showing 7 changed files with 42 additions and 0 deletions. UnifiedSplit
+1 −0 resources/test-config.lua
@@ -35,6 +35,7 @@ oxwm.set_terminal("st")
35 35 oxwm.set_modkey(modkey)
36 36 oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })
37 37 oxwm.auto_tile(true);
38 +oxwm.bar.set_hide_vacant_tags(true);
38 39
39 40 oxwm.set_layout_symbol("tiling", "[T]")
40 41 oxwm.set_layout_symbol("normie", "[F]")
+22 −0 src/bar/bar.rs
@@ -28,6 +28,9 @@ pub struct Bar {
28 28 scheme_occupied: crate::ColorScheme,
29 29 scheme_selected: crate::ColorScheme,
30 30 scheme_urgent: crate::ColorScheme,
31 + hide_vacant_tags: bool,
32 + last_occupied_tags: u32,
33 + last_current_tags: u32,
31 34 }
32 35
33 36 impl Bar {
@@ -129,6 +132,9 @@ impl Bar {
129 132 scheme_occupied: config.scheme_occupied,
130 133 scheme_selected: config.scheme_selected,
131 134 scheme_urgent: config.scheme_urgent,
135 + hide_vacant_tags: config.hide_vacant_tags,
136 + last_occupied_tags: 0,
137 + last_current_tags: 0,
132 138 })
133 139 }
134 140
@@ -206,6 +212,9 @@ impl Bar {
206 212 x11::xlib::XFreeGC(display, gc);
207 213 }
208 214
215 + self.last_occupied_tags = occupied_tags;
216 + self.last_current_tags = current_tags;
217 +
209 218 let mut x_position: i16 = 0;
210 219
211 220 for (tag_index, tag) in self.tags.iter().enumerate() {
@@ -214,6 +223,10 @@ impl Bar {
214 223 let is_occupied = (occupied_tags & tag_mask) != 0;
215 224 let is_urgent = (urgent_tags & tag_mask) != 0;
216 225
226 + if self.hide_vacant_tags && !is_occupied && !is_selected {
227 + continue;
228 + }
229 +
217 230 let tag_width = self.tag_widths[tag_index];
218 231
219 232 let scheme = if is_selected {
@@ -374,6 +387,14 @@ impl Bar {
374 387 let mut current_x_position = 0;
375 388
376 389 for (tag_index, &tag_width) in self.tag_widths.iter().enumerate() {
390 + let tag_mask = 1 << tag_index;
391 + let is_selected = (self.last_current_tags & tag_mask) != 0;
392 + let is_occupied = (self.last_occupied_tags & tag_mask) != 0;
393 +
394 + if self.hide_vacant_tags && !is_occupied && !is_selected {
395 + continue;
396 + }
397 +
377 398 if click_x >= current_x_position && click_x < current_x_position + tag_width as i16 {
378 399 return Some(tag_index);
379 400 }
@@ -406,6 +427,7 @@ impl Bar {
406 427 self.scheme_occupied = config.scheme_occupied;
407 428 self.scheme_selected = config.scheme_selected;
408 429 self.scheme_urgent = config.scheme_urgent;
430 + self.hide_vacant_tags = config.hide_vacant_tags;
409 431
410 432 self.status_text.clear();
411 433 self.needs_redraw = true;
+1 −0 src/config/lua.rs
@@ -51,6 +51,7 @@ pub fn parse_lua_config(
51 51 scheme_urgent: builder_data.scheme_urgent,
52 52 autostart: builder_data.autostart,
53 53 auto_tile: builder_data.auto_tile,
54 + hide_vacant_tags: builder_data.hide_vacant_tags,
54 55 path: None,
55 56 })
56 57 }
+9 −0 src/config/lua_api.rs
@@ -35,6 +35,7 @@ pub struct ConfigBuilder {
35 35 pub scheme_urgent: ColorScheme,
36 36 pub autostart: Vec<String>,
37 37 pub auto_tile: bool,
38 + pub hide_vacant_tags: bool,
38 39 }
39 40
40 41 impl Default for ConfigBuilder {
@@ -80,6 +81,7 @@ impl Default for ConfigBuilder {
80 81 },
81 82 autostart: Vec::new(),
82 83 auto_tile: false,
84 + hide_vacant_tags: false,
83 85 }
84 86 }
85 87 }
@@ -726,6 +728,12 @@ fn register_bar_module(
726 728 Ok(())
727 729 })?;
728 730
731 + let builder_clone = builder.clone();
732 + let set_hide_vacant_tags = lua.create_function(move |_, hide: bool| {
733 + builder_clone.borrow_mut().hide_vacant_tags = hide;
734 + Ok(())
735 + })?;
736 +
729 737 bar_table.set("set_font", set_font)?;
730 738 bar_table.set("block", block_table)?;
731 739 bar_table.set("add_block", add_block)?; // Deprecated, for backwards compatibility
@@ -734,6 +742,7 @@ fn register_bar_module(
734 742 bar_table.set("set_scheme_occupied", set_scheme_occupied)?;
735 743 bar_table.set("set_scheme_selected", set_scheme_selected)?;
736 744 bar_table.set("set_scheme_urgent", set_scheme_urgent)?;
745 + bar_table.set("set_hide_vacant_tags", set_hide_vacant_tags)?;
737 746 parent.set("bar", bar_table)?;
738 747 Ok(())
739 748 }
+2 −0 src/lib.rs
@@ -103,6 +103,7 @@ pub struct Config {
103 103
104 104 pub autostart: Vec<String>,
105 105 pub auto_tile: bool,
106 + pub hide_vacant_tags: bool,
106 107 }
107 108
108 109 #[derive(Debug, Clone, Copy)]
@@ -353,6 +354,7 @@ impl Default for Config {
353 354 },
354 355 autostart: vec![],
355 356 auto_tile: false,
357 + hide_vacant_tags: false,
356 358 }
357 359 }
358 360 }
+3 −0 templates/config.lua
@@ -172,6 +172,9 @@ oxwm.bar.set_scheme_selected(colors.cyan, colors.bg, colors.purple)
172 172 -- Urgent tags (windows requesting attention)
173 173 oxwm.bar.set_scheme_urgent(colors.red, colors.bg, colors.red)
174 174
175 +-- Hide tags that have no windows and are not selected
176 +-- oxwm.bar.set_hide_vacant_tags(true)
177 +
175 178 -------------------------------------------------------------------------------
176 179 -- Keybindings
177 180 -------------------------------------------------------------------------------
+4 −0 templates/oxwm.lua
@@ -315,6 +315,10 @@ function oxwm.bar.set_scheme_selected(foreground, background, underline) end
315 315 ---@param underline string|integer Underline color
316 316 function oxwm.bar.set_scheme_urgent(foreground, background, underline) end
317 317
318 +---Hide tags that have no windows and are not currently selected
319 +---@param hide boolean Whether to hide vacant tags
320 +function oxwm.bar.set_hide_vacant_tags(hide) end
321 +
318 322 ---Add an autostart command
319 323 ---@param cmd string Command to run at startup
320 324 function oxwm.autostart(cmd) end