Skip to content

Commit

Permalink
🔀 Merge branch develop into `mrkai77/loop-636-crash-when-minimizing…
Browse files Browse the repository at this point in the history
…-or-hiding-an-app-with-an-keybind`

# Conflicts:
#	Loop/Window Management/WindowAction.swift
  • Loading branch information
MrKai77 committed Sep 28, 2024
2 parents 0653b32 + cbabeb6 commit e2e39cb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Loop/Preview Window/LuminarePreviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct LuminarePreviewView: View {
.offset(x: actionRect.minX, y: actionRect.minY)
.scaleEffect(CGSize(width: scale, height: scale))
.onAppear {
actionRect = action.getFrame(window: nil, bounds: .init(origin: .zero, size: geo.size))
actionRect = action.getFrame(window: nil, bounds: .init(origin: .zero, size: geo.size), isPreview: true)

withAnimation(
.interpolatingSpring(
Expand Down
3 changes: 2 additions & 1 deletion Loop/Preview Window/PreviewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class PreviewController {
let targetWindowFrame = action.getFrame(
window: window,
bounds: screen.safeScreenFrame,
screen: screen
screen: screen,
isPreview: true
)
.flipY(maxY: NSScreen.screens[0].frame.maxY)

Expand Down
23 changes: 20 additions & 3 deletions Loop/Window Management/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
return result.normalized()
}

func getFrame(window: Window?, bounds: CGRect, disablePadding: Bool = false, screen: NSScreen? = nil) -> CGRect {
func getFrame(window: Window?, bounds: CGRect, disablePadding: Bool = false, screen: NSScreen? = nil, isPreview: Bool = false) -> CGRect {
let noFrameActions: [WindowDirection] = [.noAction, .cycle, .minimize, .hide]
guard !noFrameActions.contains(direction) else {
return NSRect(origin: bounds.center, size: .zero)
Expand All @@ -152,7 +152,7 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
LoopManager.sidesToAdjust = nil
}

result = calculateTargetFrame(direction, window, bounds)
result = calculateTargetFrame(direction, window, bounds, isPreview)

if !disablePadding {
// If window can't be resized, center it within the already-resized frame.
Expand All @@ -179,17 +179,28 @@ struct WindowAction: Codable, Identifiable, Hashable, Equatable, Defaults.Serial
// MARK: - Window Frame Calculations

private extension WindowAction {
func calculateTargetFrame(_ direction: WindowDirection, _ window: Window?, _ bounds: CGRect) -> CGRect {
func calculateTargetFrame(_ direction: WindowDirection, _ window: Window?, _ bounds: CGRect, _ isPreview: Bool) -> CGRect {
var result: CGRect = .zero

if direction.frameMultiplyValues != nil {
result = applyFrameMultiplyValues(bounds)

} else if direction.willAdjustSize {
// Return final frame of preview
if Defaults[.previewVisibility], !isPreview {
return LoopManager.lastTargetFrame
}

let frameToResizeFrom = LoopManager.lastTargetFrame

result = calculateSizeAdjustment(frameToResizeFrom, bounds)

} else if direction.willShrink || direction.willGrow {
// Return final frame of preview
if Defaults[.previewVisibility], !isPreview {
return LoopManager.lastTargetFrame
}

// This allows for control over each side
let frameToResizeFrom = LoopManager.lastTargetFrame

Expand All @@ -208,7 +219,13 @@ private extension WindowAction {
result = calculateSizeAdjustment(frameToResizeFrom, bounds)

} else if direction.willMove {
// Return final frame of preview
if Defaults[.previewVisibility], !isPreview {
return LoopManager.lastTargetFrame
}

let frameToResizeFrom = LoopManager.lastTargetFrame

result = calculatePositionAdjustment(frameToResizeFrom)

} else if direction == .custom {
Expand Down

0 comments on commit e2e39cb

Please sign in to comment.