mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #443 from mitchellh/hide-decorations-macos
macos: allow to hide decorations
This commit is contained in:
@ -19,7 +19,7 @@ class PrimaryWindow: NSWindow {
|
|||||||
static func create(ghostty: Ghostty.AppState, appDelegate: AppDelegate, baseConfig: ghostty_surface_config_s? = nil) -> PrimaryWindow {
|
static func create(ghostty: Ghostty.AppState, appDelegate: AppDelegate, baseConfig: ghostty_surface_config_s? = nil) -> PrimaryWindow {
|
||||||
let window = PrimaryWindow(
|
let window = PrimaryWindow(
|
||||||
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
|
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
|
||||||
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
styleMask: getStyleMask(renderDecoration: ghostty.windowDecorations),
|
||||||
backing: .buffered,
|
backing: .buffered,
|
||||||
defer: false)
|
defer: false)
|
||||||
window.center()
|
window.center()
|
||||||
@ -45,6 +45,15 @@ class PrimaryWindow: NSWindow {
|
|||||||
return window
|
return window
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func getStyleMask(renderDecoration: Bool) -> NSWindow.StyleMask {
|
||||||
|
var mask: NSWindow.StyleMask = [.resizable, .closable, .miniaturizable]
|
||||||
|
if renderDecoration {
|
||||||
|
mask.insert(.titled)
|
||||||
|
}
|
||||||
|
|
||||||
|
return mask
|
||||||
|
}
|
||||||
|
|
||||||
override var canBecomeKey: Bool {
|
override var canBecomeKey: Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,15 @@ extension Ghostty {
|
|||||||
return Info(mode: raw.build_mode, version: String(version))
|
return Info(mode: raw.build_mode, version: String(version))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// True if we want to render window decorations
|
||||||
|
var windowDecorations: Bool {
|
||||||
|
guard let config = self.config else { return true }
|
||||||
|
var v = false;
|
||||||
|
let key = "window-decoration"
|
||||||
|
_ = ghostty_config_get(config, &v, key, UInt(key.count))
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
/// Cached clipboard string for `read_clipboard` callback.
|
/// Cached clipboard string for `read_clipboard` callback.
|
||||||
private var cached_clipboard_string: String? = nil
|
private var cached_clipboard_string: String? = nil
|
||||||
|
|
||||||
@ -296,7 +305,8 @@ extension Ghostty {
|
|||||||
// We only support the standard clipboard
|
// We only support the standard clipboard
|
||||||
if (location != GHOSTTY_CLIPBOARD_STANDARD) { return nil }
|
if (location != GHOSTTY_CLIPBOARD_STANDARD) { return nil }
|
||||||
|
|
||||||
guard let appState = self.appState(fromSurface: userdata) else { return nil }
|
guard let surface = self.surfaceUserdata(from: userdata) else { return nil }
|
||||||
|
guard let appState = self.appState(fromView: surface) else { return nil }
|
||||||
guard let str = NSPasteboard.general.string(forType: .string) else { return nil }
|
guard let str = NSPasteboard.general.string(forType: .string) else { return nil }
|
||||||
|
|
||||||
// Ghostty requires we cache the string because the pointer we return has to remain
|
// Ghostty requires we cache the string because the pointer we return has to remain
|
||||||
@ -376,6 +386,17 @@ extension Ghostty {
|
|||||||
static func newTab(_ userdata: UnsafeMutableRawPointer?, config: ghostty_surface_config_s) {
|
static func newTab(_ userdata: UnsafeMutableRawPointer?, config: ghostty_surface_config_s) {
|
||||||
guard let surface = self.surfaceUserdata(from: userdata) else { return }
|
guard let surface = self.surfaceUserdata(from: userdata) else { return }
|
||||||
|
|
||||||
|
guard let appState = self.appState(fromView: surface) else { return }
|
||||||
|
guard appState.windowDecorations else {
|
||||||
|
let alert = NSAlert()
|
||||||
|
alert.messageText = "Tabs are disabled"
|
||||||
|
alert.informativeText = "Enable window decorations to use tabs"
|
||||||
|
alert.addButton(withTitle: "OK")
|
||||||
|
alert.alertStyle = .warning
|
||||||
|
_ = alert.runModal()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
NotificationCenter.default.post(
|
NotificationCenter.default.post(
|
||||||
name: Notification.ghosttyNewTab,
|
name: Notification.ghosttyNewTab,
|
||||||
object: surface,
|
object: surface,
|
||||||
@ -398,9 +419,8 @@ extension Ghostty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the GhosttyState from the given userdata value.
|
/// Returns the GhosttyState from the given userdata value.
|
||||||
static private func appState(fromSurface userdata: UnsafeMutableRawPointer?) -> AppState? {
|
static private func appState(fromView view: SurfaceView) -> AppState? {
|
||||||
let surfaceView = Unmanaged<SurfaceView>.fromOpaque(userdata!).takeUnretainedValue()
|
guard let surface = view.surface else { return nil }
|
||||||
guard let surface = surfaceView.surface else { return nil }
|
|
||||||
guard let app = ghostty_surface_app(surface) else { return nil }
|
guard let app = ghostty_surface_app(surface) else { return nil }
|
||||||
guard let app_ud = ghostty_app_userdata(app) else { return nil }
|
guard let app_ud = ghostty_app_userdata(app) else { return nil }
|
||||||
return Unmanaged<AppState>.fromOpaque(app_ud).takeUnretainedValue()
|
return Unmanaged<AppState>.fromOpaque(app_ud).takeUnretainedValue()
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import GhosttyKit
|
import GhosttyKit
|
||||||
|
|
||||||
class FullScreenHandler {
|
class FullScreenHandler { var previousTabGroup: NSWindowTabGroup?
|
||||||
var previousTabGroup: NSWindowTabGroup?
|
|
||||||
var previousTabGroupIndex: Int?
|
var previousTabGroupIndex: Int?
|
||||||
var previousContentFrame: NSRect?
|
var previousContentFrame: NSRect?
|
||||||
var isInFullscreen: Bool = false
|
var previousStyleMask: NSWindow.StyleMask? = nil
|
||||||
|
|
||||||
// We keep track of whether we entered non-native fullscreen in case
|
// We keep track of whether we entered non-native fullscreen in case
|
||||||
// a user goes to fullscreen, changes the config to disable non-native fullscreen
|
// a user goes to fullscreen, changes the config to disable non-native fullscreen
|
||||||
// and then wants to toggle it off
|
// and then wants to toggle it off
|
||||||
var isInNonNativeFullscreen: Bool = false
|
var isInNonNativeFullscreen: Bool = false
|
||||||
|
var isInFullscreen: Bool = false
|
||||||
|
|
||||||
func toggleFullscreen(window: NSWindow, nonNativeFullscreen: ghostty_non_native_fullscreen_e) {
|
func toggleFullscreen(window: NSWindow, nonNativeFullscreen: ghostty_non_native_fullscreen_e) {
|
||||||
let useNonNativeFullscreen = nonNativeFullscreen != GHOSTTY_NON_NATIVE_FULLSCREEN_FALSE
|
let useNonNativeFullscreen = nonNativeFullscreen != GHOSTTY_NON_NATIVE_FULLSCREEN_FALSE
|
||||||
@ -89,6 +89,7 @@ class FullScreenHandler {
|
|||||||
|
|
||||||
// This is important: it gives us the full screen, including the
|
// This is important: it gives us the full screen, including the
|
||||||
// notch area on MacBooks.
|
// notch area on MacBooks.
|
||||||
|
self.previousStyleMask = window.styleMask
|
||||||
window.styleMask.remove(.titled)
|
window.styleMask.remove(.titled)
|
||||||
|
|
||||||
// Set frame to screen size, accounting for the menu bar if needed
|
// Set frame to screen size, accounting for the menu bar if needed
|
||||||
@ -126,8 +127,8 @@ class FullScreenHandler {
|
|||||||
func leaveFullscreen(window: NSWindow) {
|
func leaveFullscreen(window: NSWindow) {
|
||||||
guard let previousFrame = previousContentFrame else { return }
|
guard let previousFrame = previousContentFrame else { return }
|
||||||
|
|
||||||
// Restore title bar
|
// Restore the style mask
|
||||||
window.styleMask.insert(.titled)
|
window.styleMask = self.previousStyleMask!
|
||||||
|
|
||||||
// Restore previous presentation options
|
// Restore previous presentation options
|
||||||
NSApp.presentationOptions = []
|
NSApp.presentationOptions = []
|
||||||
|
@ -242,7 +242,6 @@ keybind: Keybinds = .{},
|
|||||||
|
|
||||||
/// If false, windows won't have native decorations, i.e. titlebar and
|
/// If false, windows won't have native decorations, i.e. titlebar and
|
||||||
/// borders.
|
/// borders.
|
||||||
/// Currently only supported with GTK.
|
|
||||||
@"window-decoration": bool = true,
|
@"window-decoration": bool = true,
|
||||||
|
|
||||||
/// Whether to allow programs running in the terminal to read/write to
|
/// Whether to allow programs running in the terminal to read/write to
|
||||||
|
Reference in New Issue
Block a user