-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix minimal UI terminal top-row hit testing #6073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2685f38
test: cover minimal terminal titlebar hit testing
austinywang eaa049e
fix: keep minimal terminal top row clickable
austinywang 45049b3
Merge remote-tracking branch 'origin/main' into issue-6066-minimal-ui…
austinywang 4a0cbc1
test: move titlebar hit test out of large suite
austinywang 31df166
fix: preserve titlebar control hit testing
austinywang b6198ed
test: guard titlebar band preconditions
austinywang 7a74b84
test: use Swift Testing for titlebar hit tests
austinywang 293b605
fix: defer titlebar double-clicks over terminal
austinywang cedb2fa
perf: reuse terminal hit in titlebar routing
austinywang 44e1711
chore: normalize project file
austinywang 2fa0b9f
fix: defer app titlebar double-clicks over terminal
austinywang 227c6dc
fix: bound terminal titlebar hit lookup
austinywang 2b98ced
fix: align chrome titlebar terminal routing
austinywang 891801b
Merge origin/main into issue-6066-minimal-ui-toolbar-hittest
austinywang 0288a7f
perf: lazily resolve terminal titlebar hits
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import AppKit | ||
| import Testing | ||
|
|
||
| #if canImport(cmux_DEV) | ||
| @testable import cmux_DEV | ||
| #elseif canImport(cmux) | ||
| @testable import cmux | ||
| #endif | ||
|
|
||
| @MainActor | ||
| @Suite("Window terminal host titlebar hit testing") | ||
| struct WindowTerminalHostViewTitlebarHitTests { | ||
| @Test func hostViewKeepsTerminalTopRowClickableInsideTitlebarBand() throws { | ||
| let window = NSWindow( | ||
| contentRect: NSRect(x: 0, y: 0, width: 420, height: 260), | ||
| styleMask: [.titled, .closable], | ||
| backing: .buffered, | ||
| defer: false | ||
| ) | ||
| defer { window.orderOut(nil) } | ||
| let contentView = try #require(window.contentView, "Expected window content view") | ||
| let container = try #require(contentView.superview, "Expected window content container") | ||
|
|
||
| let host = WindowTerminalHostView(frame: container.convert(contentView.bounds, from: contentView)) | ||
| let hostedView = makeHostedTerminalView(frame: host.bounds) | ||
| host.addSubview(hostedView) | ||
| container.addSubview(host, positioned: .above, relativeTo: contentView) | ||
|
|
||
| let pointInHostedView = NSPoint(x: hostedView.bounds.midX, y: hostedView.bounds.maxY - 0.5) | ||
| let pointInWindow = hostedView.convert(pointInHostedView, to: nil) | ||
| let pointInHost = host.convert(pointInWindow, from: nil) | ||
| let event = try makeMouseDownEvent(at: pointInWindow, window: window) | ||
|
|
||
| try #require( | ||
| pointInWindow.y >= BonsplitTabBarPassThrough.titlebarInteractionBandMinY(in: window), | ||
| "The regression point must exercise the fixed-height titlebar pass-through band" | ||
| ) | ||
| assertHitFallsInsideHostedTerminal( | ||
| host.performHitTest(at: pointInHost, currentEvent: event), | ||
| hostedView: hostedView, | ||
| message: "Terminal content inside the titlebar band should keep receiving top-row mouse-downs" | ||
| ) | ||
| } | ||
|
|
||
| @Test func hostViewPassesThroughRegisteredTitlebarControlsAboveTerminal() throws { | ||
| let window = NSWindow( | ||
| contentRect: NSRect(x: 0, y: 0, width: 420, height: 260), | ||
| styleMask: [.titled, .closable], | ||
| backing: .buffered, | ||
| defer: false | ||
| ) | ||
| defer { window.orderOut(nil) } | ||
| let contentView = try #require(window.contentView, "Expected window content view") | ||
| let container = try #require(contentView.superview, "Expected window content container") | ||
|
|
||
| let host = WindowTerminalHostView(frame: container.convert(contentView.bounds, from: contentView)) | ||
| host.addSubview(makeHostedTerminalView(frame: host.bounds)) | ||
| container.addSubview(host, positioned: .above, relativeTo: contentView) | ||
|
|
||
| let region = TitlebarInteractiveControlRegion.RegisteredView( | ||
| frame: NSRect(x: 24, y: contentView.bounds.maxY - 24, width: 18, height: 18) | ||
| ) | ||
| contentView.addSubview(region) | ||
|
|
||
| let pointInWindow = contentView.convert(NSPoint(x: region.frame.midX, y: region.frame.midY), to: nil) | ||
| let pointInHost = host.convert(pointInWindow, from: nil) | ||
| let event = try makeMouseDownEvent(at: pointInWindow, window: window) | ||
|
|
||
| try #require( | ||
| pointInWindow.y >= BonsplitTabBarPassThrough.titlebarInteractionBandMinY(in: window), | ||
| "The control point must sit inside the fixed titlebar interaction band" | ||
| ) | ||
| #expect( | ||
| host.performHitTest(at: pointInHost, currentEvent: event) == nil, | ||
| "Registered titlebar controls must keep receiving clicks even when terminal content underlaps them" | ||
| ) | ||
| } | ||
|
|
||
| private func makeHostedTerminalView(frame: NSRect) -> GhosttySurfaceScrollView { | ||
| let surfaceView = GhosttyNSView(frame: frame) | ||
| let hostedView = GhosttySurfaceScrollView(surfaceView: surfaceView) | ||
| hostedView.frame = frame | ||
| hostedView.autoresizingMask = [.width, .height] | ||
| return hostedView | ||
| } | ||
|
|
||
| private func makeMouseDownEvent(at locationInWindow: NSPoint, window: NSWindow) throws -> NSEvent { | ||
| try #require(NSEvent.mouseEvent( | ||
| with: .leftMouseDown, | ||
| location: locationInWindow, | ||
| modifierFlags: [], | ||
| timestamp: ProcessInfo.processInfo.systemUptime, | ||
| windowNumber: window.windowNumber, | ||
| context: nil, | ||
| eventNumber: 0, | ||
| clickCount: 1, | ||
| pressure: 1.0 | ||
| ), "Failed to create leftMouseDown event") | ||
| } | ||
|
|
||
| private func assertHitFallsInsideHostedTerminal( | ||
| _ hitView: NSView?, | ||
| hostedView: GhosttySurfaceScrollView, | ||
| message: String | ||
| ) { | ||
| guard let hitView else { | ||
| Issue.record(Comment(rawValue: message)) | ||
| return | ||
| } | ||
| #expect(hitView === hostedView || hitView.isDescendant(of: hostedView), Comment(rawValue: message)) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.