From ed8b5bc28381c2ce97520c13d1280d05d71b7fd7 Mon Sep 17 00:00:00 2001 From: SoraTenshi Date: Wed, 13 Sep 2023 23:16:33 +0200 Subject: [PATCH] macos: allow to hide decorations --- include/ghostty.h | 2 ++ .../Features/Primary Window/PrimaryWindow.swift | 13 +++++++++++-- src/config/CAPI.zig | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/ghostty.h b/include/ghostty.h index 7b4afa1d5..48c1990bc 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -309,6 +309,7 @@ typedef struct { void *nsview; double scale_factor; uint16_t font_size; + bool render_decoration; } ghostty_surface_config_s; typedef void (*ghostty_runtime_wakeup_cb)(void *); @@ -364,6 +365,7 @@ bool ghostty_config_get(ghostty_config_t, void *, const char *, uintptr_t); ghostty_input_trigger_s ghostty_config_trigger(ghostty_config_t, const char *, uintptr_t); uint32_t ghostty_config_errors_count(ghostty_config_t); ghostty_error_s ghostty_config_get_error(ghostty_config_t, uint32_t); +bool ghostty_config_render_decoration(ghostty_config_t); ghostty_app_t ghostty_app_new(const ghostty_runtime_config_s *, ghostty_config_t); void ghostty_app_free(ghostty_app_t); diff --git a/macos/Sources/Features/Primary Window/PrimaryWindow.swift b/macos/Sources/Features/Primary Window/PrimaryWindow.swift index b959e494b..258c7d19b 100644 --- a/macos/Sources/Features/Primary Window/PrimaryWindow.swift +++ b/macos/Sources/Features/Primary Window/PrimaryWindow.swift @@ -15,11 +15,20 @@ class FocusedSurfaceWrapper { // such as non-native fullscreen. class PrimaryWindow: NSWindow { var focusedSurfaceWrapper: FocusedSurfaceWrapper = FocusedSurfaceWrapper() - + + static func getStyleMask(render_decoration: Bool) -> NSWindow.StyleMask { + var mask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable] + if render_decoration { + mask.insert(.titled) + } + return mask + } + static func create(ghostty: Ghostty.AppState, appDelegate: AppDelegate, baseConfig: ghostty_surface_config_s? = nil) -> PrimaryWindow { + let decorations = baseConfig?.render_decoration ?? ghostty_config_render_decoration(ghostty.config) let window = PrimaryWindow( contentRect: NSRect(x: 0, y: 0, width: 800, height: 600), - styleMask: [.titled, .closable, .miniaturizable, .resizable], + styleMask: getStyleMask(render_decoration: decorations), backing: .buffered, defer: false) window.center() diff --git a/src/config/CAPI.zig b/src/config/CAPI.zig index be2a491e7..46cc8edad 100644 --- a/src/config/CAPI.zig +++ b/src/config/CAPI.zig @@ -119,6 +119,10 @@ export fn ghostty_config_get_error(self: *Config, idx: u32) Error { return .{ .message = err.message.ptr }; } +export fn ghostty_config_render_decoration(self: *Config) bool { + return self.@"window-decoration"; +} + /// Sync with ghostty_error_s const Error = extern struct { message: [*:0]const u8 = "",