Skip to content

Commit

Permalink
🎨 Make method to determine if window should be resized
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jan 10, 2025
1 parent 8a882ec commit b60be9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
6 changes: 5 additions & 1 deletion Loop/Managers/SystemWindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ class SystemWindowManager {
}

static var padding: CGFloat {
windowManagerDefaults?.float(forKey: "TiledWindowSpacing") ?? 8
CGFloat(windowManagerDefaults?.float(forKey: "TiledWindowSpacing") ?? 8)
}

static var enableAnimations: Bool {
!(windowManagerDefaults?.bool(forKey: "DisableTilingAnimations") ?? false)
}

static func syncPadding() {
Expand Down
31 changes: 24 additions & 7 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,7 @@ enum WindowEngine {
WindowRecords.removeLastAction(for: window)
}

// If enhancedUI is enabled, then window animations will likely lag a LOT. So, if it's enabled, force-disable animations
let enhancedUI = window.enhancedUserInterface
let animate: Bool = if let windowManagerDefaults = UserDefaults(suiteName: "com.apple.WindowManager") {
!windowManagerDefaults.bool(forKey: "DisableTilingAnimations")
} else {
Defaults[.animateWindowResizes] && !enhancedUI
}
let animate = shouldAnimateResize(for: window)

// If the window is one of Loop's windows, resize it using the actual NSWindow, preventing crashes
if window.nsRunningApplication?.bundleIdentifier == Bundle.main.bundleIdentifier,
Expand Down Expand Up @@ -216,6 +210,29 @@ enum WindowEngine {
return (0.5 * windowHeightPercent - 0.5) * halfScreenHeight
}

/// Determines if a window resize should be animated by Loop or not.
/// Note that this does not affect the system window manager.
/// - Parameter window: The window to be resized
/// - Returns: Whether the window should be animated or not
private static func shouldAnimateResize(for window: Window) -> Bool {
// If enhancedUI is enabled, then window animations will likely lag a LOT. So, if it's enabled, force-disable animations
if window.enhancedUserInterface {
return false
}

// If the user has enabled the system window manager, then return the system's animation setting
if #available(macOS 15, *), Defaults[.useSystemWindowManagerWhenAvailable] {
return SystemWindowManager.MoveAndResize.enableAnimations
}

// If the user has disabled window animations, then return false
if !Defaults[.animateWindowResizes] {
return false
}

return true
}

/// Will move a window back onto the screen. To be run AFTER a window has been resized.
/// - Parameters:
/// - window: Window
Expand Down

0 comments on commit b60be9f

Please sign in to comment.