gamemode: Add linux_gamemode_is_active field to Platform
This commit is contained in:
parent
2612684ef3
commit
6eaacde444
1 changed files with 14 additions and 10 deletions
|
|
@ -38,6 +38,8 @@ pub const Platform = struct {
|
||||||
|
|
||||||
last_cursor_position: structs.WindowPos,
|
last_cursor_position: structs.WindowPos,
|
||||||
|
|
||||||
|
linux_gamemode_is_active: bool,
|
||||||
|
|
||||||
const EventQueue = std.TailQueue(structs.Event);
|
const EventQueue = std.TailQueue(structs.Event);
|
||||||
const EventNode = EventQueue.Node;
|
const EventNode = EventQueue.Node;
|
||||||
|
|
||||||
|
|
@ -52,7 +54,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 {
|
||||||
try initLinuxGamemode(allocator);
|
const linux_gamemode_is_active = try initLinuxGamemode(allocator);
|
||||||
|
|
||||||
const options = core.options;
|
const options = core.options;
|
||||||
const backend_type = try util.detectBackendType(allocator);
|
const backend_type = try util.detectBackendType(allocator);
|
||||||
|
|
@ -211,6 +213,7 @@ pub const Platform = struct {
|
||||||
.y = cursor_pos.ypos,
|
.y = cursor_pos.ypos,
|
||||||
},
|
},
|
||||||
.native_instance = native_instance,
|
.native_instance = native_instance,
|
||||||
|
.linux_gamemode_is_active = linux_gamemode_is_active,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,24 +239,25 @@ pub const Platform = struct {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
fn initLinuxGamemode(allocator: std.mem.Allocator) error{ OutOfMemory, InvalidUtf8 }!void {
|
fn initLinuxGamemode(allocator: std.mem.Allocator) error{ OutOfMemory, InvalidUtf8 }!bool {
|
||||||
if (builtin.os.tag == .linux) {
|
if (builtin.os.tag == .linux) {
|
||||||
const gamemode = @import("gamemode");
|
const gamemode = @import("gamemode");
|
||||||
if (try activateGamemode(allocator)) {
|
if (try activateGamemode(allocator)) {
|
||||||
gamemode.requestStart() catch |err| {
|
if (gamemode.requestStart()) {
|
||||||
|
return true;
|
||||||
|
} else |err| {
|
||||||
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
fn deinitLinuxGamemode(platform: *Platform) void {
|
fn deinitLinuxGamemode(platform: *Platform) void {
|
||||||
if (builtin.os.tag == .linux) {
|
if (builtin.os.tag == .linux and platform.linux_gamemode_is_active) {
|
||||||
const gamemode = @import("gamemode");
|
const gamemode = @import("gamemode");
|
||||||
if (activateGamemode(platform.allocator) catch unreachable) {
|
gamemode.requestEnd() catch |err| {
|
||||||
gamemode.requestEnd() catch |err| {
|
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
||||||
std.log.err("Gamemode error {} -> {s}", .{ err, gamemode.errorString() });
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue