diff --git a/src/ui/App.swift b/src/ui/App.swift index 55c5b1c7..1fc1c1dd 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -97,7 +97,7 @@ class App: AppCenterApplication, NSApplicationDelegate { // we put application code here which should be executed on init() and Preferences change func resetPreferencesDependentComponents() { ThumbnailsView.recycledViews = ThumbnailsView.recycledViews.map { _ in ThumbnailView() } - thumbnailsPanel.thumbnailsView.layer!.cornerRadius = Preferences.windowCornerRadius + thumbnailsPanel.thumbnailsView.updateRoundedCorners(Preferences.windowCornerRadius) } func restart() { diff --git a/src/ui/main-window/ThumbnailsPanel.swift b/src/ui/main-window/ThumbnailsPanel.swift index 7ce9b764..a0ec4bed 100644 --- a/src/ui/main-window/ThumbnailsPanel.swift +++ b/src/ui/main-window/ThumbnailsPanel.swift @@ -13,7 +13,7 @@ class ThumbnailsPanel: NSPanel, NSWindowDelegate { hasShadow = false titleVisibility = .hidden backgroundColor = .clear - contentView!.addSubview(thumbnailsView) + contentView! = thumbnailsView // triggering AltTab before or during Space transition animation brings the window on the Space post-transition collectionBehavior = .canJoinAllSpaces // 2nd highest level possible; this allows the app to go on top of context menus diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index 3730f674..e8df9d47 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -10,12 +10,26 @@ class ThumbnailsView: NSVisualEffectView { material = Preferences.windowMaterial state = .active wantsLayer = true - layer!.cornerRadius = Preferences.windowCornerRadius + updateRoundedCorners(Preferences.windowCornerRadius) addSubview(scrollView) // TODO: think about this optimization more (1...100).forEach { _ in ThumbnailsView.recycledViews.append(ThumbnailView()) } } + /// using layer!.cornerRadius works but the corners are aliased; this custom approach gives smooth rounded corners + /// see https://stackoverflow.com/a/29386935/2249756 + func updateRoundedCorners(_ cornerRadius: CGFloat) { + let edgeLength = 2.0 * cornerRadius + 1.0 + maskImage = NSImage(size: NSSize(width: edgeLength, height: edgeLength), flipped: false) { rect in + let bezierPath = NSBezierPath(roundedRect: rect, xRadius: cornerRadius, yRadius: cornerRadius) + NSColor.black.set() + bezierPath.fill() + return true + } + maskImage!.capInsets = NSEdgeInsets(top: cornerRadius, left: cornerRadius, bottom: cornerRadius, right: cornerRadius) + maskImage!.resizingMode = .stretch + } + func nextRow(_ direction: Direction) -> [ThumbnailView]? { let step = direction == .down ? 1 : -1 if let currentRow = Windows.focusedWindow()?.row {