From d1bea9d737eef15cfb0a2a6a3f8e33f132158a48 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 19 Dec 2025 10:28:51 -0800 Subject: [PATCH] macos: window width/height should be clamped, work with position Fixes #9952 Fixes #9969 This fixes our `constrainToScreen` implementation to properly clamp the window size to the visible screen its coming on as documented. Further, this addresses the positioning problem, too. --- .../Helpers/Extensions/NSWindow+Extension.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/macos/Sources/Helpers/Extensions/NSWindow+Extension.swift b/macos/Sources/Helpers/Extensions/NSWindow+Extension.swift index d834f5e63..f8df803db 100644 --- a/macos/Sources/Helpers/Extensions/NSWindow+Extension.swift +++ b/macos/Sources/Helpers/Extensions/NSWindow+Extension.swift @@ -16,19 +16,23 @@ extension NSWindow { return firstWindow === self } - /// Adjusts the window origin if necessary to ensure the window remains visible on screen. + /// Adjusts the window frame if necessary to ensure the window remains visible on screen. + /// This constrains both the size (to not exceed the screen) and the origin (to keep the window on screen). func constrainToScreen() { guard let screen = screen ?? NSScreen.main else { return } let visibleFrame = screen.visibleFrame var windowFrame = frame + windowFrame.size.width = min(windowFrame.size.width, visibleFrame.size.width) + windowFrame.size.height = min(windowFrame.size.height, visibleFrame.size.height) + windowFrame.origin.x = max(visibleFrame.minX, min(windowFrame.origin.x, visibleFrame.maxX - windowFrame.width)) windowFrame.origin.y = max(visibleFrame.minY, min(windowFrame.origin.y, visibleFrame.maxY - windowFrame.height)) - if windowFrame.origin != frame.origin { - setFrameOrigin(windowFrame.origin) + if windowFrame != frame { + setFrame(windowFrame, display: true) } } }