From 57213547cd21c6186e9ef567513c2052792afabf Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 27 Sep 2023 18:34:04 -0700 Subject: [PATCH 1/2] macos: custom fullscreen menu item to respect non-native fullscreen Related to #392 --- macos/Sources/AppDelegate.swift | 15 +++++++++++++++ macos/Sources/Ghostty/AppState.swift | 7 +++++++ macos/Sources/MainMenu.xib | 11 +++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/macos/Sources/AppDelegate.swift b/macos/Sources/AppDelegate.swift index e4a3e939c..2b0c10f5a 100644 --- a/macos/Sources/AppDelegate.swift +++ b/macos/Sources/AppDelegate.swift @@ -27,6 +27,7 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp @IBOutlet private var menuCopy: NSMenuItem? @IBOutlet private var menuPaste: NSMenuItem? + @IBOutlet private var menuToggleFullScreen: NSMenuItem? @IBOutlet private var menuZoomSplit: NSMenuItem? @IBOutlet private var menuPreviousSplit: NSMenuItem? @IBOutlet private var menuNextSplit: NSMenuItem? @@ -53,6 +54,14 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp //MARK: - NSApplicationDelegate + func applicationWillFinishLaunching(_ notification: Notification) { + UserDefaults.standard.register(defaults: [ + // Disable the automatic full screen menu item because we handle + // it manually. + "NSFullScreenMenuItemEverywhere": false, + ]) + } + func applicationDidFinishLaunching(_ notification: Notification) { // System settings overrides UserDefaults.standard.register(defaults: [ @@ -143,6 +152,7 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp syncMenuShortcut(action: "copy_to_clipboard", menuItem: self.menuCopy) syncMenuShortcut(action: "paste_from_clipboard", menuItem: self.menuPaste) + syncMenuShortcut(action: "toggle_fullscreen", menuItem: self.menuToggleFullScreen) syncMenuShortcut(action: "toggle_split_zoom", menuItem: self.menuZoomSplit) syncMenuShortcut(action: "goto_split:previous", menuItem: self.menuPreviousSplit) syncMenuShortcut(action: "goto_split:next", menuItem: self.menuNextSplit) @@ -307,4 +317,9 @@ class AppDelegate: NSObject, ObservableObject, NSApplicationDelegate, GhosttyApp guard let url = URL(string: "https://github.com/mitchellh/ghostty") else { return } NSWorkspace.shared.open(url) } + + @IBAction func toggleFullScreen(_ sender: Any) { + guard let surface = focusedSurface() else { return } + ghostty.toggleFullscreen(surface: surface) + } } diff --git a/macos/Sources/Ghostty/AppState.swift b/macos/Sources/Ghostty/AppState.swift index 8ecaf0941..5cf39f044 100644 --- a/macos/Sources/Ghostty/AppState.swift +++ b/macos/Sources/Ghostty/AppState.swift @@ -260,6 +260,13 @@ extension Ghostty { AppDelegate.logger.warning("action failed action=\(action)") } } + + func toggleFullscreen(surface: ghostty_surface_t) { + let action = "toggle_fullscreen" + if (!ghostty_surface_binding_action(surface, action, UInt(action.count))) { + AppDelegate.logger.warning("action failed action=\(action)") + } + } // Called when the selected keyboard changes. We have to notify Ghostty so that // it can reload the keyboard mapping for input. diff --git a/macos/Sources/MainMenu.xib b/macos/Sources/MainMenu.xib index 7166541e7..051aad2f5 100644 --- a/macos/Sources/MainMenu.xib +++ b/macos/Sources/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -30,6 +30,7 @@ + @@ -163,6 +164,12 @@ + + + + + + From 21b46bd61275f45c1b2cbc1d7acd51c91e2b4c77 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 27 Sep 2023 18:41:30 -0700 Subject: [PATCH 2/2] macos: change text to "toggle full screen" --- macos/Sources/MainMenu.xib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macos/Sources/MainMenu.xib b/macos/Sources/MainMenu.xib index 051aad2f5..3e20e8476 100644 --- a/macos/Sources/MainMenu.xib +++ b/macos/Sources/MainMenu.xib @@ -164,7 +164,7 @@ - +