tony / oxwm

Added layout names into bar, and in config files to be configurable. Updated test config and default config to include ExchangeClient, and SmartMoveWin Browse files
tonybtw committed 2025-10-27 parent 8f52c5d commit 78580639c90d1c3ad8eccdbc3f1f938f57afcc72
Showing 9 changed files with 94 additions and 1 deletions. UnifiedSplit
+15 −0 src/bar/bar.rs
@@ -171,6 +171,7 @@ impl Bar {
171 171 current_tags: u32,
172 172 occupied_tags: u32,
173 173 draw_blocks: bool,
174 + layout_symbol: &str,
174 175 ) -> Result<(), X11Error> {
175 176 if !self.needs_redraw {
176 177 return Ok(());
@@ -246,6 +247,20 @@ impl Bar {
246 247 x_position += tag_width as i16;
247 248 }
248 249
250 + x_position += 10;
251 +
252 + let text_x = x_position;
253 + let top_padding = 4;
254 + let text_y = top_padding + font.ascent();
255 +
256 + self.font_draw.draw_text(
257 + font,
258 + self.scheme_normal.foreground,
259 + text_x,
260 + text_y,
261 + layout_symbol
262 + );
263 +
249 264 if draw_blocks && !self.status_text.is_empty() {
250 265 let padding = 10;
251 266 let mut x_position = self.width as i16 - padding;
+18 −0 src/config/mod.rs
@@ -161,6 +161,12 @@ pub fn parse_config(input: &str) -> Result<crate::Config, ConfigError> {
161 161 config_data_to_config(config_data)
162 162 }
163 163
164 +#[derive(Debug, Deserialize)]
165 +struct LayoutSymbolOverrideData {
166 + name: String,
167 + symbol: String,
168 +}
169 +
164 170 #[derive(Debug, Deserialize)]
165 171 struct ConfigData {
166 172 border_width: u32,
@@ -178,6 +184,8 @@ struct ConfigData {
178 184 modkey: ModKey,
179 185
180 186 tags: Vec<String>,
187 + #[serde(default)]
188 + layout_symbols: Vec<LayoutSymbolOverrideData>,
181 189 keybindings: Vec<KeybindingData>,
182 190 status_blocks: Vec<StatusBlockData>,
183 191
@@ -307,6 +315,15 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
307 315 });
308 316 }
309 317
318 + let layout_symbols = data
319 + .layout_symbols
320 + .into_iter()
321 + .map(|l| crate::LayoutSymbolOverride {
322 + name: l.name,
323 + symbol: l.symbol,
324 + })
325 + .collect();
326 +
310 327 Ok(crate::Config {
311 328 border_width: data.border_width,
312 329 border_focused: data.border_focused,
@@ -320,6 +337,7 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError>
320 337 terminal: data.terminal,
321 338 modkey,
322 339 tags: data.tags,
340 + layout_symbols,
323 341 keybindings,
324 342 status_blocks,
325 343 scheme_normal: crate::ColorScheme {
+1 −0 src/layout/mod.rs
@@ -41,6 +41,7 @@ pub trait Layout {
41 41 gaps: &GapConfig,
42 42 ) -> Vec<WindowGeometry>;
43 43 fn name(&self) -> &'static str;
44 + fn symbol(&self) -> &'static str;
44 45 }
45 46
46 47 pub struct WindowGeometry {
+4 −0 src/layout/normie.rs
@@ -9,6 +9,10 @@ impl Layout for NormieLayout {
9 9 super::NORMIE
10 10 }
11 11
12 + fn symbol(&self) -> &'static str {
13 + "><>"
14 + }
15 +
12 16 fn arrange(
13 17 &self,
14 18 windows: &[Window],
+4 −0 src/layout/tiling.rs
@@ -8,6 +8,10 @@ impl Layout for TilingLayout {
8 8 super::TILING
9 9 }
10 10
11 + fn symbol(&self) -> &'static str {
12 + "[]="
13 + }
14 +
11 15 fn arrange(
12 16 &self,
13 17 windows: &[Window],
+11 −0 src/lib.rs
@@ -8,11 +8,18 @@ pub mod window_manager;
8 8
9 9 pub mod prelude {
10 10 pub use crate::ColorScheme;
11 + pub use crate::LayoutSymbolOverride;
11 12 pub use crate::bar::{BlockCommand, BlockConfig};
12 13 pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes};
13 14 pub use x11rb::protocol::xproto::KeyButMask;
14 15 }
15 16
17 +#[derive(Clone)]
18 +pub struct LayoutSymbolOverride {
19 + pub name: String,
20 + pub symbol: String,
21 +}
22 +
16 23 #[derive(Clone)]
17 24 pub struct Config {
18 25 // Appearance
@@ -35,6 +42,9 @@ pub struct Config {
35 42 // Tags
36 43 pub tags: Vec<String>,
37 44
45 + // Layout symbol overrides
46 + pub layout_symbols: Vec<LayoutSymbolOverride>,
47 +
38 48 // Keybindings
39 49 pub keybindings: Vec<crate::keyboard::handlers::Key>,
40 50
@@ -81,6 +91,7 @@ impl Default for Config {
81 91 .into_iter()
82 92 .map(String::from)
83 93 .collect(),
94 + layout_symbols: vec![],
84 95 keybindings: vec![
85 96 Key::new(
86 97 vec![MODKEY],
+15 −0 src/window_manager.rs
@@ -789,7 +789,19 @@ impl WindowManager {
789 789 Ok(())
790 790 }
791 791
792 + fn get_layout_symbol(&self) -> String {
793 + let layout_name = self.layout.name();
794 + self.config
795 + .layout_symbols
796 + .iter()
797 + .find(|l| l.name == layout_name)
798 + .map(|l| l.symbol.clone())
799 + .unwrap_or_else(|| self.layout.symbol().to_string())
800 + }
801 +
792 802 fn update_bar(&mut self) -> WmResult<()> {
803 + let layout_symbol = self.get_layout_symbol();
804 +
793 805 for (monitor_index, monitor) in self.monitors.iter().enumerate() {
794 806 if let Some(bar) = self.bars.get_mut(monitor_index) {
795 807 let mut occupied_tags: TagMask = 0;
@@ -808,6 +820,7 @@ impl WindowManager {
808 820 monitor.selected_tags,
809 821 occupied_tags,
810 822 draw_blocks,
823 + &layout_symbol,
811 824 )?;
812 825 }
813 826 }
@@ -842,6 +855,7 @@ impl WindowManager {
842 855 Ok(layout) => {
843 856 self.layout = layout;
844 857 self.apply_layout()?;
858 + self.update_bar()?;
845 859 }
846 860 Err(e) => eprintln!("Failed to change layout: {}", e),
847 861 }
@@ -854,6 +868,7 @@ impl WindowManager {
854 868 Ok(layout) => {
855 869 self.layout = layout;
856 870 self.apply_layout()?;
871 + self.update_bar()?;
857 872 }
858 873 Err(e) => eprintln!("Failed to cycle layout: {}", e),
859 874 }
+17 −0 templates/config.ron
@@ -18,6 +18,10 @@
18 18 modkey: Mod4,
19 19
20 20 tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
21 + layout_symbols: [
22 + (name: "tiling", symbol: "[T]"),
23 + (name: "normie", symbol: "[F]"),
24 + ],
21 25
22 26 keybindings: [
23 27 (modifiers: [Mod4], key: Return, action: Spawn, arg: "st"),
@@ -28,6 +32,7 @@
28 32 (modifiers: [Mod4, Shift], key: Space, action: ToggleFloating),
29 33 (modifiers: [Mod4], key: F, action: ChangeLayout, arg: "normie"),
30 34 (modifiers: [Mod4], key: C, action: ChangeLayout, arg: "tiling"),
35 + (modifiers: [Mod1], key: N, action: CycleLayout),
31 36 (modifiers: [Mod4], key: A, action: ToggleGaps),
32 37 (modifiers: [Mod4, Shift], key: Q, action: Quit),
33 38 (modifiers: [Mod4, Shift], key: R, action: Restart),
@@ -53,6 +58,18 @@
53 58 (modifiers: [Mod4, Shift], key: Key7, action: MoveToTag, arg: 6),
54 59 (modifiers: [Mod4, Shift], key: Key8, action: MoveToTag, arg: 7),
55 60 (modifiers: [Mod4, Shift], key: Key9, action: MoveToTag, arg: 8),
61 +
62 + // Moving Windows
63 + (modifiers: [Mod4, Control], key: K, action: SmartMoveWin, arg: 0), // UP
64 + (modifiers: [Mod4, Control], key: J, action: SmartMoveWin, arg: 1), // DOWN
65 + (modifiers: [Mod4, Control], key: H, action: SmartMoveWin, arg: 2), // LEFT
66 + (modifiers: [Mod4, Control], key: L, action: SmartMoveWin, arg: 3), // RIGHT
67 +
68 + // Exchanging Clients
69 + (modifiers: [Mod4, Shift], key: K, action: ExchangeClient, arg: 0), // UP
70 + (modifiers: [Mod4, Shift], key: J, action: ExchangeClient, arg: 1), // DOWN
71 + (modifiers: [Mod4, Shift], key: H, action: ExchangeClient, arg: 2), // LEFT
72 + (modifiers: [Mod4, Shift], key: L, action: ExchangeClient, arg: 3), // RIGHT
56 73 ],
57 74
58 75 status_blocks: [
+9 −1 test-config.ron
@@ -16,7 +16,6 @@
16 16
17 17 terminal: "st",
18 18 modkey: Mod1,
19 -
20 19 tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"],
21 20
22 21 // Alternative icon tags (uncomment to use):
@@ -25,6 +24,11 @@
25 24 // Alternative text tags (uncomment to use):
26 25 // tags: ["DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC"],
27 26
27 + layout_symbols: [
28 + (name: "tiling", symbol: "[T]"),
29 + (name: "normie", symbol: "[F]"),
30 + ],
31 +
28 32 keybindings: [
29 33 (modifiers: [Mod1], key: Return, action: Spawn, arg: "st"),
30 34 (modifiers: [Mod1], key: D, action: Spawn, arg: ["sh", "-c", "dmenu_run -l 10"]),
@@ -41,6 +45,10 @@
41 45 (modifiers: [Mod1], key: J, action: FocusStack, arg: -1),
42 46 (modifiers: [Mod1], key: K, action: FocusStack, arg: 1),
43 47 // Exchange client (vim-style with Mod+Shift)
48 + (modifiers: [Mod1, Control], key: K, action: SmartMoveWin, arg: 0), // UP
49 + (modifiers: [Mod1, Control], key: J, action: SmartMoveWin, arg: 1), // DOWN
50 + (modifiers: [Mod1, Control], key: H, action: SmartMoveWin, arg: 2), // LEFT
51 + (modifiers: [Mod1, Control], key: L, action: SmartMoveWin, arg: 3), // RIGHT
44 52 (modifiers: [Mod1, Shift], key: K, action: ExchangeClient, arg: 0), // UP
45 53 (modifiers: [Mod1, Shift], key: J, action: ExchangeClient, arg: 1), // DOWN
46 54 (modifiers: [Mod1, Shift], key: H, action: ExchangeClient, arg: 2), // LEFT