diff options
| author | Mitchell Hashimoto <m@mitchellh.com> | 2025-10-10 10:19:33 -0700 |
|---|---|---|
| committer | Mitchell Hashimoto <m@mitchellh.com> | 2025-10-10 10:20:35 -0700 |
| commit | cd7621167fb9be3f3d7b3f547283f71771941a86 (patch) | |
| tree | 2bd7cdb696b66f8ca25798442059a629f1d65ada | |
| parent | c28104e62fe552db6846c58b75c0e0e682c660d0 (diff) | |
macos: update accessory in the titlebar should not move the window
This is annoyingly easy to trigger, just disable this.
| -rw-r--r-- | macos/Ghostty.xcodeproj/project.pbxproj | 1 | ||||
| -rw-r--r-- | macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift | 2 | ||||
| -rw-r--r-- | macos/Sources/Helpers/NonDraggableHostingView.swift | 13 |
3 files changed, 15 insertions, 1 deletions
diff --git a/macos/Ghostty.xcodeproj/project.pbxproj b/macos/Ghostty.xcodeproj/project.pbxproj index 558937582..c2baf834d 100644 --- a/macos/Ghostty.xcodeproj/project.pbxproj +++ b/macos/Ghostty.xcodeproj/project.pbxproj @@ -167,6 +167,7 @@ Helpers/KeyboardLayout.swift, Helpers/LastWindowPosition.swift, Helpers/MetalView.swift, + Helpers/NonDraggableHostingView.swift, Helpers/PermissionRequest.swift, Helpers/Private/CGS.swift, Helpers/Private/Dock.swift, diff --git a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift index 661c89121..95126e188 100644 --- a/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/Window Styles/TerminalWindow.swift @@ -108,7 +108,7 @@ class TerminalWindow: NSWindow { // Create update notification accessory if supportsUpdateAccessory { updateAccessory.layoutAttribute = .right - updateAccessory.view = NSHostingView(rootView: UpdateAccessoryView( + updateAccessory.view = NonDraggableHostingView(rootView: UpdateAccessoryView( viewModel: viewModel, model: appDelegate.updateViewModel )) diff --git a/macos/Sources/Helpers/NonDraggableHostingView.swift b/macos/Sources/Helpers/NonDraggableHostingView.swift new file mode 100644 index 000000000..26238182f --- /dev/null +++ b/macos/Sources/Helpers/NonDraggableHostingView.swift @@ -0,0 +1,13 @@ +import SwiftUI + +/// An NSHostingView subclass that prevents window dragging when clicking on the view. +/// +/// By default, NSHostingViews in the titlebar allow the window to be dragged when +/// clicked. This subclass overrides `mouseDownCanMoveWindow` to return false, +/// preventing the window from being dragged when the user clicks on this view. +/// +/// This is useful for titlebar accessories that contain interactive elements +/// (buttons, links, etc.) where you don't want accidental window dragging. +class NonDraggableHostingView<Content: View>: NSHostingView<Content> { + override var mouseDownCanMoveWindow: Bool { false } +} |
