tony / oxwm

Added smartgaps impl Browse files
tonybanters committed 2026-02-27 parent 5bb9e13 commit c09f00418c8076b209700f78b7d41c32fe07fef1
Showing 6 changed files with 30 additions and 9 deletions. UnifiedSplit
+2 −2 src/layouts/grid.zig
@@ -20,8 +20,8 @@ pub fn grid(monitor: *Monitor) void {
20 20
21 if (client_count == 0) return; 21 if (client_count == 0) return;
22 22
23 - const gap_outer_h = monitor.gap_outer_h; 23 + const gap_outer_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h;
24 - const gap_outer_v = monitor.gap_outer_v; 24 + const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v;
25 const gap_inner_h = monitor.gap_inner_h; 25 const gap_inner_h = monitor.gap_inner_h;
26 const gap_inner_v = monitor.gap_inner_v; 26 const gap_inner_v = monitor.gap_inner_v;
27 27
+8 −2 src/layouts/monocle.zig
@@ -13,8 +13,14 @@ pub const layout = monitor_mod.Layout{
13 }; 13 };
14 14
15 pub fn monocle(monitor: *Monitor) void { 15 pub fn monocle(monitor: *Monitor) void {
16 - const gap_h = monitor.gap_outer_h; 16 + var client_count: u32 = 0;
17 - const gap_v = monitor.gap_outer_v; 17 + var count_current = client_mod.nextTiled(monitor.clients);
18 + while (count_current) |_| : (count_current = client_mod.nextTiled(count_current.?.next)) {
19 + client_count += 1;
20 + }
21 +
22 + const gap_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h;
23 + const gap_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v;
18 24
19 var current = client_mod.nextTiled(monitor.clients); 25 var current = client_mod.nextTiled(monitor.clients);
20 while (current) |client| { 26 while (current) |client| {
+9 −3 src/layouts/scrolling.zig
@@ -21,8 +21,8 @@ pub fn scroll(monitor: *Monitor) void {
21 21
22 if (client_count == 0) return; 22 if (client_count == 0) return;
23 23
24 - const gap_outer_h = monitor.gap_outer_h; 24 + const gap_outer_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h;
25 - const gap_outer_v = monitor.gap_outer_v; 25 + const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v;
26 const gap_inner_v = monitor.gap_inner_v; 26 const gap_inner_v = monitor.gap_inner_v;
27 27
28 const visible_count: u32 = @intCast(@max(1, monitor.nmaster)); 28 const visible_count: u32 = @intCast(@max(1, monitor.nmaster));
@@ -68,7 +68,13 @@ pub fn scroll(monitor: *Monitor) void {
68 } 68 }
69 69
70 pub fn getScrollStep(monitor: *Monitor) i32 { 70 pub fn getScrollStep(monitor: *Monitor) i32 {
71 - const gap_outer_v = monitor.gap_outer_v; 71 + var client_count: u32 = 0;
72 + var current = client_mod.nextTiled(monitor.clients);
73 + while (current) |_| : (current = client_mod.nextTiled(current.?.next)) {
74 + client_count += 1;
75 + }
76 +
77 + const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v;
72 const gap_inner_v = monitor.gap_inner_v; 78 const gap_inner_v = monitor.gap_inner_v;
73 const visible_count: u32 = @intCast(@max(1, monitor.nmaster)); 79 const visible_count: u32 = @intCast(@max(1, monitor.nmaster));
74 const available_width = monitor.win_w - 2 * gap_outer_v; 80 const available_width = monitor.win_w - 2 * gap_outer_v;
+8 −2 src/layouts/tiling.zig
@@ -88,8 +88,14 @@ fn getGaps(monitor: *Monitor, gap_outer_h: *i32, gap_outer_v: *i32, gap_inner_h:
88 count += 1; 88 count += 1;
89 } 89 }
90 90
91 - gap_outer_h.* = monitor.gap_outer_h; 91 + if (monitor.smartgaps_enabled and count == 1) {
92 - gap_outer_v.* = monitor.gap_outer_v; 92 + gap_outer_h.* = 0;
93 + gap_outer_v.* = 0;
94 + } else {
95 + gap_outer_h.* = monitor.gap_outer_h;
96 + gap_outer_v.* = monitor.gap_outer_v;
97 + }
98 +
93 gap_inner_h.* = monitor.gap_inner_h; 99 gap_inner_h.* = monitor.gap_inner_h;
94 gap_inner_v.* = monitor.gap_inner_v; 100 gap_inner_v.* = monitor.gap_inner_v;
95 client_count.* = count; 101 client_count.* = count;
+1 −0 src/monitor.zig
@@ -37,6 +37,7 @@ pub const Monitor = struct {
37 gap_inner_v: i32 = 0, 37 gap_inner_v: i32 = 0,
38 gap_outer_h: i32 = 0, 38 gap_outer_h: i32 = 0,
39 gap_outer_v: i32 = 0, 39 gap_outer_v: i32 = 0,
40 + smartgaps_enabled: bool = false,
40 scroll_offset: i32 = 0, 41 scroll_offset: i32 = 0,
41 sel_tags: u32 = 0, 42 sel_tags: u32 = 0,
42 sel_lt: u32 = 0, 43 sel_lt: u32 = 0,
+2 −0 src/wm/wm.zig
@@ -246,6 +246,8 @@ pub const WindowManager = struct {
246 const any_gap_nonzero = cfg.gap_inner_h != 0 or cfg.gap_inner_v != 0 or 246 const any_gap_nonzero = cfg.gap_inner_h != 0 or cfg.gap_inner_v != 0 or
247 cfg.gap_outer_h != 0 or cfg.gap_outer_v != 0; 247 cfg.gap_outer_h != 0 or cfg.gap_outer_v != 0;
248 248
249 + mon.smartgaps_enabled = cfg.smartgaps_enabled;
250 +
249 if (cfg.gaps_enabled and any_gap_nonzero) { 251 if (cfg.gaps_enabled and any_gap_nonzero) {
250 mon.gap_inner_h = cfg.gap_inner_h; 252 mon.gap_inner_h = cfg.gap_inner_h;
251 mon.gap_inner_v = cfg.gap_inner_v; 253 mon.gap_inner_v = cfg.gap_inner_v;