Commit Graph
3 Commits
Author SHA1 Message Date
yetone ecc26a3394 gui: a Dock flap's frames are let go on macOS (#4162)
Each Dock reopen (clicking the Dock icon, or `open magpie.app` while
magpie runs) plays the Dock flap: 29 frames of 512x512 RGBA, each
handed to the Dock tile as an NSImage made on a Go thread. A Go thread
has no autorelease pool, so the NSCGImageSnapshotRep that
initWithCGImage:size: autoreleases, with its 1 MB of pixels, went to
the thread's implicit pool, which drains only when the thread exits.
Every flap kept ~30 MB for good. faithleysath's heap on 0.1.3117 had
1074 NSCGImageSnapshotRep and 16K+1008K+16K CG raster regions: the
frames of about 37 flaps.

mpDockFrameNS makes each frame's NSImage inside its own
@autoreleasepool, and mpDockStill drops the last frame from the view.
The tray's mpTrayPlace and mpSetTrayPlace run on Go threads too and
get a pool each (same class; their objects are small).

Run on mote (macOS 26, M5 Pro), a real build in a sandbox HOME
(MAGPIE_ADDR=127.0.0.1:3561), 5 reopens through `open magpie.app`,
heap/footprint/vmmap 45s after the last:
- before (12a9970d6): footprint 69 MB -> 220 MB; NSCGImageSnapshotRep
  0 -> 145 (5 x 29); CG raster data 151.3M in 447 regions, the
  reporter's 16K+1008K+16K layout. Nothing freed after 45s.
- after: footprint 75 MB -> 78 MB; NSCGImageSnapshotRep 0 (1 mid-flap,
  so the flap ran); CG raster 5.2M in 15 regions.
- TestDockFrameLeavesNothing makes a frame on a locked Go thread and
  checks its image rep is gone after release. Broken by hand (pool
  taken out of mpDockFrameNS): it fails. Restored: passes, with
  TestDockFlap* and TestTray*.
- go vet ./internal/gui, GOOS=linux go vet -tags nogui, GOOS=windows
  go vet, go build, gofmt -l: clean.

Not tried: a Retina screen (mote's is 1x, so frames there are the same
512px), the reporter's macOS 26.6, and the hidden 1470x33 windows in
their window list.

Reported-by: cgoder
Reported-by: faithleysath
Reported-by: xgxg-mdl
Reported-by: Matrix (Discord)
2026-11-06 22:56:33 +08:00
yetoneandggbdpq 629ae1891a gui: the dock and tray bitmaps name their alpha as a CGBitmapInfo (#4819)
CGBitmapContextCreate takes a CGBitmapInfo, and the three calls in
dockflap_darwin.go (mpDockContext, mpDockFill) and trayimage_darwin.go
(mpMasked) passed a CGImageAlphaInfo value. The macOS 26 SDK's clang
warns on that implicit enum-to-enum conversion, and the CI log's problem
matcher shows each warning as an ##[error] line. Each call now casts the
constant to CGBitmapInfo; the alpha info sits in the same low bits, so
the bitmaps are the same.

These warnings do not fail go vet (its exit is 0 before and after), so
this does not turn the macOS CI job green: that job fails on
TestStopLetsARenewalEnd in internal/plugin. It takes three false
##[error] lines out of the log.

Run on mote (macOS 27, CLT clang), base origin/main 4e7661adc:
- go vet ./internal/gui/ before: exit 0, three -Wenum-conversion warnings
  in internal/gui; after: exit 0, none in internal/gui
- gofmt -l on both files: nothing; go build ./internal/gui/: ok

Not tried: no test covers the bitmaps' pixels; the change is a C type
cast only. GOOS=linux/windows builds don't compile these files.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
yetone 7536477c8e gui: the Dock icon flaps its wing and tail as the header logo does
Clicking magpie's Dock icon plays the header logo's .logo.wag on the
tile: the same keyframes, turn points, .9s and cubic-bezier(.3, 0, .3, 1),
a frame every 30ms. The icon macOS draws (its glass tile and glossy bird)
is cut into body, tail and wing by index.html's own clip paths, the tile
under the bird filled with the tile's colour read either side of it, and
each frame turns the pieces over it, set as the Dock tile's content view.
The tile goes back to the system's icon after. It plays only when the
Dock draws icons light (no AppleIconAppearanceTheme, RegularLight, or
RegularAutomatic in light mode); a dark, clear or tinted Dock is left as
it is. A click while it plays doesn't start another.

Run:
- go test ./internal/gui/ -run TestDockFlap: TestDockFlapIsTheLogos holds
  the keyframes, origins, length and easing to app.css and parses the
  bird and clips out of the embedded index.html. Broken by hand: changing
  one keyframe in flapkeys.go turns it red.
- TestDockFlapFrames (MAGPIE_DOCK_APP=/Applications/magpie.app) wrote the
  31 frames; looked at by eye. Frame 0 against the system's own 512px
  render: inside the tile 0.03% of pixels differ by over 40/255 (the
  tile's rim resampled); the pieces' seams were visible until they
  overlapped by 1px.
- A sandbox bundle (own bundle id, sandbox HOME, ports 3446/3447) got the
  Dock's reopen event by pid: a burst of screen captures of the real Dock
  shows the tile in different poses.
- go vet ./internal/gui/, GOOS=windows go vet, GOOS=linux go vet -tags
  nogui, GOOS=linux go build -tags nogui, GOOS=windows go build, gofmt -l.

Not tried: a dark or tinted Dock (skipped by the gate, not drawn), a
real mouse click on the Dock (the same reopen event, sent by pid).
2026-10-25 19:28:05 +08:00