From 572d64c280b5b51395c1a64da0e42558ef5d392c Mon Sep 17 00:00:00 2001 From: weishaupt <1+weishaupt@noreply.localhost> Date: Sun, 8 Nov 2026 03:52:53 +0000 Subject: [PATCH] MirrorBar+ panels follow the bar transparency, part 1 --- README.md | 2 ++ flyout.go | 84 +++++++++++++++++++++++++-------------------------- newsflyout.go | 9 +++--- radardraw.go | 3 +- sysflyout.go | 13 ++++---- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 9392bb1..68e8a49 100644 --- a/README.md +++ b/README.md @@ -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. +- 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. - 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. diff --git a/flyout.go b/flyout.go index 7ceb892..03f1256 100644 --- a/flyout.go +++ b/flyout.go @@ -106,7 +106,7 @@ func weatherInit(inst uintptr) { wc.Size = uint32(unsafe.Sizeof(wc)) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) wxHwnd, _, _ = pCreateWindowEx.Call( - wsExToolWindow|wsExTopmost|wsExNoActivate, + wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered, uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16(""))), wsPopup, @@ -223,7 +223,7 @@ func weatherPlace() { x = clampI(x, 0, sw-cw) y = clampI(y, 0, sh-ch) 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 @@ -302,44 +302,13 @@ func wxMakeFonts() { func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) } -// flyPaint paints a panel at double size into a memory bitmap with the given -// drawing function, then shrinks it onto the window. +// flyPaint answers a paint request: the panel is rendered see-through (see +// flyrender.go) instead of being painted by Windows. func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) { var ps paintStruct - hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) - defer pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) - - 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) + pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) + pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps))) + flyRender(hwnd, draw) } var ( @@ -362,8 +331,7 @@ func wxText(hdc uintptr, s string, r rect, font, col, flags uintptr) { // here is a double size distance. func wxDraw(hdc uintptr, W, H int32) { u := px - fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color - fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack) + flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting pad := u(14) inner := W - 2*pad @@ -512,8 +480,40 @@ func wxSunGlyph(hdc uintptr, cx, cy, s float64) { } func wxCrescent(hdc uintptr, cx, cy, rad float64) { - wxCircle(hdc, cx, cy, rad, rgb(235, 232, 205)) - wxCircle(hdc, cx+0.45*rad, cy-0.25*rad, 0.85*rad, colBack) + brush, _, _ := pCreateSolidBrush.Call(rgb(235, 232, 205)) + 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. diff --git a/newsflyout.go b/newsflyout.go index e6e7777..3dc8db9 100644 --- a/newsflyout.go +++ b/newsflyout.go @@ -65,7 +65,7 @@ func newsInit(inst uintptr) { wc.Size = uint32(unsafe.Sizeof(wc)) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) newsHwnd, _, _ = pCreateWindowEx.Call( - wsExToolWindow|wsExTopmost|wsExNoActivate, + wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered, uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16(""))), wsPopup, @@ -168,7 +168,7 @@ func newsPlace() { lh = newsHead + float64(newsVisible)*newsRow + newsFoot } flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh)) - pInvalidateRect.Call(newsHwnd, 0, 1) + flyRefresh(newsHwnd) } // newsDone runs when a download finishes. @@ -202,7 +202,7 @@ func newsPoll() { } if h != newsHover { 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) { u := px - fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color - fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack) + flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting pad := u(14) s := newsSnapshot() diff --git a/radardraw.go b/radardraw.go index 9b251e1..5c454c2 100644 --- a/radardraw.go +++ b/radardraw.go @@ -37,8 +37,7 @@ func radarAdvance() { } rdHold = 0 rdIdx = (rdIdx + 1) % n - rc := rect{px(14), px(226), px(14 + 312), px(226 + 150)} - pInvalidateRect.Call(wxHwnd, uintptr(unsafe.Pointer(&rc)), 0) + flyRefresh(wxHwnd) } func radarBox(hdc uintptr, r rect) { diff --git a/sysflyout.go b/sysflyout.go index 12b7739..95b23ef 100644 --- a/sysflyout.go +++ b/sysflyout.go @@ -66,7 +66,7 @@ func sysInit(inst uintptr) { wc.Size = uint32(unsafe.Sizeof(wc)) pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc))) sysHwnd, _, _ = pCreateWindowEx.Call( - wsExToolWindow|wsExTopmost|wsExNoActivate, + wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered, uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16(""))), wsPopup, @@ -91,7 +91,7 @@ func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) { case wmTimer: if wparam == sysRefreshTimerID { sysRows = sysGather() // uptime and memory move - pInvalidateRect.Call(sysHwnd, 0, 0) + flyRefresh(sysHwnd) return 0 } sysPoll() @@ -172,7 +172,7 @@ func sysPlace() { } lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot 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. @@ -214,7 +214,7 @@ func sysPoll() { changed = true } if changed { - pInvalidateRect.Call(sysHwnd, 0, 0) + flyRefresh(sysHwnd) } } @@ -225,7 +225,7 @@ func sysCopy(text, what string) { sysCopied = "Copy failed" } sysCopiedAt = time.Now() - pInvalidateRect.Call(sysHwnd, 0, 0) + flyRefresh(sysHwnd) } func sysClick(x, y int32) { @@ -242,8 +242,7 @@ func sysClick(x, y int32) { func sysDraw(hdc uintptr, W, H int32) { u := px - fillRaw(hdc, rect{0, 0, W, H}, iconColor()) // the outline follows the tray icon color - fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack) + flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting pad := u(14) line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)