From 3e811dad2c84ac4a40693fefe0520d312daa1d71 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 10 Jan 2024 18:28:19 +0100 Subject: [PATCH 1/2] macos: stop windows glitching when cascading Noticed that windows glitch when cascading: they show up in center of screen, then quickly move to the correct position at last-cascade point. This fixes the issue, by moving the `showWindow` call to _after_ the setting of the last cascade point. Now if you look at the code and think: "shouldn't this work without the async-dispatch, like this?" ```swift if (!window.styleMask.contains(.fullScreen)) { Self.lastCascadePoint = window.cascadeTopLeft(from: Self.lastCascadePoint) } c.showWindow(self) ``` Then, yes, I had the same thought, but it doesn't. And as discussed on Discord, we probably don't know what's going on behind the scenes. So this is the simplified code of the version we have to live with: async dispatching the cascade and non-cascade versions both. --- macos/Sources/Features/Terminal/TerminalManager.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index 65ba5b03a..8a6b75322 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -78,14 +78,13 @@ class TerminalManager { window.toggleFullScreen(nil) } - c.showWindow(self) - - // Only cascade if we aren't fullscreen. This has to be dispatched async - // because it takes one event loop tick for showWindow to work. - if (!window.styleMask.contains(.fullScreen)) { - DispatchQueue.main.async { + // We're dispatching this async because otherwise the last-cascade-point won't work. + DispatchQueue.main.async { + // Only cascade if we aren't fullscreen. + if (!window.styleMask.contains(.fullScreen)) { Self.lastCascadePoint = window.cascadeTopLeft(from: Self.lastCascadePoint) } + c.showWindow(self) } } From 88c525d59300e68cfe62da120064fb5f6b1862f2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 10 Jan 2024 09:37:36 -0800 Subject: [PATCH 2/2] macos: minor style changes --- macos/Sources/Features/Terminal/TerminalManager.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/macos/Sources/Features/Terminal/TerminalManager.swift b/macos/Sources/Features/Terminal/TerminalManager.swift index 8a6b75322..6f00bed18 100644 --- a/macos/Sources/Features/Terminal/TerminalManager.swift +++ b/macos/Sources/Features/Terminal/TerminalManager.swift @@ -78,12 +78,15 @@ class TerminalManager { window.toggleFullScreen(nil) } - // We're dispatching this async because otherwise the last-cascade-point won't work. + // We're dispatching this async because otherwise the lastCascadePoint doesn't + // take effect. Our best theory is there is some next-event-loop-tick logic + // that Cocoa is doing that we need to be after. DispatchQueue.main.async { // Only cascade if we aren't fullscreen. if (!window.styleMask.contains(.fullScreen)) { Self.lastCascadePoint = window.cascadeTopLeft(from: Self.lastCascadePoint) } + c.showWindow(self) } }