Skip to content

Commit

Permalink
πŸ”€ Merge pull request #473 from MrKai77/padding-fixes
Browse files Browse the repository at this point in the history
🐞 Padding fixes
  • Loading branch information
MrKai77 authored Jun 27, 2024
2 parents d4b64fb + fd2eb55 commit 5fb1775
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
16 changes: 8 additions & 8 deletions Loop/Utilities/PaddingModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
9 changes: 7 additions & 2 deletions Loop/Window Management/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ enum WindowEngine {
return
}

let bounds = action.direction.willMove ? .zero : 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,
Expand Down Expand Up @@ -186,25 +192,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)
}
}

0 comments on commit 5fb1775

Please sign in to comment.