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..3e20e8476 100644 --- a/macos/Sources/MainMenu.xib +++ b/macos/Sources/MainMenu.xib @@ -1,8 +1,8 @@ - + - + @@ -30,6 +30,7 @@ + @@ -163,6 +164,12 @@ + + + + + +