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:
parent
03fd4d0087
commit
b4c4019cad
7 changed files with 133 additions and 137 deletions
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
||||||
186
src/config/BarConfig.zig
Normal file
186
src/config/BarConfig.zig
Normal file
|
|
@ -0,0 +1,186 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
const BarConfig = @This();
|
||||||
|
|
||||||
|
const NodeName = enum {
|
||||||
|
fonts,
|
||||||
|
text_color,
|
||||||
|
background_color,
|
||||||
|
position,
|
||||||
|
margins,
|
||||||
|
};
|
||||||
|
const MarginsNodeName = enum { top, right, bottom, left };
|
||||||
|
|
||||||
|
// Comma separated list of FontConfig formatted font specifications.
|
||||||
|
// null means use the default ("monospace:size=14").
|
||||||
|
fonts: ?[]const u8 = null,
|
||||||
|
text_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
|
||||||
|
background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"),
|
||||||
|
position: Bar.Position = .top,
|
||||||
|
margin_top: i32 = 0,
|
||||||
|
margin_right: i32 = 0,
|
||||||
|
margin_bottom: i32 = 0,
|
||||||
|
margin_left: i32 = 0,
|
||||||
|
// TODO: Support only having the bar on specific outputs
|
||||||
|
// output: []const u8,
|
||||||
|
|
||||||
|
pub fn toBarOptions(config: BarConfig) Bar.Options {
|
||||||
|
return .{
|
||||||
|
.fonts = config.fonts orelse "monospace:size=14",
|
||||||
|
.text_color = config.text_color,
|
||||||
|
.background_color = config.background_color,
|
||||||
|
.position = config.position,
|
||||||
|
.margins = .{
|
||||||
|
.top = config.margin_top,
|
||||||
|
.right = config.margin_right,
|
||||||
|
.bottom = config.margin_bottom,
|
||||||
|
.left = config.margin_left,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
config.bar_config = .{}; // Presence of block = enabled; initialize with defaults
|
||||||
|
|
||||||
|
const BarChild = enum { margins };
|
||||||
|
var next_child_block: ?BarChild = null;
|
||||||
|
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
if (next_child_block) |child| {
|
||||||
|
log.warn("Expected child block for bar.{s}, got node instead. Ignoring", .{@tagName(child)});
|
||||||
|
next_child_block = null;
|
||||||
|
}
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
logDebugHostMismatch(name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
switch (name) {
|
||||||
|
.fonts => {
|
||||||
|
if (node.argcount() < 1) {
|
||||||
|
logWarnMissingNodeArg(name, "font specification");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
config.bar_config.?.fonts = utils.gpa.dupe(u8, val_str) catch @panic("Out of memory");
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
},
|
||||||
|
.position => {
|
||||||
|
if (std.meta.stringToEnum(Bar.Position, val_str)) |pos| {
|
||||||
|
config.bar_config.?.position = pos;
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
} else {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.margins => next_child_block = .margins,
|
||||||
|
inline .background_color,
|
||||||
|
.text_color,
|
||||||
|
=> |tag| {
|
||||||
|
@field(config.bar_config.?, @tagName(tag)) = utils.parseRgbaPixman(val_str) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
if (next_child_block) |child| {
|
||||||
|
switch (child) {
|
||||||
|
.margins => try loadMarginsBlock(config, parser, hostname),
|
||||||
|
}
|
||||||
|
next_child_block = null;
|
||||||
|
} else {
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_end => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loadMarginsBlock(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
const node_name = std.meta.stringToEnum(MarginsNodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
logDebugHostMismatch(name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
const val = fmt.parseInt(i32, val_str, 10) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
switch (name) {
|
||||||
|
.top => config.bar_config.?.margin_top = val,
|
||||||
|
.right => config.bar_config.?.margin_right = val,
|
||||||
|
.bottom => config.bar_config.?.margin_bottom = val,
|
||||||
|
.left => config.bar_config.?.margin_left = val,
|
||||||
|
}
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => try helpers.skipChildBlock(parser),
|
||||||
|
.child_block_end => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logDebugSettingNode(node_name: anytype, node_value: []const u8) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.debug("Setting bar.{s} to {s}", .{ @tagName(node_name), node_value }),
|
||||||
|
MarginsNodeName => log.debug("Setting bar.margins.{s} to {s}", .{ @tagName(node_name), node_value }),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(@TypeOf(node_name)) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logDebugHostMismatch(node_name: anytype) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.debug("Skipping \"bar.{s}\" (host mismatch)", .{@tagName(node_name)}),
|
||||||
|
MarginsNodeName => log.debug("Skipping \"bar.margins.{s}\" (host mismatch)", .{@tagName(node_name)}),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(node_name_type) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: anytype, node_value: []const u8) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.warn("Invalid \"bar.{s}\" ({s}). Using default value", .{ @tagName(node_name), node_value }),
|
||||||
|
MarginsNodeName => log.warn("Invalid \"bar.margins.{s}\" ({s}). Using default value", .{ @tagName(node_name), node_value }),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(node_name_type) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnMissingNodeArg(node_name: NodeName, comptime arg: []const u8) void {
|
||||||
|
log.warn("\"bar.{s}\" missing " ++ arg ++ " argument. Ignoring", .{@tagName(node_name)});
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
const pixman = @import("pixman");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Bar = @import("../Bar.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_bar);
|
||||||
172
src/config/InputConfig.zig
Normal file
172
src/config/InputConfig.zig
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
const InputConfig = @This();
|
||||||
|
|
||||||
|
const NodeName = enum {
|
||||||
|
send_events,
|
||||||
|
tap,
|
||||||
|
tap_button_map,
|
||||||
|
drag,
|
||||||
|
drag_lock,
|
||||||
|
three_finger_drag,
|
||||||
|
accel_profile,
|
||||||
|
accel_speed,
|
||||||
|
natural_scroll,
|
||||||
|
left_handed,
|
||||||
|
click_method,
|
||||||
|
clickfinger_button_map,
|
||||||
|
middle_emulation,
|
||||||
|
scroll_method,
|
||||||
|
scroll_button,
|
||||||
|
scroll_button_lock,
|
||||||
|
dwt,
|
||||||
|
dwtp,
|
||||||
|
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 {
|
||||||
|
var input_config: InputConfig = .{ .name = name };
|
||||||
|
errdefer if (input_config.name) |n| utils.gpa.free(n);
|
||||||
|
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |tag| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
log.debug("Skipping \"input.{s}\" (host mismatch)", .{@tagName(tag)});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse {
|
||||||
|
log.warn("\"input.{s}\" missing value argument. Ignoring", .{@tagName(tag)});
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
switch (tag) {
|
||||||
|
.accel_speed => {
|
||||||
|
const speed = fmt.parseFloat(f64, val_str) catch {
|
||||||
|
logWarnInvalidNodeArg(tag, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
input_config.accel_speed = speed;
|
||||||
|
log.debug("input.accel_speed: {s}", .{val_str});
|
||||||
|
},
|
||||||
|
.scroll_button => {
|
||||||
|
const button = helpers.parseButton(val_str) orelse {
|
||||||
|
logWarnInvalidNodeArg(tag, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
input_config.scroll_button = button;
|
||||||
|
log.debug("input.scroll_button: {s}", .{val_str});
|
||||||
|
},
|
||||||
|
.rotation => {
|
||||||
|
const angle = fmt.parseInt(u32, val_str, 0) catch {
|
||||||
|
logWarnInvalidNodeArg(tag, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
input_config.rotation = angle;
|
||||||
|
log.debug("input.rotation: {s}", .{val_str});
|
||||||
|
},
|
||||||
|
inline .send_events,
|
||||||
|
.tap,
|
||||||
|
.tap_button_map,
|
||||||
|
.drag,
|
||||||
|
.drag_lock,
|
||||||
|
.three_finger_drag,
|
||||||
|
.accel_profile,
|
||||||
|
.natural_scroll,
|
||||||
|
.left_handed,
|
||||||
|
.click_method,
|
||||||
|
.clickfinger_button_map,
|
||||||
|
.middle_emulation,
|
||||||
|
.scroll_method,
|
||||||
|
.scroll_button_lock,
|
||||||
|
.dwt,
|
||||||
|
.dwtp,
|
||||||
|
=> |cmd| {
|
||||||
|
// These all have arguments, but we can use compile time constructs to reduce
|
||||||
|
// code re-use here.
|
||||||
|
// Because all the fields are optional, we have to use @typeInfo and get the optional's child type.
|
||||||
|
const field_name = @tagName(cmd);
|
||||||
|
const FieldType = @typeInfo(@TypeOf(@field(input_config, field_name))).optional.child;
|
||||||
|
if (std.meta.stringToEnum(FieldType, val_str)) |val| {
|
||||||
|
@field(input_config, field_name) = val;
|
||||||
|
log.debug("input.{s}: {s}", .{ field_name, val_str });
|
||||||
|
} else {
|
||||||
|
logWarnInvalidNodeArg(cmd, val_str);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
},
|
||||||
|
.child_block_end => {
|
||||||
|
try config.input_configs.append(utils.gpa, input_config);
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: NodeName, node_value: []const u8) void {
|
||||||
|
log.warn("Invalid \"input.{s}\" ({s}). Ignoring", .{ @tagName(node_name), node_value });
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const wayland = @import("wayland");
|
||||||
|
const river = wayland.client.river;
|
||||||
|
const AccelProfile = river.LibinputDeviceV1.AccelProfile;
|
||||||
|
const ClickfingerButtonMap = river.LibinputDeviceV1.ClickfingerButtonMap;
|
||||||
|
const ClickMethod = river.LibinputDeviceV1.ClickMethod;
|
||||||
|
const DragLockState = river.LibinputDeviceV1.DragLockState;
|
||||||
|
const DragState = river.LibinputDeviceV1.DragState;
|
||||||
|
const DwtState = river.LibinputDeviceV1.DwtState;
|
||||||
|
const DwtpState = river.LibinputDeviceV1.DwtpState;
|
||||||
|
const LeftHandedState = river.LibinputDeviceV1.LeftHandedState;
|
||||||
|
const MiddleEmulationState = river.LibinputDeviceV1.MiddleEmulationState;
|
||||||
|
const NaturalScrollState = river.LibinputDeviceV1.NaturalScrollState;
|
||||||
|
const ScrollButtonLockState = river.LibinputDeviceV1.ScrollButtonLockState;
|
||||||
|
const ScrollMethod = river.LibinputDeviceV1.ScrollMethod;
|
||||||
|
const SendEventsModes = river.LibinputDeviceV1.SendEventsModes;
|
||||||
|
const TapButtonMap = river.LibinputDeviceV1.TapButtonMap;
|
||||||
|
const TapState = river.LibinputDeviceV1.TapState;
|
||||||
|
const ThreeFingerDragState = river.LibinputDeviceV1.ThreeFingerDragState;
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_input);
|
||||||
277
src/config/TagOverlayConfig.zig
Normal file
277
src/config/TagOverlayConfig.zig
Normal file
|
|
@ -0,0 +1,277 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
const TagOverlayConfig = @This();
|
||||||
|
|
||||||
|
const NodeName = enum {
|
||||||
|
border_width,
|
||||||
|
tag_amount,
|
||||||
|
tags_per_row,
|
||||||
|
square_size,
|
||||||
|
square_inner_padding,
|
||||||
|
square_padding,
|
||||||
|
square_border_width,
|
||||||
|
background_color,
|
||||||
|
border_color,
|
||||||
|
square_active_background_color,
|
||||||
|
square_active_border_color,
|
||||||
|
square_active_occupied_color,
|
||||||
|
square_inactive_background_color,
|
||||||
|
square_inactive_border_color,
|
||||||
|
square_inactive_occupied_color,
|
||||||
|
timeout,
|
||||||
|
anchors,
|
||||||
|
margins,
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnchorsNodeName = enum { top, right, bottom, left };
|
||||||
|
const MarginsNodeName = enum { top, right, bottom, left };
|
||||||
|
|
||||||
|
border_width: u8 = 2,
|
||||||
|
tag_amount: u8 = 9,
|
||||||
|
tags_per_row: u8 = 32,
|
||||||
|
square_size: u8 = 40,
|
||||||
|
square_inner_padding: u8 = 10,
|
||||||
|
square_padding: u8 = 15,
|
||||||
|
square_border_width: u8 = 1,
|
||||||
|
background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x1e1e2e"),
|
||||||
|
border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
|
||||||
|
square_active_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x89b4fa"),
|
||||||
|
square_active_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
|
||||||
|
square_active_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
|
||||||
|
square_inactive_background_color: pixman.Color = utils.parseRgbaPixmanComptime("0x585b70"),
|
||||||
|
square_inactive_border_color: pixman.Color = utils.parseRgbaPixmanComptime("0x6c7086"),
|
||||||
|
square_inactive_occupied_color: pixman.Color = utils.parseRgbaPixmanComptime("0xcdd6f4"),
|
||||||
|
timeout: u32 = 500,
|
||||||
|
anchor_top: bool = false,
|
||||||
|
anchor_right: bool = false,
|
||||||
|
anchor_bottom: bool = false,
|
||||||
|
anchor_left: bool = false,
|
||||||
|
margin_top: i32 = 0,
|
||||||
|
margin_right: i32 = 0,
|
||||||
|
margin_bottom: i32 = 0,
|
||||||
|
margin_left: i32 = 0,
|
||||||
|
|
||||||
|
pub fn toTagOverlayOptions(config: TagOverlayConfig) TagOverlay.Options {
|
||||||
|
return .{
|
||||||
|
.border_width = config.border_width,
|
||||||
|
.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)),
|
||||||
|
.square_size = config.square_size,
|
||||||
|
.square_inner_padding = config.square_inner_padding,
|
||||||
|
.square_padding = config.square_padding,
|
||||||
|
.square_border_width = config.square_border_width,
|
||||||
|
.background_color = config.background_color,
|
||||||
|
.border_color = config.border_color,
|
||||||
|
.square_active_background_color = config.square_active_background_color,
|
||||||
|
.square_active_border_color = config.square_active_border_color,
|
||||||
|
.square_active_occupied_color = config.square_active_occupied_color,
|
||||||
|
.square_inactive_background_color = config.square_inactive_background_color,
|
||||||
|
.square_inactive_border_color = config.square_inactive_border_color,
|
||||||
|
.square_inactive_occupied_color = config.square_inactive_occupied_color,
|
||||||
|
.anchors = .{
|
||||||
|
.top = config.anchor_top,
|
||||||
|
.right = config.anchor_right,
|
||||||
|
.bottom = config.anchor_bottom,
|
||||||
|
.left = config.anchor_left,
|
||||||
|
},
|
||||||
|
.margins = .{
|
||||||
|
.top = config.margin_top,
|
||||||
|
.right = config.margin_right,
|
||||||
|
.bottom = config.margin_bottom,
|
||||||
|
.left = config.margin_left,
|
||||||
|
},
|
||||||
|
.timeout = config.timeout,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
config.tag_overlay_config = .{}; // Presence of block = enabled; initialize with defaults
|
||||||
|
|
||||||
|
const TagOverlayChild = enum { anchors, margins };
|
||||||
|
var next_child_block: ?TagOverlayChild = null;
|
||||||
|
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
if (next_child_block) |child| {
|
||||||
|
log.warn("Expected child block for tag_overlay.{s}, got node instead. Ignoring", .{@tagName(child)});
|
||||||
|
next_child_block = null;
|
||||||
|
}
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
logDebugHostMismatch(name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
switch (name) {
|
||||||
|
.anchors => next_child_block = .anchors,
|
||||||
|
.margins => next_child_block = .margins,
|
||||||
|
// These are all u8s, so we can inline the branch
|
||||||
|
inline .border_width,
|
||||||
|
.tag_amount,
|
||||||
|
.tags_per_row,
|
||||||
|
.square_size,
|
||||||
|
.square_inner_padding,
|
||||||
|
.square_padding,
|
||||||
|
.square_border_width,
|
||||||
|
=> |tag| {
|
||||||
|
const val = fmt.parseInt(u8, val_str, 10) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
@field(config.tag_overlay_config.?, @tagName(tag)) = val;
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
},
|
||||||
|
.timeout => {
|
||||||
|
config.tag_overlay_config.?.timeout = fmt.parseInt(u32, val_str, 10) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
},
|
||||||
|
inline .background_color,
|
||||||
|
.border_color,
|
||||||
|
.square_active_background_color,
|
||||||
|
.square_active_border_color,
|
||||||
|
.square_active_occupied_color,
|
||||||
|
.square_inactive_background_color,
|
||||||
|
.square_inactive_border_color,
|
||||||
|
.square_inactive_occupied_color,
|
||||||
|
=> |tag| {
|
||||||
|
@field(config.tag_overlay_config.?, @tagName(tag)) = utils.parseRgbaPixman(val_str) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
if (next_child_block) |child| {
|
||||||
|
switch (child) {
|
||||||
|
.anchors => try loadAnchorsBlock(config, parser, hostname),
|
||||||
|
.margins => try loadMarginsBlock(config, parser, hostname),
|
||||||
|
}
|
||||||
|
next_child_block = null;
|
||||||
|
} else {
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_end => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loadAnchorsBlock(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
const node_name = std.meta.stringToEnum(AnchorsNodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
logDebugHostMismatch(name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
if (helpers.boolFromKdlStr(val_str)) |val| {
|
||||||
|
switch (name) {
|
||||||
|
.top => config.tag_overlay_config.?.anchor_top = val,
|
||||||
|
.right => config.tag_overlay_config.?.anchor_right = val,
|
||||||
|
.bottom => config.tag_overlay_config.?.anchor_bottom = val,
|
||||||
|
.left => config.tag_overlay_config.?.anchor_left = val,
|
||||||
|
}
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
} else {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => try helpers.skipChildBlock(parser),
|
||||||
|
.child_block_end => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn loadMarginsBlock(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
const node_name = std.meta.stringToEnum(MarginsNodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
logDebugHostMismatch(name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const val_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
const val = fmt.parseInt(i32, val_str, 10) catch {
|
||||||
|
logWarnInvalidNodeArg(name, val_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
switch (name) {
|
||||||
|
.top => config.tag_overlay_config.?.margin_top = val,
|
||||||
|
.right => config.tag_overlay_config.?.margin_right = val,
|
||||||
|
.bottom => config.tag_overlay_config.?.margin_bottom = val,
|
||||||
|
.left => config.tag_overlay_config.?.margin_left = val,
|
||||||
|
}
|
||||||
|
logDebugSettingNode(name, val_str);
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => try helpers.skipChildBlock(parser),
|
||||||
|
.child_block_end => return,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logDebugSettingNode(node_name: anytype, node_value: []const u8) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.debug("Setting tag_overlay.{s} to {s}", .{ @tagName(node_name), node_value }),
|
||||||
|
AnchorsNodeName => log.debug("Setting tag_overlay.anchors.{s} to {s}", .{ @tagName(node_name), node_value }),
|
||||||
|
MarginsNodeName => log.debug("Setting tag_overlay.margins.{s} to {s}", .{ @tagName(node_name), node_value }),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(@TypeOf(node_name)) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logDebugHostMismatch(node_name: anytype) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.debug("Skipping \"tag_overlay.{s}\" (host mismatch)", .{@tagName(node_name)}),
|
||||||
|
AnchorsNodeName => log.debug("Skipping \"tag_overlay.anchors.{s}\" (host mismatch)", .{@tagName(node_name)}),
|
||||||
|
MarginsNodeName => log.debug("Skipping \"tag_overlay.margins.{s}\" (host mismatch)", .{@tagName(node_name)}),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(node_name_type) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: anytype, node_value: []const u8) void {
|
||||||
|
const node_name_type = @TypeOf(node_name);
|
||||||
|
switch (node_name_type) {
|
||||||
|
NodeName => log.warn("Invalid \"tag_overlay.{s}\" ({s}). Using default value", .{ @tagName(node_name), node_value }),
|
||||||
|
AnchorsNodeName => log.warn("Invalid \"tag_overlay.anchors.{s}\" ({s}). Using default value", .{ @tagName(node_name), node_value }),
|
||||||
|
MarginsNodeName => log.warn("Invalid \"tag_overlay.margins.{s}\" ({s}). Using default value", .{ @tagName(node_name), node_value }),
|
||||||
|
else => @compileError("This function does not (yet) support type \"" ++ @typeName(node_name_type) ++ "\""),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
const pixman = @import("pixman");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
const TagOverlay = @import("../TagOverlay.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_tag_overlay);
|
||||||
82
src/config/border.zig
Normal file
82
src/config/border.zig
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
pub const NodeName = enum {
|
||||||
|
width,
|
||||||
|
color_focused,
|
||||||
|
color_unfocused,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
// If it's a node, we check if it's a valid NodeName
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
log.debug("Skipping \"border.{s}\" (host mismatch)", .{@tagName(name)});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (name) {
|
||||||
|
.width => {
|
||||||
|
const width_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
config.border_width = fmt.parseInt(u8, width_str, 10) catch {
|
||||||
|
logWarnInvalidNodeArg(name, width_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, width_str);
|
||||||
|
},
|
||||||
|
.color_focused => {
|
||||||
|
const color_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
config.border_color_focused = utils.parseRgba(color_str) catch {
|
||||||
|
logWarnInvalidNodeArg(name, color_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, color_str);
|
||||||
|
},
|
||||||
|
.color_unfocused => {
|
||||||
|
const color_str = utils.stripQuotes(node.arg(parser, 0) orelse "");
|
||||||
|
config.border_color_unfocused = utils.parseRgba(color_str) catch {
|
||||||
|
logWarnInvalidNodeArg(name, color_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
logDebugSettingNode(name, color_str);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
// borders should never have a nested child block
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
},
|
||||||
|
.child_block_end => {
|
||||||
|
// Done parsing the borders block; return
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logDebugSettingNode(node_name: NodeName, node_value: []const u8) void {
|
||||||
|
log.debug("Setting border.{s} to {s}", .{ @tagName(node_name), node_value });
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: NodeName, node_value: []const u8) void {
|
||||||
|
log.warn("Invalid \"border.{s}\" ({s}). Ignoring", .{ @tagName(node_name), node_value });
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_borders);
|
||||||
235
src/config/keybind.zig
Normal file
235
src/config/keybind.zig
Normal file
|
|
@ -0,0 +1,235 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
// We can just directly use the tag type from Command as our node name
|
||||||
|
const NodeName = @typeInfo(XkbBindings.Command).@"union".tag_type.?;
|
||||||
|
|
||||||
|
pub const Keybind = struct {
|
||||||
|
modifiers: river.SeatV1.Modifiers,
|
||||||
|
command: XkbBindings.Command,
|
||||||
|
keysym: ?xkbcommon.Keysym,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Key = struct {
|
||||||
|
modifiers: river.SeatV1.Modifiers,
|
||||||
|
keysym: xkbcommon.Keysym,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const Map = std.AutoArrayHashMapUnmanaged(Key, XkbBindings.Command);
|
||||||
|
|
||||||
|
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
// tag_bind is a special case node name not in KeybindNodeName
|
||||||
|
if (mem.eql(u8, node.name, "tag_bind")) {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
log.debug("Skipping \"keybind.tag_bind\" (host mismatch)", .{});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const mod_str = utils.stripQuotes(node.arg(parser, 0) orelse {
|
||||||
|
log.warn("tag_bind: missing modifier argument. Ignoring", .{});
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const cmd_str = utils.stripQuotes(node.arg(parser, 1) orelse {
|
||||||
|
log.warn("tag_bind: missing command argument. Ignoring", .{});
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const modifiers = try utils.parseModifiers(mod_str) orelse {
|
||||||
|
log.warn("tag_bind: invalid modifiers \"{s}\". Ignoring", .{mod_str});
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
const command_tag_type = std.meta.stringToEnum(NodeName, cmd_str) orelse {
|
||||||
|
log.warn("tag_bind: invalid command \"{s}\". Ignoring", .{cmd_str});
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
const command: XkbBindings.Command = switch (command_tag_type) {
|
||||||
|
// We can set these to "0" since they're not used (when in the tag_bind node)
|
||||||
|
.set_output_tags => .{ .set_output_tags = 0 },
|
||||||
|
.set_window_tags => .{ .set_window_tags = 0 },
|
||||||
|
.toggle_output_tags => .{ .toggle_output_tags = 0 },
|
||||||
|
.toggle_window_tags => .{ .toggle_window_tags = 0 },
|
||||||
|
else => {
|
||||||
|
log.warn("tag_bind: invalid command \"{s}\". Only tag-keybinds can be used with tag_binds. Ignoring", .{cmd_str});
|
||||||
|
continue;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
try config.tag_binds.append(utils.gpa, .{
|
||||||
|
.modifiers = modifiers,
|
||||||
|
.command = command,
|
||||||
|
.keysym = null, // Tag binds don't need a keysym (automatically 1-9)
|
||||||
|
});
|
||||||
|
|
||||||
|
log.debug("tag_bind: {s} {s}", .{ mod_str, cmd_str });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Handle the rest of the possibilities like all the other types of block
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
log.debug("Skipping \"keybind.{s}\" (host mismatch)", .{@tagName(name)});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// All nodes should have at least a command, modifiers, and a keysym
|
||||||
|
// Some may have more arguments handled in the switch
|
||||||
|
const mod_str = utils.stripQuotes(node.arg(parser, 0) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "modifier(s)");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const modifiers = try utils.parseModifiers(mod_str) orelse {
|
||||||
|
log.warn("keybinds: invalid modifiers \"{s}\". Ignoring", .{mod_str});
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
const key_str = utils.stripQuotes(node.arg(parser, 1) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "keysym");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
// Keysym.fromName() needs a [*:0]const u8
|
||||||
|
const z = try utils.gpa.dupeZ(u8, key_str);
|
||||||
|
defer utils.gpa.free(z);
|
||||||
|
const keysym = xkbcommon.Keysym.fromName(z, .case_insensitive);
|
||||||
|
|
||||||
|
const command: XkbBindings.Command = sw: switch (name) {
|
||||||
|
.spawn => {
|
||||||
|
// TODO: Add propert(ies) to support ENV vars
|
||||||
|
const exec_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "command");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
var split_exec = try utils.tokenizeToOwnedSlices(exec_str, ' ');
|
||||||
|
if (split_exec.len > 0) {
|
||||||
|
// Expand ~ in executable paths
|
||||||
|
const expanded = helpers.expandTilde(split_exec[0]) catch |e| {
|
||||||
|
if (e == error.HomeNotSet) {
|
||||||
|
// No ~, just return what we had.
|
||||||
|
break :sw .{ .spawn = split_exec };
|
||||||
|
} else {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// tokenizeToOwnedSlices dupes each token, so we have to
|
||||||
|
// free the original value before replacing it.
|
||||||
|
utils.gpa.free(split_exec[0]);
|
||||||
|
split_exec[0] = expanded;
|
||||||
|
}
|
||||||
|
break :sw .{ .spawn = split_exec };
|
||||||
|
},
|
||||||
|
.change_ratio => {
|
||||||
|
const diff_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "diff");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const diff = fmt.parseFloat(f32, diff_str) catch {
|
||||||
|
logWarnInvalidNodeArg(name, diff_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
break :sw .{ .change_ratio = diff };
|
||||||
|
},
|
||||||
|
inline .focus_next_window,
|
||||||
|
.focus_prev_window,
|
||||||
|
.focus_next_output,
|
||||||
|
.focus_prev_output,
|
||||||
|
.send_to_next_output,
|
||||||
|
.send_to_prev_output,
|
||||||
|
.toggle_float,
|
||||||
|
.zoom,
|
||||||
|
.reload_config,
|
||||||
|
.toggle_fullscreen,
|
||||||
|
.close_window,
|
||||||
|
.increment_primary_count,
|
||||||
|
.decrement_primary_count,
|
||||||
|
.swap_next,
|
||||||
|
.swap_prev,
|
||||||
|
.center_float,
|
||||||
|
=> |cmd| {
|
||||||
|
// None of these have arguments, just create the union and give it back
|
||||||
|
break :sw @unionInit(XkbBindings.Command, @tagName(cmd), {});
|
||||||
|
},
|
||||||
|
inline .move_up,
|
||||||
|
.move_down,
|
||||||
|
.move_left,
|
||||||
|
.move_right,
|
||||||
|
.resize_width,
|
||||||
|
.resize_height,
|
||||||
|
=> |cmd| {
|
||||||
|
const amount_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "amount");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const amount = fmt.parseInt(i32, amount_str, 0) catch {
|
||||||
|
logWarnInvalidNodeArg(name, amount_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
break :sw @unionInit(XkbBindings.Command, @tagName(cmd), amount);
|
||||||
|
},
|
||||||
|
inline .set_output_tags, .set_window_tags, .toggle_output_tags, .toggle_window_tags => |cmd| {
|
||||||
|
const tags_str = utils.stripQuotes(node.arg(parser, 2) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "tags");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const tags = fmt.parseInt(u32, tags_str, 0) catch {
|
||||||
|
logWarnInvalidNodeArg(name, tags_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
break :sw @unionInit(XkbBindings.Command, @tagName(cmd), tags);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const gop = try config.keybinds.getOrPut(utils.gpa, .{
|
||||||
|
.modifiers = modifiers,
|
||||||
|
.keysym = keysym,
|
||||||
|
});
|
||||||
|
if (gop.found_existing) {
|
||||||
|
switch (gop.value_ptr.*) {
|
||||||
|
.spawn => |argv| {
|
||||||
|
for (argv) |arg| utils.gpa.free(arg);
|
||||||
|
utils.gpa.free(argv);
|
||||||
|
},
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gop.value_ptr.* = command;
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
// keybinds should never have a nested child block
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
},
|
||||||
|
.child_block_end => {
|
||||||
|
// Done parsing the keybinds block; return
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnMissingNodeArg(node_name: NodeName, comptime arg: []const u8) void {
|
||||||
|
log.warn("\"keybind.{s}\" missing " ++ arg ++ " argument. Ignoring", .{@tagName(node_name)});
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: NodeName, node_value: []const u8) void {
|
||||||
|
log.warn("Invalid \"keybind.{s}\" ({s}). Ignoring", .{ @tagName(node_name), node_value });
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
const mem = std.mem;
|
||||||
|
|
||||||
|
const wayland = @import("wayland");
|
||||||
|
const river = wayland.client.river;
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
const xkbcommon = @import("xkbcommon");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
const XkbBindings = @import("../XkbBindings.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_keybinds);
|
||||||
97
src/config/pointer_bind.zig
Normal file
97
src/config/pointer_bind.zig
Normal file
|
|
@ -0,0 +1,97 @@
|
||||||
|
// SPDX-FileCopyrightText: 2026 Ben Buhse <me@benbuhse.email>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
|
pub const PointerBind = struct {
|
||||||
|
modifiers: river.SeatV1.Modifiers,
|
||||||
|
button: u32, // Linux button code (BTN_LEFT=0x110, BTN_RIGHT=0x111, BTN_MIDDLE=0x112)
|
||||||
|
action: PointerAction,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const PointerAction = enum {
|
||||||
|
move_window,
|
||||||
|
resize_window,
|
||||||
|
};
|
||||||
|
|
||||||
|
const NodeName = enum {
|
||||||
|
move_window,
|
||||||
|
resize_window,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn load(config: *Config, parser: *kdl.Parser, hostname: ?[]const u8) !void {
|
||||||
|
while (try parser.next()) |event| {
|
||||||
|
switch (event) {
|
||||||
|
.node => |node| {
|
||||||
|
const node_name = std.meta.stringToEnum(NodeName, node.name);
|
||||||
|
if (node_name) |name| {
|
||||||
|
if (!helpers.hostMatches(node, parser, hostname)) {
|
||||||
|
log.debug("Skipping \"pointer_binds.{s}\" (host mismatch)", .{@tagName(name)});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Parse modifiers (arg 0)
|
||||||
|
const mod_str = utils.stripQuotes(node.arg(parser, 0) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "modifier(s)");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const modifiers = try utils.parseModifiers(mod_str) orelse {
|
||||||
|
logWarnInvalidNodeArg(name, mod_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Parse button (arg 1)
|
||||||
|
const button_str = utils.stripQuotes(node.arg(parser, 1) orelse {
|
||||||
|
logWarnMissingNodeArg(name, "button");
|
||||||
|
continue;
|
||||||
|
});
|
||||||
|
const button = helpers.parseButton(button_str) orelse {
|
||||||
|
logWarnInvalidNodeArg(name, button_str);
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
|
||||||
|
const action: PointerAction = switch (name) {
|
||||||
|
.move_window => .move_window,
|
||||||
|
.resize_window => .resize_window,
|
||||||
|
};
|
||||||
|
|
||||||
|
try config.pointer_binds.append(utils.gpa, .{
|
||||||
|
.modifiers = modifiers,
|
||||||
|
.button = button,
|
||||||
|
.action = action,
|
||||||
|
});
|
||||||
|
|
||||||
|
log.debug("pointer_binds.{s}: {s} {s}", .{ @tagName(name), mod_str, button_str });
|
||||||
|
} else {
|
||||||
|
helpers.logWarnInvalidNode(node.name);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.child_block_begin => {
|
||||||
|
try helpers.skipChildBlock(parser);
|
||||||
|
},
|
||||||
|
.child_block_end => {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnInvalidNodeArg(node_name: NodeName, node_value: []const u8) void {
|
||||||
|
log.warn("Invalid \"pointer_binds.{s}\" ({s}). Ignoring", .{ @tagName(node_name), node_value });
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fn logWarnMissingNodeArg(node_name: NodeName, comptime arg: []const u8) void {
|
||||||
|
log.warn("\"pointer_binds.{s}\" missing " ++ arg ++ " argument. Ignoring", .{@tagName(node_name)});
|
||||||
|
}
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const wayland = @import("wayland");
|
||||||
|
const river = wayland.client.river;
|
||||||
|
const kdl = @import("kdl");
|
||||||
|
|
||||||
|
const utils = @import("../utils.zig");
|
||||||
|
const Config = @import("../Config.zig");
|
||||||
|
|
||||||
|
const helpers = @import("helpers.zig");
|
||||||
|
|
||||||
|
const log = std.log.scoped(.config_pointer_binds);
|
||||||
Loading…
Reference in a new issue