Skip to content

Commit 797e3e4

Browse files
fix(drawer): smooth Genie animation on 60 Hz displays
1 parent d6856c8 commit 797e3e4

9 files changed

Lines changed: 203 additions & 41 deletions

File tree

‎App/FileMint/FileDrawerController.swift‎

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ final class FileDrawerController: NSObject, NSWindowDelegate {
102102
}
103103
}
104104

105-
func show() {
105+
func show() { show(on: pointerScreen) }
106+
107+
func show(on targetScreen: NSScreen?) {
106108
guard settings.committedPreferences.fileDrawer.enabled else { return }
107109
if let modal = NSApp.modalWindow ?? NSApp.windows.compactMap(\.attachedSheet).first {
108110
modal.makeKeyAndOrderFront(nil)
@@ -111,7 +113,7 @@ final class FileDrawerController: NSObject, NSWindowDelegate {
111113
if let panel {
112114
let reopening = closing
113115
closing = false
114-
if !hasActiveInteraction, let screen = pointerScreen, display != screen {
116+
if !hasActiveInteraction, let screen = targetScreen, display != screen {
115117
display = screen
116118
requestedFrame = nil
117119
layout(settings.committedPreferences.fileDrawer)
@@ -120,7 +122,7 @@ final class FileDrawerController: NSObject, NSWindowDelegate {
120122
panel.makeKeyAndOrderFront(nil)
121123
return
122124
}
123-
guard !model.writing, let screen = pointerScreen else { return }
125+
guard !model.writing, let screen = targetScreen else { return }
124126
display = screen
125127
previousApp = NSWorkspace.shared.frontmostApplication?.processIdentifier
126128
let p = DrawerPanel(contentRect: .init(x: 0, y: 0, width: 520, height: 650),
@@ -423,9 +425,10 @@ final class FileDrawerController: NSObject, NSWindowDelegate {
423425

424426
private final class DrawerBackground: NSView {
425427
let controls = NSView()
428+
private let material = NSView()
426429
private let effect = NSVisualEffectView()
427430
private let solid = NSBox()
428-
private let tintMask = CALayer()
431+
private let genieMask = CAShapeLayer()
429432

430433
var showsGlass: Bool { !effect.isHidden }
431434

@@ -442,12 +445,18 @@ private final class DrawerBackground: NSView {
442445
solid.borderWidth = 0
443446
solid.titlePosition = .noTitle
444447
solid.fillColor = .windowBackgroundColor
448+
material.wantsLayer = true
445449
controls.wantsLayer = true
446-
for view in [effect as NSView, solid, controls] {
450+
for view in [material, controls] {
447451
view.frame = bounds
448452
view.autoresizingMask = [.width, .height]
449453
addSubview(view)
450454
}
455+
for view in [effect as NSView, solid] {
456+
view.frame = material.bounds
457+
view.autoresizingMask = [.width, .height]
458+
material.addSubview(view)
459+
}
451460
}
452461
required init?(coder: NSCoder) { nil }
453462

@@ -483,35 +492,28 @@ private final class DrawerBackground: NSView {
483492
}
484493

485494
func genieBackdropUpdate() -> FileDrawerGenieTransition.BackdropUpdate? {
486-
guard showsGlass, !effect.bounds.isEmpty else { return nil }
487-
let size = effect.bounds.size
488-
// AppKit composites a behind-window mask at its raster dimensions.
489-
let pixels = CGRect(origin: .zero, size: effect.convertToBacking(effect.bounds).integral.size)
490-
guard let context = CGContext(data: nil, width: Int(pixels.width), height: Int(pixels.height), bitsPerComponent: 8,
491-
bytesPerRow: 0, space: CGColorSpaceCreateDeviceGray(),
492-
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
495+
guard showsGlass, !material.bounds.isEmpty, let layer = material.layer else { return nil }
496+
let size = material.bounds.size
497+
// Clip the live glass and its tint together at the backing scale.
498+
genieMask.frame = material.bounds
499+
genieMask.contentsScale = window?.backingScaleFactor ?? 1
493500
let edgeCount = FileDrawerGenieGeometry.columns + 1
494501
return { [weak self] vertices, opacity in
495502
guard let self else { return }
496503
let outline = Array(vertices.prefix(edgeCount)) + vertices.suffix(edgeCount).reversed()
497-
context.clear(pixels)
498-
context.addLines(between: outline.map { CGPoint(x: CGFloat($0.x) * pixels.width, y: CGFloat($0.y) * pixels.height) })
499-
context.closePath()
500-
context.setFillColor(gray: 1, alpha: opacity)
501-
context.fillPath()
502-
guard let image = context.makeImage() else { return }
503-
effect.maskImage = NSImage(cgImage: image, size: size)
504-
tintMask.frame = solid.bounds
505-
tintMask.contents = image
506-
solid.layer?.mask = tintMask
504+
let path = CGMutablePath()
505+
path.addLines(between: outline.map { CGPoint(x: CGFloat($0.x) * size.width, y: CGFloat($0.y) * size.height) })
506+
path.closeSubpath()
507+
genieMask.path = path
508+
genieMask.opacity = Float(opacity)
509+
if layer.mask == nil { layer.mask = genieMask }
507510
}
508511
}
509512

510513
func clearGenieBackdrop() {
511514
controls.layer?.opacity = 1
512-
effect.maskImage = nil
513-
solid.layer?.mask = nil
514-
tintMask.contents = nil
515+
material.layer?.mask = nil
516+
genieMask.path = nil
515517
}
516518

517519
func apply(_ options: FileDrawerPreferences) {

‎App/FileMint/FileDrawerGenieTransition.swift‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ final class FileDrawerGenieTransition: MTKView {
2525
private var completionTask: Task<Void, Never>?
2626
private(set) var progress: Float
2727
var restoredOpeningImage: (@MainActor () -> CGImage?)?
28+
// The signed fixture samples the actual display presentation times.
29+
var framePresented: (@Sendable (TimeInterval) -> Void)?
2830

2931
init?(image: CGImage, frame: CGRect, side: FileDrawerPreferences.Side, opening: Bool, framesPerSecond: Int,
3032
updateBackdrop: BackdropUpdate?) {
@@ -67,6 +69,9 @@ final class FileDrawerGenieTransition: MTKView {
6769
override func draw(_ dirtyRect: NSRect) {
6870
guard let motion, let pass = currentRenderPassDescriptor, let drawable = currentDrawable,
6971
let buffer = queue.makeCommandBuffer() else { return }
72+
if let framePresented {
73+
drawable.addPresentedHandler { framePresented($0.presentedTime) }
74+
}
7075
CATransaction.begin()
7176
CATransaction.setDisableActions(true)
7277
if motion.to == 0, let image = restoredOpeningImage?() {

‎docs/ACCEPTANCE.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
Observations below apply to the revisions and environments stated in each entry.
44
Use [HARNESS](../specs/HARNESS.md) to select present-day verification.
55

6+
## Drawer Genie on a fixed 60 Hz display — 2026-11-23
7+
8+
On a 5K external display in a fixed 60 Hz mode, the signed fixture on `d6856c8`
9+
with the mask change presented 28–31 frames in each of 12 opening or closing
10+
transitions. Median intervals were 16.7 ms, with occasional 33.3 ms intervals.
11+
The composited outline, tint, restored file rows and handoff passed the signed
12+
drawer suite. See the [cadence record](tasks/2026-11-20-file-drawer.md#genie-cadence-at-60-hz--2026-11-23).
13+
14+
The signed Debug build with the fix was installed for the owner's 60 Hz retest.
15+
The running host and enabled Finder extension mapped the replacement binaries.
16+
617
## Drawer Genie backing resolution and motion — 2026-11-22
718

819
The signed drawer fixture captured both directions on both edges at three

‎docs/tasks/2026-11-20-file-drawer.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,44 @@ Acceptance follows the app, Core and native rows of the [Harness](../../specs/HA
1010

1111
## Drawer refinements
1212

13+
### Genie cadence at 60 Hz — 2026-11-23
14+
15+
The owner reported stuttering on a 60 Hz screen and paused 0.8.3 publication.
16+
On arm64 macOS 27.2.1, the signed fixture reproduced it on a 5K external
17+
display at 60 Hz and 2× scale. The first glass opening with the old mask
18+
presented 15 frames, with a 33.3 ms median interval and a 66.7 ms maximum.
19+
The baseline measures that first opening because the fixture compared two
20+
spellings of its temporary folder path before the next motion.
21+
22+
The live glass and tint now share a `CAShapeLayer` mask at the window's backing
23+
scale. The compositor rasterizes the mesh outline without a new AppKit bitmap
24+
for every frame. The glass and moving controls still present in the same Core
25+
Animation transaction.
26+
27+
- `run.7gq_zdez` passed `file-drawer-cadence` on `d6856c8` with the local fix.
28+
Three open/close cycles each for glass and solid backgrounds all presented
29+
28–31 frames with 16.7 ms medians. The worst interval was 33.3 ms.
30+
- The same run stopped the general `file-drawer` suite at a settings-window
31+
focus assertion. The isolated rerun `run.t1tc2x2n` passed with the same code,
32+
including composited captures at three sizes on both edges in both directions,
33+
restored file rows, tint, reversal, resize and Reduce Motion.
34+
- `make verify` passed with 467 Swift tests. The unsigned Release build produced
35+
arm64 executables for both FileMint and its embedded Finder extension.
36+
Logs are in `build/drawer-genie-cadence.IczG4I/`.
37+
- The native reports in `build/native-checks.noindex/` cover the isolated
38+
signed drawer and the measured display. Moving an active transition between
39+
physical displays and running it on macOS 13/14 remain unverified.
40+
41+
At the owner's request, Developer ID signed Debug 0.8.2 (31) with the fix was
42+
installed at `/Applications/FileMint.app`. Both running processes mapped the
43+
new installed executables and Finder had one enabled registration. The prior
44+
bundle archive and installation logs are in
45+
`build/local-debug-install.noindex/genie-cadence.RkAF6E/`. The owner will check
46+
animation quality on the installed build at 60 Hz.
47+
48+
When 0.8.3 release preparation resumes, feature the drawer prominently on the
49+
Chinese and English website and include multiple real screenshots of its use.
50+
1351
### Drawer animations — 2026-11-22
1452

1553
Appearance settings offer Genie, Scale, and Slide and Fade. Genie is the default

‎scripts/design_ui_smoke.swift‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ final class DesignUISmoke: NSObject, NSApplicationDelegate {
3737
private func prepare() throws {
3838
guard let path = Bundle.main.object(forInfoDictionaryKey: "FixturePath") as? String else { throw ResourceError.failed }
3939
let base = URL(fileURLWithPath: path, isDirectory: true)
40-
let automatic = ["--verify-automation", "--verify-updates", "--verify-file-drawer"].contains { CommandLine.arguments.contains($0) }
40+
let drawerCadence = CommandLine.arguments.contains("--verify-file-drawer-cadence")
41+
let verifyDrawer = CommandLine.arguments.contains("--verify-file-drawer")
42+
let automatic = drawerCadence || verifyDrawer || ["--verify-automation", "--verify-updates"].contains {
43+
CommandLine.arguments.contains($0)
44+
}
4145
let root: URL
4246
if automatic {
4347
// Keep the normal-layout fixture's displayed destination short.
@@ -164,12 +168,17 @@ final class DesignUISmoke: NSObject, NSApplicationDelegate {
164168
NSApp.mainMenu = bar
165169
NSApp.activate(ignoringOtherApps: true)
166170
print("READY isolated FileMint UI: \(root.path)")
167-
if CommandLine.arguments.contains("--verify-file-drawer") {
171+
if verifyDrawer || drawerCadence {
168172
Task { @MainActor in
169173
do {
170174
try await waitForSettingsReady()
171-
try await checkFileDrawer(settings: model, favorites: favoriteModel, root: root)
172-
print("PASS file drawer: shortcut toggling, absolute path menus, verified row navigation, scoped creation and Quick Look")
175+
if drawerCadence {
176+
try await checkFileDrawerCadence(settings: model, favorites: favoriteModel, root: root)
177+
print("PASS file drawer cadence: visible Genie endpoints and presentation samples")
178+
} else {
179+
try await checkFileDrawer(settings: model, favorites: favoriteModel, root: root)
180+
print("PASS file drawer: shortcut toggling, absolute path menus, verified row navigation, scoped creation and Quick Look")
181+
}
173182
fflush(nil)
174183
NSApp.terminate(nil)
175184
} catch {

0 commit comments

Comments
 (0)