tony / oxwm

Branch: e95e4af
Switch branches/tags
master
tonybanters Zig port. e95e4af 2026-02-02
185 lines · 4.4 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 focus_next,
11 focus_prev,
12 move_next,
13 move_prev,
14 resize_master,
15 inc_master,
16 dec_master,
17 toggle_floating,
18 toggle_fullscreen,
19 toggle_gaps,
20 cycle_layout,
21 set_layout,
22 set_layout_tiling,
23 set_layout_floating,
24 view_tag,
25 view_next_tag,
26 view_prev_tag,
27 view_next_nonempty_tag,
28 view_prev_nonempty_tag,
29 move_to_tag,
30 toggle_view_tag,
31 toggle_tag,
32 focus_monitor,
33 send_to_monitor,
34 scroll_left,
35 scroll_right,
36 };
37
38 pub const Keybind = struct {
39 mod_mask: u32,
40 keysym: u64,
41 action: Action,
42 int_arg: i32 = 0,
43 str_arg: ?[]const u8 = null,
44 };
45
46 pub const Rule = struct {
47 class: ?[]const u8,
48 instance: ?[]const u8,
49 title: ?[]const u8,
50 tags: u32,
51 is_floating: bool,
52 monitor: i32,
53 };
54
55 pub const Block_Type = enum {
56 static,
57 datetime,
58 ram,
59 shell,
60 battery,
61 cpu_temp,
62 };
63
64 pub const Click_Target = enum {
65 client_win,
66 root_win,
67 tag_bar,
68 };
69
70 pub const Mouse_Action = enum {
71 move_mouse,
72 resize_mouse,
73 toggle_floating,
74 };
75
76 pub const Mouse_Button = struct {
77 click: Click_Target,
78 mod_mask: u32,
79 button: u32,
80 action: Mouse_Action,
81 };
82
83 pub const Block = struct {
84 block_type: Block_Type,
85 format: []const u8,
86 command: ?[]const u8 = null,
87 interval: u32,
88 color: u32,
89 underline: bool = true,
90 datetime_format: ?[]const u8 = null,
91 format_charging: ?[]const u8 = null,
92 format_discharging: ?[]const u8 = null,
93 format_full: ?[]const u8 = null,
94 battery_name: ?[]const u8 = null,
95 thermal_zone: ?[]const u8 = null,
96 };
97
98 pub const Color_Scheme = struct {
99 fg: u32 = 0xbbbbbb,
100 bg: u32 = 0x1a1b26,
101 border: u32 = 0x444444,
102 };
103
104 pub const Config = struct {
105 allocator: std.mem.Allocator,
106
107 terminal: []const u8 = "st",
108 font: []const u8 = "monospace:size=10",
109 tags: [9][]const u8 = .{ "1", "2", "3", "4", "5", "6", "7", "8", "9" },
110
111 border_width: i32 = 2,
112 border_focused: u32 = 0x6dade3,
113 border_unfocused: u32 = 0x444444,
114
115 gaps_enabled: bool = true,
116 smartgaps_enabled: bool = false,
117 gap_inner_h: i32 = 5,
118 gap_inner_v: i32 = 5,
119 gap_outer_h: i32 = 5,
120 gap_outer_v: i32 = 5,
121
122 modkey: u32 = (1 << 6),
123 auto_tile: bool = false,
124 tag_back_and_forth: bool = false,
125 hide_vacant_tags: bool = false,
126
127 layout_tile_symbol: []const u8 = "[]=",
128 layout_monocle_symbol: []const u8 = "[M]",
129 layout_floating_symbol: []const u8 = "><>",
130
131 scheme_normal: Color_Scheme = .{ .fg = 0xbbbbbb, .bg = 0x1a1b26, .border = 0x444444 },
132 scheme_selected: Color_Scheme = .{ .fg = 0x0db9d7, .bg = 0x1a1b26, .border = 0xad8ee6 },
133 scheme_occupied: Color_Scheme = .{ .fg = 0x0db9d7, .bg = 0x1a1b26, .border = 0x0db9d7 },
134 scheme_urgent: Color_Scheme = .{ .fg = 0xf7768e, .bg = 0x1a1b26, .border = 0xf7768e },
135
136 keybinds: std.ArrayListUnmanaged(Keybind) = .{},
137 rules: std.ArrayListUnmanaged(Rule) = .{},
138 blocks: std.ArrayListUnmanaged(Block) = .{},
139 buttons: std.ArrayListUnmanaged(Mouse_Button) = .{},
140 autostart: std.ArrayListUnmanaged([]const u8) = .{},
141
142 pub fn init(allocator: std.mem.Allocator) Config {
143 return Config{
144 .allocator = allocator,
145 };
146 }
147
148 pub fn deinit(self: *Config) void {
149 self.keybinds.deinit(self.allocator);
150 self.rules.deinit(self.allocator);
151 self.blocks.deinit(self.allocator);
152 self.buttons.deinit(self.allocator);
153 self.autostart.deinit(self.allocator);
154 }
155
156 pub fn add_keybind(self: *Config, keybind: Keybind) !void {
157 try self.keybinds.append(self.allocator, keybind);
158 }
159
160 pub fn add_rule(self: *Config, rule: Rule) !void {
161 try self.rules.append(self.allocator, rule);
162 }
163
164 pub fn add_block(self: *Config, block: Block) !void {
165 try self.blocks.append(self.allocator, block);
166 }
167
168 pub fn add_button(self: *Config, button: Mouse_Button) !void {
169 try self.buttons.append(self.allocator, button);
170 }
171
172 pub fn add_autostart(self: *Config, cmd: []const u8) !void {
173 try self.autostart.append(self.allocator, cmd);
174 }
175 };
176
177 pub var global_config: ?*Config = null;
178
179 pub fn get_config() ?*Config {
180 return global_config;
181 }
182
183 pub fn set_config(cfg: *Config) void {
184 global_config = cfg;
185 }