Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/Canvas/CanvasPaneContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ final class CanvasPaneContentMount: CanvasPaneContentMounting {
func setRendering(_ rendering: Bool) {
switch content {
case .terminal(let panel):
panel.surface.setRendererPortalVisible(rendering)
if rendering {
panel.surface.realizeRenderer()
}
panel.surface.setOcclusion(rendering)
case .hosted(let panel, _):
// Offscreen browsers may hidden-discard their webview; coming
Expand All @@ -148,6 +152,8 @@ final class CanvasPaneContentMount: CanvasPaneContentMounting {
hostedView.setActive(false)
hostedView.setFocusHandler(nil)
hostedView.setInactiveOverlay(color: .clear, opacity: 0, visible: false)
panel.surface.setRendererPortalVisible(true)
panel.surface.realizeRenderer()
panel.surface.setOcclusion(true)
Comment thread
austinywang marked this conversation as resolved.
Resolved
hostedView.removeFromSuperview()
case .hosted(let panel, let view):
Expand Down
59 changes: 43 additions & 16 deletions cmuxTests/GhosttyTerminalViewVisibilityPolicyTests.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import XCTest
import AppKit
import Testing

#if canImport(cmux_DEV)
@testable import cmux_DEV
#elseif canImport(cmux)
@testable import cmux
#endif

final class GhosttyTerminalViewVisibilityPolicyTests: XCTestCase {
func testImmediateStateUpdateAllowedWhenDesiredStateIsHidden() {
XCTAssertTrue(
@Suite
struct GhosttyTerminalViewVisibilityPolicyTests {
@Test func immediateStateUpdateAllowedWhenDesiredStateIsHidden() {
#expect(
GhosttyTerminalView.shouldApplyImmediateHostedStateUpdate(
desiredVisibleInUI: false,
hostedViewHasSuperview: true,
Expand All @@ -17,8 +19,8 @@ final class GhosttyTerminalViewVisibilityPolicyTests: XCTestCase {
)
}

func testImmediateStateUpdateAllowedWhenBoundToCurrentHost() {
XCTAssertTrue(
@Test func immediateStateUpdateAllowedWhenBoundToCurrentHost() {
#expect(
GhosttyTerminalView.shouldApplyImmediateHostedStateUpdate(
desiredVisibleInUI: true,
hostedViewHasSuperview: true,
Expand All @@ -27,18 +29,18 @@ final class GhosttyTerminalViewVisibilityPolicyTests: XCTestCase {
)
}

func testImmediateStateUpdateSkippedForStaleHostBoundElsewhere() {
XCTAssertFalse(
GhosttyTerminalView.shouldApplyImmediateHostedStateUpdate(
@Test func immediateStateUpdateSkippedForStaleHostBoundElsewhere() {
#expect(
!GhosttyTerminalView.shouldApplyImmediateHostedStateUpdate(
desiredVisibleInUI: true,
hostedViewHasSuperview: true,
isBoundToCurrentHost: false
)
)
}

func testImmediateStateUpdateAllowedWhenUnboundAndNotAttachedAnywhere() {
XCTAssertTrue(
@Test func immediateStateUpdateAllowedWhenUnboundAndNotAttachedAnywhere() {
#expect(
GhosttyTerminalView.shouldApplyImmediateHostedStateUpdate(
desiredVisibleInUI: true,
hostedViewHasSuperview: false,
Expand All @@ -47,21 +49,46 @@ final class GhosttyTerminalViewVisibilityPolicyTests: XCTestCase {
)
}

func testSwiftUIHostGeometryCallbackUsesImmediateSyncWithoutLayoutFlush() {
@Test func swiftUIHostGeometryCallbackUsesImmediateSyncWithoutLayoutFlush() {
switch GhosttyTerminalView.hostCallbackPortalGeometrySynchronizationAction(window: 3873) {
case .synchronizeWithoutLayoutFlush(let window):
XCTAssertEqual(window, 3873)
#expect(window == 3873)
case .skip:
XCTFail("Window-attached host callbacks should immediately reconcile portal geometry without layout flushes")
Issue.record("Window-attached host callbacks should immediately reconcile portal geometry without layout flushes")
}
}

func testSwiftUIHostGeometryCallbackSkipsWithoutWindow() {
@Test func swiftUIHostGeometryCallbackSkipsWithoutWindow() {
switch GhosttyTerminalView.hostCallbackPortalGeometrySynchronizationAction(window: Optional<Int>.none) {
case .synchronizeWithoutLayoutFlush:
XCTFail("Detached host callbacks must not synchronize terminal portal geometry")
Issue.record("Detached host callbacks must not synchronize terminal portal geometry")
case .skip:
break
}
}

@Test @MainActor func canvasTerminalRenderingDrivesRendererVisibility() {
let panel = TerminalPanel(workspaceId: UUID())
let container = NSView(frame: NSRect(x: 0, y: 0, width: 800, height: 600))
let mount = CanvasPaneContentMount(
content: .terminal(panel),
panelId: panel.id,
container: container,
onFocusPanel: { _ in }
)

#expect(panel.surface.isRendererPortalVisible)

mount.setRendering(false)
#expect(!panel.surface.isRendererPortalVisible)
Comment thread
austinywang marked this conversation as resolved.
Resolved

mount.setRendering(true)
#expect(panel.surface.isRendererPortalVisible)

mount.setRendering(false)
#expect(!panel.surface.isRendererPortalVisible)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

mount.unmount()
#expect(panel.surface.isRendererPortalVisible)
}
Comment thread
austinywang marked this conversation as resolved.
Resolved
}
Loading