mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-01 15:38:35 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user