From 338f89679dfadffdab39614c082191b1ca8c3f29 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 3 Jul 2023 19:44:06 -0700 Subject: [PATCH] apprt: add C API for detecting background transparency per surface --- include/ghostty.h | 1 + macos/Sources/Ghostty/SurfaceView.swift | 9 +++++++++ src/apprt/embedded.zig | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index 43d478ab1..9b3c6b904 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -276,6 +276,7 @@ void *ghostty_app_userdata(ghostty_app_t); ghostty_surface_t ghostty_surface_new(ghostty_app_t, ghostty_surface_config_s*); void ghostty_surface_free(ghostty_surface_t); ghostty_app_t ghostty_surface_app(ghostty_surface_t); +bool ghostty_surface_transparent(ghostty_surface_t); void ghostty_surface_refresh(ghostty_surface_t); void ghostty_surface_set_content_scale(ghostty_surface_t, double, double); void ghostty_surface_set_focus(ghostty_surface_t, bool); diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 48467e264..bb3db5fa1 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -197,6 +197,15 @@ extension Ghostty { ghostty_surface_set_size(surface, UInt32(scaledSize.width), UInt32(scaledSize.height)) } + override func viewDidMoveToWindow() { + guard let window = self.window else { return } + guard let surface = self.surface else { return } + guard ghostty_surface_transparent(surface) else { return } + window.isOpaque = false + window.hasShadow = false + window.backgroundColor = .clear + } + override func resignFirstResponder() -> Bool { let result = super.resignFirstResponder() diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index f5a8f899a..a90cef4e5 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -470,6 +470,11 @@ pub const CAPI = struct { return surface.app; } + /// Returns ture if the surface has transparency set. + export fn ghostty_surface_transparent(surface: *Surface) bool { + return surface.app.config.@"background-opacity" < 1.0; + } + /// Tell the surface that it needs to schedule a render export fn ghostty_surface_refresh(surface: *Surface) void { surface.refresh();