tony / oxwm

Added vanity gaps. with toggle =) Browse files
tonybtw committed 2025-10-06 parent 6f26d6c commit 605d25b8f04e8c3be82c0f02509557e060284e06
Showing 5 changed files with 96 additions and 18 deletions. UnifiedSplit
+11 −1 src/config.rs
@@ -6,11 +6,20 @@ use x11rb::protocol::xproto::KeyButMask;
6 // ======================================== 6 // ========================================
7 // APPEARANCE 7 // APPEARANCE
8 // ======================================== 8 // ========================================
9 -pub const BORDER_WIDTH: u32 = 1; 9 +pub const BORDER_WIDTH: u32 = 0;
10 pub const BORDER_FOCUSED: u32 = 0x6dade3; 10 pub const BORDER_FOCUSED: u32 = 0x6dade3;
11 pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb; 11 pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb;
12 pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=14"; 12 pub const FONT: &str = "JetBrainsMono Nerd Font:style=Bold:size=14";
13 13
14 +// ========================================
15 +// GAPS (Vanity Gaps)
16 +// ========================================
17 +pub const GAPS_ENABLED: bool = true;
18 +pub const GAP_INNER_HORIZONTAL: u32 = 3;
19 +pub const GAP_INNER_VERTICAL: u32 = 3;
20 +pub const GAP_OUTER_HORIZONTAL: u32 = 3;
21 +pub const GAP_OUTER_VERTICAL: u32 = 3;
22 +//
14 // ======================================== 23 // ========================================
15 // DEFAULTS 24 // DEFAULTS
16 // ======================================== 25 // ========================================
@@ -89,6 +98,7 @@ pub const KEYBINDINGS: &[Key] = &[
89 Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)), 98 Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)),
90 Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)), 99 Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)),
91 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None), 100 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
101 + Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
92 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None), 102 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
93 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None), 103 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
94 Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)), 104 Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
+1 −0 src/keyboard/handlers.rs
@@ -11,6 +11,7 @@ pub enum KeyAction {
11 Quit, 11 Quit,
12 Restart, 12 Restart,
13 ViewTag, 13 ViewTag,
14 + ToggleGaps,
14 MoveToTag, 15 MoveToTag,
15 None, 16 None,
16 } 17 }
+8 −0 src/layout/mod.rs
@@ -2,12 +2,20 @@ pub mod tiling;
2 2
3 use x11rb::protocol::xproto::Window; 3 use x11rb::protocol::xproto::Window;
4 4
5 +pub struct GapConfig {
6 + pub inner_horizontal: u32,
7 + pub inner_vertical: u32,
8 + pub outer_horizontal: u32,
9 + pub outer_vertical: u32,
10 +}
11 +
5 pub trait Layout { 12 pub trait Layout {
6 fn arrange( 13 fn arrange(
7 &self, 14 &self,
8 windows: &[Window], 15 windows: &[Window],
9 screen_width: u32, 16 screen_width: u32,
10 screen_height: u32, 17 screen_height: u32,
18 + gaps: &GapConfig,
11 ) -> Vec<WindowGeometry>; 19 ) -> Vec<WindowGeometry>;
12 } 20 }
13 21
+45 −15 src/layout/tiling.rs
@@ -1,4 +1,4 @@
1 -use super::{Layout, WindowGeometry}; 1 +use super::{GapConfig, Layout, WindowGeometry};
2 use x11rb::protocol::xproto::Window; 2 use x11rb::protocol::xproto::Window;
3 3
4 pub struct TilingLayout; 4 pub struct TilingLayout;
@@ -9,6 +9,7 @@ impl Layout for TilingLayout {
9 windows: &[Window], 9 windows: &[Window],
10 screen_width: u32, 10 screen_width: u32,
11 screen_height: u32, 11 screen_height: u32,
12 + gaps: &GapConfig,
12 ) -> Vec<WindowGeometry> { 13 ) -> Vec<WindowGeometry> {
13 let window_count = windows.len(); 14 let window_count = windows.len();
14 if window_count == 0 { 15 if window_count == 0 {
@@ -16,31 +17,60 @@ impl Layout for TilingLayout {
16 } 17 }
17 18
18 if window_count == 1 { 19 if window_count == 1 {
20 + let x = gaps.outer_horizontal as i32;
21 + let y = gaps.outer_vertical as i32;
22 + let width = screen_width.saturating_sub(2 * gaps.outer_horizontal);
23 + let height = screen_height.saturating_sub(2 * gaps.outer_vertical);
24 +
19 vec![WindowGeometry { 25 vec![WindowGeometry {
20 - x_coordinate: 0, 26 + x_coordinate: x,
21 - y_coordinate: 0, 27 + y_coordinate: y,
22 - width: screen_width, 28 + width,
23 - height: screen_height, 29 + height,
24 }] 30 }]
25 } else { 31 } else {
26 - let master_width = screen_width / 2; 32 + let mut geometries = Vec::new();
27 - let mut geometries = vec![WindowGeometry { 33 +
28 - x_coordinate: 0, 34 + let master_width = (screen_width / 2)
29 - y_coordinate: 0, 35 + .saturating_sub(gaps.outer_horizontal)
36 + .saturating_sub(gaps.inner_horizontal / 2);
37 +
38 + let master_x = gaps.outer_horizontal as i32;
39 + let master_y = gaps.outer_vertical as i32;
40 + let master_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
41 +
42 + geometries.push(WindowGeometry {
43 + x_coordinate: master_x,
44 + y_coordinate: master_y,
30 width: master_width, 45 width: master_width,
31 - height: screen_height, 46 + height: master_height,
32 - }]; 47 + });
48 +
49 + let stack_count = window_count - 1;
50 + let stack_x = (screen_width / 2 + gaps.inner_horizontal / 2) as i32;
51 + let stack_width = (screen_width / 2)
52 + .saturating_sub(gaps.outer_horizontal)
53 + .saturating_sub(gaps.inner_horizontal / 2);
54 +
55 + let total_stack_height = screen_height.saturating_sub(2 * gaps.outer_vertical);
56 +
57 + let total_inner_gaps = gaps.inner_vertical * (stack_count as u32 - 1);
58 + let stack_height =
59 + total_stack_height.saturating_sub(total_inner_gaps) / stack_count as u32;
33 60
34 - let stack_height = screen_height / (window_count - 1) as u32;
35 for i in 1..window_count { 61 for i in 1..window_count {
36 - let y_offset = ((i - 1) as u32) * stack_height; 62 + let stack_index = i - 1;
63 + let y_offset = gaps.outer_vertical
64 + + (stack_index as u32) * (stack_height + gaps.inner_vertical);
65 +
37 geometries.push(WindowGeometry { 66 geometries.push(WindowGeometry {
38 - x_coordinate: master_width as i32, 67 + x_coordinate: stack_x,
39 y_coordinate: y_offset as i32, 68 y_coordinate: y_offset as i32,
40 - width: master_width, 69 + width: stack_width,
41 height: stack_height, 70 height: stack_height,
42 }); 71 });
43 } 72 }
73 +
44 return geometries; 74 return geometries;
45 } 75 }
46 } 76 }
+31 −2 src/window_manager.rs
@@ -1,6 +1,10 @@
1 use crate::bar::Bar; 1 use crate::bar::Bar;
2 -use crate::config::{BORDER_FOCUSED, BORDER_UNFOCUSED, BORDER_WIDTH, TAG_COUNT}; 2 +use crate::config::{
3 + BORDER_FOCUSED, BORDER_UNFOCUSED, BORDER_WIDTH, GAP_INNER_HORIZONTAL, GAP_INNER_VERTICAL,
4 + GAP_OUTER_HORIZONTAL, GAP_OUTER_VERTICAL, GAPS_ENABLED, TAG_COUNT,
5 +};
3 use crate::keyboard::{self, Arg, KeyAction}; 6 use crate::keyboard::{self, Arg, KeyAction};
7 +use crate::layout::GapConfig;
4 use crate::layout::Layout; 8 use crate::layout::Layout;
5 use crate::layout::tiling::TilingLayout; 9 use crate::layout::tiling::TilingLayout;
6 use anyhow::Result; 10 use anyhow::Result;
@@ -25,6 +29,7 @@ pub struct WindowManager {
25 layout: Box<dyn Layout>, 29 layout: Box<dyn Layout>,
26 window_tags: std::collections::HashMap<Window, TagMask>, 30 window_tags: std::collections::HashMap<Window, TagMask>,
27 selected_tags: TagMask, 31 selected_tags: TagMask,
32 + gaps_enabled: bool,
28 bar: Bar, 33 bar: Bar,
29 } 34 }
30 35
@@ -49,6 +54,7 @@ impl WindowManager {
49 let bar = Bar::new(&connection, &screen, screen_number)?; 54 let bar = Bar::new(&connection, &screen, screen_number)?;
50 55
51 let selected_tags = Self::get_saved_selected_tags(&connection, root)?; 56 let selected_tags = Self::get_saved_selected_tags(&connection, root)?;
57 + let gaps_enabled = GAPS_ENABLED;
52 58
53 let mut window_manger = Self { 59 let mut window_manger = Self {
54 connection, 60 connection,
@@ -60,6 +66,7 @@ impl WindowManager {
60 layout: Box::new(TilingLayout), 66 layout: Box::new(TilingLayout),
61 window_tags: std::collections::HashMap::new(), 67 window_tags: std::collections::HashMap::new(),
62 selected_tags, 68 selected_tags,
69 + gaps_enabled,
63 bar, 70 bar,
64 }; 71 };
65 72
@@ -287,6 +294,10 @@ impl WindowManager {
287 self.move_to_tag(*tag_index as usize)?; 294 self.move_to_tag(*tag_index as usize)?;
288 } 295 }
289 } 296 }
297 + KeyAction::ToggleGaps => {
298 + self.gaps_enabled = !self.gaps_enabled;
299 + self.apply_layout()?;
300 + }
290 KeyAction::None => { 301 KeyAction::None => {
291 //no-op 302 //no-op
292 } 303 }
@@ -520,8 +531,26 @@ impl WindowManager {
520 let bar_height = self.bar.height() as u32; 531 let bar_height = self.bar.height() as u32;
521 let usable_height = screen_height.saturating_sub(bar_height); 532 let usable_height = screen_height.saturating_sub(bar_height);
522 533
534 + let gaps = if self.gaps_enabled {
535 + GapConfig {
536 + inner_horizontal: GAP_INNER_HORIZONTAL,
537 + inner_vertical: GAP_INNER_VERTICAL,
538 + outer_horizontal: GAP_OUTER_HORIZONTAL,
539 + outer_vertical: GAP_OUTER_VERTICAL,
540 + }
541 + } else {
542 + GapConfig {
543 + inner_horizontal: 0,
544 + inner_vertical: 0,
545 + outer_horizontal: 0,
546 + outer_vertical: 0,
547 + }
548 + };
549 +
523 let visible = self.visible_windows(); 550 let visible = self.visible_windows();
524 - let geometries = self.layout.arrange(&visible, screen_width, usable_height); 551 + let geometries = self
552 + .layout
553 + .arrange(&visible, screen_width, usable_height, &gaps);
525 554
526 for (window, geometry) in visible.iter().zip(geometries.iter()) { 555 for (window, geometry) in visible.iter().zip(geometries.iter()) {
527 let adjusted_width = geometry.width.saturating_sub(2 * border_width); 556 let adjusted_width = geometry.width.saturating_sub(2 * border_width);