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
+15 −0 src/bar/bar.rs
| @@ -171,6 +171,7 @@ impl Bar { | |||
| 171 | current_tags: u32, | 171 | current_tags: u32, |
| 172 | occupied_tags: u32, | 172 | occupied_tags: u32, |
| 173 | draw_blocks: bool, | 173 | draw_blocks: bool, |
| 174 | + layout_symbol: &str, | ||
| 174 | ) -> Result<(), X11Error> { | 175 | ) -> Result<(), X11Error> { |
| 175 | if !self.needs_redraw { | 176 | if !self.needs_redraw { |
| 176 | return Ok(()); | 177 | return Ok(()); |
| @@ -246,6 +247,20 @@ impl Bar { | |||
| 246 | x_position += tag_width as i16; | 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 | if draw_blocks && !self.status_text.is_empty() { | 264 | if draw_blocks && !self.status_text.is_empty() { |
| 250 | let padding = 10; | 265 | let padding = 10; |
| 251 | let mut x_position = self.width as i16 - padding; | 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 | config_data_to_config(config_data) | 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 | #[derive(Debug, Deserialize)] | 170 | #[derive(Debug, Deserialize)] |
| 165 | struct ConfigData { | 171 | struct ConfigData { |
| 166 | border_width: u32, | 172 | border_width: u32, |
| @@ -178,6 +184,8 @@ struct ConfigData { | |||
| 178 | modkey: ModKey, | 184 | modkey: ModKey, |
| 179 | 185 | ||
| 180 | tags: Vec<String>, | 186 | tags: Vec<String>, |
| 187 | + #[serde(default)] | ||
| 188 | + layout_symbols: Vec<LayoutSymbolOverrideData>, | ||
| 181 | keybindings: Vec<KeybindingData>, | 189 | keybindings: Vec<KeybindingData>, |
| 182 | status_blocks: Vec<StatusBlockData>, | 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 | Ok(crate::Config { | 327 | Ok(crate::Config { |
| 311 | border_width: data.border_width, | 328 | border_width: data.border_width, |
| 312 | border_focused: data.border_focused, | 329 | border_focused: data.border_focused, |
| @@ -320,6 +337,7 @@ fn config_data_to_config(data: ConfigData) -> Result<crate::Config, ConfigError> | |||
| 320 | terminal: data.terminal, | 337 | terminal: data.terminal, |
| 321 | modkey, | 338 | modkey, |
| 322 | tags: data.tags, | 339 | tags: data.tags, |
| 340 | + layout_symbols, | ||
| 323 | keybindings, | 341 | keybindings, |
| 324 | status_blocks, | 342 | status_blocks, |
| 325 | scheme_normal: crate::ColorScheme { | 343 | scheme_normal: crate::ColorScheme { |
+1 −0 src/layout/mod.rs
| @@ -41,6 +41,7 @@ pub trait Layout { | |||
| 41 | gaps: &GapConfig, | 41 | gaps: &GapConfig, |
| 42 | ) -> Vec<WindowGeometry>; | 42 | ) -> Vec<WindowGeometry>; |
| 43 | fn name(&self) -> &'static str; | 43 | fn name(&self) -> &'static str; |
| 44 | + fn symbol(&self) -> &'static str; | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | pub struct WindowGeometry { | 47 | pub struct WindowGeometry { |
+4 −0 src/layout/normie.rs
| @@ -9,6 +9,10 @@ impl Layout for NormieLayout { | |||
| 9 | super::NORMIE | 9 | super::NORMIE |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | + fn symbol(&self) -> &'static str { | ||
| 13 | + "><>" | ||
| 14 | + } | ||
| 15 | + | ||
| 12 | fn arrange( | 16 | fn arrange( |
| 13 | &self, | 17 | &self, |
| 14 | windows: &[Window], | 18 | windows: &[Window], |
+4 −0 src/layout/tiling.rs
| @@ -8,6 +8,10 @@ impl Layout for TilingLayout { | |||
| 8 | super::TILING | 8 | super::TILING |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | + fn symbol(&self) -> &'static str { | ||
| 12 | + "[]=" | ||
| 13 | + } | ||
| 14 | + | ||
| 11 | fn arrange( | 15 | fn arrange( |
| 12 | &self, | 16 | &self, |
| 13 | windows: &[Window], | 17 | windows: &[Window], |
+11 −0 src/lib.rs
| @@ -8,11 +8,18 @@ pub mod window_manager; | |||
| 8 | 8 | ||
| 9 | pub mod prelude { | 9 | pub mod prelude { |
| 10 | pub use crate::ColorScheme; | 10 | pub use crate::ColorScheme; |
| 11 | + pub use crate::LayoutSymbolOverride; | ||
| 11 | pub use crate::bar::{BlockCommand, BlockConfig}; | 12 | pub use crate::bar::{BlockCommand, BlockConfig}; |
| 12 | pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes}; | 13 | pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes}; |
| 13 | pub use x11rb::protocol::xproto::KeyButMask; | 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 | #[derive(Clone)] | 23 | #[derive(Clone)] |
| 17 | pub struct Config { | 24 | pub struct Config { |
| 18 | // Appearance | 25 | // Appearance |
| @@ -35,6 +42,9 @@ pub struct Config { | |||
| 35 | // Tags | 42 | // Tags |
| 36 | pub tags: Vec<String>, | 43 | pub tags: Vec<String>, |
| 37 | 44 | ||
| 45 | + // Layout symbol overrides | ||
| 46 | + pub layout_symbols: Vec<LayoutSymbolOverride>, | ||
| 47 | + | ||
| 38 | // Keybindings | 48 | // Keybindings |
| 39 | pub keybindings: Vec<crate::keyboard::handlers::Key>, | 49 | pub keybindings: Vec<crate::keyboard::handlers::Key>, |
| 40 | 50 | ||
| @@ -81,6 +91,7 @@ impl Default for Config { | |||
| 81 | .into_iter() | 91 | .into_iter() |
| 82 | .map(String::from) | 92 | .map(String::from) |
| 83 | .collect(), | 93 | .collect(), |
| 94 | + layout_symbols: vec![], | ||
| 84 | keybindings: vec![ | 95 | keybindings: vec![ |
| 85 | Key::new( | 96 | Key::new( |
| 86 | vec![MODKEY], | 97 | vec![MODKEY], |
+15 −0 src/window_manager.rs
| @@ -789,7 +789,19 @@ impl WindowManager { | |||
| 789 | Ok(()) | 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 | fn update_bar(&mut self) -> WmResult<()> { | 802 | fn update_bar(&mut self) -> WmResult<()> { |
| 803 | + let layout_symbol = self.get_layout_symbol(); | ||
| 804 | + | ||
| 793 | for (monitor_index, monitor) in self.monitors.iter().enumerate() { | 805 | for (monitor_index, monitor) in self.monitors.iter().enumerate() { |
| 794 | if let Some(bar) = self.bars.get_mut(monitor_index) { | 806 | if let Some(bar) = self.bars.get_mut(monitor_index) { |
| 795 | let mut occupied_tags: TagMask = 0; | 807 | let mut occupied_tags: TagMask = 0; |
| @@ -808,6 +820,7 @@ impl WindowManager { | |||
| 808 | monitor.selected_tags, | 820 | monitor.selected_tags, |
| 809 | occupied_tags, | 821 | occupied_tags, |
| 810 | draw_blocks, | 822 | draw_blocks, |
| 823 | + &layout_symbol, | ||
| 811 | )?; | 824 | )?; |
| 812 | } | 825 | } |
| 813 | } | 826 | } |
| @@ -842,6 +855,7 @@ impl WindowManager { | |||
| 842 | Ok(layout) => { | 855 | Ok(layout) => { |
| 843 | self.layout = layout; | 856 | self.layout = layout; |
| 844 | self.apply_layout()?; | 857 | self.apply_layout()?; |
| 858 | + self.update_bar()?; | ||
| 845 | } | 859 | } |
| 846 | Err(e) => eprintln!("Failed to change layout: {}", e), | 860 | Err(e) => eprintln!("Failed to change layout: {}", e), |
| 847 | } | 861 | } |
| @@ -854,6 +868,7 @@ impl WindowManager { | |||
| 854 | Ok(layout) => { | 868 | Ok(layout) => { |
| 855 | self.layout = layout; | 869 | self.layout = layout; |
| 856 | self.apply_layout()?; | 870 | self.apply_layout()?; |
| 871 | + self.update_bar()?; | ||
| 857 | } | 872 | } |
| 858 | Err(e) => eprintln!("Failed to cycle layout: {}", e), | 873 | Err(e) => eprintln!("Failed to cycle layout: {}", e), |
| 859 | } | 874 | } |
+17 −0 templates/config.ron
| @@ -18,6 +18,10 @@ | |||
| 18 | modkey: Mod4, | 18 | modkey: Mod4, |
| 19 | 19 | ||
| 20 | tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"], | 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 | keybindings: [ | 26 | keybindings: [ |
| 23 | (modifiers: [Mod4], key: Return, action: Spawn, arg: "st"), | 27 | (modifiers: [Mod4], key: Return, action: Spawn, arg: "st"), |
| @@ -28,6 +32,7 @@ | |||
| 28 | (modifiers: [Mod4, Shift], key: Space, action: ToggleFloating), | 32 | (modifiers: [Mod4, Shift], key: Space, action: ToggleFloating), |
| 29 | (modifiers: [Mod4], key: F, action: ChangeLayout, arg: "normie"), | 33 | (modifiers: [Mod4], key: F, action: ChangeLayout, arg: "normie"), |
| 30 | (modifiers: [Mod4], key: C, action: ChangeLayout, arg: "tiling"), | 34 | (modifiers: [Mod4], key: C, action: ChangeLayout, arg: "tiling"), |
| 35 | + (modifiers: [Mod1], key: N, action: CycleLayout), | ||
| 31 | (modifiers: [Mod4], key: A, action: ToggleGaps), | 36 | (modifiers: [Mod4], key: A, action: ToggleGaps), |
| 32 | (modifiers: [Mod4, Shift], key: Q, action: Quit), | 37 | (modifiers: [Mod4, Shift], key: Q, action: Quit), |
| 33 | (modifiers: [Mod4, Shift], key: R, action: Restart), | 38 | (modifiers: [Mod4, Shift], key: R, action: Restart), |
| @@ -53,6 +58,18 @@ | |||
| 53 | (modifiers: [Mod4, Shift], key: Key7, action: MoveToTag, arg: 6), | 58 | (modifiers: [Mod4, Shift], key: Key7, action: MoveToTag, arg: 6), |
| 54 | (modifiers: [Mod4, Shift], key: Key8, action: MoveToTag, arg: 7), | 59 | (modifiers: [Mod4, Shift], key: Key8, action: MoveToTag, arg: 7), |
| 55 | (modifiers: [Mod4, Shift], key: Key9, action: MoveToTag, arg: 8), | 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 | status_blocks: [ | 75 | status_blocks: [ |
+9 −1 test-config.ron
| @@ -16,7 +16,6 @@ | |||
| 16 | 16 | ||
| 17 | terminal: "st", | 17 | terminal: "st", |
| 18 | modkey: Mod1, | 18 | modkey: Mod1, |
| 19 | - | ||
| 20 | tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"], | 19 | tags: ["1", "2", "3", "4", "5", "6", "7", "8", "9"], |
| 21 | 20 | ||
| 22 | // Alternative icon tags (uncomment to use): | 21 | // Alternative icon tags (uncomment to use): |
| @@ -25,6 +24,11 @@ | |||
| 25 | // Alternative text tags (uncomment to use): | 24 | // Alternative text tags (uncomment to use): |
| 26 | // tags: ["DEV", "WWW", "SYS", "DOC", "VBOX", "CHAT", "MUS", "VID", "MISC"], | 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 | keybindings: [ | 32 | keybindings: [ |
| 29 | (modifiers: [Mod1], key: Return, action: Spawn, arg: "st"), | 33 | (modifiers: [Mod1], key: Return, action: Spawn, arg: "st"), |
| 30 | (modifiers: [Mod1], key: D, action: Spawn, arg: ["sh", "-c", "dmenu_run -l 10"]), | 34 | (modifiers: [Mod1], key: D, action: Spawn, arg: ["sh", "-c", "dmenu_run -l 10"]), |
| @@ -41,6 +45,10 @@ | |||
| 41 | (modifiers: [Mod1], key: J, action: FocusStack, arg: -1), | 45 | (modifiers: [Mod1], key: J, action: FocusStack, arg: -1), |
| 42 | (modifiers: [Mod1], key: K, action: FocusStack, arg: 1), | 46 | (modifiers: [Mod1], key: K, action: FocusStack, arg: 1), |
| 43 | // Exchange client (vim-style with Mod+Shift) | 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 | (modifiers: [Mod1, Shift], key: K, action: ExchangeClient, arg: 0), // UP | 52 | (modifiers: [Mod1, Shift], key: K, action: ExchangeClient, arg: 0), // UP |
| 45 | (modifiers: [Mod1, Shift], key: J, action: ExchangeClient, arg: 1), // DOWN | 53 | (modifiers: [Mod1, Shift], key: J, action: ExchangeClient, arg: 1), // DOWN |
| 46 | (modifiers: [Mod1, Shift], key: H, action: ExchangeClient, arg: 2), // LEFT | 54 | (modifiers: [Mod1, Shift], key: H, action: ExchangeClient, arg: 2), // LEFT |