From a201ced77d8b2fa75665f3833dd6475641edf2a9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Fri, 21 Aug 2020 19:32:21 +0200 Subject: [PATCH] config: clean up initialization --- river/Config.zig | 44 +++++++++++++++++++------------------------- river/Server.zig | 2 +- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/river/Config.zig b/river/Config.zig index 6add4cd..a2814f1 100644 --- a/river/Config.zig +++ b/river/Config.zig @@ -26,22 +26,22 @@ const Server = @import("Server.zig"); const Mapping = @import("Mapping.zig"); /// Color of background in RGBA (alpha should only affect nested sessions) -background_color: [4]f32, +background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03 /// Width of borders in pixels -border_width: u32, +border_width: u32 = 2, /// Color of border of focused window in RGBA -border_color_focused: [4]f32, +border_color_focused: [4]f32 = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }, // Solarized base1 /// Color of border of unfocused window in RGBA -border_color_unfocused: [4]f32, +border_color_unfocused: [4]f32 = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }, // Solarized base0 /// Amount of view padding in pixels -view_padding: u32, +view_padding: u32 = 8, /// Amount of padding arount the outer edge of the layout in pixels -outer_padding: u32, +outer_padding: u32 = 8, /// Map of keymap mode name to mode id mode_to_id: std.StringHashMap(usize), @@ -55,29 +55,23 @@ float_filter: std.ArrayList([]const u8), /// List of app_ids which are allowed to use client side decorations csd_filter: std.ArrayList([]const u8), -pub fn init(self: *Self) !void { - self.background_color = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }; // Solarized base03 - self.border_width = 2; - self.border_color_focused = [_]f32{ 0.57647059, 0.63137255, 0.63137255, 1.0 }; // Solarized base1 - self.border_color_unfocused = [_]f32{ 0.34509804, 0.43137255, 0.45882353, 1.0 }; // Solarized base0 - self.view_padding = 8; - self.outer_padding = 8; - - self.mode_to_id = std.StringHashMap(usize).init(util.gpa); - errdefer self.mode_to_id.deinit(); +pub fn init() !Self { + var mode_to_id = std.StringHashMap(usize).init(util.gpa); + errdefer mode_to_id.deinit(); const owned_slice = try std.mem.dupe(util.gpa, u8, "normal"); errdefer util.gpa.free(owned_slice); - try self.mode_to_id.putNoClobber(owned_slice, 0); + try mode_to_id.putNoClobber(owned_slice, 0); - self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa); - errdefer self.modes.deinit(); - try self.modes.append(std.ArrayList(Mapping).init(util.gpa)); + var modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa); + errdefer modes.deinit(); + try modes.append(std.ArrayList(Mapping).init(util.gpa)); - self.float_filter = std.ArrayList([]const u8).init(util.gpa); - errdefer self.float_filter.deinit(); - - self.csd_filter = std.ArrayList([]const u8).init(util.gpa); - errdefer self.csd_filter.deinit(); + return Self{ + .mode_to_id = mode_to_id, + .modes = modes, + .float_filter = std.ArrayList([]const u8).init(util.gpa), + .csd_filter = std.ArrayList([]const u8).init(util.gpa), + }; } pub fn deinit(self: Self) void { diff --git a/river/Server.zig b/river/Server.zig index e06e1c6..639c2fd 100644 --- a/river/Server.zig +++ b/river/Server.zig @@ -118,7 +118,7 @@ pub fn init(self: *Self) !void { c.wl_signal_add(&self.wlr_xwayland.events.new_surface, &self.listen_new_xwayland_surface); } - try self.config.init(); + self.config = try Config.init(); try self.decoration_manager.init(self); try self.root.init(self); // Must be called after root is initialized