config: clean up initialization

This commit is contained in:
Isaac Freund 2020-08-21 19:32:21 +02:00
parent 71a751f1ad
commit a201ced77d
No known key found for this signature in database
GPG key ID: 86DED400DDFD7A11
2 changed files with 20 additions and 26 deletions

View file

@ -26,22 +26,22 @@ const Server = @import("Server.zig");
const Mapping = @import("Mapping.zig"); const Mapping = @import("Mapping.zig");
/// Color of background in RGBA (alpha should only affect nested sessions) /// 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 /// Width of borders in pixels
border_width: u32, border_width: u32 = 2,
/// Color of border of focused window in RGBA /// 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 /// 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 /// 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 /// 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 /// Map of keymap mode name to mode id
mode_to_id: std.StringHashMap(usize), 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 /// List of app_ids which are allowed to use client side decorations
csd_filter: std.ArrayList([]const u8), csd_filter: std.ArrayList([]const u8),
pub fn init(self: *Self) !void { pub fn init() !Self {
self.background_color = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }; // Solarized base03 var mode_to_id = std.StringHashMap(usize).init(util.gpa);
self.border_width = 2; errdefer mode_to_id.deinit();
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();
const owned_slice = try std.mem.dupe(util.gpa, u8, "normal"); const owned_slice = try std.mem.dupe(util.gpa, u8, "normal");
errdefer util.gpa.free(owned_slice); 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); var modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
errdefer self.modes.deinit(); errdefer modes.deinit();
try self.modes.append(std.ArrayList(Mapping).init(util.gpa)); try modes.append(std.ArrayList(Mapping).init(util.gpa));
self.float_filter = std.ArrayList([]const u8).init(util.gpa); return Self{
errdefer self.float_filter.deinit(); .mode_to_id = mode_to_id,
.modes = modes,
self.csd_filter = std.ArrayList([]const u8).init(util.gpa); .float_filter = std.ArrayList([]const u8).init(util.gpa),
errdefer self.csd_filter.deinit(); .csd_filter = std.ArrayList([]const u8).init(util.gpa),
};
} }
pub fn deinit(self: Self) void { pub fn deinit(self: Self) void {

View file

@ -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); 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.decoration_manager.init(self);
try self.root.init(self); try self.root.init(self);
// Must be called after root is initialized // Must be called after root is initialized