diff --git a/src/Bar.zig b/src/Bar.zig index 3055092..d205a15 100644 --- a/src/Bar.zig +++ b/src/Bar.zig @@ -27,17 +27,15 @@ layer_surface: ?*zwlr.LayerSurfaceV1 = null, configured: bool = false, pub fn init(context: *Context, output: *Output) !Bar { - // Get the local environment - // Needed for the timezone - // XXX: It might be better to store this in Context? - var env = try process.getEnvMap(utils.gpa); - defer env.deinit(); + const timezone = try zeit.local(utils.gpa, &context.env); + errdefer timezone.deinit(); - const timezone = try zeit.local(utils.gpa, &env); + const fonts = try getFcftFonts("monospace:size=14", 1); + errdefer fonts.destroy(); return .{ .context = context, - .fonts = try getFcftFonts("monospace:size=14", 1), + .fonts = fonts, .timezone = timezone, .output = output, }; @@ -82,6 +80,7 @@ pub fn initSurface(bar: *Bar) !void { pub fn deinit(bar: *Bar) void { bar.configured = false; bar.timezone.deinit(); + bar.fonts.destroy(); if (bar.wl_surface) |wl_surface| { wl_surface.destroy(); } diff --git a/src/Context.zig b/src/Context.zig index 2c8eeda..d99d225 100644 --- a/src/Context.zig +++ b/src/Context.zig @@ -7,6 +7,8 @@ const Context = @This(); initialized: bool, +env: process.EnvMap, + // Wayland globals wl_compositor: *wl.Compositor, wl_display: *wl.Display, @@ -60,10 +62,21 @@ pub const Options = struct { pub fn create(options: Options) !*Context { const context = try utils.gpa.create(Context); - errdefer context.destroy(); + errdefer utils.gpa.destroy(context); + + const im = try InputManager.create(context, options.river_input_manager_v1, options.river_libinput_config_v1); + errdefer im.destroy(); + const wm = try WindowManager.create(context, options.river_window_manager_v1); + errdefer wm.destroy(); + const xkb_bindings = try XkbBindings.create(context, options.river_xkb_bindings_v1); + errdefer xkb_bindings.destroy(); + + const env = try process.getEnvMap(utils.gpa); + errdefer env.deinit(); context.* = .{ .initialized = false, + .env = env, .wl_compositor = options.wl_compositor, .wl_display = options.wl_display, .wl_registry = options.wl_registry, @@ -72,9 +85,9 @@ pub fn create(options: Options) !*Context { .river_layer_shell_v1 = options.river_layer_shell_v1, .zwlr_layer_shell_v1 = options.zwlr_layer_shell_v1, .wallpaper_image = loadWallpaperImage(options.config), - .im = try InputManager.create(context, options.river_input_manager_v1, options.river_libinput_config_v1), - .wm = try WindowManager.create(context, options.river_window_manager_v1), - .xkb_bindings = try XkbBindings.create(context, options.river_xkb_bindings_v1), + .im = im, + .wm = wm, + .xkb_bindings = xkb_bindings, .config = options.config, }; @@ -82,8 +95,10 @@ pub fn create(options: Options) !*Context { } pub fn destroy(context: *Context) void { - context.xkb_bindings.destroy(); + context.env.deinit(); + context.im.destroy(); context.wm.destroy(); + context.xkb_bindings.destroy(); if (context.wallpaper_image) |wallpaper_image| { wallpaper_image.destroy(); @@ -165,6 +180,7 @@ fn pathsEqual(a: ?[]const u8, b: ?[]const u8) bool { const std = @import("std"); const mem = std.mem; +const process = std.process; const wayland = @import("wayland"); const river = wayland.client.river;