tony / oxwm

Branch: 2d0cf46
Switch branches/tags
master
tonybanters Added ability to have 12 tags for Just a guy linux. a6b2117 2026-06-03
325 lines · 10.3 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 MouseButton = struct {
106 click: ClickTarget,
107 mod_mask: u32,
108 button: u32,
109 action: MouseAction,
110 };
111
112 pub const FloatingPosition = enum {
113 top_left,
114 top_center,
115 top_right,
116 center_left,
117 center,
118 center_right,
119 bottom_left,
120 bottom_center,
121 bottom_right,
122
123 pub fn fromString(name: []const u8) ?FloatingPosition {
124 const map = .{
125 .{ "top-left", .top_left },
126 .{ "top_left", .top_left },
127 .{ "top-center", .top_center },
128 .{ "top_center", .top_center },
129 .{ "top-middle", .top_center },
130 .{ "top-right", .top_right },
131 .{ "top_right", .top_right },
132 .{ "center-left", .center_left },
133 .{ "center_left", .center_left },
134 .{ "center", .center },
135 .{ "center-right", .center_right },
136 .{ "center_right", .center_right },
137 .{ "bottom-left", .bottom_left },
138 .{ "bottom_left", .bottom_left },
139 .{ "bottom-center", .bottom_center },
140 .{ "bottom_center", .bottom_center },
141 .{ "bottom-middle", .bottom_center },
142 .{ "bottom-right", .bottom_right },
143 .{ "bottom_right", .bottom_right },
144 };
145 inline for (map) |entry| {
146 if (std.mem.eql(u8, name, entry[0])) return entry[1];
147 }
148 return null;
149 }
150 };
151
152 pub const ClickAction = struct {
153 command: []const u8,
154 floating: bool = false,
155 bypass_rules: bool = false,
156 };
157
158 pub const Block = struct {
159 block_type: BlockType,
160 format: []const u8,
161 command: ?[]const u8 = null,
162 interval: u32,
163 color: u32,
164 underline: bool = true,
165 datetime_format: ?[]const u8 = null,
166 format_charging: ?[]const u8 = null,
167 format_discharging: ?[]const u8 = null,
168 format_full: ?[]const u8 = null,
169 battery_name: ?[]const u8 = null,
170 thermal_zone: ?[]const u8 = null,
171 click: ?ClickAction = null,
172 };
173
174 pub const ColorScheme = struct {
175 foreground: u32 = 0xbbbbbb,
176 background: u32 = 0x1a1b26,
177 border: u32 = 0x444444,
178 };
179
180 pub const Config = struct {
181 allocator: std.mem.Allocator,
182 string_arena: std.heap.ArenaAllocator,
183
184 terminal: []const u8 = "st",
185 font: []const u8 = "monospace:size=10",
186 bar_position: []const u8 = "top",
187 tags: [12][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" },
188 tag_count: u32 = 9,
189 layout: []const u8 = "tiling",
190 tag_layouts: [12]?[]const u8 = .{null} ** 12,
191
192 border_width: i32 = 2,
193 border_focused: u32 = 0x6dade3,
194 border_unfocused: u32 = 0x444444,
195
196 gaps_enabled: bool = true,
197 smartgaps_enabled: bool = false,
198 gap_inner_h: i32 = 5,
199 gap_inner_v: i32 = 5,
200 gap_outer_h: i32 = 5,
201 gap_outer_v: i32 = 5,
202
203 modkey: u32 = (1 << 6),
204 auto_tile: bool = false,
205 tag_back_and_forth: bool = false,
206 hide_vacant_tags: bool = false,
207 floating_position: FloatingPosition = .center,
208 tiled_resize_mode: bool = false,
209 warp_cursor_to_monitor: bool = false,
210 warp_cursor_on_send: bool = false,
211
212 layout_tile_symbol: []const u8 = "[]=",
213 layout_monocle_symbol: []const u8 = "[M]",
214 layout_floating_symbol: []const u8 = "><>",
215 layout_scrolling_symbol: []const u8 = "[S]",
216 layout_grid_symbol: []const u8 = "[#]",
217 layout_dwindle_symbol: []const u8 = "[\\]",
218
219 scheme_normal: ColorScheme = .{ .foreground = 0xbbbbbb, .background = 0x1a1b26, .border = 0x444444 },
220 scheme_selected: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0xad8ee6 },
221 scheme_occupied: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0x0db9d7 },
222 scheme_urgent: ColorScheme = .{ .foreground = 0xf7768e, .background = 0x1a1b26, .border = 0xf7768e },
223
224 keybinds: std.ArrayListUnmanaged(Keybind) = .empty,
225 rules: std.ArrayListUnmanaged(Rule) = .empty,
226 blocks: std.ArrayListUnmanaged(Block) = .empty,
227 buttons: std.ArrayListUnmanaged(MouseButton) = .empty,
228 autostart: std.ArrayListUnmanaged([]const u8) = .empty,
229
230 pub fn init(allocator: std.mem.Allocator) Config {
231 return Config{
232 .allocator = allocator,
233 .string_arena = std.heap.ArenaAllocator.init(allocator),
234 };
235 }
236
237 pub fn deinit(self: *Config) void {
238 self.string_arena.deinit();
239 self.keybinds.deinit(self.allocator);
240 self.rules.deinit(self.allocator);
241 self.blocks.deinit(self.allocator);
242 self.buttons.deinit(self.allocator);
243 self.autostart.deinit(self.allocator);
244 }
245
246 pub fn addKeybind(self: *Config, keybind: Keybind) !void {
247 try self.keybinds.append(self.allocator, keybind);
248 }
249
250 pub fn addRule(self: *Config, rule: Rule) !void {
251 try self.rules.append(self.allocator, rule);
252 }
253
254 pub fn addBlock(self: *Config, block: Block) !void {
255 try self.blocks.append(self.allocator, block);
256 }
257
258 pub fn addButton(self: *Config, button: MouseButton) !void {
259 try self.buttons.append(self.allocator, button);
260 }
261
262 pub fn addAutostart(self: *Config, cmd: []const u8) !void {
263 try self.autostart.append(self.allocator, cmd);
264 }
265 };
266
267 pub fn initializeDefaultConfig(cfg: *Config) void {
268 const mod_key: u32 = 1 << 6;
269 const shift_key: u32 = 1 << 0;
270 const control_key: u32 = 1 << 2;
271
272 cfg.addKeybind(makeKeybind(mod_key, 0xff0d, .spawn_terminal)) catch {};
273 cfg.addKeybind(makeKeybindStr(mod_key, 'd', .spawn, "rofi -show drun")) catch {};
274 cfg.addKeybind(makeKeybindStr(mod_key, 's', .spawn, "maim -s | xclip -selection clipboard -t image/png")) catch {};
275 cfg.addKeybind(makeKeybind(mod_key, 'q', .kill_client)) catch {};
276 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'q', .quit)) catch {};
277 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'r', .reload_config)) catch {};
278 cfg.addKeybind(makeKeybind(mod_key, 'j', .focus_next)) catch {};
279 cfg.addKeybind(makeKeybind(mod_key, 'k', .focus_prev)) catch {};
280 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'j', .move_next)) catch {};
281 cfg.addKeybind(makeKeybind(mod_key | shift_key, 'k', .move_prev)) catch {};
282 cfg.addKeybind(makeKeybindInt(mod_key, 'h', .resize_master, -50)) catch {};
283 cfg.addKeybind(makeKeybindInt(mod_key, 'l', .resize_master, 50)) catch {};
284 cfg.addKeybind(makeKeybind(mod_key, 'i', .inc_master)) catch {};
285 cfg.addKeybind(makeKeybind(mod_key, 'p', .dec_master)) catch {};
286 cfg.addKeybind(makeKeybind(mod_key, 'a', .toggle_gaps)) catch {};
287 cfg.addKeybind(makeKeybind(mod_key, 'f', .toggle_fullscreen)) catch {};
288 cfg.addKeybind(makeKeybind(mod_key, 0x0020, .toggle_floating)) catch {};
289 cfg.addKeybind(makeKeybind(mod_key, 'n', .cycle_layout)) catch {};
290 cfg.addKeybind(makeKeybindInt(mod_key, 0x002c, .focus_monitor, -1)) catch {};
291 cfg.addKeybind(makeKeybindInt(mod_key, 0x002e, .focus_monitor, 1)) catch {};
292 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, 0x002c, .send_to_monitor, -1)) catch {};
293 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, 0x002e, .send_to_monitor, 1)) catch {};
294
295 var tag_index: i32 = 0;
296 while (tag_index < 9) : (tag_index += 1) {
297 const keysym: u64 = @as(u64, '1') + @as(u64, @intCast(tag_index));
298 cfg.addKeybind(makeKeybindInt(mod_key, keysym, .view_tag, tag_index)) catch {};
299 cfg.addKeybind(makeKeybindInt(mod_key | shift_key, keysym, .move_to_tag, tag_index)) catch {};
300 cfg.addKeybind(makeKeybindInt(mod_key | control_key, keysym, .toggle_view_tag, tag_index)) catch {};
301 cfg.addKeybind(makeKeybindInt(mod_key | control_key | shift_key, keysym, .toggle_tag, tag_index)) catch {};
302 }
303
304 cfg.addButton(.{ .click = .client_win, .mod_mask = mod_key, .button = 1, .action = .move_mouse }) catch {};
305 cfg.addButton(.{ .click = .client_win, .mod_mask = mod_key, .button = 3, .action = .resize_mouse }) catch {};
306 }
307
308 fn makeKeybind(mod: u32, key: u64, action: Action) Keybind {
309 var kb: Keybind = .{ .action = action };
310 kb.keys[0] = .{ .mod_mask = mod, .keysym = key };
311 kb.key_count = 1;
312 return kb;
313 }
314
315 fn makeKeybindInt(mod: u32, key: u64, action: Action, int_arg: i32) Keybind {
316 var kb = makeKeybind(mod, key, action);
317 kb.int_arg = int_arg;
318 return kb;
319 }
320
321 fn makeKeybindStr(mod: u32, key: u64, action: Action, str_arg: []const u8) Keybind {
322 var kb = makeKeybind(mod, key, action);
323 kb.str_arg = str_arg;
324 return kb;
325 }