implements #121 : per tag default layouts
Browse files
+10 −0 src/config/config.zig
| @@ -86,6 +86,15 @@ pub const Layouts = enum(u32) { | ||
| 86 | 86 | floating, |
| 87 | 87 | scrolling, |
| 88 | 88 | grid, |
| 89 | + | |
| 90 | + pub fn fromString(name: []const u8) ?Layouts { | |
| 91 | + if (std.meta.stringToEnum(Layouts, name)) |v| return v; | |
| 92 | + if (std.mem.eql(u8, name, "tile")) return .tiling; | |
| 93 | + if (std.mem.eql(u8, name, "normie")) return .floating; | |
| 94 | + if (std.mem.eql(u8, name, "float")) return .floating; | |
| 95 | + if (std.mem.eql(u8, name, "scroll")) return .scrolling; | |
| 96 | + return null; | |
| 97 | + } | |
| 89 | 98 | }; |
| 90 | 99 | |
| 91 | 100 | pub const MouseButton = struct { |
| @@ -125,6 +134,7 @@ pub const Config = struct { | ||
| 125 | 134 | bar_position: []const u8 = "top", |
| 126 | 135 | tags: [9][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, |
| 127 | 136 | layout: []const u8 = "tiling", |
| 137 | + tag_layouts: [9]?[]const u8 = .{null} ** 9, | |
| 128 | 138 | |
| 129 | 139 | border_width: i32 = 2, |
| 130 | 140 | border_focused: u32 = 0x6dade3, |
+25 −16 src/config/lua.zig
| @@ -338,6 +338,9 @@ fn registerMiscFunctions(state: *c.lua_State) void { | ||
| 338 | 338 | |
| 339 | 339 | c.lua_pushcfunction(state, luaIncNumMaster); |
| 340 | 340 | c.lua_setfield(state, -2, "inc_num_master"); |
| 341 | + | |
| 342 | + c.lua_pushcfunction(state, luaSetTagLayout); | |
| 343 | + c.lua_setfield(state, -2, "set_tag_layout"); | |
| 341 | 344 | } |
| 342 | 345 | |
| 343 | 346 | fn createActionTable(state: *c.lua_State, action_name: [*:0]const u8) void { |
| @@ -1083,23 +1086,29 @@ fn luaSetLayoutSymbol(state: ?*c.lua_State) callconv(.c) c_int { | ||
| 1083 | 1086 | const name = getStringArg(s, 1) orelse return 0; |
| 1084 | 1087 | const symbol = dupeLuaString(s, 2) orelse return 0; |
| 1085 | 1088 | |
| 1086 | - const layout_map = .{ | |
| 1087 | - .{ "tiling", &cfg.layout_tile_symbol }, | |
| 1088 | - .{ "tile", &cfg.layout_tile_symbol }, | |
| 1089 | - .{ "normie", &cfg.layout_floating_symbol }, | |
| 1090 | - .{ "floating", &cfg.layout_floating_symbol }, | |
| 1091 | - .{ "float", &cfg.layout_floating_symbol }, | |
| 1092 | - .{ "monocle", &cfg.layout_monocle_symbol }, | |
| 1093 | - .{ "scrolling", &cfg.layout_scrolling_symbol }, | |
| 1094 | - .{ "scroll", &cfg.layout_scrolling_symbol }, | |
| 1095 | - .{ "grid", &cfg.layout_grid_symbol }, | |
| 1096 | - }; | |
| 1089 | + const layout = config_mod.Layouts.fromString(name) orelse return 0; | |
| 1090 | + switch (layout) { | |
| 1091 | + .tiling => cfg.layout_tile_symbol = symbol, | |
| 1092 | + .monocle => cfg.layout_monocle_symbol = symbol, | |
| 1093 | + .floating => cfg.layout_floating_symbol = symbol, | |
| 1094 | + .scrolling => cfg.layout_scrolling_symbol = symbol, | |
| 1095 | + .grid => cfg.layout_grid_symbol = symbol, | |
| 1096 | + } | |
| 1097 | + return 0; | |
| 1098 | +} | |
| 1097 | 1099 | |
| 1098 | - inline for (layout_map) |entry| { | |
| 1099 | - if (std.mem.eql(u8, name, entry[0])) { | |
| 1100 | - entry[1].* = symbol; | |
| 1101 | - return 0; | |
| 1102 | - } | |
| 1100 | +fn luaSetTagLayout(state: ?*c.lua_State) callconv(.c) c_int { | |
| 1101 | + const cfg = config orelse return 0; | |
| 1102 | + const s = state orelse return 0; | |
| 1103 | + const tag_index = c.lua_tointegerx(s, 1, null); | |
| 1104 | + if (tag_index < 1 or tag_index > 9) return 0; | |
| 1105 | + const name = getStringArg(s, 2) orelse return 0; | |
| 1106 | + if (config_mod.Layouts.fromString(name) == null) { | |
| 1107 | + std.debug.print("set_tag_layout: unknown layout '{s}'\n", .{name}); | |
| 1108 | + return 0; | |
| 1109 | + } | |
| 1110 | + if (dupeLuaString(s, 2)) |layout_str| { | |
| 1111 | + cfg.tag_layouts[@intCast(tag_index - 1)] = layout_str; | |
| 1103 | 1112 | } |
| 1104 | 1113 | return 0; |
| 1105 | 1114 | } |
+1 −1 src/wm/actions.zig
| @@ -358,7 +358,7 @@ pub fn cycleLayout(wm: *WindowManager) void { | ||
| 358 | 358 | pub fn setLayout(layout_name: ?[]const u8, wm: *WindowManager) void { |
| 359 | 359 | const monitor = wm.selected_monitor orelse return; |
| 360 | 360 | const name = layout_name orelse return; |
| 361 | - const new_lt: u32 = if (std.meta.stringToEnum(config_mod.Layouts, name)) |value| | |
| 361 | + const new_lt: u32 = if (config_mod.Layouts.fromString(name)) |value| | |
| 362 | 362 | @intFromEnum(value) |
| 363 | 363 | else { |
| 364 | 364 | std.debug.print("set_layout: unknown layout '{s}'\n", .{name}); |
+9 −1 src/wm/wm.zig
| @@ -181,7 +181,7 @@ pub const WindowManager = struct { | ||
| 181 | 181 | slot.* = layout; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if (std.meta.stringToEnum(config_mod.Layouts, self.config.layout)) |value| { | |
| 184 | + if (config_mod.Layouts.fromString(self.config.layout)) |value| { | |
| 185 | 185 | mon.sel_lt = @intFromEnum(value); |
| 186 | 186 | } |
| 187 | 187 | |
| @@ -192,6 +192,14 @@ pub const WindowManager = struct { | ||
| 192 | 192 | mon.pertag.sellts[i] = mon.sel_lt; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | + for (self.config.tag_layouts, 0..) |maybe_layout, i| { | |
| 196 | + if (maybe_layout) |layout_name| { | |
| 197 | + if (config_mod.Layouts.fromString(layout_name)) |value| { | |
| 198 | + mon.pertag.sellts[i + 1] = @intFromEnum(value); | |
| 199 | + } | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 195 | 203 | self.initMonitorGaps(mon); |
| 196 | 204 | } |
| 197 | 205 |
+4 −0 templates/config.lua
| @@ -114,6 +114,10 @@ oxwm.set_layout_symbol("tiling", "[T]") | ||
| 114 | 114 | oxwm.set_layout_symbol("normie", "[F]") |
| 115 | 115 | oxwm.set_layout_symbol("tabbed", "[=]") |
| 116 | 116 | |
| 117 | +-- Set default layout of specific tag (tag_index, layout_name) | |
| 118 | +-- Unset value uses oxwm.set_layout value | |
| 119 | +-- oxwm.set_tag_layout(1, "grid") | |
| 120 | + | |
| 117 | 121 | ------------------------------------------------------------------------------- |
| 118 | 122 | -- Appearance |
| 119 | 123 | ------------------------------------------------------------------------------- |