tony / oxwm

Branch: 362633f
Switch branches/tags
master
tonybanters fixed attachBottom dropping clients after the anchor, removed dead ChangeAttachMethod action, stored attach method as enum and applied it to all attach sites 0331bc4 2026-09-15
338 lines · 10.5 KB Raw Blame History
1 const std = @import("std");
2
3 pub const Action = enum {
4 spawn_terminal,
5 spawn,
6 kill_client,
7 quit,
8 reload_config,
9 restart,
10 show_keybinds,
11 focus_next,
12 focus_prev,
13 move_next,
14 move_prev,
15 resize_master,
16 inc_master,
17 dec_master,
18 toggle_floating,
19 toggle_fullscreen,
20 toggle_gaps,
21 toggle_bar,
22 cycle_layout,
23 set_layout,
24 set_layout_tiling,
25 set_layout_floating,
26 view_tag,
27 view_next_tag,
28 view_prev_tag,
29 view_next_nonempty_tag,
30 view_prev_nonempty_tag,
31 move_to_tag,
32 toggle_view_tag,
33 toggle_tag,
34 focus_monitor,
35 send_to_monitor,
36 scroll_left,
37 scroll_right,
38 };
39
40 pub const KeyPress = struct {
41 mod_mask: u32 = 0,
42 keysym: u64 = 0,
43 };
44
45 pub const Keybind = struct {
46 keys: [4]KeyPress = [_]KeyPress{.{}} ** 4,
47 key_count: u8 = 1,
48 action: Action,
49 int_arg: i32 = 0,
50 str_arg: ?[]const u8 = null,
51 };
52
53 pub const Rule = struct {
54 class: ?[]const u8,
55 instance: ?[]const u8,
56 title: ?[]const u8,
57 tags: u32,
58 is_floating: bool,
59 monitor: i32,
60 focus: bool,
61 };
62
63 pub const BlockType = enum {
64 static,
65 datetime,
66 ram,
67 shell,
68 battery,
69 cpu_temp,
70 systray,
71 };
72
73 pub const ClickTarget = enum {
74 client_win,
75 root_win,
76 tag_bar,
77 };
78
79 pub const MouseAction = enum {
80 move_mouse,
81 resize_mouse,
82 toggle_floating,
83 };
84
85 pub const Layouts = enum(u32) {
86 tiling,
87 monocle,
88 floating,
89 scrolling,
90 grid,
91 dwindle,
92
93 pub fn fromString(name: []const u8) ?Layouts {
94 if (std.meta.stringToEnum(Layouts, name)) |v| return v;
95 if (std.mem.eql(u8, name, "tile")) return .tiling;
96 if (std.mem.eql(u8, name, "normie")) return .floating;
97 if (std.mem.eql(u8, name, "float")) return .floating;
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;
101 return null;
102 }
103 };
104
105 pub const AttachMethods = enum {
106 aside,
107 top,
108 bottom,
109 above,
110 below,
111
112 pub fn fromString(name: []const u8) ?AttachMethods {
113 return std.meta.stringToEnum(AttachMethods, name);
114 }
115 };
116
117 pub const MouseButton = struct {
118 click: ClickTarget,
119 mod_mask: u32,
120 button: u32,
121 action: MouseAction,
122 };
123
124 pub const FloatingPosition = enum {
125 top_left,
126 top_center,
127 top_right,
128 center_left,
129 center,
130 center_right,
131 bottom_left,
132 bottom_center,
133 bottom_right,
134
135 pub fn fromString(name: []const u8) ?FloatingPosition {
136 const map = .{
137 .{ "top-left", .top_left },
138 .{ "top_left", .top_left },
139 .{ "top-center", .top_center },
140 .{ "top_center", .top_center },
141 .{ "top-middle", .top_center },
142 .{ "top-right", .top_right },
143 .{ "top_right", .top_right },
144 .{ "center-left", .center_left },
145 .{ "center_left", .center_left },
146 .{ "center", .center },
147 .{ "center-right", .center_right },
148 .{ "center_right", .center_right },
149 .{ "bottom-left", .bottom_left },
150 .{ "bottom_left", .bottom_left },
151 .{ "bottom-center", .bottom_center },
152 .{ "bottom_center", .bottom_center },
153 .{ "bottom-middle", .bottom_center },
154 .{ "bottom-right", .bottom_right },
155 .{ "bottom_right", .bottom_right },
156 };
157 inline for (map) |entry| {
158 if (std.mem.eql(u8, name, entry[0])) return entry[1];
159 }
160 return null;
161 }
162 };
163
164 pub const ClickAction = struct {
165 command: []const u8,
166 floating: bool = false,
167 bypass_rules: bool = false,
168 };
169
170 pub const Block = struct {
171 block_type: BlockType,
172 format: []const u8,
173 command: ?[]const u8 = null,
174 interval: u32,
175 color: u32,
176 underline: bool = true,
177 datetime_format: ?[]const u8 = null,
178 format_charging: ?[]const u8 = null,
179 format_discharging: ?[]const u8 = null,
180 format_full: ?[]const u8 = null,
181 battery_name: ?[]const u8 = null,
182 thermal_zone: ?[]const u8 = null,
183 click: ?ClickAction = null,
184 };
185
186 pub const ColorScheme = struct {
187 foreground: u32 = 0xbbbbbb,
188 background: u32 = 0x1a1b26,
189 border: u32 = 0x444444,
190 };
191
192 pub const Config = struct {
193 allocator: std.mem.Allocator,
194 string_arena: std.heap.ArenaAllocator,
195
196 terminal: []const u8 = "st",
197 font: []const u8 = "monospace:size=10",
198 bar_position: []const u8 = "top",
199 tags: [12][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" },
200 tag_count: u32 = 9,
201 layout: []const u8 = "tiling",
202 attach_method: AttachMethods = .aside,
203 tag_layouts: [12]?[]const u8 = .{null} ** 12,
204
205 border_width: i32 = 2,
206 border_focused: u32 = 0x6dade3,
207 border_unfocused: u32 = 0x444444,
208
209 gaps_enabled: bool = true,
210 smartgaps_enabled: bool = false,
211 gap_inner_h: i32 = 5,
212 gap_inner_v: i32 = 5,
213 gap_outer_h: i32 = 5,
214 gap_outer_v: i32 = 5,
215
216 modkey: u32 = (1 << 6),
217 auto_tile: bool = false,
218 tag_back_and_forth: bool = false,
219 hide_vacant_tags: bool = false,
220 floating_position: FloatingPosition = .center,
221 tiled_resize_mode: bool = false,
222 warp_cursor_to_monitor: bool = false,
223 warp_cursor_on_send: bool = false,
224
225 layout_tile_symbol: []const u8 = "[]=",
226 layout_monocle_symbol: []const u8 = "[M]",
227 layout_floating_symbol: []const u8 = "><>",
228 layout_scrolling_symbol: []const u8 = "[S]",
229 layout_grid_symbol: []const u8 = "[#]",
230 layout_dwindle_symbol: []const u8 = "[\\]",
231
232 scheme_normal: ColorScheme = .{ .foreground = 0xbbbbbb, .background = 0x1a1b26, .border = 0x444444 },
233 scheme_selected: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0xad8ee6 },
234 scheme_occupied: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0x0db9d7 },
235 scheme_urgent: ColorScheme = .{ .foreground = 0xf7768e, .background = 0x1a1b26, .border = 0xf7768e },
236
237 keybinds: std.ArrayListUnmanaged(Keybind) = .empty,
238 rules: std.ArrayListUnmanaged(Rule) = .empty,
239 blocks: std.ArrayListUnmanaged(Block) = .empty,
240 buttons: std.ArrayListUnmanaged(MouseButton) = .empty,
241 autostart: std.ArrayListUnmanaged([]const u8) = .empty,
242
243 pub fn init(allocator: std.mem.Allocator) Config {
244 return Config{
245 .allocator = allocator,
246 .string_arena = std.heap.ArenaAllocator.init(allocator),
247 };
248 }
249
250 pub fn deinit(self: *Config) void {
251 self.string_arena.deinit();
252 self.keybinds.deinit(self.allocator);
253 self.rules.deinit(self.allocator);
254 self.blocks.deinit(self.allocator);
255 self.buttons.deinit(self.allocator);
256 self.autostart.deinit(self.allocator);
257 }
258
259 pub fn addKeybind(self: *Config, keybind: Keybind) !void {
260 try self.keybinds.append(self.allocator, keybind);
261 }
262
263 pub fn addRule(self: *Config, rule: Rule) !void {
264 try self.rules.append(self.allocator, rule);
265 }
266
267 pub fn addBlock(self: *Config, block: Block) !void {
268 try self.blocks.append(self.allocator, block);
269 }
270
271 pub fn addButton(self: *Config, button: MouseButton) !void {
272 try self.buttons.append(self.allocator, button);
273 }
274
275 pub fn addAutostart(self: *Config, cmd: []const u8) !void {
276 try self.autostart.append(self.allocator, cmd);
277 }
278 };
279
280 pub fn initializeDefaultConfig(cfg: *Config) void {
281 const mod_key: u32 = 1 << 6;
282 const shift_key: u32 = 1 << 0;
283 const control_key: u32 = 1 << 2;
284
285 cfg.addKeybind(makeKeybind(mod_key, 0xff0d, .spawn_terminal)) catch {};
286 cfg.addKeybind(makeKeybindStr(mod_key, 'd', .spawn, "rofi -show drun")) catch {};
287 cfg.addKeybind(makeKeybindStr(mod_key, 's', .spawn, "maim -s | xclip -selection clipboard -t image/png")) catch {};
288 cfg.addKeybind(makeKeybind(mod_key, 'q', .kill_client)) catch {};
289 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'q', .quit)) catch {};
290 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'r', .reload_config)) catch {};
291 cfg.addKeybind(makeKeybind(mod_key, 'j', .focus_next)) catch {};
292 cfg.addKeybind(makeKeybind(mod_key, 'k', .focus_prev)) catch {};
293 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'j', .move_next)) catch {};
294 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'k', .move_prev)) catch {};
295 cfg.addKeybind(makeKeybindInt(mod_key, 'h', .resize_master, -50)) catch {};
296 cfg.addKeybind(makeKeybindInt(mod_key, 'l', .resize_master, 50)) catch {};
297 cfg.addKeybind(makeKeybind(mod_key, 'i', .inc_master)) catch {};
298 cfg.addKeybind(makeKeybind(mod_key, 'p', .dec_master)) catch {};
299 cfg.addKeybind(makeKeybind(mod_key, 'a', .toggle_gaps)) catch {};
300 cfg.addKeybind(makeKeybind(mod_key, 'f', .toggle_fullscreen)) catch {};
301 cfg.addKeybind(makeKeybind(mod_key, 0x0020, .toggle_floating)) catch {};
302 cfg.addKeybind(makeKeybind(mod_key, 'n', .cycle_layout)) catch {};
303 cfg.addKeybind(makeKeybindInt(mod_key, 0x002c, .focus_monitor, -1)) catch {};
304 cfg.addKeybind(makeKeybindInt(mod_key, 0x002e, .focus_monitor, 1)) catch {};
305 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, 0x002c, .send_to_monitor, -1)) catch {};
306 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, 0x002e, .send_to_monitor, 1)) catch {};
307
308 var tag_index: i32 = 0;
309 while (tag_index < 9) : (tag_index += 1) {
310 const keysym: u64 = @as(u64, '1') + @as(u64, @intCast(tag_index));
311 cfg.addKeybind(makeKeybindInt(mod_key, keysym, .view_tag, tag_index)) catch {};
312 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, keysym, .move_to_tag, tag_index)) catch {};
313 cfg.addKeybind(makeKeybindInt(mod_key | control_key, keysym, .toggle_view_tag, tag_index)) catch {};
314 cfg.addKeybind(makeKeybindInt(mod_key | control_key | shift_key, keysym, .toggle_tag, tag_index)) catch {};
315 }
316
317 cfg.addButton(.{ .click = .client_win, .mod_mask = mod_key, .button = 1, .action = .move_mouse }) catch {};
318 cfg.addButton(.{ .click = .client_win, .mod_mask = mod_key, .button = 3, .action = .resize_mouse }) catch {};
319 }
320
321 fn makeKeybind(mod: u32, key: u64, action: Action) Keybind {
322 var kb: Keybind = .{ .action = action };
323 kb.keys[0] = .{ .mod_mask = mod, .keysym = key };
324 kb.key_count = 1;
325 return kb;
326 }
327
328 fn makeKeybindInt(mod: u32, key: u64, action: Action, int_arg: i32) Keybind {
329 var kb = makeKeybind(mod, key, action);
330 kb.int_arg = int_arg;
331 return kb;
332 }
333
334 fn makeKeybindStr(mod: u32, key: u64, action: Action, str_arg: []const u8) Keybind {
335 var kb = makeKeybind(mod, key, action);
336 kb.str_arg = str_arg;
337 return kb;
338 }