Skip to content

Commit

Permalink
🐛 Fix LOOP-553
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jun 21, 2024
1 parent 22f1d04 commit 0d6d911
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
46 changes: 26 additions & 20 deletions Loop/Window Management/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
return NSRect(origin: bounds.center, size: .zero)
}
var bounds = bounds
if !disablePadding { bounds = getPaddedBounds(bounds) }
if !disablePadding && Defaults[.enablePadding] {
bounds = getPaddedBounds(bounds)
}
var result = CGRect(origin: bounds.origin, size: .zero)

if !willManipulateExistingWindowFrame {
Expand Down Expand Up @@ -221,7 +223,7 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial

if !disablePadding {
if direction != .undo, direction != .initialFrame {
result = applyPadding(result, bounds)
result = cropThenApplyPadding(result, bounds)
}

LoopManager.lastTargetFrame = result
Expand Down Expand Up @@ -391,45 +393,49 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
return bounds
}

private func applyPadding(_ windowFrame: CGRect, _ bounds: CGRect) -> CGRect {
private func cropThenApplyPadding(_ windowFrame: CGRect, _ bounds: CGRect) -> CGRect {
guard !direction.willMove else {
return windowFrame
}

let padding = Defaults[.padding]
let halfPadding = padding.window / 2
var paddedWindowFrame = windowFrame.intersection(bounds)
var croppedWindowFrame = windowFrame.intersection(bounds)

guard !willManipulateExistingWindowFrame else {
return paddedWindowFrame
guard
!willManipulateExistingWindowFrame,
Defaults[.enablePadding]
else {
return croppedWindowFrame
}

let padding = Defaults[.padding]
let halfPadding = padding.window / 2

if direction == .macOSCenter,
windowFrame.height >= bounds.height {
paddedWindowFrame.origin.y = bounds.minY
paddedWindowFrame.size.height = bounds.height
croppedWindowFrame.origin.y = bounds.minY
croppedWindowFrame.size.height = bounds.height
}

if direction == .center || direction == .macOSCenter {
return paddedWindowFrame
return croppedWindowFrame
}

if paddedWindowFrame.minX != bounds.minX {
paddedWindowFrame = paddedWindowFrame.padding(.leading, halfPadding)
if croppedWindowFrame.minX != bounds.minX {
croppedWindowFrame = croppedWindowFrame.padding(.leading, halfPadding)
}

if paddedWindowFrame.maxX != bounds.maxX {
paddedWindowFrame = paddedWindowFrame.padding(.trailing, halfPadding)
if croppedWindowFrame.maxX != bounds.maxX {
croppedWindowFrame = croppedWindowFrame.padding(.trailing, halfPadding)
}

if paddedWindowFrame.minY != bounds.minY {
paddedWindowFrame = paddedWindowFrame.padding(.top, halfPadding)
if croppedWindowFrame.minY != bounds.minY {
croppedWindowFrame = croppedWindowFrame.padding(.top, halfPadding)
}

if paddedWindowFrame.maxY != bounds.maxY {
paddedWindowFrame = paddedWindowFrame.padding(.bottom, halfPadding)
if croppedWindowFrame.maxY != bounds.maxY {
croppedWindowFrame = croppedWindowFrame.padding(.bottom, halfPadding)
}

return paddedWindowFrame
return croppedWindowFrame
}
}
6 changes: 4 additions & 2 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ enum WindowEngine {
var fixedWindowFrame = windowFrame

if fixedWindowFrame.maxX > bounds.maxX {
fixedWindowFrame.origin.x = bounds.maxX - fixedWindowFrame.width - Defaults[.padding].right
let rightPadding = Defaults[.enablePadding] ? Defaults[.padding].right : 0
fixedWindowFrame.origin.x = bounds.maxX - fixedWindowFrame.width - rightPadding
}

if fixedWindowFrame.maxY > bounds.maxY {
fixedWindowFrame.origin.y = bounds.maxY - fixedWindowFrame.height - Defaults[.padding].bottom
let bottomPadding = Defaults[.enablePadding] ? Defaults[.padding].bottom : 0
fixedWindowFrame.origin.y = bounds.maxY - fixedWindowFrame.height - bottomPadding
}

window.setPosition(fixedWindowFrame.origin)
Expand Down

0 comments on commit 0d6d911

Please sign in to comment.