windows: the app's icon fills its square in the taskbar, the tray and Start (dzxx0496)
On Windows 10 magpie's icon looked a size smaller than its neighbours in the taskbar, the tray overflow and Start's "Recently added" (dzxx0496 on Discord, #general). Every Windows icon was the Mac's tile: build/windows/icon-*.png (75cb19264, the exe's icon group #3, which the window, the taskbar and the Start shortcut's IconLocation exe,0 all use) and internal/gui/icon.png (the tray) were build/icon/gen.go's app(), on macOS's grid, the tile 80% of the canvas with 10% clear on each side. Windows draws an app to the edges of its square. - gen.go: app() and the new win() share tile(). win() is the same white tile, shading and bird (.8 of the tile), a 32nd of the side clear from 32px up (1px at 32 and 48, 8px at 256) so the rounded corners' soft edge stays inside, and to the edge under 32px, where that pixel would only blur it; corner radius .2 of the side (.225 on the Mac). No new colour. - build/windows: icon-16 to icon-256 drawn by win(), plus 20, 24 and 40 px, which Windows asks for at 125% to 250%; winres.json lists them. - The tray takes internal/gui/icon-windows.ico (16, 20, 24, 32, 40, 48, 64); Wails picks the SM_CXSMICON entry, where the 64px PNG was scaled down by the system. icon.png, only the tray's, is gone. - Makefile's icons target draws all of these. Not changed: macOS (app() is byte for byte the same at 64, 256 and 1024: cmp against the committed icon-256.png and icon-1024.png; the .icns, Assets.car and tray.png untouched). Linux: its tray is the glyph with no tile, and its desktop icon (icon-256.png) keeps the margin GNOME's and the hicolor theme's app icons have too. What was run: - mote: go test ./internal/gui: TestWindowsIconsFillTheirSquare (new), TestTrayIconPerOS and TestTrayIconSize ok. Red, each filed and none about icons: TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red 3 of 3 at a fresh origin/main733fac48f), TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27) and TestColdTurnsTaken once in the package run, ok when run again (#4510). go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build and GOOS=windows go build: ok. gofmt -l prints nothing. - Broken by hand: the old PNGs, winres.json and the old 64px picture as the tray's .ico: TestWindowsIconsFillTheirSquare red, "tile (25,25)-(231,231) in (0,0)-(256,256), want at least 15/16 of the side, centred" and the same for each size, "icon-windows.ico has no 16px picture". - make release-windows on mote at origin/main and at this change, both exes on the Windows 11 box (xiaomi-gpu). Its console was locked at the PIN screen, so no desktop screenshot: instead Windows itself drew each exe and a .lnk to it through IShellItemImageFactory (what Explorer, the taskbar and Start use) at 16/24/32/48/256, beside Docker Desktop, Claude, Explorer, Edge and Notepad, and the tray icon through CreateIconFromResourceEx at 16 to 40 as Wails makes it. Before: the tile 80% of the square, the tray blurred. After: the tile fills it as Docker's, Claude's and Edge's do; the tray is crisp at each size. Not run: go test -tags nogui ./... (the change is internal/gui's embeds, which nogui leaves out, and build/). Not tried: Windows 10 itself, and the real taskbar, tray and Start with the desktop unlocked. Windows keeps an exe's icon in its icon cache by path, so a user may see the old one until the cache renews.
@@ -70,7 +70,12 @@ app: build
|
||||
icons:
|
||||
@go run build/icon/gen.go tray internal/gui/tray.png
|
||||
@go run build/icon/gen.go tray-flap internal/gui/trayflap
|
||||
@go run build/icon/gen.go app 64 internal/gui/icon.png
|
||||
@# Windows draws an app's icon to the edges of its square: the exe's
|
||||
@# icon group (build/windows/winres.json) and the tray's .ico
|
||||
@for s in 16 20 24 32 40 48 64 128 256; do \
|
||||
go run build/icon/gen.go win $$s build/windows/icon-$$s.png; \
|
||||
done
|
||||
@go run build/icon/gen.go win-ico internal/gui/icon-windows.ico
|
||||
@go run build/icon/gen.go app 1024 internal/gui/icon-1024.png
|
||||
@go run build/icon/gen.go app 256 internal/gui/icon-256.png
|
||||
@rm -rf build/darwin/magpie.iconset && mkdir -p build/darwin/magpie.iconset
|
||||
|
||||
@@ -11,11 +11,15 @@
|
||||
// go run build/icon/gen.go tray internal/gui/tray.png # 44px black template icon (macOS menu bar)
|
||||
// go run build/icon/gen.go tray-flap internal/gui/trayflap # its frames when clicked (a size after the folder for a bigger look)
|
||||
// go run build/icon/gen.go app 64 internal/gui/icon.png # app icon at a given size
|
||||
// go run build/icon/gen.go win 256 build/windows/icon-256.png # the Windows tile, filling its square
|
||||
// go run build/icon/gen.go win-ico internal/gui/icon-windows.ico # it at the tray's sizes, one .ico
|
||||
// make icons # regenerates all of them plus magpie.icns
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
@@ -58,8 +62,17 @@ func main() {
|
||||
case len(os.Args) == 4 && (os.Args[1] == "app" || os.Args[1] == "app-dark"):
|
||||
n, _ := strconv.Atoi(os.Args[2])
|
||||
img = app(n, os.Args[1] == "app-dark")
|
||||
case len(os.Args) == 4 && os.Args[1] == "win":
|
||||
n, _ := strconv.Atoi(os.Args[2])
|
||||
img = win(n)
|
||||
case len(os.Args) == 3 && os.Args[1] == "win-ico":
|
||||
if err := winICO(os.Args[2], trayICOSizes); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
default:
|
||||
fmt.Fprintln(os.Stderr, "usage: gen.go tray <out.png> | gen.go app|app-dark <size> <out.png>")
|
||||
fmt.Fprintln(os.Stderr, "usage: gen.go tray <out.png> | gen.go app|app-dark|win <size> <out.png> | gen.go win-ico <out.ico>")
|
||||
os.Exit(2)
|
||||
}
|
||||
f, err := os.Create(os.Args[len(os.Args)-1])
|
||||
@@ -262,13 +275,30 @@ func glyph(n int) image.Image {
|
||||
}
|
||||
|
||||
// app draws a rounded square, white shading to the palest grey, with the
|
||||
// bird on it in ink.
|
||||
// bird on it in ink, on macOS's icon grid: the tile is ~80% of the
|
||||
// canvas, the rest left clear as the Dock and Finder expect.
|
||||
func app(n int, dark bool) image.Image {
|
||||
S := float64(n)
|
||||
// macOS icon grid: the squircle occupies ~80% of the canvas
|
||||
inset := S * 0.1
|
||||
return tile(n, inset, (S-2*inset)*0.225, dark)
|
||||
}
|
||||
|
||||
// win is the same tile as Windows draws an app's icon: filling its square,
|
||||
// as the icons beside it in the taskbar, the tray and Start do. On macOS's
|
||||
// grid it was a fifth smaller than its neighbours there (dzxx0496). A
|
||||
// pixel is left round it from 32px up, a 32nd of the side, so the rounded
|
||||
// corners' soft edge stays inside the square; under 32px that pixel would
|
||||
// be most of the margin and only blur the edge, so the tile meets it.
|
||||
func win(n int) image.Image {
|
||||
inset := float64(n / 32)
|
||||
return tile(n, inset, (float64(n)-2*inset)*0.2, false)
|
||||
}
|
||||
|
||||
// tile draws the rounded square inset from each edge of an n-pixel canvas,
|
||||
// its corners of the given radius, and the bird on it at .8 of its side.
|
||||
func tile(n int, inset, radius float64, dark bool) image.Image {
|
||||
S := float64(n)
|
||||
side := S - 2*inset
|
||||
radius := side * 0.225
|
||||
k := side * 0.8 / 44
|
||||
o := inset + side/2 - 22*k
|
||||
ss := 4
|
||||
@@ -315,6 +345,46 @@ func app(n int, dark bool) image.Image {
|
||||
return img
|
||||
}
|
||||
|
||||
// trayICOSizes are the sizes Windows asks a tray icon for (SM_CXSMICON):
|
||||
// 16px at 100% scaling, 20, 24, 32 and 40 at 125% to 250%, and 48 and 64
|
||||
// beyond. Wails picks the one it needs from the .ico, where a single PNG
|
||||
// was scaled down by the system and blurred.
|
||||
var trayICOSizes = []int{16, 20, 24, 32, 40, 48, 64}
|
||||
|
||||
// winICO writes win's tile at each size into one .ico, each image a PNG
|
||||
// (Windows Vista on reads them).
|
||||
func winICO(out string, sizes []int) error {
|
||||
var pngs [][]byte
|
||||
for _, n := range sizes {
|
||||
var b bytes.Buffer
|
||||
if err := png.Encode(&b, win(n)); err != nil {
|
||||
return err
|
||||
}
|
||||
pngs = append(pngs, b.Bytes())
|
||||
}
|
||||
var ico bytes.Buffer
|
||||
le := binary.LittleEndian
|
||||
ico.Write(le.AppendUint16(le.AppendUint16(le.AppendUint16(nil, 0), 1), uint16(len(sizes))))
|
||||
at := 6 + 16*len(sizes)
|
||||
for i, n := range sizes {
|
||||
d := byte(n)
|
||||
if n >= 256 {
|
||||
d = 0
|
||||
}
|
||||
e := []byte{d, d, 0, 0}
|
||||
e = le.AppendUint16(e, 1) // planes
|
||||
e = le.AppendUint16(e, 32) // bits per pixel
|
||||
e = le.AppendUint32(e, uint32(len(pngs[i])))
|
||||
e = le.AppendUint32(e, uint32(at))
|
||||
ico.Write(e)
|
||||
at += len(pngs[i])
|
||||
}
|
||||
for _, p := range pngs {
|
||||
ico.Write(p)
|
||||
}
|
||||
return os.WriteFile(out, ico.Bytes(), 0o644)
|
||||
}
|
||||
|
||||
// coverage rasterises a shape, scaled by k and moved to (ox, oy), onto an n×n
|
||||
// grid of pixels with ss×ss samples each, and gives each pixel's coverage in
|
||||
// 0..1. It fills even-odd, a scanline at a time.
|
||||
|
||||
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 459 B After Width: | Height: | Size: 485 B |
|
After Width: | Height: | Size: 648 B |
|
After Width: | Height: | Size: 800 B |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 948 B After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.1 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"RT_GROUP_ICON": {
|
||||
"#3": {
|
||||
"0000": ["icon-256.png", "icon-128.png", "icon-64.png", "icon-48.png", "icon-32.png", "icon-16.png"]
|
||||
"0000": ["icon-256.png", "icon-128.png", "icon-64.png", "icon-48.png", "icon-40.png", "icon-32.png", "icon-24.png", "icon-20.png", "icon-16.png"]
|
||||
}
|
||||
},
|
||||
"RT_MANIFEST": {
|
||||
|
||||
@@ -42,8 +42,12 @@ var trayIcon []byte // black glyph, tinted by the macOS menu bar
|
||||
//go:embed trayflap/*.png
|
||||
var trayFlap embed.FS
|
||||
|
||||
//go:embed icon.png
|
||||
var appIcon []byte // coloured, for Windows' tray
|
||||
// winTrayIcon is the tile for Windows' tray, at each size it asks for
|
||||
// (build/icon/gen.go win-ico): filling its square as the icons beside it
|
||||
// do, where the Mac's tile with its clear margin looked a size smaller.
|
||||
//
|
||||
//go:embed icon-windows.ico
|
||||
var winTrayIcon []byte
|
||||
|
||||
// The app's own icon: the Mac's Dock (which it replaces the bundle's .icns
|
||||
// in, at up to 512pt), window icons and the about box. At 64px it was
|
||||
|
||||
|
After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -56,7 +56,7 @@ func trayIconFor(goos string, light bool) (icon []byte, template bool) {
|
||||
case "linux":
|
||||
return linuxTrayIcon(light), false
|
||||
}
|
||||
return appIcon, false
|
||||
return winTrayIcon, false
|
||||
}
|
||||
|
||||
// linuxTrayIcon is the glyph for a desktop whose colour scheme preference
|
||||
|
||||
@@ -57,8 +57,8 @@ func TestTrayIconPerOS(t *testing.T) {
|
||||
if icon, template := trayIconFor("darwin", false); !template || !bytes.Equal(icon, trayIcon) {
|
||||
t.Errorf("darwin: want the template bird")
|
||||
}
|
||||
if icon, template := trayIconFor("windows", false); template || !bytes.Equal(icon, appIcon) {
|
||||
t.Errorf("windows: want the app's own icon")
|
||||
if icon, template := trayIconFor("windows", false); template || !bytes.Equal(icon, winTrayIcon) {
|
||||
t.Errorf("windows: want the Windows tile")
|
||||
}
|
||||
if img, _ := png.Decode(bytes.NewReader(trayGlyph(trayGlyphLight))); img == nil || img.ColorModel() != color.NRGBAModel {
|
||||
t.Errorf("trayGlyph: want an NRGBA png, got %T", img)
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//go:build !nogui
|
||||
|
||||
package gui
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"image"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Windows draws an app's icon to the edges of its square. Made on the
|
||||
// Mac's grid, magpie's tile was 80% of it and looked a size smaller than
|
||||
// its neighbours in the taskbar, the tray and Start (dzxx0496). Each
|
||||
// picture the exe's icon group lists (the taskbar, the window, Start's
|
||||
// shortcut) and each size of the tray's .ico is a tile over at least
|
||||
// 15/16 of its side, centred, and opaque in the middle.
|
||||
func TestWindowsIconsFillTheirSquare(t *testing.T) {
|
||||
var res struct {
|
||||
Group map[string]map[string][]string `json:"RT_GROUP_ICON"`
|
||||
}
|
||||
b, err := os.ReadFile(filepath.Join("..", "..", "build", "windows", "winres.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := json.Unmarshal(b, &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files := map[string][]byte{}
|
||||
for _, f := range res.Group["#3"]["0000"] {
|
||||
b, err := os.ReadFile(filepath.Join("..", "..", "build", "windows", f))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files["build/windows/"+f] = b
|
||||
}
|
||||
if len(files) == 0 {
|
||||
t.Fatal("winres.json lists no icon for group #3")
|
||||
}
|
||||
ico := winTrayIcon
|
||||
le := binary.LittleEndian
|
||||
if len(ico) < 6 || le.Uint16(ico[2:]) != 1 {
|
||||
t.Fatal("icon-windows.ico is not an .ico")
|
||||
}
|
||||
n := int(le.Uint16(ico[4:]))
|
||||
sizes := map[int]bool{}
|
||||
for i := range n {
|
||||
e := ico[6+16*i:]
|
||||
size, at := int(le.Uint32(e[8:])), int(le.Uint32(e[12:]))
|
||||
files["icon-windows.ico#"+string(rune('0'+i))] = ico[at : at+size]
|
||||
sizes[int(e[0])] = true
|
||||
}
|
||||
for _, s := range []int{16, 24, 32} {
|
||||
if !sizes[s] {
|
||||
t.Errorf("icon-windows.ico has no %dpx picture", s)
|
||||
}
|
||||
}
|
||||
for name, b := range files {
|
||||
img, err := png.Decode(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
r := img.Bounds()
|
||||
box := image.Rectangle{Min: r.Max, Max: r.Min}
|
||||
for y := r.Min.Y; y < r.Max.Y; y++ {
|
||||
for x := r.Min.X; x < r.Max.X; x++ {
|
||||
if _, _, _, a := img.At(x, y).RGBA(); a > 0 {
|
||||
box = box.Union(image.Rect(x, y, x+1, y+1))
|
||||
}
|
||||
}
|
||||
}
|
||||
if box.Dx()*16 < r.Dx()*15 || box.Dy()*16 < r.Dy()*15 || box.Min.X-r.Min.X != r.Max.X-box.Max.X {
|
||||
t.Errorf("%s: tile %v in %v, want at least 15/16 of the side, centred", name, box, r)
|
||||
}
|
||||
if _, _, _, a := img.At(r.Dx()/2, r.Dy()/8).RGBA(); a != 0xffff {
|
||||
t.Errorf("%s: the tile is not opaque inside", name)
|
||||
}
|
||||
}
|
||||
}
|
||||