tony / oxwm

Merge pull request #168 from Iziram/master Browse files
Features : Quality of life
Tony, btw. committed 2026-03-30 parents 4670ae7 2d0f539 commit f6a28b2350b32683922c6bc428a3c1c30650b78d
Showing 12 changed files with 415 additions and 110 deletions. UnifiedSplit
+32 −9 src/bar/bar.zig
@@ -9,13 +9,13 @@ const Monitor = monitor_mod.Monitor;
9 9 const Block = blocks_mod.Block;
10 10
11 11 fn getLayoutSymbol(layout_index: u32, config: config_mod.Config) []const u8 {
12 - return switch (layout_index) {
13 - 0 => config.layout_tile_symbol,
14 - 1 => config.layout_monocle_symbol,
15 - 2 => config.layout_floating_symbol,
16 - 3 => config.layout_scrolling_symbol,
17 - 4 => "[#]",
18 - else => "[?]",
12 + const layout = std.meta.intToEnum(config_mod.Layouts, layout_index) catch return "[?]";
13 + return switch (layout) {
14 + .tiling => config.layout_tile_symbol,
15 + .monocle => config.layout_monocle_symbol,
16 + .floating => config.layout_floating_symbol,
17 + .scrolling => config.layout_scrolling_symbol,
18 + .grid => config.layout_grid_symbol,
19 19 };
20 20 }
21 21
@@ -73,11 +73,23 @@ pub const Bar = struct {
73 73 const font_height = font.*.ascent + font.*.descent;
74 74 const bar_height: i32 = @intCast(@as(i32, font_height) + 8);
75 75
76 + var bar_y: i32 = 0;
77 +
78 + if (std.mem.eql(u8, config.bar_position, "top")) {
79 + bar_y = monitor.mon_y;
80 + monitor.win_y = monitor.mon_y + bar_height;
81 + } else if (std.mem.eql(u8, config.bar_position, "bottom")) {
82 + bar_y = monitor.mon_y + monitor.mon_h - bar_height;
83 + monitor.win_y = monitor.mon_y;
84 + } else {
85 + return null;
86 + }
87 +
76 88 const window = xlib.c.XCreateSimpleWindow(
77 89 display,
78 90 root,
79 91 monitor.mon_x,
80 - monitor.mon_y,
92 + bar_y,
81 93 @intCast(monitor.mon_w),
82 94 @intCast(bar_height),
83 95 0,
@@ -125,7 +137,6 @@ pub const Bar = struct {
125 137 };
126 138
127 139 monitor.bar_win = window;
128 - monitor.win_y = monitor.mon_y + bar_height;
129 140 monitor.win_h = monitor.mon_h - bar_height;
130 141
131 142 return bar;
@@ -206,6 +217,8 @@ pub const Bar = struct {
206 217 const content = block.getContent();
207 218 const content_width = self.textWidth(display, content);
208 219 block_x -= content_width;
220 + block.x_start = block_x;
221 + block.x_end = block_x + content_width;
209 222 self.drawText(display, block_x, @divTrunc(self.height + self.font_height, 2) - 4, content, block.color());
210 223 if (block.underline) {
211 224 self.fillRect(display, block_x, self.height - 2, content_width, 2, block.color());
@@ -245,6 +258,16 @@ pub const Bar = struct {
245 258 return null;
246 259 }
247 260
261 + /// Returns the click action of the block the user clicked on, or null.
262 + pub fn handleBlockClick(self: *Bar, click_x: i32) ?config_mod.ClickAction {
263 + for (self.blocks.items) |*block| {
264 + if (block.click != null and click_x >= block.x_start and click_x < block.x_end) {
265 + return block.click;
266 + }
267 + }
268 + return null;
269 + }
270 +
248 271 /// Updates all blocks and marks the bar dirty if any block changed.
249 272 pub fn updateBlocks(self: *Bar) void {
250 273 var changed = false;
+4 −0 src/bar/blocks/blocks.zig
@@ -1,4 +1,5 @@
1 1 const std = @import("std");
2 +const config_mod = @import("../../config/config.zig");
2 3
3 4 pub const Static = @import("static.zig").Static;
4 5 pub const DateTime = @import("datetime.zig").DateTime;
@@ -13,6 +14,9 @@ pub const Block = struct {
13 14 cached_content: [256]u8,
14 15 cached_len: usize,
15 16 underline: bool,
17 + click: ?config_mod.ClickAction = null,
18 + x_start: i32 = 0,
19 + x_end: i32 = 0,
16 20
17 21 pub const Data = union(enum) {
18 22 static: Static,
+70 −0 src/config/config.zig
@@ -18,6 +18,7 @@ pub const Action = enum {
18 18 toggle_floating,
19 19 toggle_fullscreen,
20 20 toggle_gaps,
21 + toggle_bar,
21 22 cycle_layout,
22 23 set_layout,
23 24 set_layout_tiling,
@@ -80,6 +81,23 @@ pub const MouseAction = enum {
80 81 toggle_floating,
81 82 };
82 83
84 +pub const Layouts = enum(u32) {
85 + tiling,
86 + monocle,
87 + floating,
88 + scrolling,
89 + grid,
90 +
91 + pub fn fromString(name: []const u8) ?Layouts {
92 + if (std.meta.stringToEnum(Layouts, name)) |v| return v;
93 + if (std.mem.eql(u8, name, "tile")) return .tiling;
94 + if (std.mem.eql(u8, name, "normie")) return .floating;
95 + if (std.mem.eql(u8, name, "float")) return .floating;
96 + if (std.mem.eql(u8, name, "scroll")) return .scrolling;
97 + return null;
98 + }
99 +};
100 +
83 101 pub const MouseButton = struct {
84 102 click: ClickTarget,
85 103 mod_mask: u32,
@@ -87,6 +105,52 @@ pub const MouseButton = struct {
87 105 action: MouseAction,
88 106 };
89 107
108 +pub const FloatingPosition = enum {
109 + top_left,
110 + top_center,
111 + top_right,
112 + center_left,
113 + center,
114 + center_right,
115 + bottom_left,
116 + bottom_center,
117 + bottom_right,
118 +
119 + pub fn fromString(name: []const u8) ?FloatingPosition {
120 + const map = .{
121 + .{ "top-left", .top_left },
122 + .{ "top_left", .top_left },
123 + .{ "top-center", .top_center },
124 + .{ "top_center", .top_center },
125 + .{ "top-middle", .top_center },
126 + .{ "top-right", .top_right },
127 + .{ "top_right", .top_right },
128 + .{ "center-left", .center_left },
129 + .{ "center_left", .center_left },
130 + .{ "center", .center },
131 + .{ "center-right", .center_right },
132 + .{ "center_right", .center_right },
133 + .{ "bottom-left", .bottom_left },
134 + .{ "bottom_left", .bottom_left },
135 + .{ "bottom-center", .bottom_center },
136 + .{ "bottom_center", .bottom_center },
137 + .{ "bottom-middle", .bottom_center },
138 + .{ "bottom-right", .bottom_right },
139 + .{ "bottom_right", .bottom_right },
140 + };
141 + inline for (map) |entry| {
142 + if (std.mem.eql(u8, name, entry[0])) return entry[1];
143 + }
144 + return null;
145 + }
146 +};
147 +
148 +pub const ClickAction = struct {
149 + command: []const u8,
150 + floating: bool = false,
151 + bypass_rules: bool = false,
152 +};
153 +
90 154 pub const Block = struct {
91 155 block_type: BlockType,
92 156 format: []const u8,
@@ -100,6 +164,7 @@ pub const Block = struct {
100 164 format_full: ?[]const u8 = null,
101 165 battery_name: ?[]const u8 = null,
102 166 thermal_zone: ?[]const u8 = null,
167 + click: ?ClickAction = null,
103 168 };
104 169
105 170 pub const ColorScheme = struct {
@@ -114,7 +179,10 @@ pub const Config = struct {
114 179
115 180 terminal: []const u8 = "st",
116 181 font: []const u8 = "monospace:size=10",
182 + bar_position: []const u8 = "top",
117 183 tags: [9][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9" },
184 + layout: []const u8 = "tiling",
185 + tag_layouts: [9]?[]const u8 = .{null} ** 9,
118 186
119 187 border_width: i32 = 2,
120 188 border_focused: u32 = 0x6dade3,
@@ -131,12 +199,14 @@ pub const Config = struct {
131 199 auto_tile: bool = false,
132 200 tag_back_and_forth: bool = false,
133 201 hide_vacant_tags: bool = false,
202 + floating_position: FloatingPosition = .center,
134 203 tiled_resize_mode: bool = false,
135 204
136 205 layout_tile_symbol: []const u8 = "[]=",
137 206 layout_monocle_symbol: []const u8 = "[M]",
138 207 layout_floating_symbol: []const u8 = "><>",
139 208 layout_scrolling_symbol: []const u8 = "[S]",
209 + layout_grid_symbol: []const u8 = "[#]",
140 210
141 211 scheme_normal: ColorScheme = .{ .foreground = 0xbbbbbb, .background = 0x1a1b26, .border = 0x444444 },
142 212 scheme_selected: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0xad8ee6 },
+115 −17 src/config/lua.zig
@@ -274,6 +274,9 @@ fn registerBarModule(state: *c.lua_State) void {
274 274 c.lua_pushcfunction(state, luaBarSetHideVacantTags);
275 275 c.lua_setfield(state, -2, "set_hide_vacant_tags");
276 276
277 + c.lua_pushcfunction(state, luaBarSetPosition);
278 + c.lua_setfield(state, -2, "set_position");
279 +
277 280 c.lua_createtable(state, 0, 6);
278 281
279 282 c.lua_pushcfunction(state, luaBarBlockRam);
@@ -300,6 +303,9 @@ fn registerMiscFunctions(state: *c.lua_State) void {
300 303 c.lua_pushcfunction(state, luaSetTerminal);
301 304 c.lua_setfield(state, -2, "set_terminal");
302 305
306 + c.lua_pushcfunction(state, luaSetLayout);
307 + c.lua_setfield(state, -2, "set_layout");
308 +
303 309 c.lua_pushcfunction(state, luaSetModkey);
304 310 c.lua_setfield(state, -2, "set_modkey");
305 311
@@ -327,6 +333,9 @@ fn registerMiscFunctions(state: *c.lua_State) void {
327 333 c.lua_pushcfunction(state, luaToggleGaps);
328 334 c.lua_setfield(state, -2, "toggle_gaps");
329 335
336 + c.lua_pushcfunction(state, luaToggleBar);
337 + c.lua_setfield(state, -2, "toggle_bar");
338 +
330 339 c.lua_pushcfunction(state, luaShowKeybinds);
331 340 c.lua_setfield(state, -2, "show_keybinds");
332 341
@@ -335,6 +344,12 @@ fn registerMiscFunctions(state: *c.lua_State) void {
335 344
336 345 c.lua_pushcfunction(state, luaIncNumMaster);
337 346 c.lua_setfield(state, -2, "inc_num_master");
347 +
348 + c.lua_pushcfunction(state, luaSetTagLayout);
349 + c.lua_setfield(state, -2, "set_tag_layout");
350 +
351 + c.lua_pushcfunction(state, luaSetFloatingPosition);
352 + c.lua_setfield(state, -2, "set_floating_position");
338 353 }
339 354
340 355 fn createActionTable(state: *c.lua_State, action_name: [*:0]const u8) void {
@@ -755,6 +770,15 @@ fn luaBarSetFont(state: ?*c.lua_State) callconv(.c) c_int {
755 770 return 0;
756 771 }
757 772
773 +fn luaBarSetPosition(state: ?*c.lua_State) callconv(.c) c_int {
774 + const cfg = config orelse return 0;
775 + const s = state orelse return 0;
776 + if (dupeLuaString(s, 1)) |position| {
777 + cfg.bar_position = position;
778 + }
779 + return 0;
780 +}
781 +
758 782 fn luaBarSetBlocks(state: ?*c.lua_State) callconv(.c) c_int {
759 783 const cfg = config orelse return 0;
760 784 const s = state orelse return 0;
@@ -805,12 +829,17 @@ fn parseBlockConfig(state: *c.lua_State, idx: c_int) ?Block {
805 829 const underline = c.lua_toboolean(state, -1) != 0;
806 830 c.lua_settop(state, -2);
807 831
832 + _ = c.lua_getfield(state, idx, "click");
833 + const click = parseClickAction(state, -1);
834 + c.lua_settop(state, -2);
835 +
808 836 var block = Block{
809 837 .block_type = .static,
810 838 .format = format,
811 839 .interval = interval,
812 840 .color = color,
813 841 .underline = underline,
842 + .click = click,
814 843 };
815 844
816 845 if (std.mem.eql(u8, block_type_str, "Ram")) {
@@ -931,7 +960,7 @@ fn luaBarBlockStatic(state: ?*c.lua_State) callconv(.c) c_int {
931 960 fn luaBarBlockBattery(state: ?*c.lua_State) callconv(.c) c_int {
932 961 const s = state orelse return 0;
933 962
934 - c.lua_createtable(s, 0, 6);
963 + c.lua_createtable(s, 0, 7);
935 964
936 965 _ = c.lua_pushstring(s, "Battery");
937 966 c.lua_setfield(s, -2, "__block_type");
@@ -948,6 +977,9 @@ fn luaBarBlockBattery(state: ?*c.lua_State) callconv(.c) c_int {
948 977 _ = c.lua_getfield(s, 1, "underline");
949 978 c.lua_setfield(s, -2, "underline");
950 979
980 + _ = c.lua_getfield(s, 1, "click");
981 + c.lua_setfield(s, -2, "click");
982 +
951 983 c.lua_createtable(s, 0, 4);
952 984 _ = c.lua_getfield(s, 1, "charging");
953 985 c.lua_setfield(s, -2, "charging");
@@ -963,7 +995,7 @@ fn luaBarBlockBattery(state: ?*c.lua_State) callconv(.c) c_int {
963 995 }
964 996
965 997 fn createBlockTable(state: *c.lua_State, block_type: [*:0]const u8, arg: ?[]const u8) void {
966 - c.lua_createtable(state, 0, 6);
998 + c.lua_createtable(state, 0, 7);
967 999
968 1000 _ = c.lua_pushstring(state, block_type);
969 1001 c.lua_setfield(state, -2, "__block_type");
@@ -980,6 +1012,9 @@ fn createBlockTable(state: *c.lua_State, block_type: [*:0]const u8, arg: ?[]cons
980 1012 _ = c.lua_getfield(state, 1, "underline");
981 1013 c.lua_setfield(state, -2, "underline");
982 1014
1015 + _ = c.lua_getfield(state, 1, "click");
1016 + c.lua_setfield(state, -2, "click");
1017 +
983 1018 if (arg) |a| {
984 1019 var buf: [256]u8 = undefined;
985 1020 if (a.len < buf.len) {
@@ -991,6 +1026,17 @@ fn createBlockTable(state: *c.lua_State, block_type: [*:0]const u8, arg: ?[]cons
991 1026 }
992 1027 }
993 1028
1029 +fn luaSetFloatingPosition(state: ?*c.lua_State) callconv(.c) c_int {
1030 + const cfg = config orelse return 0;
1031 + const s = state orelse return 0;
1032 + if (getLuaString(s, 1)) |name| {
1033 + if (config_mod.FloatingPosition.fromString(name)) |pos| {
1034 + cfg.floating_position = pos;
1035 + }
1036 + }
1037 + return 0;
1038 +}
1039 +
994 1040 fn luaSetTerminal(state: ?*c.lua_State) callconv(.c) c_int {
995 1041 const cfg = config orelse return 0;
996 1042 const s = state orelse return 0;
@@ -1000,6 +1046,20 @@ fn luaSetTerminal(state: ?*c.lua_State) callconv(.c) c_int {
1000 1046 return 0;
1001 1047 }
1002 1048
1049 +fn luaSetLayout(state: ?*c.lua_State) callconv(.c) c_int {
1050 + const cfg = config orelse return 0;
1051 + const s = state orelse return 0;
1052 + const name = getStringArg(s, 1) orelse return 0;
1053 + if (config_mod.Layouts.fromString(name) == null) {
1054 + std.debug.print("set_layout: unknown layout '{s}'\n", .{name});
1055 + return 0;
1056 + }
1057 + if (dupeLuaString(s, 1)) |layout| {
1058 + cfg.layout = layout;
1059 + }
1060 + return 0;
1061 +}
1062 +
1003 1063 fn luaSetModkey(state: ?*c.lua_State) callconv(.c) c_int {
1004 1064 const cfg = config orelse return 0;
1005 1065 const s = state orelse return 0;
@@ -1069,22 +1129,29 @@ fn luaSetLayoutSymbol(state: ?*c.lua_State) callconv(.c) c_int {
1069 1129 const name = getStringArg(s, 1) orelse return 0;
1070 1130 const symbol = dupeLuaString(s, 2) orelse return 0;
1071 1131
1072 - const layout_map = .{
1073 - .{ "tiling", &cfg.layout_tile_symbol },
1074 - .{ "tile", &cfg.layout_tile_symbol },
1075 - .{ "normie", &cfg.layout_floating_symbol },
1076 - .{ "floating", &cfg.layout_floating_symbol },
1077 - .{ "float", &cfg.layout_floating_symbol },
1078 - .{ "monocle", &cfg.layout_monocle_symbol },
1079 - .{ "scrolling", &cfg.layout_scrolling_symbol },
1080 - .{ "scroll", &cfg.layout_scrolling_symbol },
1081 - };
1132 + const layout = config_mod.Layouts.fromString(name) orelse return 0;
1133 + switch (layout) {
1134 + .tiling => cfg.layout_tile_symbol = symbol,
1135 + .monocle => cfg.layout_monocle_symbol = symbol,
1136 + .floating => cfg.layout_floating_symbol = symbol,
1137 + .scrolling => cfg.layout_scrolling_symbol = symbol,
1138 + .grid => cfg.layout_grid_symbol = symbol,
1139 + }
1140 + return 0;
1141 +}
1082 1142
1083 - inline for (layout_map) |entry| {
1084 - if (std.mem.eql(u8, name, entry[0])) {
1085 - entry[1].* = symbol;
1086 - return 0;
1087 - }
1143 +fn luaSetTagLayout(state: ?*c.lua_State) callconv(.c) c_int {
1144 + const cfg = config orelse return 0;
1145 + const s = state orelse return 0;
1146 + const tag_index = c.lua_tointegerx(s, 1, null);
1147 + if (tag_index < 1 or tag_index > 9) return 0;
1148 + const name = getStringArg(s, 2) orelse return 0;
1149 + if (config_mod.Layouts.fromString(name) == null) {
1150 + std.debug.print("set_tag_layout: unknown layout '{s}'\n", .{name});
1151 + return 0;
1152 + }
1153 + if (dupeLuaString(s, 2)) |layout_str| {
1154 + cfg.tag_layouts[@intCast(tag_index - 1)] = layout_str;
1088 1155 }
1089 1156 return 0;
1090 1157 }
@@ -1107,6 +1174,12 @@ fn luaToggleGaps(state: ?*c.lua_State) callconv(.c) c_int {
1107 1174 return 1;
1108 1175 }
1109 1176
1177 +fn luaToggleBar(state: ?*c.lua_State) callconv(.c) c_int {
1178 + const s = state orelse return 0;
1179 + createActionTable(s, "ToggleBar");
1180 + return 1;
1181 +}
1182 +
1110 1183 fn luaShowKeybinds(state: ?*c.lua_State) callconv(.c) c_int {
1111 1184 const s = state orelse return 0;
1112 1185 createActionTable(s, "ShowKeybinds");
@@ -1179,6 +1252,30 @@ fn dupeLuaString(state: *c.lua_State, idx: c_int) ?[]const u8 {
1179 1252 return duped;
1180 1253 }
1181 1254
1255 +fn parseClickAction(state: *c.lua_State, idx: c_int) ?config_mod.ClickAction {
1256 + const lua_type = c.lua_type(state, idx);
1257 + if (lua_type == c.LUA_TSTRING) {
1258 + const cmd = dupeLuaString(state, idx) orelse return null;
1259 + return .{ .command = cmd };
1260 + } else if (lua_type == c.LUA_TTABLE) {
1261 + _ = c.lua_getfield(state, idx, "command");
1262 + const cmd = dupeLuaString(state, -1);
1263 + c.lua_settop(state, -2);
1264 + if (cmd == null) return null;
1265 +
1266 + _ = c.lua_getfield(state, idx, "floating");
1267 + const floating = c.lua_toboolean(state, -1) != 0;
1268 + c.lua_settop(state, -2);
1269 +
1270 + _ = c.lua_getfield(state, idx, "bypass_rules");
1271 + const bypass_rules = c.lua_toboolean(state, -1) != 0;
1272 + c.lua_settop(state, -2);
1273 +
1274 + return .{ .command = cmd.?, .floating = floating, .bypass_rules = bypass_rules };
1275 + }
1276 + return null;
1277 +}
1278 +
1182 1279 fn parseColor(state: *c.lua_State, idx: c_int) u32 {
1183 1280 const lua_type = c.lua_type(state, idx);
1184 1281 if (lua_type == c.LUA_TNUMBER) {
@@ -1257,6 +1354,7 @@ fn parseAction(name: []const u8) ?Action {
1257 1354 .{ "ToggleFloating", Action.toggle_floating },
1258 1355 .{ "ToggleFullScreen", Action.toggle_fullscreen },
1259 1356 .{ "ToggleGaps", Action.toggle_gaps },
1357 + .{ "ToggleBar", Action.toggle_bar },
1260 1358 .{ "CycleLayout", Action.cycle_layout },
1261 1359 .{ "ChangeLayout", Action.set_layout },
1262 1360 .{ "ViewTag", Action.view_tag },
+1 −1 src/overlay.zig
@@ -172,7 +172,7 @@ pub const KeybindOverlay = struct {
172 172 if (self.display) |display| {
173 173 _ = xlib.XUngrabKeyboard(display, xlib.CurrentTime);
174 174 if (self.window != 0) {
175 - _ = xlib.c.XUnmapWindow(display, self.window);
175 + _ = xlib.XUnmapWindow(display, self.window);
176 176 }
177 177 }
178 178 self.visible = false;
+49 −21 src/wm/actions.zig
@@ -6,6 +6,7 @@ const lua = @import("../config/lua.zig");
6 6 const core = @import("core.zig");
7 7 const tiling = @import("../layouts/tiling.zig");
8 8 const monitor_mod = @import("../monitor.zig");
9 +const bar_mod = @import("../bar/bar.zig");
9 10 const wm_mod = @import("wm.zig");
10 11 const xlib = @import("../x11/xlib.zig");
11 12
@@ -148,6 +149,12 @@ pub fn toggleView(tag_mask: u32, wm: *WindowManager) void {
148 149 monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag];
149 150 monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag];
150 151
152 + const new_show_bar = monitor.pertag.showbars[monitor.pertag.curtag];
153 + if (new_show_bar != monitor.show_bar) {
154 + monitor.show_bar = new_show_bar;
155 + updateBarVisibility(monitor, wm);
156 + }
157 +
151 158 core.focusTopClient(monitor, wm);
152 159 core.arrange(monitor, wm);
153 160 wm.invalidateBars();
@@ -182,6 +189,35 @@ pub fn toggleGaps(wm: *WindowManager) void {
182 189 core.arrange(monitor, wm);
183 190 }
184 191
192 +pub fn updateBarVisibility(monitor: *Monitor, wm: *WindowManager) void {
193 + const bar = bar_mod.windowToBar(wm.bars, monitor.bar_win) orelse return;
194 +
195 + if (monitor.show_bar) {
196 + _ = xlib.XMapWindow(wm.display.handle, bar.window);
197 + monitor.win_h -= bar.height;
198 + if (std.mem.eql(u8, wm.config.bar_position, "top")) {
199 + monitor.win_y += bar.height;
200 + }
201 + } else {
202 + _ = xlib.XUnmapWindow(wm.display.handle, bar.window);
203 + monitor.win_h += bar.height;
204 + if (std.mem.eql(u8, wm.config.bar_position, "top")) {
205 + monitor.win_y -= bar.height;
206 + }
207 + }
208 +}
209 +
210 +pub fn toggleBar(wm: *WindowManager) void {
211 + const monitor = wm.selected_monitor orelse return;
212 + monitor.show_bar = !monitor.show_bar;
213 + monitor.pertag.showbars[monitor.pertag.curtag] = monitor.show_bar;
214 +
215 + updateBarVisibility(monitor, wm);
216 +
217 + core.arrange(monitor, wm);
218 + wm.invalidateBars();
219 +}
220 +
185 221 pub fn killFocused(wm: *WindowManager) void {
186 222 const selected = wm.selected_monitor orelse return;
187 223 const client = selected.sel orelse return;
@@ -342,15 +378,15 @@ pub fn setmfact(delta: f32, wm: *WindowManager) void {
342 378
343 379 pub fn cycleLayout(wm: *WindowManager) void {
344 380 const monitor = wm.selected_monitor orelse return;
345 - const new_lt = (monitor.sel_lt + 1) % 5;
381 + const new_lt = (monitor.sel_lt + 1) % @as(u32, @intCast(std.meta.fields(config_mod.Layouts).len));
346 382 monitor.sel_lt = new_lt;
347 383 monitor.pertag.sellts[monitor.pertag.curtag] = new_lt;
348 - if (new_lt != 3) {
384 + if (new_lt != @intFromEnum(config_mod.Layouts.scrolling)) {
349 385 monitor.scroll_offset = 0;
350 386 }
351 387 core.arrange(monitor, wm);
352 388 wm.invalidateBars();
353 - if (monitor.lt[monitor.sel_lt]) |layout| {
389 + if (monitor.lt[@as(usize, monitor.sel_lt)]) |layout| {
354 390 std.debug.print("cycle_layout: {s}\n", .{layout.symbol});
355 391 }
356 392 }
@@ -358,44 +394,35 @@ pub fn cycleLayout(wm: *WindowManager) void {
358 394 pub fn setLayout(layout_name: ?[]const u8, wm: *WindowManager) void {
359 395 const monitor = wm.selected_monitor orelse return;
360 396 const name = layout_name orelse return;
361 -
362 - const new_lt: u32 = if (std.mem.eql(u8, name, "tiling") or std.mem.eql(u8, name, "[]="))
363 - 0
364 - else if (std.mem.eql(u8, name, "monocle") or std.mem.eql(u8, name, "[M]"))
365 - 1
366 - else if (std.mem.eql(u8, name, "floating") or std.mem.eql(u8, name, "><>"))
367 - 2
368 - else if (std.mem.eql(u8, name, "scrolling") or std.mem.eql(u8, name, "[S]"))
369 - 3
370 - else if (std.mem.eql(u8, name, "grid") or std.mem.eql(u8, name, "[#]"))
371 - 4
397 + const new_lt: u32 = if (config_mod.Layouts.fromString(name)) |value|
398 + @intFromEnum(value)
372 399 else {
373 400 std.debug.print("set_layout: unknown layout '{s}'\n", .{name});
374 401 return;
375 402 };
376 -
377 403 monitor.sel_lt = new_lt;
378 404 monitor.pertag.sellts[monitor.pertag.curtag] = new_lt;
379 - if (new_lt != 3) {
405 + if (new_lt != @intFromEnum(config_mod.Layouts.scrolling)) {
380 406 monitor.scroll_offset = 0;
381 407 }
382 408 core.arrange(monitor, wm);
383 409 wm.invalidateBars();
384 - if (monitor.lt[monitor.sel_lt]) |layout| {
410 + if (monitor.lt[@as(usize, monitor.sel_lt)]) |layout| {
385 411 std.debug.print("set_layout: {s}\n", .{layout.symbol});
386 412 }
387 413 }
388 414
389 415 pub fn setLayoutIndex(index: u32, wm: *WindowManager) void {
390 416 const monitor = wm.selected_monitor orelse return;
391 - monitor.sel_lt = index;
392 - monitor.pertag.sellts[monitor.pertag.curtag] = index;
393 - if (index != 3) {
417 + const lt_index = index % @as(u32, @intCast(std.meta.fields(config_mod.Layouts).len));
418 + monitor.sel_lt = lt_index;
419 + monitor.pertag.sellts[monitor.pertag.curtag] = lt_index;
420 + if (lt_index != @intFromEnum(config_mod.Layouts.scrolling)) {
394 421 monitor.scroll_offset = 0;
395 422 }
396 423 core.arrange(monitor, wm);
397 424 wm.invalidateBars();
398 - if (monitor.lt[monitor.sel_lt]) |layout| {
425 + if (monitor.lt[@as(usize, monitor.sel_lt)]) |layout| {
399 426 std.debug.print("set_layout_index: {s}\n", .{layout.symbol});
400 427 }
401 428 }
@@ -774,6 +801,7 @@ pub fn executeAction(action: config_mod.Action, int_arg: i32, str_arg: ?[]const
774 801 .toggle_floating => toggleFloating(wm),
775 802 .toggle_fullscreen => toggleFullscreen(wm),
776 803 .toggle_gaps => toggleGaps(wm),
804 + .toggle_bar => toggleBar(wm),
777 805 .cycle_layout => cycleLayout(wm),
778 806 .set_layout => setLayout(str_arg, wm),
779 807 .set_layout_tiling => setLayoutIndex(0, wm),
+38 −1 src/wm/core.zig
@@ -6,6 +6,8 @@ const tiling = @import("../layouts/tiling.zig");
6 6 const scrolling = @import("../layouts/scrolling.zig");
7 7 const window_manager = @import("wm.zig");
8 8
9 +const config_mod = @import("../config/config.zig");
10 +
9 11 const Client = client_mod.Client;
10 12 const Monitor = monitor_mod.Monitor;
11 13 const WindowManager = window_manager.WindowManager;
@@ -38,7 +40,19 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
38 40
39 41 if (client.monitor == null) {
40 42 client.monitor = wm.selected_monitor;
41 - applyRules(client, wm);
43 + if (wm.next_spawn_bypass_rules) {
44 + if (client.monitor) |monitor| {
45 + client.tags = monitor.tagset[monitor.sel_tags];
46 + }
47 + wm.next_spawn_bypass_rules = false;
48 + } else {
49 + applyRules(client, wm);
50 + }
51 + }
52 +
53 + if (wm.next_spawn_floating) {
54 + client.is_floating = true;
55 + wm.next_spawn_floating = false;
42 56 }
43 57
44 58 const monitor = client.monitor orelse return;
@@ -72,6 +86,7 @@ pub fn manage(win: xlib.Window, window_attrs: *xlib.XWindowAttributes, wm: *Wind
72 86 client.old_state = client.is_floating;
73 87 }
74 88 if (client.is_floating) {
89 + positionFloating(client, monitor, wm.config.floating_position);
75 90 _ = xlib.XRaiseWindow(wm.display.handle, client.window);
76 91 }
77 92
@@ -432,6 +447,22 @@ pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void {
432 447 }
433 448 }
434 449
450 +fn positionFloating(client: *Client, monitor: *Monitor, pos: config_mod.FloatingPosition) void {
451 + const bw = 2 * client.border_width;
452 + const x: i32 = switch (pos) {
453 + .top_left, .center_left, .bottom_left => monitor.win_x,
454 + .top_center, .center, .bottom_center => monitor.win_x + @divTrunc(monitor.win_w - client.width - bw, 2),
455 + .top_right, .center_right, .bottom_right => monitor.win_x + monitor.win_w - client.width - bw,
456 + };
457 + const y: i32 = switch (pos) {
458 + .top_left, .top_center, .top_right => monitor.win_y,
459 + .center_left, .center, .center_right => monitor.win_y + @divTrunc(monitor.win_h - client.height - bw, 2),
460 + .bottom_left, .bottom_center, .bottom_right => monitor.win_y + monitor.win_h - client.height - bw,
461 + };
462 + client.x = x;
463 + client.y = y;
464 +}
465 +
435 466 pub fn applyRules(client: *Client, wm: *WindowManager) void {
436 467 var class_hint: xlib.XClassHint = .{ .res_name = null, .res_class = null };
437 468 _ = xlib.XGetClassHint(wm.display.handle, client.window, &class_hint);
@@ -729,6 +760,12 @@ pub fn view(tag_mask: u32, wm: *WindowManager) void {
729 760 monitor.mfact = monitor.pertag.mfacts[monitor.pertag.curtag];
730 761 monitor.sel_lt = monitor.pertag.sellts[monitor.pertag.curtag];
731 762
763 + const new_show_bar = monitor.pertag.showbars[monitor.pertag.curtag];
764 + if (new_show_bar != monitor.show_bar) {
765 + monitor.show_bar = new_show_bar;
766 + window_manager.actions.updateBarVisibility(monitor, wm);
767 + }
768 +
732 769 focusTopClient(monitor, wm);
733 770 arrange(monitor, wm);
734 771 wm.invalidateBars();
+4 −0 src/wm/handlers.zig
@@ -232,6 +232,10 @@ fn handleButtonPress(event: *xlib.XButtonEvent, wm: *WindowManager) void {
232 232 if (clicked_tag) |tag_index| {
233 233 const tag_mask: u32 = @as(u32, 1) << @intCast(tag_index);
234 234 core.view(tag_mask, wm);
235 + } else if (bar.handleBlockClick(event.x)) |click_action| {
236 + wm.next_spawn_floating = click_action.floating;
237 + wm.next_spawn_bypass_rules = click_action.bypass_rules;
238 + actions.spawnCommand(wm, click_action.command);
235 239 }
236 240 return;
237 241 }
+56 −56 src/wm/wm.zig
@@ -85,6 +85,8 @@ pub const WindowManager = struct {
85 85 animation_config: animations.AnimationConfig,
86 86
87 87 running: bool,
88 + next_spawn_floating: bool = false,
89 + next_spawn_bypass_rules: bool = false,
88 90 last_motion_monitor: ?*Monitor,
89 91
90 92 /// Initialises the window manager
@@ -159,43 +161,65 @@ pub const WindowManager = struct {
159 161 self.config.deinit();
160 162 }
161 163
164 + const layouts = [_]*const monitor_mod.Layout{
165 + &tiling.layout,
166 + &monocle.layout,
167 + &floating.layout,
168 + &scrolling.layout,
169 + &grid.layout,
170 + };
171 +
172 + fn initMonitor(self: *WindowManager, mon: *Monitor, num: usize, x: i16, y: i16, w: c_int, h: c_int) void {
173 + mon.num = @intCast(num);
174 + mon.mon_x = x;
175 + mon.mon_y = y;
176 + mon.mon_w = w;
177 + mon.mon_h = h;
178 + mon.win_x = x;
179 + mon.win_y = y;
180 + mon.win_w = w;
181 + mon.win_h = h;
182 +
183 + for (&mon.lt, layouts) |*slot, layout| {
184 + slot.* = layout;
185 + }
186 +
187 + if (config_mod.Layouts.fromString(self.config.layout)) |value| {
188 + mon.sel_lt = @intFromEnum(value);
189 + }
190 +
191 + for (0..10) |i| {
192 + for (0..layouts.len) |j| {
193 + mon.pertag.ltidxs[i][j] = mon.lt[j];
194 + }
195 + mon.pertag.sellts[i] = mon.sel_lt;
196 + }
197 +
198 + for (self.config.tag_layouts, 0..) |maybe_layout, i| {
199 + if (maybe_layout) |layout_name| {
200 + if (config_mod.Layouts.fromString(layout_name)) |value| {
201 + mon.pertag.sellts[i + 1] = @intFromEnum(value);
202 + }
203 + }
204 + }
205 +
206 + self.initMonitorGaps(mon);
207 + }
208 +
162 209 fn setupMonitors(self: *WindowManager) void {
163 210 if (xlib.XineramaIsActive(self.display.handle) != 0) {
164 211 var screen_count: c_int = 0;
165 212 const screens = xlib.XineramaQueryScreens(self.display.handle, &screen_count);
213 + defer if (screens != null) {
214 + _ = xlib.XFree(@ptrCast(screens));
215 + };
166 216
167 217 if (screen_count > 0 and screens != null) {
168 218 var prev_monitor: ?*Monitor = null;
169 - var index: usize = 0;
170 -
171 - while (index < @as(usize, @intCast(screen_count))) : (index += 1) {
219 + for (0..@as(usize, @intCast(screen_count))) |index| {
172 220 const screen = screens[index];
173 221 const mon = monitor_mod.create(self.allocator) orelse continue;
174 -
175 - mon.num = @intCast(index);
176 - mon.mon_x = screen.x_org;
177 - mon.mon_y = screen.y_org;
178 - mon.mon_w = screen.width;
179 - mon.mon_h = screen.height;
180 - mon.win_x = screen.x_org;
181 - mon.win_y = screen.y_org;
182 - mon.win_w = screen.width;
183 - mon.win_h = screen.height;
184 - mon.lt[0] = &tiling.layout;
185 - mon.lt[1] = &monocle.layout;
186 - mon.lt[2] = &floating.layout;
187 - mon.lt[3] = &scrolling.layout;
188 - mon.lt[4] = &grid.layout;
189 -
190 - for (0..10) |i| {
191 - mon.pertag.ltidxs[i][0] = mon.lt[0];
192 - mon.pertag.ltidxs[i][1] = mon.lt[1];
193 - mon.pertag.ltidxs[i][2] = mon.lt[2];
194 - mon.pertag.ltidxs[i][3] = mon.lt[3];
195 - mon.pertag.ltidxs[i][4] = mon.lt[4];
196 - }
197 -
198 - self.initMonitorGaps(mon);
222 + self.initMonitor(mon, index, screen.x_org, screen.y_org, screen.width, screen.height);
199 223
200 224 if (prev_monitor) |prev| {
201 225 prev.next = mon;
@@ -205,38 +229,12 @@ pub const WindowManager = struct {
205 229 }
206 230 prev_monitor = mon;
207 231 }
208 -
209 - _ = xlib.XFree(@ptrCast(screens));
210 232 }
211 233 }
212 234
213 - // Fallback: single monitor covering the full screen.
214 235 if (self.monitors == null) {
215 236 const mon = monitor_mod.create(self.allocator) orelse return;
216 - mon.num = 0;
217 - mon.mon_x = 0;
218 - mon.mon_y = 0;
219 - mon.mon_w = self.display.screenWidth();
220 - mon.mon_h = self.display.screenHeight();
221 - mon.win_x = 0;
222 - mon.win_y = 0;
223 - mon.win_w = mon.mon_w;
224 - mon.win_h = mon.mon_h;
225 - mon.lt[0] = &tiling.layout;
226 - mon.lt[1] = &monocle.layout;
227 - mon.lt[2] = &floating.layout;
228 - mon.lt[3] = &scrolling.layout;
229 - mon.lt[4] = &grid.layout;
230 -
231 - for (0..10) |i| {
232 - mon.pertag.ltidxs[i][0] = mon.lt[0];
233 - mon.pertag.ltidxs[i][1] = mon.lt[1];
234 - mon.pertag.ltidxs[i][2] = mon.lt[2];
235 - mon.pertag.ltidxs[i][3] = mon.lt[3];
236 - mon.pertag.ltidxs[i][4] = mon.lt[4];
237 - }
238 -
239 - self.initMonitorGaps(mon);
237 + self.initMonitor(mon, 0, 0, 0, self.display.screenWidth(), self.display.screenHeight());
240 238 self.monitors = mon;
241 239 self.selected_monitor = mon;
242 240 }
@@ -714,7 +712,7 @@ pub const WindowManager = struct {
714 712
715 713 /// Converts a config block description into a live status bar block.
716 714 pub fn configBlockToBarBlock(cfg: config_mod.Block) blocks_mod.Block {
717 - return switch (cfg.block_type) {
715 + var block = switch (cfg.block_type) {
718 716 .static => blocks_mod.Block.initStatic(cfg.format, cfg.color, cfg.underline),
719 717 .datetime => blocks_mod.Block.initDatetime(
720 718 cfg.format,
@@ -748,4 +746,6 @@ pub fn configBlockToBarBlock(cfg: config_mod.Block) blocks_mod.Block {
748 746 cfg.underline,
749 747 ),
750 748 };
749 + block.click = cfg.click;
750 + return block;
751 751 }
+1 −0 src/x11/xlib.zig
@@ -42,6 +42,7 @@ pub const XQueryTree = c.XQueryTree;
42 42 pub const XFree = c.XFree;
43 43 pub const XGetWindowAttributes = c.XGetWindowAttributes;
44 44 pub const XMapWindow = c.XMapWindow;
45 +pub const XUnmapWindow = c.XUnmapWindow;
45 46 pub const XConfigureWindow = c.XConfigureWindow;
46 47 pub const XSetInputFocus = c.XSetInputFocus;
47 48 pub const XRaiseWindow = c.XRaiseWindow;
+19 −0 templates/config.lua
@@ -92,6 +92,9 @@ local blocks = {
92 92 interval = 30,
93 93 color = colors.green,
94 94 underline = true,
95 + -- click: run a command when the block is clicked
96 + -- click = "alacritty -e btop",
97 + -- click = { command = "bluetui", floating = true },
95 98 }),
96 99 };
97 100
@@ -102,6 +105,9 @@ oxwm.set_terminal(terminal)
102 105 oxwm.set_modkey(modkey) -- This is for Mod + mouse binds, such as drag/resize
103 106 oxwm.set_tags(tags)
104 107
108 +-- Set default layout (tiling by default)
109 +-- oxwm.set_layout("tiling")
110 +
105 111 -------------------------------------------------------------------------------
106 112 -- Layouts
107 113 -------------------------------------------------------------------------------
@@ -111,6 +117,10 @@ oxwm.set_layout_symbol("tiling", "[T]")
111 117 oxwm.set_layout_symbol("normie", "[F]")
112 118 oxwm.set_layout_symbol("tabbed", "[=]")
113 119
120 +-- Set default layout of specific tag (tag_index, layout_name)
121 +-- Unset value uses oxwm.set_layout value
122 +-- oxwm.set_tag_layout(1, "grid")
123 +
114 124 -------------------------------------------------------------------------------
115 125 -- Appearance
116 126 -------------------------------------------------------------------------------
@@ -123,6 +133,10 @@ oxwm.border.set_focused_color(colors.blue)
123 133 -- Color of unfocused window borders
124 134 oxwm.border.set_unfocused_color(colors.grey)
125 135
136 +-- Where floating windows spawn: "top-left", "top-center", "top-right",
137 +-- "center-left", "center", "center-right", "bottom-left", "bottom-center", "bottom-right"
138 +oxwm.set_floating_position("center")
139 +
126 140 -- Smart Enabled = No border if 1 window
127 141 oxwm.gaps.set_smart(enabled)
128 142 -- Inner gaps (horizontal, vertical) in pixels
@@ -158,6 +172,9 @@ oxwm.rule.add({ instance = "gimp", floating = true })
158 172 -- Font configuration
159 173 oxwm.bar.set_font(bar_font)
160 174
175 +-- Position configuration (top/bottom, top is default)
176 +-- oxwm.bar.set_position("bottom")
177 +
161 178 -- Set your blocks here (defined above)
162 179 oxwm.bar.set_blocks(blocks)
163 180
@@ -222,6 +239,8 @@ oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1))
222 239
223 240 -- Gaps toggle
224 241 oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
242 +-- Bar toggle
243 +oxwm.key.bind({ modkey }, "B", oxwm.toggle_bar())
225 244
226 245 -- Window manager controls
227 246 oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
+26 −5 templates/oxwm.lua
@@ -50,6 +50,23 @@ function oxwm.tiled_resize_mode(enabled) end
50 50 ---@param symbol string Symbol to display (e.g., "[T]", "[F]", "[=]")
51 51 function oxwm.set_layout_symbol(name, symbol) end
52 52
53 +---Set default layout for all tags
54 +---@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", or aliases: "tile", "float", "scroll", "normie")
55 +function oxwm.set_layout(name) end
56 +
57 +---Set default layout for a specific tag
58 +---@param tag integer Tag index (1-9)
59 +---@param name string Layout name ("tiling", "floating", "scrolling", "grid", "monocle", or aliases)
60 +function oxwm.set_tag_layout(tag, name) end
61 +
62 +---Set floating window spawn position
63 +---@param position string Position ("center", "top-left", "top-right", "bottom-left", "bottom-right", "top-center", "bottom-center", "center-left", "center-right", or underscore variants)
64 +function oxwm.set_floating_position(position) end
65 +
66 +---Toggle the status bar visibility
67 +---@return table Action table for keybinding
68 +function oxwm.toggle_bar() end
69 +
53 70 ---Window rule module
54 71 ---@class oxwm.rule
55 72 oxwm.rule = {}
@@ -260,6 +277,10 @@ oxwm.bar = {}
260 277 ---@param font string Font string (e.g., "monospace:style=Bold:size=10")
261 278 function oxwm.bar.set_font(font) end
262 279
280 +---Set status bar position
281 +---@param position string Bar position ("top" or "bottom")
282 +function oxwm.bar.set_position(position) end
283 +
263 284 ---DEPRECATED: Add a status bar block (use oxwm.bar.set_blocks with block constructors instead)
264 285 ---@deprecated
265 286 ---@param format string Format string with {} placeholders
@@ -279,27 +300,27 @@ function oxwm.bar.set_blocks(blocks) end
279 300 oxwm.bar.block = {}
280 301
281 302 ---Create a RAM usage block
282 ----@param config {format: string, interval: integer, color: string|integer, underline: boolean} Block configuration
303 +---@param config {format: string, interval: integer, color: string|integer, underline: boolean, click: string|{command: string, floating: boolean?, bypass_rules: boolean?}?} Block configuration
283 304 ---@return table Block configuration
284 305 function oxwm.bar.block.ram(config) end
285 306
286 307 ---Create a date/time block
287 ----@param config {format: string, date_format: string, interval: integer, color: string|integer, underline: boolean} Block configuration (format is display template with {}, date_format is strftime format)
308 +---@param config {format: string, date_format: string, interval: integer, color: string|integer, underline: boolean, click: string|{command: string, floating: boolean?, bypass_rules: boolean?}?} Block configuration (format is display template with {}, date_format is strftime format)
288 309 ---@return table Block configuration
289 310 function oxwm.bar.block.datetime(config) end
290 311
291 312 ---Create a shell command block
292 ----@param config {format: string, command: string, interval: integer, color: string|integer, underline: boolean} Block configuration
313 +---@param config {format: string, command: string, interval: integer, color: string|integer, underline: boolean, click: string|{command: string, floating: boolean?, bypass_rules: boolean?}?} Block configuration
293 314 ---@return table Block configuration
294 315 function oxwm.bar.block.shell(config) end
295 316
296 317 ---Create a static text block
297 ----@param config {format: string, text: string, interval: integer, color: string|integer, underline: boolean} Block configuration
318 +---@param config {format: string, text: string, interval: integer, color: string|integer, underline: boolean, click: string|{command: string, floating: boolean?, bypass_rules: boolean?}?} Block configuration
298 319 ---@return table Block configuration
299 320 function oxwm.bar.block.static(config) end
300 321
301 322 ---Create a battery status block
302 ----@param config {format: string, charging: string, discharging: string, full: string, interval: integer, color: string|integer, underline: boolean, battery_name: string} Block configuration
323 +---@param config {format: string, charging: string, discharging: string, full: string, interval: integer, color: string|integer, underline: boolean, battery_name: string, click: string|{command: string, floating: boolean?, bypass_rules: boolean?}?} Block configuration
303 324 ---@return table Block configuration
304 325 function oxwm.bar.block.battery(config) end
305 326