tony / oxwm

Added size hints for old terminals, and added smartgaps flag to lua config for single window gaps Browse files
tonybtw committed 2025-12-01 parent 16b90b9 commit 23d144c8b1d6ce0d4b778c35729daf19dc232d4c
Showing 11 changed files with 35 additions and 3 deletions. UnifiedSplit
+1 −0 resources/test-config.lua
@@ -42,6 +42,7 @@ oxwm.border.set_focused_color(colors.blue)
42 42 oxwm.border.set_unfocused_color(colors.grey)
43 43
44 44 oxwm.gaps.set_enabled(true)
45 +oxwm.gaps.set_smart(true) -- Disable outer gaps when only 1 window (dwm smartgaps)
45 46 oxwm.gaps.set_inner(5, 5)
46 47 oxwm.gaps.set_outer(5, 5)
47 48
+1 −0 src/config/lua.rs
@@ -32,6 +32,7 @@ pub fn parse_lua_config(
32 32 border_unfocused: builder_data.border_unfocused,
33 33 font: builder_data.font,
34 34 gaps_enabled: builder_data.gaps_enabled,
35 + smartgaps_enabled: builder_data.smartgaps_enabled,
35 36 gap_inner_horizontal: builder_data.gap_inner_horizontal,
36 37 gap_inner_vertical: builder_data.gap_inner_vertical,
37 38 gap_outer_horizontal: builder_data.gap_outer_horizontal,
+9 −0 src/config/lua_api.rs
@@ -16,6 +16,7 @@ pub struct ConfigBuilder {
16 16 pub border_unfocused: u32,
17 17 pub font: String,
18 18 pub gaps_enabled: bool,
19 + pub smartgaps_enabled: bool,
19 20 pub gap_inner_horizontal: u32,
20 21 pub gap_inner_vertical: u32,
21 22 pub gap_outer_horizontal: u32,
@@ -40,6 +41,7 @@ impl Default for ConfigBuilder {
40 41 border_unfocused: 0xbbbbbb,
41 42 font: "monospace:style=Bold:size=10".to_string(),
42 43 gaps_enabled: true,
44 + smartgaps_enabled: true,
43 45 gap_inner_horizontal: 5,
44 46 gap_inner_vertical: 5,
45 47 gap_outer_horizontal: 5,
@@ -184,11 +186,18 @@ fn register_gaps_module(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Re
184 186 Ok(())
185 187 })?;
186 188
189 + let builder_clone = builder.clone();
190 + let set_smart = lua.create_function(move |_, enabled: bool| {
191 + builder_clone.borrow_mut().smartgaps_enabled = enabled;
192 + Ok(())
193 + })?;
194 +
187 195 gaps_table.set("set_enabled", set_enabled)?;
188 196 gaps_table.set("enable", enable)?;
189 197 gaps_table.set("disable", disable)?;
190 198 gaps_table.set("set_inner", set_inner)?;
191 199 gaps_table.set("set_outer", set_outer)?;
200 + gaps_table.set("set_smart", set_smart)?;
192 201 parent.set("gaps", gaps_table)?;
193 202 Ok(())
194 203 }
+1 −0 src/layout/grid.rs
@@ -20,6 +20,7 @@ impl Layout for GridLayout {
20 20 gaps: &GapConfig,
21 21 _master_factor: f32,
22 22 _num_master: i32,
23 + _smartgaps_enabled: bool,
23 24 ) -> Vec<WindowGeometry> {
24 25 let window_count = windows.len();
25 26 if window_count == 0 {
+1 −0 src/layout/mod.rs
@@ -88,6 +88,7 @@ pub trait Layout {
88 88 gaps: &GapConfig,
89 89 master_factor: f32,
90 90 num_master: i32,
91 + smartgaps_enabled: bool,
91 92 ) -> Vec<WindowGeometry>;
92 93 fn name(&self) -> &'static str;
93 94 fn symbol(&self) -> &'static str;
+1 −0 src/layout/monocle.rs
@@ -20,6 +20,7 @@ impl Layout for MonocleLayout {
20 20 gaps: &GapConfig,
21 21 _master_factor: f32,
22 22 _num_master: i32,
23 + _smartgaps_enabled: bool,
23 24 ) -> Vec<WindowGeometry> {
24 25 let window_count = windows.len();
25 26 if window_count == 0 {
+1 −0 src/layout/normie.rs
@@ -21,6 +21,7 @@ impl Layout for NormieLayout {
21 21 _gaps: &GapConfig,
22 22 _master_factor: f32,
23 23 _num_master: i32,
24 + _smartgaps_enabled: bool,
24 25 ) -> Vec<WindowGeometry> {
25 26 const DEFAULT_WIDTH_RATIO: f32 = 0.6;
26 27 const DEFAULT_HEIGHT_RATIO: f32 = 0.6;
+1 −0 src/layout/tabbed.rs
@@ -22,6 +22,7 @@ impl Layout for TabbedLayout {
22 22 gaps: &GapConfig,
23 23 _master_factor: f32,
24 24 _num_master: i32,
25 + _smartgaps_enabled: bool,
25 26 ) -> Vec<WindowGeometry> {
26 27 let window_count = windows.len();
27 28 if window_count == 0 {
+1 −1 src/layout/tiling.rs
@@ -87,13 +87,13 @@ impl Layout for TilingLayout {
87 87 gaps: &GapConfig,
88 88 master_factor: f32,
89 89 num_master: i32,
90 + smartgaps_enabled: bool,
90 91 ) -> Vec<WindowGeometry> {
91 92 let window_count = windows.len();
92 93 if window_count == 0 {
93 94 return Vec::new();
94 95 }
95 96
96 - let smartgaps_enabled = true;
97 97 let gap_values = Self::getgaps(gaps, window_count, smartgaps_enabled);
98 98
99 99 let outer_gap_horizontal = gap_values.outer_horizontal;
+2 −0 src/lib.rs
@@ -33,6 +33,7 @@ pub struct Config {
33 33
34 34 // Gaps
35 35 pub gaps_enabled: bool,
36 + pub smartgaps_enabled: bool,
36 37 pub gap_inner_horizontal: u32,
37 38 pub gap_inner_vertical: u32,
38 39 pub gap_outer_horizontal: u32,
@@ -87,6 +88,7 @@ impl Default for Config {
87 88 border_unfocused: 0xbbbbbb,
88 89 font: "monospace:size=10".to_string(),
89 90 gaps_enabled: false,
91 + smartgaps_enabled: true,
90 92 gap_inner_horizontal: 0,
91 93 gap_inner_vertical: 0,
92 94 gap_outer_horizontal: 0,
+16 −2 src/window_manager.rs
@@ -2698,6 +2698,7 @@ impl WindowManager {
2698 2698 let usable_height = monitor_height.saturating_sub(bar_height as i32);
2699 2699 let master_factor = monitor.master_factor;
2700 2700 let num_master = monitor.num_master;
2701 + let smartgaps_enabled = self.config.smartgaps_enabled;
2701 2702
2702 2703 let geometries = self.layout.arrange(
2703 2704 &visible,
@@ -2706,11 +2707,24 @@ impl WindowManager {
2706 2707 &gaps,
2707 2708 master_factor,
2708 2709 num_master,
2710 + smartgaps_enabled,
2709 2711 );
2710 2712
2711 2713 for (window, geometry) in visible.iter().zip(geometries.iter()) {
2712 - let adjusted_width = geometry.width.saturating_sub(2 * border_width);
2713 - let adjusted_height = geometry.height.saturating_sub(2 * border_width);
2714 + let mut adjusted_width = geometry.width.saturating_sub(2 * border_width);
2715 + let mut adjusted_height = geometry.height.saturating_sub(2 * border_width);
2716 +
2717 + if let Some(client) = self.clients.get(window) {
2718 + if !client.is_floating {
2719 + let (hint_width, hint_height) = self.apply_size_hints(
2720 + client,
2721 + adjusted_width as i32,
2722 + adjusted_height as i32,
2723 + );
2724 + adjusted_width = hint_width as u32;
2725 + adjusted_height = hint_height as u32;
2726 + }
2727 + }
2714 2728
2715 2729 let adjusted_x = geometry.x_coordinate + monitor_x;
2716 2730 let adjusted_y = geometry.y_coordinate + monitor_y + bar_height as i32;