Keep portal sync responsive during live resize

This commit is contained in:
Lawrence Chen 2026-03-16 18:49:40 -07:00
parent 8d1d4722f6
commit 95ef1c8ca7
No known key found for this signature in database
2 changed files with 14 additions and 4 deletions

View file

@ -8573,13 +8573,17 @@ struct GhosttyTerminalView: NSViewRepresentable {
return !hostedViewHasSuperview
}
private static func scheduleDeferredPortalGeometrySynchronize(
private static func synchronizePortalGeometry(
for host: HostContainerView,
coordinator: Coordinator
) {
let geometryRevision = host.geometryRevision
guard coordinator.lastSynchronizedHostGeometryRevision != geometryRevision else { return }
coordinator.lastSynchronizedHostGeometryRevision = geometryRevision
if host.inLiveResize || host.window?.inLiveResize == true {
TerminalWindowPortalRegistry.synchronizeForAnchor(host)
return
}
// Avoid synchronizing the terminal portal while AppKit is still inside
// the current layout turn. Re-entrant syncs here can wedge window resize
// handling and leave the app spinning on the wait cursor.
@ -8745,7 +8749,7 @@ struct GhosttyTerminalView: NSViewRepresentable {
hostedView.setActive(coordinator.desiredIsActive)
hostedView.setNotificationRing(visible: coordinator.desiredShowsUnreadNotificationRing)
}
Self.scheduleDeferredPortalGeometrySynchronize(
Self.synchronizePortalGeometry(
for: host,
coordinator: coordinator
)
@ -8783,7 +8787,7 @@ struct GhosttyTerminalView: NSViewRepresentable {
coordinator.lastBoundHostId = hostId
coordinator.lastSynchronizedHostGeometryRevision = geometryRevision
} else if coordinator.lastSynchronizedHostGeometryRevision != geometryRevision {
Self.scheduleDeferredPortalGeometrySynchronize(
Self.synchronizePortalGeometry(
for: host,
coordinator: coordinator
)

View file

@ -680,12 +680,18 @@ final class WindowTerminalPortal: NSObject {
private func scheduleExternalGeometrySynchronize() {
guard !hasExternalGeometrySyncScheduled else { return }
hasExternalGeometrySyncScheduled = true
let requiresSettledLayout = !(hostView.inLiveResize || window?.inLiveResize == true)
DispatchQueue.main.async { [weak self] in
guard let self else { return }
DispatchQueue.main.async {
let performSync = {
self.hasExternalGeometrySyncScheduled = false
self.synchronizeAllEntriesFromExternalGeometryChange()
}
if requiresSettledLayout {
DispatchQueue.main.async(execute: performSync)
} else {
performSync()
}
}
}