Rename config files

Switch to file-as-struct for the ones that are just the configs structs
and use singular for the ones that are just parsers
This commit is contained in:
Ben Buhse 2026-02-17 12:53:15 -06:00
commit b4c4019cad
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
7 changed files with 131 additions and 135 deletions

View file

@ -39,17 +39,13 @@ bar_config: ?BarConfig = null,
/// Tag bind entries parsed from config (tag_bind nodes in keybinds block) /// Tag bind entries parsed from config (tag_bind nodes in keybinds block)
tag_binds: std.ArrayList(Keybind) = .{}, tag_binds: std.ArrayList(Keybind) = .{},
// We use a hash map so that duplicate keybinds can be easily de-duplicated // We use a hash map so that duplicate keybinds can be easily de-duplicated
keybinds: keybind_helper.Map = .{}, keybinds: keybind.Map = .{},
pointer_binds: std.ArrayList(PointerBind) = .{}, pointer_binds: std.ArrayList(PointerBind) = .{},
input_configs: std.ArrayList(InputConfig) = .{}, input_configs: std.ArrayList(InputConfig) = .{},
// Re-exports // Re-exports
pub const Keybind = keybind_helper.Keybind; pub const Keybind = keybind.Keybind;
pub const PointerBind = pointer_bind_helper.PointerBind; pub const PointerBind = pointer_bind.PointerBind;
pub const BarConfig = bar_helper.BarConfig;
pub const TagOverlayConfig = tag_overlay_helper.TagOverlayConfig;
pub const InputConfig = input_helper.InputConfig;
pub const AttachMode = enum { pub const AttachMode = enum {
top, top,
@ -268,15 +264,15 @@ fn load(config: *Config, reader: *Io.Reader) !void {
.child_block_begin => { .child_block_begin => {
if (next_child_block) |child_block| { if (next_child_block) |child_block| {
switch (child_block) { switch (child_block) {
.bar => try bar_helper.load(config, &parser, hostname), .bar => try BarConfig.load(config, &parser, hostname),
.borders => try borders_helper.load(config, &parser, hostname), .borders => try border.load(config, &parser, hostname),
.keybinds => try keybind_helper.load(config, &parser, hostname), .keybinds => try keybind.load(config, &parser, hostname),
.pointer_binds => try pointer_bind_helper.load(config, &parser, hostname), .pointer_binds => try pointer_bind.load(config, &parser, hostname),
.input => { .input => {
try input_helper.load(config, &parser, pending_input_name, hostname); try InputConfig.load(config, &parser, pending_input_name, hostname);
pending_input_name = null; // ownership transferred pending_input_name = null; // ownership transferred
}, },
.tag_overlay => try tag_overlay_helper.load(config, &parser, hostname), .tag_overlay => try TagOverlayConfig.load(config, &parser, hostname),
else => { else => {
// Nothing else should ever be marked as a next_child_block // Nothing else should ever be marked as a next_child_block
unreachable; unreachable;
@ -322,13 +318,13 @@ const utils = @import("utils.zig");
const RiverColor = utils.RiverColor; const RiverColor = utils.RiverColor;
const XkbBindings = @import("XkbBindings.zig"); const XkbBindings = @import("XkbBindings.zig");
const bar_helper = @import("config/bar.zig"); const border = @import("config/border.zig");
const borders_helper = @import("config/borders.zig");
const input_helper = @import("config/input.zig");
const keybind_helper = @import("config/keybinds.zig");
const pointer_bind_helper = @import("config/pointer_binds.zig");
const tag_overlay_helper = @import("config/tag_overlay.zig");
const helpers = @import("config/helpers.zig"); const helpers = @import("config/helpers.zig");
const keybind = @import("config/keybind.zig");
const pointer_bind = @import("config/pointer_bind.zig");
const BarConfig = @import("config/BarConfig.zig");
const InputConfig = @import("config/InputConfig.zig");
const TagOverlayConfig = @import("config/TagOverlayConfig.zig");
const log = std.log.scoped(.Config); const log = std.log.scoped(.Config);

View file

@ -2,44 +2,44 @@
// //
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pub const NodeName = enum { const BarConfig = @This();
const NodeName = enum {
fonts, fonts,
text_color, text_color,
background_color, background_color,
position, position,
margins, margins,
}; };
pub const MarginsNodeName = enum { top, right, bottom, left }; const MarginsNodeName = enum { top, right, bottom, left };
pub const BarConfig = struct { // Comma separated list of FontConfig formatted font specifications.
// Comma separated list of FontConfig formatted font specifications. // null means use the default ("monospace:size=14").
// null means use the default ("monospace:size=14"). fonts: ?[]const u8 = null,
fonts: ?[]const u8 = null, text_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
text_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"), background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"),
background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"), position: Bar.Position = .top,
position: Bar.Position = .top, margin_top: i32 = 0,
margin_top: i32 = 0, margin_right: i32 = 0,
margin_right: i32 = 0, margin_bottom: i32 = 0,
margin_bottom: i32 = 0, margin_left: i32 = 0,
margin_left: i32 = 0, // TODO: Support only having the bar on specific outputs
// TODO: Support only having the bar on specific outputs // output: []const u8,
// output: []const u8,
pub fn toBarOptions(config: BarConfig) Bar.Options { pub fn toBarOptions(config: BarConfig) Bar.Options {
return .{ return .{
.fonts = config.fonts orelse "monospace:size=14", .fonts = config.fonts orelse "monospace:size=14",
.text_color = config.text_color, .text_color = config.text_color,
.background_color = config.background_color, .background_color = config.background_color,
.position = config.position, .position = config.position,
.margins = .{ .margins = .{
.top = config.margin_top, .top = config.margin_top,
.right = config.margin_right, .right = config.margin_right,
.bottom = config.margin_bottom, .bottom = config.margin_bottom,
.left = config.margin_left, .left = config.margin_left,
}, },
}; };
} }
};
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void { pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
config.bar_config = .{}; // Presence of block = enabled; initialize with defaults config.bar_config = .{}; // Presence of block = enabled; initialize with defaults

View file

@ -2,31 +2,7 @@
// //
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pub const InputConfig = struct { const InputConfig = @This();
/// Device name to match
/// If this is null, applies to all devices
name: ?[]const u8 = null,
send_events: ?SendEventsModes.Enum = null,
tap: ?TapState = null,
tap_button_map: ?TapButtonMap = null,
drag: ?DragState = null,
drag_lock: ?DragLockState = null,
three_finger_drag: ?ThreeFingerDragState = null,
accel_profile: ?AccelProfile = null,
accel_speed: ?f64 = null,
natural_scroll: ?NaturalScrollState = null,
left_handed: ?LeftHandedState = null,
click_method: ?ClickMethod = null,
clickfinger_button_map: ?ClickfingerButtonMap = null,
middle_emulation: ?MiddleEmulationState = null,
scroll_method: ?ScrollMethod = null,
scroll_button: ?u32 = null,
scroll_button_lock: ?ScrollButtonLockState = null,
dwt: ?DwtState = null,
dwtp: ?DwtpState = null,
rotation: ?u32 = null,
};
const NodeName = enum { const NodeName = enum {
send_events, send_events,
@ -50,6 +26,30 @@ const NodeName = enum {
rotation, rotation,
}; };
/// Device name to match
/// If this is null, applies to all devices
name: ?[]const u8 = null,
send_events: ?SendEventsModes.Enum = null,
tap: ?TapState = null,
tap_button_map: ?TapButtonMap = null,
drag: ?DragState = null,
drag_lock: ?DragLockState = null,
three_finger_drag: ?ThreeFingerDragState = null,
accel_profile: ?AccelProfile = null,
accel_speed: ?f64 = null,
natural_scroll: ?NaturalScrollState = null,
left_handed: ?LeftHandedState = null,
click_method: ?ClickMethod = null,
clickfinger_button_map: ?ClickfingerButtonMap = null,
middle_emulation: ?MiddleEmulationState = null,
scroll_method: ?ScrollMethod = null,
scroll_button: ?u32 = null,
scroll_button_lock: ?ScrollButtonLockState = null,
dwt: ?DwtState = null,
dwtp: ?DwtpState = null,
rotation: ?u32 = null,
pub fn load(config: *Config, parser: *kdl.Parser, name: ?[]const u8, hostname: ?[]const u8) !void { pub fn load(config: *Config, parser: *kdl.Parser, name: ?[]const u8, hostname: ?[]const u8) !void {
var input_config: InputConfig = .{ .name = name }; var input_config: InputConfig = .{ .name = name };
errdefer if (input_config.name) |n| utils.gpa.free(n); errdefer if (input_config.name) |n| utils.gpa.free(n);

View file

@ -2,7 +2,9 @@
// //
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
pub const NodeName = enum { const TagOverlayConfig = @This();
const NodeName = enum {
border_width, border_width,
tag_amount, tag_amount,
tags_per_row, tags_per_row,
@ -23,68 +25,66 @@ pub const NodeName = enum {
margins, margins,
}; };
pub const AnchorsNodeName = enum { top, right, bottom, left }; const AnchorsNodeName = enum { top, right, bottom, left };
pub const MarginsNodeName = enum { top, right, bottom, left }; const MarginsNodeName = enum { top, right, bottom, left };
pub const TagOverlayConfig = struct { border_width: u8 = 2,
border_width: u8 = 2, tag_amount: u8 = 9,
tag_amount: u8 = 9, tags_per_row: u8 = 32,
tags_per_row: u8 = 32, square_size: u8 = 40,
square_size: u8 = 40, square_inner_padding: u8 = 10,
square_inner_padding: u8 = 10, square_padding: u8 = 15,
square_padding: u8 = 15, square_border_width: u8 = 1,
square_border_width: u8 = 1, background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"),
background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"), border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"), square_active_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x89b4fa"),
square_active_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x89b4fa"), square_active_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
square_active_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"), square_active_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
square_active_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"), square_inactive_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x585b70"),
square_inactive_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x585b70"), square_inactive_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
square_inactive_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"), square_inactive_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
square_inactive_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"), timeout: u32 = 500,
timeout: u32 = 500, anchor_top: bool = false,
anchor_top: bool = false, anchor_right: bool = false,
anchor_right: bool = false, anchor_bottom: bool = false,
anchor_bottom: bool = false, anchor_left: bool = false,
anchor_left: bool = false, margin_top: i32 = 0,
margin_top: i32 = 0, margin_right: i32 = 0,
margin_right: i32 = 0, margin_bottom: i32 = 0,
margin_bottom: i32 = 0, margin_left: i32 = 0,
margin_left: i32 = 0,
pub fn toTagOverlayOptions(config: TagOverlayConfig) TagOverlay.Options { pub fn toTagOverlayOptions(config: TagOverlayConfig) TagOverlay.Options {
return .{ return .{
.border_width = config.border_width, .border_width = config.border_width,
.tag_amount = @intCast(std.math.clamp(@as(u32, config.tag_amount), 1, 32)), .tag_amount = @intCast(std.math.clamp(@as(u32, config.tag_amount), 1, 32)),
.tags_per_row = @intCast(std.math.clamp(@as(u32, config.tags_per_row), 1, 32)), .tags_per_row = @intCast(std.math.clamp(@as(u32, config.tags_per_row), 1, 32)),
.square_size = config.square_size, .square_size = config.square_size,
.square_inner_padding = config.square_inner_padding, .square_inner_padding = config.square_inner_padding,
.square_padding = config.square_padding, .square_padding = config.square_padding,
.square_border_width = config.square_border_width, .square_border_width = config.square_border_width,
.background_color = config.background_color, .background_color = config.background_color,
.border_color = config.border_color, .border_color = config.border_color,
.square_active_background_color = config.square_active_background_color, .square_active_background_color = config.square_active_background_color,
.square_active_border_color = config.square_active_border_color, .square_active_border_color = config.square_active_border_color,
.square_active_occupied_color = config.square_active_occupied_color, .square_active_occupied_color = config.square_active_occupied_color,
.square_inactive_background_color = config.square_inactive_background_color, .square_inactive_background_color = config.square_inactive_background_color,
.square_inactive_border_color = config.square_inactive_border_color, .square_inactive_border_color = config.square_inactive_border_color,
.square_inactive_occupied_color = config.square_inactive_occupied_color, .square_inactive_occupied_color = config.square_inactive_occupied_color,
.anchors = .{ .anchors = .{
.top = config.anchor_top, .top = config.anchor_top,
.right = config.anchor_right, .right = config.anchor_right,
.bottom = config.anchor_bottom, .bottom = config.anchor_bottom,
.left = config.anchor_left, .left = config.anchor_left,
}, },
.margins = .{ .margins = .{
.top = config.margin_top, .top = config.margin_top,
.right = config.margin_right, .right = config.margin_right,
.bottom = config.margin_bottom, .bottom = config.margin_bottom,
.left = config.margin_left, .left = config.margin_left,
}, },
.timeout = config.timeout, .timeout = config.timeout,
}; };
} }
};
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void { pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
config.tag_overlay_config = .{}; // Presence of block = enabled; initialize with defaults config.tag_overlay_config = .{}; // Presence of block = enabled; initialize with defaults