tony / oxwm

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