apprt/embedded: add occlusion state callback

This commit is contained in:
Mitchell Hashimoto
2024-02-12 13:48:09 -08:00
parent f115e257a4
commit be0595d71d
3 changed files with 412 additions and 339 deletions

View File

@@ -1527,6 +1527,16 @@ pub fn textCallback(self: *Surface, text: []const u8) !void {
try self.completeClipboardPaste(text, true);
}
/// Callback for when the surface is fully visible or not, regardless
/// of focus state. This is used to pause rendering when the surface
/// is not visible, and also re-render when it becomes visible again.
pub fn occlusionCallback(self: *Surface, visible: bool) !void {
// If we became visible, then we queue a render. This helps scenarios
// where the apprt pauses rendering when the surface is not visible,
// i.e. macOS with Metal (see issue #1510).
if (visible) try self.queueRender();
}
pub fn focusCallback(self: *Surface, focused: bool) !void {
// Notify our render thread of the new state
_ = self.renderer_thread.mailbox.push(.{

View File

@@ -945,6 +945,13 @@ pub const Surface = struct {
};
}
pub fn occlusionCallback(self: *Surface, visible: bool) void {
self.core_surface.occlusionCallback(visible) catch |err| {
log.err("error in occlusion callback err={}", .{err});
return;
};
}
pub fn gotoTab(self: *Surface, n: usize) void {
const func = self.app.opts.goto_tab orelse {
log.info("runtime embedder does not goto_tab", .{});
@@ -1546,6 +1553,11 @@ pub const CAPI = struct {
surface.focusCallback(focused);
}
/// Update the occlusion state of a surface.
export fn ghostty_surface_set_occlusion(surface: *Surface, visible: bool) void {
surface.occlusionCallback(visible);
}
/// Filter the mods if necessary. This handles settings such as
/// `macos-option-as-alt`. The filtered mods should be used for
/// key translation but should NOT be sent back via the `_key`