Added smartgaps impl
Browse files
+2 −2 src/layouts/grid.zig
| @@ -20,8 +20,8 @@ pub fn grid(monitor: *Monitor) void { | ||
| 20 | 20 | |
| 21 | 21 | if (client_count == 0) return; |
| 22 | 22 | |
| 23 | - const gap_outer_h = monitor.gap_outer_h; | |
| 24 | - const gap_outer_v = monitor.gap_outer_v; | |
| 23 | + const gap_outer_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h; | |
| 24 | + const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v; | |
| 25 | 25 | const gap_inner_h = monitor.gap_inner_h; |
| 26 | 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 | 15 | pub fn monocle(monitor: *Monitor) void { |
| 16 | - const gap_h = monitor.gap_outer_h; | |
| 17 | - const gap_v = monitor.gap_outer_v; | |
| 16 | + var client_count: u32 = 0; | |
| 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 | 25 | var current = client_mod.nextTiled(monitor.clients); |
| 20 | 26 | while (current) |client| { |
+9 −3 src/layouts/scrolling.zig
| @@ -21,8 +21,8 @@ pub fn scroll(monitor: *Monitor) void { | ||
| 21 | 21 | |
| 22 | 22 | if (client_count == 0) return; |
| 23 | 23 | |
| 24 | - const gap_outer_h = monitor.gap_outer_h; | |
| 25 | - const gap_outer_v = monitor.gap_outer_v; | |
| 24 | + const gap_outer_h = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_h; | |
| 25 | + const gap_outer_v = if (monitor.smartgaps_enabled and client_count == 1) 0 else monitor.gap_outer_v; | |
| 26 | 26 | const gap_inner_v = monitor.gap_inner_v; |
| 27 | 27 | |
| 28 | 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 | 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 | 78 | const gap_inner_v = monitor.gap_inner_v; |
| 73 | 79 | const visible_count: u32 = @intCast(@max(1, monitor.nmaster)); |
| 74 | 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 | 88 | count += 1; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - gap_outer_h.* = monitor.gap_outer_h; | |
| 92 | - gap_outer_v.* = monitor.gap_outer_v; | |
| 91 | + if (monitor.smartgaps_enabled and count == 1) { | |
| 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 | 99 | gap_inner_h.* = monitor.gap_inner_h; |
| 94 | 100 | gap_inner_v.* = monitor.gap_inner_v; |
| 95 | 101 | client_count.* = count; |
+1 −0 src/monitor.zig
| @@ -37,6 +37,7 @@ pub const Monitor = struct { | ||
| 37 | 37 | gap_inner_v: i32 = 0, |
| 38 | 38 | gap_outer_h: i32 = 0, |
| 39 | 39 | gap_outer_v: i32 = 0, |
| 40 | + smartgaps_enabled: bool = false, | |
| 40 | 41 | scroll_offset: i32 = 0, |
| 41 | 42 | sel_tags: u32 = 0, |
| 42 | 43 | sel_lt: u32 = 0, |
+2 −0 src/wm/wm.zig
| @@ -246,6 +246,8 @@ pub const WindowManager = struct { | ||
| 246 | 246 | const any_gap_nonzero = cfg.gap_inner_h != 0 or cfg.gap_inner_v != 0 or |
| 247 | 247 | cfg.gap_outer_h != 0 or cfg.gap_outer_v != 0; |
| 248 | 248 | |
| 249 | + mon.smartgaps_enabled = cfg.smartgaps_enabled; | |
| 250 | + | |
| 249 | 251 | if (cfg.gaps_enabled and any_gap_nonzero) { |
| 250 | 252 | mon.gap_inner_h = cfg.gap_inner_h; |
| 251 | 253 | mon.gap_inner_v = cfg.gap_inner_v; |