Move Bar.inits() env into Context
Since each bar has its own, it's easier to just share it. This does create a consistent slight overhead, but may be useful anyways if we care about the Env more further down the line.
This commit is contained in:
parent
a122f1a439
commit
bcc0e9705e
2 changed files with 27 additions and 12 deletions
13
src/Bar.zig
13
src/Bar.zig
|
|
@ -27,17 +27,15 @@ layer_surface: ?*zwlr.LayerSurfaceV1 = null,
|
||||||
configured: bool = false,
|
configured: bool = false,
|
||||||
|
|
||||||
pub fn init(context: *Context, output: *Output) !Bar {
|
pub fn init(context: *Context, output: *Output) !Bar {
|
||||||
// Get the local environment
|
const timezone = try zeit.local(utils.gpa, &context.env);
|
||||||
// Needed for the timezone
|
errdefer timezone.deinit();
|
||||||
// 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, &env);
|
const fonts = try getFcftFonts("monospace:size=14", 1);
|
||||||
|
errdefer fonts.destroy();
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.context = context,
|
.context = context,
|
||||||
.fonts = try getFcftFonts("monospace:size=14", 1),
|
.fonts = fonts,
|
||||||
.timezone = timezone,
|
.timezone = timezone,
|
||||||
.output = output,
|
.output = output,
|
||||||
};
|
};
|
||||||
|
|
@ -82,6 +80,7 @@ pub fn initSurface(bar: *Bar) !void {
|
||||||
pub fn deinit(bar: *Bar) void {
|
pub fn deinit(bar: *Bar) void {
|
||||||
bar.configured = false;
|
bar.configured = false;
|
||||||
bar.timezone.deinit();
|
bar.timezone.deinit();
|
||||||
|
bar.fonts.destroy();
|
||||||
if (bar.wl_surface) |wl_surface| {
|
if (bar.wl_surface) |wl_surface| {
|
||||||
wl_surface.destroy();
|
wl_surface.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ const Context = @This();
|
||||||
|
|
||||||
initialized: bool,
|
initialized: bool,
|
||||||
|
|
||||||
|
env: process.EnvMap,
|
||||||
|
|
||||||
// Wayland globals
|
// Wayland globals
|
||||||
wl_compositor: *wl.Compositor,
|
wl_compositor: *wl.Compositor,
|
||||||
wl_display: *wl.Display,
|
wl_display: *wl.Display,
|
||||||
|
|
@ -60,10 +62,21 @@ pub const Options = struct {
|
||||||
|
|
||||||
pub fn create(options: Options) !*Context {
|
pub fn create(options: Options) !*Context {
|
||||||
const context = try utils.gpa.create(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.* = .{
|
context.* = .{
|
||||||
.initialized = false,
|
.initialized = false,
|
||||||
|
.env = env,
|
||||||
.wl_compositor = options.wl_compositor,
|
.wl_compositor = options.wl_compositor,
|
||||||
.wl_display = options.wl_display,
|
.wl_display = options.wl_display,
|
||||||
.wl_registry = options.wl_registry,
|
.wl_registry = options.wl_registry,
|
||||||
|
|
@ -72,9 +85,9 @@ pub fn create(options: Options) !*Context {
|
||||||
.river_layer_shell_v1 = options.river_layer_shell_v1,
|
.river_layer_shell_v1 = options.river_layer_shell_v1,
|
||||||
.zwlr_layer_shell_v1 = options.zwlr_layer_shell_v1,
|
.zwlr_layer_shell_v1 = options.zwlr_layer_shell_v1,
|
||||||
.wallpaper_image = loadWallpaperImage(options.config),
|
.wallpaper_image = loadWallpaperImage(options.config),
|
||||||
.im = try InputManager.create(context, options.river_input_manager_v1, options.river_libinput_config_v1),
|
.im = im,
|
||||||
.wm = try WindowManager.create(context, options.river_window_manager_v1),
|
.wm = wm,
|
||||||
.xkb_bindings = try XkbBindings.create(context, options.river_xkb_bindings_v1),
|
.xkb_bindings = xkb_bindings,
|
||||||
.config = options.config,
|
.config = options.config,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -82,8 +95,10 @@ pub fn create(options: Options) !*Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(context: *Context) void {
|
pub fn destroy(context: *Context) void {
|
||||||
context.xkb_bindings.destroy();
|
context.env.deinit();
|
||||||
|
context.im.destroy();
|
||||||
context.wm.destroy();
|
context.wm.destroy();
|
||||||
|
context.xkb_bindings.destroy();
|
||||||
|
|
||||||
if (context.wallpaper_image) |wallpaper_image| {
|
if (context.wallpaper_image) |wallpaper_image| {
|
||||||
wallpaper_image.destroy();
|
wallpaper_image.destroy();
|
||||||
|
|
@ -165,6 +180,7 @@ fn pathsEqual(a: ?[]const u8, b: ?[]const u8) bool {
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
|
const process = std.process;
|
||||||
|
|
||||||
const wayland = @import("wayland");
|
const wayland = @import("wayland");
|
||||||
const river = wayland.client.river;
|
const river = wayland.client.river;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue