feat: smoother rounded corners for the main window

This commit is contained in:
Louis Pontoise committed 2022-06-01 18:56:02 +09:00
1 parent d7b6b7c0ae
commit 5d0fff2276
3 files changed
+17 -3

No files matched your search

+1 -1
View File
@@ -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() {
+1 -1
View File
@@ -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
+15 -1
View File
@@ -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 {