MirrorBar+ panels follow the bar transparency, part 1

This commit is contained in:
2026-11-08 03:52:53 +00:00
parent db0249bc14
commit 572d64c280
5 changed files with 55 additions and 56 deletions
+2
View File
@@ -25,6 +25,8 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
- "Show weather on the bar" and "Show local news on the bar" in the settings window turn either feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back. - "Show weather on the bar" and "Show local news on the bar" in the settings window turn either feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back.
- The weather, news and system stats panels are as see-through as the bar itself: set the bar to Clear and the panels go clear too, with only their text, pictures and outline staying solid. Untick "Panels match the bar's transparency" in the settings window to keep the panels solid.
- Click the little monitor and a panel opens with the usual neofetch information: OS, host, kernel, uptime, resolution, CPU, GPU, memory, each fixed disk, battery and local IP. Click any line to copy it to the clipboard, or click the top of the panel to copy everything as plain text you can paste into other programs. Nothing leaves your PC; it is all read from Windows. - Click the little monitor and a panel opens with the usual neofetch information: OS, host, kernel, uptime, resolution, CPU, GPU, memory, each fixed disk, battery and local IP. Click any line to copy it to the clipboard, or click the top of the panel to copy everything as plain text you can paste into other programs. Nothing leaves your PC; it is all read from Windows.
- Pick the color of the Windows logo, the clock, and the battery/volume/wifi/arrow icons from the right-click menu (white, blue, sky blue, green, yellow, orange, red, pink, purple, black). - Pick the color of the Windows logo, the clock, and the battery/volume/wifi/arrow icons from the right-click menu (white, blue, sky blue, green, yellow, orange, red, pink, purple, black).
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons. - "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
+42 -42
View File
@@ -106,7 +106,7 @@ func weatherInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc)) wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
wxHwnd, _, _ = pCreateWindowEx.Call( wxHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate, wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))), uintptr(unsafe.Pointer(u16(""))),
wsPopup, wsPopup,
@@ -223,7 +223,7 @@ func weatherPlace() {
x = clampI(x, 0, sw-cw) x = clampI(x, 0, sw-cw)
y = clampI(y, 0, sh-ch) y = clampI(y, 0, sh-ch)
pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow) pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
pInvalidateRect.Call(wxHwnd, 0, 1) flyRefresh(wxHwnd)
} }
// weatherPoll closes the panel when a mouse button goes down anywhere outside // weatherPoll closes the panel when a mouse button goes down anywhere outside
@@ -302,44 +302,13 @@ func wxMakeFonts() {
func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) } func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) }
// flyPaint paints a panel at double size into a memory bitmap with the given // flyPaint answers a paint request: the panel is rendered see-through (see
// drawing function, then shrinks it onto the window. // flyrender.go) instead of being painted by Windows.
func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) { func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
var ps paintStruct var ps paintStruct
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
defer pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
flyRender(hwnd, draw)
var rc rect
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
if W <= 0 || H <= 0 {
return
}
const ss = 2
mem, _, _ := pCreateCompatibleDC.Call(hdc)
defer pDeleteDC.Call(mem)
bmi := bitmapInfoHeader{Width: W * ss, Height: -(H * ss), Planes: 1, BitCount: 32}
bmi.Size = uint32(unsafe.Sizeof(bmi))
var bits unsafe.Pointer
bmp, _, _ := pCreateDIBSection.Call(hdc, 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)
saved := scale
defer func() { scale = saved }()
scale *= ss
wxMakeFonts()
draw(mem, W*ss, H*ss)
scale = saved
pSetStretchBltMode.Call(hdc, halftone)
pSetBrushOrgEx.Call(hdc, 0, 0, 0)
pStretchBlt.Call(hdc, 0, 0, uintptr(W), uintptr(H), mem, 0, 0, uintptr(W*ss), uintptr(H*ss), srcCopy)
} }
var ( var (
@@ -362,8 +331,7 @@ func wxText(hdc uintptr, s string, r rect, font, col, flags uintptr) {
// here is a double size distance. // here is a double size distance.
func wxDraw(hdc uintptr, W, H int32) { func wxDraw(hdc uintptr, W, H int32) {
u := px u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
pad := u(14) pad := u(14)
inner := W - 2*pad inner := W - 2*pad
@@ -512,8 +480,40 @@ func wxSunGlyph(hdc uintptr, cx, cy, s float64) {
} }
func wxCrescent(hdc uintptr, cx, cy, rad float64) { func wxCrescent(hdc uintptr, cx, cy, rad float64) {
wxCircle(hdc, cx, cy, rad, rgb(235, 232, 205)) brush, _, _ := pCreateSolidBrush.Call(rgb(235, 232, 205))
wxCircle(hdc, cx+0.45*rad, cy-0.25*rad, 0.85*rad, colBack) defer pDeleteObject.Call(brush)
ix, iy, ir := cx+0.45*rad, cy-0.25*rad, 0.85*rad // the circle that is cut out
top := int32(math.Round(cy))
r := int32(math.Ceil(rad))
for dy := -r; dy <= r; dy++ {
y := top + dy
oh2 := rad*rad - float64(dy)*float64(dy)
if oh2 <= 0 {
continue
}
oh := math.Sqrt(oh2)
x0, x1 := cx-oh, cx+oh
var segs [][2]float64
fy := float64(y) + 0.5 - iy
if ih2 := ir*ir - fy*fy; ih2 > 0 {
ih := math.Sqrt(ih2)
if l := ix - ih; l > x0 {
segs = append(segs, [2]float64{x0, math.Min(l, x1)})
}
if rr := ix + ih; rr < x1 {
segs = append(segs, [2]float64{math.Max(rr, x0), x1})
}
} else {
segs = append(segs, [2]float64{x0, x1})
}
for _, sg := range segs {
if sg[1]-sg[0] < 0.5 {
continue
}
line := rect{int32(math.Round(sg[0])), y, int32(math.Round(sg[1])), y + 1}
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&line)), brush)
}
}
} }
// wxIcon draws the picture for a kind of weather inside the square r. // wxIcon draws the picture for a kind of weather inside the square r.
+4 -5
View File
@@ -65,7 +65,7 @@ func newsInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc)) wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
newsHwnd, _, _ = pCreateWindowEx.Call( newsHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate, wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))), uintptr(unsafe.Pointer(u16(""))),
wsPopup, wsPopup,
@@ -168,7 +168,7 @@ func newsPlace() {
lh = newsHead + float64(newsVisible)*newsRow + newsFoot lh = newsHead + float64(newsVisible)*newsRow + newsFoot
} }
flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh)) flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh))
pInvalidateRect.Call(newsHwnd, 0, 1) flyRefresh(newsHwnd)
} }
// newsDone runs when a download finishes. // newsDone runs when a download finishes.
@@ -202,7 +202,7 @@ func newsPoll() {
} }
if h != newsHover { if h != newsHover {
newsHover = h newsHover = h
pInvalidateRect.Call(newsHwnd, 0, 0) flyRefresh(newsHwnd)
} }
} }
@@ -248,8 +248,7 @@ func newsClick(x, y int32) {
func newsDraw(hdc uintptr, W, H int32) { func newsDraw(hdc uintptr, W, H int32) {
u := px u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
pad := u(14) pad := u(14)
s := newsSnapshot() s := newsSnapshot()
+1 -2
View File
@@ -37,8 +37,7 @@ func radarAdvance() {
} }
rdHold = 0 rdHold = 0
rdIdx = (rdIdx + 1) % n rdIdx = (rdIdx + 1) % n
rc := rect{px(14), px(226), px(14 + 312), px(226 + 150)} flyRefresh(wxHwnd)
pInvalidateRect.Call(wxHwnd, uintptr(unsafe.Pointer(&rc)), 0)
} }
func radarBox(hdc uintptr, r rect) { func radarBox(hdc uintptr, r rect) {
+6 -7
View File
@@ -66,7 +66,7 @@ func sysInit(inst uintptr) {
wc.Size = uint32(unsafe.Sizeof(wc)) wc.Size = uint32(unsafe.Sizeof(wc))
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
sysHwnd, _, _ = pCreateWindowEx.Call( sysHwnd, _, _ = pCreateWindowEx.Call(
wsExToolWindow|wsExTopmost|wsExNoActivate, wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(className)),
uintptr(unsafe.Pointer(u16(""))), uintptr(unsafe.Pointer(u16(""))),
wsPopup, wsPopup,
@@ -91,7 +91,7 @@ func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
case wmTimer: case wmTimer:
if wparam == sysRefreshTimerID { if wparam == sysRefreshTimerID {
sysRows = sysGather() // uptime and memory move sysRows = sysGather() // uptime and memory move
pInvalidateRect.Call(sysHwnd, 0, 0) flyRefresh(sysHwnd)
return 0 return 0
} }
sysPoll() sysPoll()
@@ -172,7 +172,7 @@ func sysPlace() {
} }
lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot
flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh)) flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh))
pInvalidateRect.Call(sysHwnd, 0, 1) flyRefresh(sysHwnd)
} }
// sysRowAt is the line under a height in the panel (real pixels), or -1. // sysRowAt is the line under a height in the panel (real pixels), or -1.
@@ -214,7 +214,7 @@ func sysPoll() {
changed = true changed = true
} }
if changed { if changed {
pInvalidateRect.Call(sysHwnd, 0, 0) flyRefresh(sysHwnd)
} }
} }
@@ -225,7 +225,7 @@ func sysCopy(text, what string) {
sysCopied = "Copy failed" sysCopied = "Copy failed"
} }
sysCopiedAt = time.Now() sysCopiedAt = time.Now()
pInvalidateRect.Call(sysHwnd, 0, 0) flyRefresh(sysHwnd)
} }
func sysClick(x, y int32) { func sysClick(x, y int32) {
@@ -242,8 +242,7 @@ func sysClick(x, y int32) {
func sysDraw(hdc uintptr, W, H int32) { func sysDraw(hdc uintptr, W, H int32) {
u := px u := px
fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
pad := u(14) pad := u(14)
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis) line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)