tony / oxwm

Merge pull request #206 from tonybanters/dwindle Browse files
Dwindle Layout
Tony, btw. committed 2026-05-11 parents 8362768 013a84e commit b0374a4d6cea53c5b3c02969ebd9a1198112b2da
Showing 8 changed files with 93 additions and 8 deletions. UnifiedSplit
+1 −0 src/bar/bar.zig
@@ -18,6 +18,7 @@ fn getLayoutSymbol(layout_index: u32, config: config_mod.Config) []const u8 {
18 18 .floating => config.layout_floating_symbol,
19 19 .scrolling => config.layout_scrolling_symbol,
20 20 .grid => config.layout_grid_symbol,
21 + .dwindle => config.layout_dwindle_symbol,
21 22 };
22 23 }
23 24
+4 −0 src/config/config.zig
@@ -88,6 +88,7 @@ pub const Layouts = enum(u32) {
88 88 floating,
89 89 scrolling,
90 90 grid,
91 + dwindle,
91 92
92 93 pub fn fromString(name: []const u8) ?Layouts {
93 94 if (std.meta.stringToEnum(Layouts, name)) |v| return v;
@@ -95,6 +96,8 @@ pub const Layouts = enum(u32) {
95 96 if (std.mem.eql(u8, name, "normie")) return .floating;
96 97 if (std.mem.eql(u8, name, "float")) return .floating;
97 98 if (std.mem.eql(u8, name, "scroll")) return .scrolling;
99 + if (std.mem.eql(u8, name, "fib")) return .dwindle;
100 + if (std.mem.eql(u8, name, "fibonacci")) return .dwindle;
98 101 return null;
99 102 }
100 103 };
@@ -208,6 +211,7 @@ pub const Config = struct {
208 211 layout_floating_symbol: []const u8 = "><>",
209 212 layout_scrolling_symbol: []const u8 = "[S]",
210 213 layout_grid_symbol: []const u8 = "[#]",
214 + layout_dwindle_symbol: []const u8 = "[\\]",
211 215
212 216 scheme_normal: ColorScheme = .{ .foreground = 0xbbbbbb, .background = 0x1a1b26, .border = 0x444444 },
213 217 scheme_selected: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0xad8ee6 },
+1 −0 src/config/lua.zig
@@ -1147,6 +1147,7 @@ fn luaSetLayoutSymbol(state: ?*c.lua_State) callconv(.c) c_int {
1147 1147 .floating => cfg.layout_floating_symbol = symbol,
1148 1148 .scrolling => cfg.layout_scrolling_symbol = symbol,
1149 1149 .grid => cfg.layout_grid_symbol = symbol,
1150 + .dwindle => cfg.layout_dwindle_symbol = symbol,
1150 1151 }
1151 1152 return 0;
1152 1153 }
+70 −0 src/layouts/dwindle.zig new file mode 100644
@@ -0,0 +1,70 @@
1 +const std = @import("std");
2 +const client_mod = @import("../client.zig");
3 +const monitor_mod = @import("../monitor.zig");
4 +const tiling = @import("tiling.zig");
5 +
6 +const Client = client_mod.Client;
7 +const Monitor = monitor_mod.Monitor;
8 +
9 +pub const layout = monitor_mod.Layout{
10 + .symbol = "[\\]",
11 + .arrange_fn = dwindle,
12 +};
13 +
14 +pub fn dwindle(monitor: *Monitor) void {
15 + var n: u32 = 0;
16 + var counter = client_mod.nextTiled(monitor.clients);
17 + while (counter) |c| : (counter = client_mod.nextTiled(c.next)) {
18 + n += 1;
19 + }
20 + if (n == 0) return;
21 +
22 + const gap_h = if (monitor.smartgaps_enabled and n == 1) 0 else monitor.gap_outer_h;
23 + const gap_v = if (monitor.smartgaps_enabled and n == 1) 0 else monitor.gap_outer_v;
24 +
25 + const work_x: i32 = monitor.win_x + gap_v;
26 + const work_y: i32 = monitor.win_y + gap_h;
27 + const work_w: i32 = monitor.win_w - 2 * gap_v;
28 + const work_h: i32 = monitor.win_h - 2 * gap_h;
29 +
30 + var nx: i32 = work_x;
31 + var ny: i32 = 0;
32 + var nw: i32 = work_w;
33 + var nh: i32 = work_h;
34 +
35 + var i: u32 = 0;
36 + var current = client_mod.nextTiled(monitor.clients);
37 + while (current) |c| : (current = client_mod.nextTiled(c.next)) {
38 + const bw = c.border_width;
39 + const can_split = (i % 2 == 1 and @divTrunc(nh, 2) > 2 * bw) or
40 + (i % 2 == 0 and @divTrunc(nw, 2) > 2 * bw);
41 +
42 + if (can_split) {
43 + if (i + 1 < n) {
44 + if (i % 2 == 1) {
45 + nh = @divTrunc(nh, 2);
46 + } else {
47 + nw = @divTrunc(nw, 2);
48 + }
49 + }
50 + switch (i % 4) {
51 + 0 => ny += nh,
52 + 1 => nx += nw,
53 + 2 => ny += nh,
54 + 3 => nx += nw,
55 + else => unreachable,
56 + }
57 + if (i == 0) {
58 + if (n != 1) {
59 + nw = @intFromFloat(@as(f32, @floatFromInt(work_w)) * monitor.mfact);
60 + }
61 + ny = work_y;
62 + } else if (i == 1) {
63 + nw = work_w - nw;
64 + }
65 + i += 1;
66 + }
67 +
68 + tiling.resize(c, nx, ny, nw - 2 * bw, nh - 2 * bw, false);
69 + }
70 +}
+2 −2 src/monitor.zig
@@ -15,7 +15,7 @@ pub const Pertag = struct {
15 15 nmasters: [10]i32 = [_]i32{1} ** 10,
16 16 mfacts: [10]f32 = [_]f32{0.55} ** 10,
17 17 sellts: [10]u32 = [_]u32{0} ** 10,
18 - ltidxs: [10][5]?*const Layout = [_][5]?*const Layout{.{ null, null, null, null, null }} ** 10,
18 + ltidxs: [10][6]?*const Layout = [_][6]?*const Layout{.{ null, null, null, null, null, null }} ** 10,
19 19 showbars: [10]bool = [_]bool{true} ** 10,
20 20 };
21 21
@@ -49,7 +49,7 @@ pub const Monitor = struct {
49 49 stack: ?*Client = null,
50 50 next: ?*Monitor = null,
51 51 bar_win: xlib.Window = 0,
52 - lt: [5]?*const Layout = .{null} ** 5,
52 + lt: [6]?*const Layout = .{null} ** 6,
53 53 pertag: Pertag = .{},
54 54 };
55 55
+5 −0 src/wm/wm.zig
@@ -17,6 +17,7 @@ const monocle = @import("../layouts/monocle.zig");
17 17 const floating = @import("../layouts/floating.zig");
18 18 const scrolling = @import("../layouts/scrolling.zig");
19 19 const grid = @import("../layouts/grid.zig");
20 +const dwindle = @import("../layouts/dwindle.zig");
20 21
21 22 pub const core = @import("core.zig");
22 23 pub const actions = @import("actions.zig");
@@ -167,6 +168,7 @@ pub const WindowManager = struct {
167 168 &floating.layout,
168 169 &scrolling.layout,
169 170 &grid.layout,
171 + &dwindle.layout,
170 172 };
171 173
172 174 fn initMonitor(self: *WindowManager, mon: *Monitor, num: usize, x: i16, y: i16, w: c_int, h: c_int) void {
@@ -267,12 +269,14 @@ pub const WindowManager = struct {
267 269 new_mon.lt[2] = &floating.layout;
268 270 new_mon.lt[3] = &scrolling.layout;
269 271 new_mon.lt[4] = &grid.layout;
272 + new_mon.lt[5] = &dwindle.layout;
270 273 for (0..10) |i| {
271 274 new_mon.pertag.ltidxs[i][0] = new_mon.lt[0];
272 275 new_mon.pertag.ltidxs[i][1] = new_mon.lt[1];
273 276 new_mon.pertag.ltidxs[i][2] = new_mon.lt[2];
274 277 new_mon.pertag.ltidxs[i][3] = new_mon.lt[3];
275 278 new_mon.pertag.ltidxs[i][4] = new_mon.lt[4];
279 + new_mon.pertag.ltidxs[i][5] = new_mon.lt[5];
276 280 }
277 281 if (last) |l| {
278 282 l.next = new_mon;
@@ -356,6 +360,7 @@ pub const WindowManager = struct {
356 360 mon.lt[2] = &floating.layout;
357 361 mon.lt[3] = &scrolling.layout;
358 362 mon.lt[4] = &grid.layout;
363 + mon.lt[5] = &dwindle.layout;
359 364 self.monitors = mon;
360 365 self.selected_monitor = mon;
361 366 }
+5 −1 templates/config.lua
@@ -112,10 +112,14 @@ oxwm.set_tags(tags)
112 112 -- Layouts
113 113 -------------------------------------------------------------------------------
114 114 -- Set custom symbols for layouts (displayed in the status bar)
115 --- Available layouts: "tiling", "normie" (floating), "grid", "monocle", "tabbed"
115 +-- Available layouts: "tiling", "normie" (floating), "grid", "monocle", "tabbed", "dwindle"
116 116 oxwm.set_layout_symbol("tiling", "[T]")
117 117 oxwm.set_layout_symbol("normie", "[F]")
118 118 oxwm.set_layout_symbol("tabbed", "[=]")
119 +-- oxwm.set_layout_symbol("dwindle", "[\\]")
120 +
121 +-- Example: bind dwindle (fibonacci) layout
122 +-- oxwm.key.bind({ modkey }, "R", oxwm.layout.set("dwindle"))
119 123
120 124 -- Set default layout of specific tag (tag_index, layout_name)
121 125 -- Unset value uses oxwm.set_layout value
+5 −5 templates/oxwm.lua
@@ -46,17 +46,17 @@ function oxwm.auto_tile(enabled) end
46 46 function oxwm.tiled_resize_mode(enabled) end
47 47
48 48 ---Set layout symbol override
49 ----@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle")
50 ----@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]")
49 +---@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle", "dwindle")
50 +---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]", "[\\]")
51 51 function oxwm.set_layout_symbol(name, symbol) end
52 52
53 53 ---Set default layout for all tags
54 ----@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", or aliases: "tile", "float", "scroll", "normie")
54 +---@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", "dwindle", or aliases: "tile", "float", "scroll", "normie", "fib", "fibonacci")
55 55 function oxwm.set_layout(name) end
56 56
57 57 ---Set default layout for a specific tag
58 58 ---@param tag integer Tag index (1-9)
59 ----@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", or aliases)
59 +---@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", "dwindle", or aliases)
60 60 function oxwm.set_tag_layout(tag, name) end
61 61
62 62 ---Set floating window spawn position
@@ -213,7 +213,7 @@ oxwm.layout = {}
213 213 function oxwm.layout.cycle() end
214 214
215 215 ---Set specific layout
216 ----@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle", "scrolling")
216 +---@param name string Layout name (e.g., "tiling", "normie", "tabbed", "grid", "monocle", "scrolling", "dwindle")
217 217 ---@return table Action table for keybinding
218 218 function oxwm.layout.set(name) end
219 219