Smooth edges, logo/clock/tray colors, hidden icons fix

This commit is contained in:
2026-11-06 11:33:14 +00:00
parent 89f60ce5b8
commit c4f2291136
3 changed files with 458 additions and 177 deletions
+33 -154
View File
@@ -22,7 +22,6 @@
package main package main
import ( import (
"math"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@@ -677,11 +676,31 @@ func appIndexAt(hwnd uintptr, x int32) int {
return -1 return -1
} }
// The bar is painted in layers (see render.go): one layer holds only the
// backgrounds and hover fills, another only the icons, text and symbols.
var layerFills, layerFg = true, true
// fill paints a background or hover rectangle (background layer only).
func fill(hdc uintptr, r rect, color uintptr) { func fill(hdc uintptr, r rect, color uintptr) {
if layerFills {
fillRaw(hdc, r, color)
}
}
// fillFg paints a solid piece of a symbol (foreground layer only).
func fillFg(hdc uintptr, r rect, color uintptr) {
if layerFg {
fillRaw(hdc, r, color)
}
}
func fillRaw(hdc uintptr, r rect, color uintptr) {
{
b, _, _ := pCreateSolidBrush.Call(color) b, _, _ := pCreateSolidBrush.Call(color)
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b) pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b)
pDeleteObject.Call(b) pDeleteObject.Call(b)
} }
}
func drawTextFmt(hdc uintptr, s string, r rect, format uintptr) { func drawTextFmt(hdc uintptr, s string, r rect, format uintptr) {
w := u16(s) w := u16(s)
@@ -707,17 +726,17 @@ func drawLogo(hdc uintptr, r rect) {
total := sq*2 + gap total := sq*2 + gap
x := r.Left + (r.Right-r.Left-total)/2 x := r.Left + (r.Right-r.Left-total)/2
y := r.Top + (r.Bottom-r.Top-total)/2 y := r.Top + (r.Bottom-r.Top-total)/2
c := rgb(0, 120, 212) c := logoColor()
fill(hdc, rect{x, y, x + sq, y + sq}, c) fillFg(hdc, rect{x, y, x + sq, y + sq}, c)
fill(hdc, rect{x + sq + gap, y, x + total, y + sq}, c) fillFg(hdc, rect{x + sq + gap, y, x + total, y + sq}, c)
fill(hdc, rect{x, y + sq + gap, x + sq, y + total}, c) fillFg(hdc, rect{x, y + sq + gap, x + sq, y + total}, c)
fill(hdc, rect{x + sq + gap, y + sq + gap, x + total, y + total}, c) fillFg(hdc, rect{x + sq + gap, y + sq + gap, x + total, y + total}, c)
} }
func drawClock(hdc uintptr, r rect) { func drawClock(hdc uintptr, r rect) {
now := time.Now() now := time.Now()
pSetBkMode.Call(hdc, transparent) pSetBkMode.Call(hdc, transparent)
pSetTextColor.Call(hdc, rgb(245, 245, 245)) pSetTextColor.Call(hdc, clockColor())
// Time and date on one line, like "11:32 PM 11/5/2026". // Time and date on one line, like "11:32 PM 11/5/2026".
old, _, _ := pSelectObject.Call(hdc, fontTime) old, _, _ := pSelectObject.Call(hdc, fontTime)
drawText(hdc, now.Format("3:04 PM 1/2/2006"), r) drawText(hdc, now.Format("3:04 PM 1/2/2006"), r)
@@ -744,7 +763,7 @@ func drawApps(hdc uintptr, w, h int32) {
fill(hdc, inner, rgb(40, 40, 48)) fill(hdc, inner, rgb(40, 40, 48))
} }
if !vertical { if !vertical && layerFg {
drawAppGlyph(hdc, inner, a) drawAppGlyph(hdc, inner, a)
} }
} }
@@ -773,152 +792,6 @@ func premul(c uint32, a uint32) uint32 {
return a<<24 | r<<16 | g<<8 | b return a<<24 | r<<16 | g<<8 | b
} }
// redraw paints the whole bar into a 32 bit bitmap, sets each pixel's
// transparency (background pixels get the chosen see-through level, everything
// drawn on top stays solid) and hands it to Windows as a layered window.
// A vertical bar is drawn horizontally first and then turned a quarter turn;
// the icons and symbols are then drawn again upright on top.
func redraw(hwnd uintptr) {
if hwnd == 0 {
return
}
// Shrink or grow the pill to fit what is in it, staying centered where it is.
pw, ph := pillSize()
var crc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
x, y := pillPos(pw, ph)
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
}
w, h := clientSize(hwnd)
if w <= 0 || h <= 0 {
return
}
screen, _, _ := pGetDC.Call(0)
defer pReleaseDC.Call(0, screen)
mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
rc := rect{0, 0, w, h}
fill(mem, rc, rgb(22, 22, 26))
cx := w / 2
sr := rect{cx - startWidth(), 0, cx, h}
if hoverStart {
fill(mem, sr, rgb(58, 58, 68))
}
drawLogo(mem, sr)
drawApps(mem, w, h)
drawTray(mem, w, h)
pGdiFlush.Call()
// The finished picture: same as above for a horizontal bar.
fmem, fbits, fw, fh := mem, bits, w, h
if vertical {
fw, fh = h, w
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
var bitsV unsafe.Pointer
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
if bmpV == 0 || bitsV == nil {
return
}
defer pDeleteObject.Call(bmpV)
memV, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(memV)
oldV, _, _ := pSelectObject.Call(memV, bmpV)
defer pSelectObject.Call(memV, oldV)
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
for y := int32(0); y < h; y++ {
for x := int32(0); x < w; x++ {
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
}
}
// Icons and symbols go back on upright.
for i, r := range appRects(w, h) {
if i < len(apps) {
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
}
}
for _, it := range trayItems(w, h) {
r := mapRect(it.r, h)
switch it.kind {
case trayBattery:
drawBattery(memV, r)
case trayVolume:
drawVolume(memV, r)
case trayWifi:
drawNetwork(memV, r)
case trayChevron:
drawChevron(memV, r)
}
}
pGdiFlush.Call()
fmem, fbits = memV, bitsV
}
pix := unsafe.Slice((*uint32)(fbits), int(fw)*int(fh))
a := uint32(bgAlpha)
hoverA := max(a, 120)
activeA := max(a, 150)
length := float64(max(fw, fh))
rad := float64(min(fw, fh)) / 2
for i, p := range pix {
c := p & 0x00FFFFFF
// Pill shape: how much of this pixel is inside the rounded ends.
along := float64(i%int(fw)) + 0.5
across := float64(i/int(fw)) + 0.5
if vertical {
along, across = across, along
}
da := 0.0
if along < rad {
da = rad - along
} else if along > length-rad {
da = along - (length - rad)
}
cov := rad - math.Hypot(da, across-rad) + 0.5
cov = math.Max(0, math.Min(1, cov))
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
switch c {
case colBg:
pix[i] = premul(c, sc(a))
case colHStart, colHApp:
pix[i] = premul(c, sc(hoverA))
case colActive:
pix[i] = premul(c, sc(activeA))
default:
pix[i] = premul(c, sc(255))
}
}
var wr rect
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
dst := point{wr.Left, wr.Top}
sz := size{fw, fh}
src := point{0, 0}
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
pUpdateLayeredWindow.Call(hwnd, screen,
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
fmem, uintptr(unsafe.Pointer(&src)), 0,
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
}
func inStart(hwnd uintptr, x int32) bool { func inStart(hwnd uintptr, x int32) bool {
w, _ := clientSize(hwnd) w, _ := clientSize(hwnd)
cx := w / 2 cx := w / 2
@@ -1029,6 +902,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
add(flags, uintptr(menuLevelBase+i), "Background: "+l.name) add(flags, uintptr(menuLevelBase+i), "Background: "+l.name)
} }
sep() sep()
addColorMenus(menu)
sep()
orientText := "Switch to vertical" orientText := "Switch to vertical"
if vertical { if vertical {
orientText = "Switch to horizontal" orientText = "Switch to horizontal"
@@ -1067,6 +942,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
pDestroyWindow.Call(hwnd) pDestroyWindow.Call(hwnd)
case cmd == menuResetPosID: case cmd == menuResetPosID:
resetPos(hwnd) resetPos(hwnd)
case handleColorCommand(cmd):
redraw(hwnd)
case cmd == menuOrientID: case cmd == menuOrientID:
vertical = !vertical vertical = !vertical
saveOrient() saveOrient()
@@ -1281,6 +1158,8 @@ func main() {
fontTime = makeFont(px(13), 400) fontTime = makeFont(px(13), 400)
fontDate = makeFont(px(11), 400) fontDate = makeFont(px(11), 400)
fontApp = makeFont(px(12), 600) fontApp = makeFont(px(12), 600)
initSuperFonts()
loadColors()
autoQuit = autoQuitDef autoQuit = autoQuitDef
if hasArg("--forever") || strings.Contains(name, "forever") { if hasArg("--forever") || strings.Contains(name, "forever") {
+381
View File
@@ -0,0 +1,381 @@
package main
// Painting the bar smoothly on a see-through background.
//
// Drawing icons and text straight onto a dark bitmap leaves a dark fringe
// around them once the background is made see-through. So the bar is painted
// in layers: one layer with only the backgrounds, and the icons, text and
// symbols drawn twice (once on black, once on white) at double size. Comparing
// the two copies shows exactly how see-through every edge pixel is, and
// shrinking back down gives smooth edges with no dark outline.
import (
"math"
"os"
"path/filepath"
"strconv"
"strings"
"unsafe"
)
const (
superSample = 2
mfPopup = 0x0010
menuLogoColorBase = 100
menuClockColorBase = 120
menuIconColorBase = 140
)
var (
fontTime2 uintptr
fontApp2 uintptr
)
// initSuperFonts makes the double size fonts used for the smooth pass.
func initSuperFonts() {
scale *= superSample
fontTime2 = makeFont(px(13), 400)
fontApp2 = makeFont(px(12), 600)
scale /= superSample
}
// ---------- colors ----------
type namedColor struct {
name string
r, g, b int
}
var palette = []namedColor{
{"White", 245, 245, 245},
{"Blue", 0, 120, 212},
{"Sky blue", 90, 190, 255},
{"Green", 70, 200, 110},
{"Yellow", 255, 205, 60},
{"Orange", 255, 140, 40},
{"Red", 235, 70, 70},
{"Pink", 255, 125, 195},
{"Purple", 175, 115, 240},
{"Black", 0, 0, 0},
}
var (
logoIdx = 1 // Blue, like the real Windows logo
clockIdx = 0 // White
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
)
func colorOf(i int) uintptr {
if i < 0 || i >= len(palette) {
i = 0
}
c := palette[i]
return rgb(c.r, c.g, c.b)
}
func logoColor() uintptr { return colorOf(logoIdx) }
func clockColor() uintptr { return colorOf(clockIdx) }
func iconColor() uintptr { return colorOf(iconIdx) }
// iconDim is the color of the "off" bars on the volume and wifi icons.
func iconDim() uintptr {
c := palette[iconIdx]
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
return rgb(140, 140, 150)
}
return rgb(110, 110, 120)
}
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
func loadColors() {
b, err := os.ReadFile(colorsFile())
if err != nil {
return
}
parts := strings.Split(strings.TrimSpace(string(b)), ",")
if len(parts) < 2 || len(parts) > 3 {
return
}
vals := []int{0, 0, 0}
for i, p := range parts {
n, err := strconv.Atoi(p)
if err != nil || n < 0 || n >= len(palette) {
return
}
vals[i] = n
}
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
}
func saveColors() {
_ = os.MkdirAll(dataDir(), 0o755)
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
}
// addColorMenus adds the two color pickers as sub menus.
func addColorMenus(menu uintptr) {
build := func(base uintptr, cur int, title string) {
sub, _, _ := pCreatePopupMenu.Call()
for i, c := range palette {
var flags uintptr
if i == cur {
flags = mfChecked
}
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
}
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
}
build(menuLogoColorBase, logoIdx, "Windows logo color")
build(menuClockColorBase, clockIdx, "Clock color")
build(menuIconColorBase, iconIdx, "Tray icon color")
}
func handleColorCommand(cmd uintptr) bool {
n := uintptr(len(palette))
switch {
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
logoIdx = int(cmd - menuLogoColorBase)
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
clockIdx = int(cmd - menuClockColorBase)
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
iconIdx = int(cmd - menuIconColorBase)
default:
return false
}
saveColors()
return true
}
// ---------- painting ----------
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
// and returns its pixels at the real orientation. fills and fg choose which
// parts are painted; base is the color everything is painted onto.
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
layerFills, layerFg = fills, fg
defer func() { layerFills, layerFg = true, true }()
mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return nil
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
fillRaw(mem, rect{0, 0, w, h}, base)
cx := w / 2
sr := rect{cx - startWidth(), 0, cx, h}
if hoverStart {
fill(mem, sr, rgb(58, 58, 68))
}
drawLogo(mem, sr)
drawApps(mem, w, h)
drawTray(mem, w, h)
pGdiFlush.Call()
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
if !vertical {
out := make([]uint32, len(src))
copy(out, src)
return out
}
// Turn a quarter turn, then put the icons and symbols back on upright.
fw, fh := h, w
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
var bitsV unsafe.Pointer
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
if bmpV == 0 || bitsV == nil {
return nil
}
defer pDeleteObject.Call(bmpV)
memV, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(memV)
oldV, _, _ := pSelectObject.Call(memV, bmpV)
defer pSelectObject.Call(memV, oldV)
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
for y := int32(0); y < h; y++ {
for x := int32(0); x < w; x++ {
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
}
}
if fg {
for i, r := range appRects(w, h) {
if i < len(apps) {
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
}
}
for _, it := range trayItems(w, h) {
r := mapRect(it.r, h)
switch it.kind {
case trayBattery:
drawBattery(memV, r)
case trayVolume:
drawVolume(memV, r)
case trayWifi:
drawNetwork(memV, r)
case trayChevron:
drawChevron(memV, r)
}
}
pGdiFlush.Call()
}
out := make([]uint32, len(dst))
copy(out, dst)
return out
}
// avg4 averages the superSample x superSample block of pixels that makes up
// one real pixel, one color channel at a time.
func avg4(p []uint32, stride, x, y int) (r, g, b uint32) {
var sr, sg, sb uint32
for dy := 0; dy < superSample; dy++ {
for dx := 0; dx < superSample; dx++ {
c := p[(y*superSample+dy)*stride+x*superSample+dx]
sr += c >> 16 & 0xFF
sg += c >> 8 & 0xFF
sb += c & 0xFF
}
}
n := uint32(superSample * superSample)
return sr / n, sg / n, sb / n
}
// redraw paints the whole bar and hands it to Windows as a layered window
// with a transparency value for every pixel.
func redraw(hwnd uintptr) {
if hwnd == 0 {
return
}
// Shrink or grow the pill to fit what is in it, staying centered where it is.
pw, ph := pillSize()
var crc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
x, y := pillPos(pw, ph)
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
}
w, h := clientSize(hwnd)
if w <= 0 || h <= 0 {
return
}
fw, fh := w, h
if vertical {
fw, fh = h, w
}
screen, _, _ := pGetDC.Call(0)
defer pReleaseDC.Call(0, screen)
// Layer 1: backgrounds, at real size.
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
savedScale, savedTime, savedApp := scale, fontTime, fontApp
scale *= superSample
fontTime, fontApp = fontTime2, fontApp2
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
scale, fontTime, fontApp = savedScale, savedTime, savedApp
n := int(fw) * int(fh)
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
return
}
// The finished bitmap that Windows will show.
mem, _, _ := pCreateCompatibleDC.Call(screen)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
uintptr(unsafe.Pointer(&bits)), 0, 0)
if bmp == 0 || bits == nil {
return
}
defer pDeleteObject.Call(bmp)
old, _, _ := pSelectObject.Call(mem, bmp)
defer pSelectObject.Call(mem, old)
pix := unsafe.Slice((*uint32)(bits), n)
a := uint32(bgAlpha)
hoverA := max(a, 120)
length := float64(max(fw, fh))
rad := float64(min(fw, fh)) / 2
stride := int(fw) * superSample
for i := range pix {
x, y := i%int(fw), i/int(fw)
// Background layer: the pill color or a hover highlight, at its own see-through level.
c := bgPix[i] & 0x00FFFFFF
bgA := a
if c != colBg {
bgA = hoverA
}
bgR := (c >> 16 & 0xFF) * bgA / 255
bgG := (c >> 8 & 0xFF) * bgA / 255
bgB := (c & 0xFF) * bgA / 255
// Foreground: how solid is this pixel, and what color is it.
br, bgn, bb := avg4(onBlack, stride, x, y)
wr, wg, wb := avg4(onWhite, stride, x, y)
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
// Foreground over background.
inv := 255 - fa
oa := fa + bgA*inv/255
or := fr + bgR*inv/255
og := fg + bgG*inv/255
ob := fb + bgB*inv/255
// Rounded ends: how much of this pixel is inside the pill.
along := float64(x) + 0.5
across := float64(y) + 0.5
if vertical {
along, across = across, along
}
da := 0.0
if along < rad {
da = rad - along
} else if along > length-rad {
da = along - (length - rad)
}
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
}
var wr rect
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
dst := point{wr.Left, wr.Top}
sz := size{fw, fh}
src := point{0, 0}
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
pUpdateLayeredWindow.Call(hwnd, screen,
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
mem, uintptr(unsafe.Pointer(&src)), 0,
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
}
func sub0(a, b uint32) uint32 {
if a > b {
return a - b
}
return 0
}
+41 -20
View File
@@ -145,13 +145,13 @@ func drawBattery(hdc uintptr, r rect) {
t := px(1) t := px(1)
left := cx - (bw+nubW)/2 left := cx - (bw+nubW)/2
top := cy - bh/2 top := cy - bh/2
white := rgb(245, 245, 245) white := iconColor()
fill(hdc, rect{left, top, left + bw, top + t}, white) fillFg(hdc, rect{left, top, left + bw, top + t}, white)
fill(hdc, rect{left, top + bh - t, left + bw, top + bh}, white) fillFg(hdc, rect{left, top + bh - t, left + bw, top + bh}, white)
fill(hdc, rect{left, top, left + t, top + bh}, white) fillFg(hdc, rect{left, top, left + t, top + bh}, white)
fill(hdc, rect{left + bw - t, top, left + bw, top + bh}, white) fillFg(hdc, rect{left + bw - t, top, left + bw, top + bh}, white)
fill(hdc, rect{left + bw, cy - nubH/2, left + bw + nubW, cy + nubH/2}, white) fillFg(hdc, rect{left + bw, cy - nubH/2, left + bw + nubW, cy + nubH/2}, white)
col := white col := white
switch { switch {
@@ -166,15 +166,15 @@ func drawBattery(hdc uintptr, r rect) {
if battPct > 0 && fw < px(1) { if battPct > 0 && fw < px(1) {
fw = px(1) fw = px(1)
} }
fill(hdc, rect{left + gap, top + gap, left + gap + fw, top + bh - gap}, col) fillFg(hdc, rect{left + gap, top + gap, left + gap + fw, top + bh - gap}, col)
} }
func drawVolume(hdc uintptr, r rect) { func drawVolume(hdc uintptr, r rect) {
cx, cy := center(r) cx, cy := center(r)
white, dim := rgb(245, 245, 245), rgb(110, 110, 120) white, dim := iconColor(), iconDim()
x0 := cx - px(9) x0 := cx - px(9)
fill(hdc, rect{x0, cy - px(3), x0 + px(3), cy + px(3)}, white) fillFg(hdc, rect{x0, cy - px(3), x0 + px(3), cy + px(3)}, white)
polygon(hdc, []point{ polygon(hdc, []point{
{x0 + px(3), cy - px(3)}, {x0 + px(3), cy - px(3)},
{x0 + px(7), cy - px(6)}, {x0 + px(7), cy - px(6)},
@@ -200,7 +200,7 @@ func drawVolume(hdc uintptr, r rect) {
if i < active { if i < active {
col = white col = white
} }
fill(hdc, rect{bx, cy - heights[i]/2, bx + px(2), cy + heights[i]/2}, col) fillFg(hdc, rect{bx, cy - heights[i]/2, bx + px(2), cy + heights[i]/2}, col)
} }
if volMuted { if volMuted {
polyline(hdc, []point{{x0 + px(10), cy - px(4)}, {x0 + px(17), cy + px(4)}}, px(1), white) polyline(hdc, []point{{x0 + px(10), cy - px(4)}, {x0 + px(17), cy + px(4)}}, px(1), white)
@@ -210,18 +210,18 @@ func drawVolume(hdc uintptr, r rect) {
func drawNetwork(hdc uintptr, r rect) { func drawNetwork(hdc uintptr, r rect) {
cx, cy := center(r) cx, cy := center(r)
white, dim := rgb(245, 245, 245), rgb(110, 110, 120) white, dim := iconColor(), iconDim()
if netKind == netWired { if netKind == netWired {
t := px(1) t := px(1)
l, tp := cx-px(7), cy-px(6) l, tp := cx-px(7), cy-px(6)
w, h := px(14), px(9) w, h := px(14), px(9)
fill(hdc, rect{l, tp, l + w, tp + t}, white) fillFg(hdc, rect{l, tp, l + w, tp + t}, white)
fill(hdc, rect{l, tp + h - t, l + w, tp + h}, white) fillFg(hdc, rect{l, tp + h - t, l + w, tp + h}, white)
fill(hdc, rect{l, tp, l + t, tp + h}, white) fillFg(hdc, rect{l, tp, l + t, tp + h}, white)
fill(hdc, rect{l + w - t, tp, l + w, tp + h}, white) fillFg(hdc, rect{l + w - t, tp, l + w, tp + h}, white)
fill(hdc, rect{cx - px(1), tp + h, cx + px(1), tp + h + px(3)}, white) fillFg(hdc, rect{cx - px(1), tp + h, cx + px(1), tp + h + px(3)}, white)
fill(hdc, rect{cx - px(4), tp + h + px(3), cx + px(4), tp + h + px(4)}, white) fillFg(hdc, rect{cx - px(4), tp + h + px(3), cx + px(4), tp + h + px(4)}, white)
return return
} }
@@ -243,7 +243,7 @@ func drawNetwork(hdc uintptr, r rect) {
if i < bars { if i < bars {
col = white col = white
} }
fill(hdc, rect{x, baseY - heights[i], x + px(2), baseY}, col) fillFg(hdc, rect{x, baseY - heights[i], x + px(2), baseY}, col)
x += px(4) x += px(4)
} }
if netKind == netNone { if netKind == netNone {
@@ -255,7 +255,7 @@ func drawNetwork(hdc uintptr, r rect) {
func drawChevron(hdc uintptr, r rect) { func drawChevron(hdc uintptr, r rect) {
cx, cy := center(r) cx, cy := center(r)
polyline(hdc, []point{{cx - px(5), cy + px(2)}, {cx, cy - px(3)}, {cx + px(5), cy + px(2)}}, polyline(hdc, []point{{cx - px(5), cy + px(2)}, {cx, cy - px(3)}, {cx + px(5), cy + px(2)}},
px(1.5), rgb(245, 245, 245)) px(1.5), iconColor())
} }
func drawTray(hdc uintptr, w, h int32) { func drawTray(hdc uintptr, w, h int32) {
@@ -263,7 +263,7 @@ func drawTray(hdc uintptr, w, h int32) {
if it.kind == hoverTray { if it.kind == hoverTray {
fill(hdc, rect{it.r.Left + px(1), it.r.Top + px(3), it.r.Right - px(1), it.r.Bottom - px(3)}, rgb(40, 40, 48)) fill(hdc, rect{it.r.Left + px(1), it.r.Top + px(3), it.r.Right - px(1), it.r.Bottom - px(3)}, rgb(40, 40, 48))
} }
if vertical && it.kind != trayClock { if !layerFg || (vertical && it.kind != trayClock) {
continue // a vertical bar draws these upright, after turning continue // a vertical bar draws these upright, after turning
} }
switch it.kind { switch it.kind {
@@ -534,6 +534,21 @@ func tapChord(mod, k uintptr) {
} }
// trayClick opens the matching Windows panel with its keyboard shortcut. // trayClick opens the matching Windows panel with its keyboard shortcut.
const vkEscape = 0x1B
// overflowOpen reports whether the hidden icons flyout is on screen.
func overflowOpen() bool {
for _, class := range []string{"TopLevelWindowForOverflowXamlIsland", "NotifyIconOverflowWindow"} {
h, _, _ := pFindWindow.Call(uintptr(unsafe.Pointer(u16(class))), 0)
if h != 0 {
if vis, _, _ := pIsWindowVisible.Call(h); vis != 0 {
return true
}
}
}
return false
}
func trayClick(kind int) { func trayClick(kind int) {
switch kind { switch kind {
case trayClock: case trayClock:
@@ -541,6 +556,12 @@ func trayClick(kind int) {
case trayBattery, trayVolume, trayWifi: case trayBattery, trayVolume, trayWifi:
tapChord(vkLWin, 'A') // quick settings tapChord(vkLWin, 'A') // quick settings
case trayChevron: case trayChevron:
// If the hidden icons are already showing, a second click closes them. Sending
// Win+B and Enter again would instead press Enter on the highlighted icon.
if overflowOpen() {
tapKey(vkEscape)
return
}
// Win+B moves focus to the notification area; Enter opens the hidden icons. // Win+B moves focus to the notification area; Enter opens the hidden icons.
tapChord(vkLWin, 'B') tapChord(vkLWin, 'B')
time.Sleep(150 * time.Millisecond) time.Sleep(150 * time.Millisecond)