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 7 // APPEARANCE
8 8 // ========================================
9 -pub const BORDER_WIDTH: u32 = 1;
9 +pub const BORDER_WIDTH: u32 = 0;
10 10 pub const BORDER_FOCUSED: u32 = 0x6dade3;
11 11 pub const BORDER_UNFOCUSED: u32 = 0xbbbbbb;
12 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 24 // DEFAULTS
16 25 // ========================================
@@ -89,6 +98,7 @@ pub const KEYBINDINGS: &[Key] = &[
89 98 Key::new(&[MODKEY], keycodes::S, KeyAction::Spawn, Arg::Array(SCREENSHOT_CMD)),
90 99 Key::new(&[MODKEY], keycodes::D, KeyAction::Spawn, Arg::Array(DMENU_CMD)),
91 100 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
101 + Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
92 102 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
93 103 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
94 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 11 Quit,
12 12 Restart,
13 13 ViewTag,
14 + ToggleGaps,
14 15 MoveToTag,
15 16 None,
16 17 }
+8 −0 src/layout/mod.rs
@@ -2,12 +2,20 @@ pub mod tiling;
2 2
3 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 12 pub trait Layout {
6 13 fn arrange(
7 14 &self,
8 15 windows: &[Window],
9 16 screen_width: u32,
10 17 screen_height: u32,
18 + gaps: &GapConfig,
11 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 2 use x11rb::protocol::xproto::Window;
3 3
4 4 pub struct TilingLayout;
@@ -9,6 +9,7 @@ impl Layout for TilingLayout {
9 9 windows: &[Window],
10 10 screen_width: u32,
11 11 screen_height: u32,
12 + gaps: &GapConfig,
12 13 ) -> Vec<WindowGeometry> {
13 14 let window_count = windows.len();
14 15 if window_count == 0 {
@@ -16,31 +17,60 @@ impl Layout for TilingLayout {
16 17 }
17 18
18 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 25 vec![WindowGeometry {
20 - x_coordinate: 0,
21 - y_coordinate: 0,
22 - width: screen_width,
23 - height: screen_height,
26 + x_coordinate: x,
27 + y_coordinate: y,
28 + width,
29 + height,
24 30 }]
25 31 } else {
26 - let master_width = screen_width / 2;
27 - let mut geometries = vec![WindowGeometry {
28 - x_coordinate: 0,
29 - y_coordinate: 0,
32 + let mut geometries = Vec::new();
33 +
34 + let master_width = (screen_width / 2)
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 45 width: master_width,
31 - height: screen_height,
32 - }];
46 + height: master_height,
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 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 66 geometries.push(WindowGeometry {
38 - x_coordinate: master_width as i32,
67 + x_coordinate: stack_x,
39 68 y_coordinate: y_offset as i32,
40 - width: master_width,
69 + width: stack_width,
41 70 height: stack_height,
42 71 });
43 72 }
73 +
44 74 return geometries;
45 75 }
46 76 }
+31 −2 src/window_manager.rs
@@ -1,6 +1,10 @@
1 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 6 use crate::keyboard::{self, Arg, KeyAction};
7 +use crate::layout::GapConfig;
4 8 use crate::layout::Layout;
5 9 use crate::layout::tiling::TilingLayout;
6 10 use anyhow::Result;
@@ -25,6 +29,7 @@ pub struct WindowManager {
25 29 layout: Box<dyn Layout>,
26 30 window_tags: std::collections::HashMap<Window, TagMask>,
27 31 selected_tags: TagMask,
32 + gaps_enabled: bool,
28 33 bar: Bar,
29 34 }
30 35
@@ -49,6 +54,7 @@ impl WindowManager {
49 54 let bar = Bar::new(&connection, &screen, screen_number)?;
50 55
51 56 let selected_tags = Self::get_saved_selected_tags(&connection, root)?;
57 + let gaps_enabled = GAPS_ENABLED;
52 58
53 59 let mut window_manger = Self {
54 60 connection,
@@ -60,6 +66,7 @@ impl WindowManager {
60 66 layout: Box::new(TilingLayout),
61 67 window_tags: std::collections::HashMap::new(),
62 68 selected_tags,
69 + gaps_enabled,
63 70 bar,
64 71 };
65 72
@@ -287,6 +294,10 @@ impl WindowManager {
287 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 301 KeyAction::None => {
291 302 //no-op
292 303 }
@@ -520,8 +531,26 @@ impl WindowManager {
520 531 let bar_height = self.bar.height() as u32;
521 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 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 555 for (window, geometry) in visible.iter().zip(geometries.iter()) {
527 556 let adjusted_width = geometry.width.saturating_sub(2 * border_width);