gamemode: Move gamemode init and deinit into their own functions
This commit is contained in:
parent
bd68745106
commit
80270a5cfc
1 changed files with 23 additions and 16 deletions
|
|
@ -52,22 +52,7 @@ pub const Platform = struct {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn init(allocator: std.mem.Allocator, core: *Core) !Platform {
|
pub fn init(allocator: std.mem.Allocator, core: *Core) !Platform {
|
||||||
if (builtin.os.tag == .linux) {
|
initLinuxGamemode(allocator);
|
||||||
const gamemode = @import("gamemode");
|
|
||||||
const GAMEMODE_ENV = try getEnvVarOwned(allocator, "GAMEMODE");
|
|
||||||
if (GAMEMODE_ENV == null) {
|
|
||||||
gamemode.requestStart() catch |err| {
|
|
||||||
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
if (!std.ascii.eqlIgnoreCase(GAMEMODE_ENV.?, "off")) {
|
|
||||||
gamemode.requestStart() catch |err| {
|
|
||||||
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
|
||||||
};
|
|
||||||
}
|
|
||||||
allocator.free(GAMEMODE_ENV.?);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const options = core.options;
|
const options = core.options;
|
||||||
const backend_type = try util.detectBackendType(allocator);
|
const backend_type = try util.detectBackendType(allocator);
|
||||||
|
|
@ -239,6 +224,28 @@ pub const Platform = struct {
|
||||||
platform.allocator.destroy(ev);
|
platform.allocator.destroy(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform.deinitLinuxGamemode();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn initLinuxGamemode(allocator: *std.mem.Allocator) void {
|
||||||
|
if (builtin.os.tag == .linux) {
|
||||||
|
const gamemode = @import("gamemode");
|
||||||
|
const GAMEMODE_ENV = try getEnvVarOwned(allocator, "GAMEMODE");
|
||||||
|
if (GAMEMODE_ENV == null) {
|
||||||
|
gamemode.requestStart() catch |err| {
|
||||||
|
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
if (!std.ascii.eqlIgnoreCase(GAMEMODE_ENV.?, "off")) {
|
||||||
|
gamemode.requestStart() catch |err| {
|
||||||
|
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
allocator.free(GAMEMODE_ENV.?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn deinitLinuxGamemode(platform: *Platform) void {
|
||||||
if (builtin.os.tag == .linux) {
|
if (builtin.os.tag == .linux) {
|
||||||
const gamemode = @import("gamemode");
|
const gamemode = @import("gamemode");
|
||||||
const GAMEMODE_ENV = getEnvVarOwned(platform.allocator, "GAMEMODE") catch unreachable;
|
const GAMEMODE_ENV = getEnvVarOwned(platform.allocator, "GAMEMODE") catch unreachable;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue