renderer/metal: stop display link when we lose focus

This commit is contained in:
Mitchell Hashimoto
2024-05-03 20:49:55 -07:00
parent a40ffad218
commit 6ae1784f4b

View File

@ -723,6 +723,18 @@ fn gridSize(self: *Metal) ?renderer.GridSize {
/// Must be called on the render thread.
pub fn setFocus(self: *Metal, focus: bool) !void {
self.focused = focus;
// If we're not focused, then we want to stop the display link
// because it is a waste of resources and we can move to pure
// change-driven updates.
if (comptime DisplayLink != void) link: {
const display_link = self.display_link orelse break :link;
if (focus) {
display_link.start() catch {};
} else {
display_link.stop() catch {};
}
}
}
/// Set the new font size.