Toggle fullscreen on super/ctrl+return, only macOS for now

This fixes or at least is the first step towards #171:

- it adds `cmd/super + return` as the default keybinding to toggle
  fullscreen for currently focused window.
- it adds a keybinding handler to the embedded apprt and then changes
  the macOS app to handle the keybinding by toggling currently focused
  window.
This commit is contained in:
Thorsten Ball
2023-07-02 19:59:41 +02:00
parent ce77002198
commit 8e464db049
8 changed files with 56 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ struct ContentView: View {
case .ready:
let center = NotificationCenter.default
let gotoTab = center.publisher(for: Ghostty.Notification.ghosttyGotoTab)
let toggleFullscreen = center.publisher(for: Ghostty.Notification.ghosttyToggleFullscreen)
let confirmQuitting = Binding<Bool>(get: {
self.appDelegate.confirmQuit && (self.window?.isKeyWindow ?? false)
@@ -39,6 +40,7 @@ struct ContentView: View {
.ghosttyApp(ghostty.app!)
.background(WindowAccessor(window: $window))
.onReceive(gotoTab) { onGotoTab(notification: $0) }
.onReceive(toggleFullscreen) { onToggleFullscreen(notification: $0) }
.confirmationDialog(
"Quit Ghostty?",
isPresented: confirmQuitting) {
@@ -84,4 +86,14 @@ struct ContentView: View {
let targetWindow = tabbedWindows[adjustedIndex]
targetWindow.makeKeyAndOrderFront(nil)
}
private func onToggleFullscreen(notification: SwiftUI.Notification) {
// Just like in `onGotoTab`, we might receive this multiple times. But
// it's fine, because `toggleFullscreen` should only apply to the
// currently focused window.
guard let window = self.window else { return }
guard window.isKeyWindow else { return }
window.toggleFullScreen(nil)
}
}