From 237bb1e0d9a7cb2d7f91f028f37b8a3dfb1ab8a2 Mon Sep 17 00:00:00 2001 From: lwouis Date: Thu, 27 Nov 2025 19:31:03 +0100 Subject: [PATCH] fix: better crop app icons on macos < 26 (closes #5080) --- src/logic/Application.swift | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/logic/Application.swift b/src/logic/Application.swift index 8a8ef70a..13fcaf85 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -30,16 +30,28 @@ class Application: NSObject { kAXApplicationShownNotification, ] - static func appIconWithoutPadding(_ icon: NSImage?) -> CGImage? { + private static let appIconPadding: CGFloat = { + // Tahoe redesigned app icons. Keeping their rounded look, and reducing their size; we trim that padding + if #available(macOS 26.0, *) { + return 84 + } + // Big Sur redesigned app icons. A big change from square icons to rounded icons, and reducing their size; we trim that padding + if #available(macOS 11.0, *) { + return 24 + } + return 0 + }() + + private static func appIconWithoutPadding(_ icon: NSImage?) -> CGImage? { guard let icon else { return nil } // we can render the icon quite big (e.g. windowless app icon), so we store it high-res let iconWidth = CGFloat(1024) // NSRunningApplication.icon returns icons with padding; we remove it manually - let paddingToRemove = CGFloat(84) - let croppedSize = iconWidth - paddingToRemove * 2 + + let croppedSize = iconWidth - appIconPadding * 2 return icon .appIconFixedSize(NSSize(width: iconWidth, height: iconWidth))? - .cropping(to: CGRect(x: paddingToRemove, y: paddingToRemove, width: croppedSize, height: croppedSize).integral) + .cropping(to: CGRect(x: appIconPadding, y: appIconPadding, width: croppedSize, height: croppedSize).integral) } init(_ runningApplication: NSRunningApplication) {