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