From 03d9c607c2cc90a9a90ab444a4a599f2adaee6ba Mon Sep 17 00:00:00 2001 From: David Allemang Date: Thu, 27 Jun 2024 22:08:36 -0400 Subject: [PATCH] lower framerate when not focused --- src/au.zig | 4 ++++ src/main.zig | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/au.zig b/src/au.zig index 2fb76af..4cf299f 100644 --- a/src/au.zig +++ b/src/au.zig @@ -427,6 +427,10 @@ pub const Window = struct { pub fn should_close(self: Self) bool { return c.glfwWindowShouldClose(self.handle) == c.GLFW_TRUE; } + + pub fn focused(self: Self) bool { + return c.glfwGetWindowAttrib(self.handle, c.GLFW_FOCUSED) == c.GLFW_TRUE; + } }; pub fn wait_events() []const Bus.Event { diff --git a/src/main.zig b/src/main.zig index 86fdc23..e4f899a 100644 --- a/src/main.zig +++ b/src/main.zig @@ -89,8 +89,10 @@ pub fn main() !void { while (!au.W.should_close()) : (flight_idx = (flight_idx + 1) % flight.len) { const frame = flight[flight_idx]; - // todo switch mode depending on if window is focused - const events = au.wait_events_timeout(0.10); + const events = if (au.W.focused()) + au.wait_events_timeout(0.1) + else + au.wait_events_timeout(0.5); for (events) |u| { switch (u) {