From 0e9fa066f2a2cf308a25fd3ee02211315b9c2a13 Mon Sep 17 00:00:00 2001 From: Kai Azim Date: Wed, 26 Jun 2024 18:01:26 -0600 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9E=20Fix=20padding=20when=20windo?= =?UTF-8?q?w=20animations=20are=20enabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loop/Utilities/PaddingModel.swift | 16 ++++++++-------- Loop/Window Management/WindowAction.swift | 9 +++++++-- Loop/Window Management/WindowEngine.swift | 23 ++++++++++------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/Loop/Utilities/PaddingModel.swift b/Loop/Utilities/PaddingModel.swift index a825d1e2..d160e919 100644 --- a/Loop/Utilities/PaddingModel.swift +++ b/Loop/Utilities/PaddingModel.swift @@ -32,15 +32,15 @@ struct PaddingModel: Codable, Defaults.Serializable, Hashable { configureScreenPadding: false ) - var totalVerticalPadding: CGFloat { - totalTopPadding + bottom - } - - var totalHorizontalPadding: CGFloat { - right + left - } - var allEqual: Bool { window == top && window == bottom && window == right && window == left } + + func apply(on initial: CGRect) -> CGRect { + initial + .padding(.leading, left) + .padding(.trailing, right) + .padding(.bottom, bottom) + .padding(.top, totalTopPadding) + } } diff --git a/Loop/Window Management/WindowAction.swift b/Loop/Window Management/WindowAction.swift index fcee2b32..570bc7b8 100644 --- a/Loop/Window Management/WindowAction.swift +++ b/Loop/Window Management/WindowAction.swift @@ -326,8 +326,13 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial var result = frameToResizeFrom let totalBounds: Edge.Set = [.top, .bottom, .leading, .trailing] let step = Defaults[.sizeIncrement] * ((direction == .larger || direction.willGrow) ? -1 : 1) - let minWidth = Defaults[.padding].totalHorizontalPadding + Defaults[.previewPadding] + 100 - let minHeight = Defaults[.padding].totalVerticalPadding + Defaults[.previewPadding] + 100 + + let padding = Defaults[.padding] + let previewPadding = Defaults[.previewPadding] + let totalHorizontalPadding = padding.left + padding.right + let totalVerticalPadding = padding.totalTopPadding + padding.bottom + let minWidth = totalHorizontalPadding + previewPadding + 100 + let minHeight = totalVerticalPadding + previewPadding + 100 if LoopManager.sidesToAdjust == nil { let edgesTouchingBounds = frameToResizeFrom.getEdgesTouchingBounds(bounds) diff --git a/Loop/Window Management/WindowEngine.swift b/Loop/Window Management/WindowEngine.swift index 5dcef5e1..038f9aa9 100644 --- a/Loop/Window Management/WindowEngine.swift +++ b/Loop/Window Management/WindowEngine.swift @@ -84,7 +84,7 @@ enum WindowEngine { return } - let bounds = action.direction.willMove ? .zero : screen.safeScreenFrame + let bounds = action.direction.willMove ? .zero : Defaults[.padding].apply(on: screen.safeScreenFrame) window.setFrame( targetFrame, @@ -186,25 +186,22 @@ enum WindowEngine { return } - let windowFrame = window.frame + var windowFrame = window.frame + // If the window is fully shown on the screen - if windowFrame.maxX <= bounds.maxX, windowFrame.maxY <= bounds.maxY { + if windowFrame.maxX <= bounds.maxX, + windowFrame.maxY <= bounds.maxY { return } - // If not, then Loop will auto re-adjust the window size to be fully shown on the screen - var fixedWindowFrame = windowFrame - - if fixedWindowFrame.maxX > bounds.maxX { - let rightPadding = Defaults[.enablePadding] ? Defaults[.padding].right : 0 - fixedWindowFrame.origin.x = bounds.maxX - fixedWindowFrame.width - rightPadding + if windowFrame.maxX > bounds.maxX { + windowFrame.origin.x = bounds.maxX - windowFrame.width } - if fixedWindowFrame.maxY > bounds.maxY { - let bottomPadding = Defaults[.enablePadding] ? Defaults[.padding].bottom : 0 - fixedWindowFrame.origin.y = bounds.maxY - fixedWindowFrame.height - bottomPadding + if windowFrame.maxY > bounds.maxY { + windowFrame.origin.y = bounds.maxY - windowFrame.height } - window.setPosition(fixedWindowFrame.origin) + window.setPosition(windowFrame.origin) } } From fd2eb55ac7f80bac67059e0c0c6599617c2df169 Mon Sep 17 00:00:00 2001 From: Kai Azim Date: Wed, 26 Jun 2024 18:07:56 -0600 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9E=20Fix=20disabling=20padding=20?= =?UTF-8?q?not=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Loop/Window Management/WindowEngine.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Loop/Window Management/WindowEngine.swift b/Loop/Window Management/WindowEngine.swift index 038f9aa9..da7eaabf 100644 --- a/Loop/Window Management/WindowEngine.swift +++ b/Loop/Window Management/WindowEngine.swift @@ -84,7 +84,13 @@ enum WindowEngine { return } - let bounds = action.direction.willMove ? .zero : Defaults[.padding].apply(on: screen.safeScreenFrame) + let screenFrame = action.direction.willMove ? .zero : screen.safeScreenFrame + + let bounds = if Defaults[.enablePadding] { + Defaults[.padding].apply(on: screenFrame) + } else { + screenFrame + } window.setFrame( targetFrame,