Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💫 Improve animation settings together with WindowEngine #668

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 24 additions & 3 deletions Loop/Window Management/WindowEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +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 = 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 @@ -212,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