From 7b5d2bd2873a5b572f2a797aedd24be79e6be917 Mon Sep 17 00:00:00 2001 From: Kai Azim <68963405+MrKai77@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:00:25 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20#208=20Fix=20custom=20window=20a?= =?UTF-8?q?ctions=20resizes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loop/Window Management/WindowAction.swift | 83 ++++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/Loop/Window Management/WindowAction.swift b/Loop/Window Management/WindowAction.swift index fddc6c91..b666543d 100644 --- a/Loop/Window Management/WindowAction.swift +++ b/Loop/Window Management/WindowAction.swift @@ -75,48 +75,49 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial result.size.width = bounds.width * frameMultiplyValues.width result.size.height = bounds.height * frameMultiplyValues.height } else { - if direction == .custom, let screenFrame = NSScreen.screenWithMouse?.frame { - switch measureSystem { - case .percentage: - result.size.width = bounds.width * ((width ?? 0) / 100.0) - result.size.height = bounds.height * ((height ?? 0) / 100.0) - case .pixels: - result.size.width += (width ?? 0) / screenFrame.width - result.size.height += (height ?? 0) / screenFrame.height - case .none: - break - } + guard direction == .custom else { return result } - switch anchor { - case .topLeft: - break - case .top: - result.origin.x = screenFrame.midX - result.width / 2 - case .topRight: - result.origin.x = screenFrame.maxX - result.width - case .right: - result.origin.x = screenFrame.maxX - result.width - result.origin.y = screenFrame.midY - result.height / 2 - case .bottomRight: - result.origin.x = screenFrame.maxX - result.width - result.origin.y = screenFrame.maxY - result.height - case .bottom: - result.origin.x = screenFrame.midX - result.width / 2 - result.origin.y = screenFrame.maxY - result.height - case .bottomLeft: - result.origin.y = screenFrame.maxY - result.height - case .left: - result.origin.y = screenFrame.midY - result.height / 2 - case .center: - result.origin.x = screenFrame.midX - result.width / 2 - result.origin.y = screenFrame.midY - result.height / 2 - case .macOSCenter: - let yOffset = WindowEngine.getMacOSCenterYOffset(result.height, screenHeight: screenFrame.height) - result.origin.x = screenFrame.midX - result.width / 2 - result.origin.y = (screenFrame.midY - result.height / 2) + yOffset - case .none: - break - } + switch measureSystem { + case .pixels: + guard let screenFrame = NSScreen.screenWithMouse?.frame else { return result } + result.size.width += (width ?? screenFrame.width) / screenFrame.width + result.size.height += (height ?? screenFrame.height) / screenFrame.height + case .percentage: + result.size.width = bounds.width * ((width ?? 0) / 100.0) + result.size.height = bounds.height * ((height ?? 0) / 100.0) + case .none: + break + } + + switch anchor { + case .topLeft: + break + case .top: + result.origin.x = bounds.midX - result.width / 2 + case .topRight: + result.origin.x = bounds.maxX - result.width + case .right: + result.origin.x = bounds.maxX - result.width + result.origin.y = bounds.midY - result.height / 2 + case .bottomRight: + result.origin.x = bounds.maxX - result.width + result.origin.y = bounds.maxY - result.height + case .bottom: + result.origin.x = bounds.midX - result.width / 2 + result.origin.y = bounds.maxY - result.height + case .bottomLeft: + result.origin.y = bounds.maxY - result.height + case .left: + result.origin.y = bounds.midY - result.height / 2 + case .center: + result.origin.x = bounds.midX - result.width / 2 + result.origin.y = bounds.midY - result.height / 2 + case .macOSCenter: + let yOffset = WindowEngine.getMacOSCenterYOffset(result.height, screenHeight: bounds.height) + result.origin.x = bounds.midX - result.width / 2 + result.origin.y = (bounds.midY - result.height / 2) + yOffset + case .none: + break } } return result