Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
807befdd53 | ||
|
|
7e5cf13afe | ||
|
|
9e6b24268f | ||
|
|
ecde38f9e8 | ||
|
|
1c43c4b4bd | ||
|
|
f8f579252d | ||
|
|
ddfd5a375b | ||
|
|
ed8a7cf275 | ||
|
|
cab30fb5d3 | ||
|
|
171afe6605 | ||
|
|
d72cf82604 | ||
|
|
c4f2291136 |
@@ -8,8 +8,17 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
||||
|
||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
||||
- Drag it anywhere by its background. It remembers where you put it. Right-click and choose "Reset position to bottom center" to send it home.
|
||||
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||
- Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
||||
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
||||
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
||||
- "Open notification center" is in the right-click menu.
|
||||
- Smooth, outline-free icons and text, even when the pill is see-through.
|
||||
- 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.
|
||||
- Background see-through level: Clear, Light, Medium or Solid.
|
||||
- "Start MirrorBar when I sign in" in the right-click menu.
|
||||
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package main
|
||||
|
||||
// Resizing the left half: the center line (where the Start button and the
|
||||
// clock meet) stays put, but the two halves no longer have to be the same
|
||||
// length. Pull the far left end of the pill (the top end when it stands up) and
|
||||
// the empty space shrinks, down to where the buttons touch. Open more apps and
|
||||
// the left half stretches back out to fit them.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
menuResetWidthID = 44
|
||||
|
||||
wmSetCursor = 0x0020
|
||||
idcSizeWE = 32644
|
||||
idcSizeNS = 32645
|
||||
)
|
||||
|
||||
var (
|
||||
pSetCursor = user32.NewProc("SetCursor")
|
||||
|
||||
leftPref int32 // 0: mirror the right half (the original look), -1: hug the buttons, else the chosen length
|
||||
resizing bool
|
||||
resizeFrom int32 // where the cursor was along the bar when the drag began
|
||||
resizeLen int32 // the length of the left half when the drag began
|
||||
)
|
||||
|
||||
func widthFile() string { return filepath.Join(dataDir(), "leftwidth.txt") }
|
||||
|
||||
func loadLeftPref() {
|
||||
b, err := os.ReadFile(widthFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch s := strings.TrimSpace(string(b)); s {
|
||||
case "tight":
|
||||
leftPref = -1
|
||||
case "", "mirror":
|
||||
leftPref = 0
|
||||
default:
|
||||
if n, err := strconv.Atoi(s); err == nil && n > 0 {
|
||||
leftPref = int32(n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveLeftPref() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
s := "mirror"
|
||||
switch {
|
||||
case leftPref < 0:
|
||||
s = "tight"
|
||||
case leftPref > 0:
|
||||
s = strconv.Itoa(int(leftPref))
|
||||
}
|
||||
_ = os.WriteFile(widthFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
// halfLimit is the longest either half may be.
|
||||
func halfLimit() int32 {
|
||||
sw, _ := screenSize()
|
||||
return sw/2 - px(4)
|
||||
}
|
||||
|
||||
// rightHalf is the length of the right half: the tray items plus a little padding.
|
||||
func rightHalf() int32 {
|
||||
items := trayItemsAt(0, 1)
|
||||
return min(items[len(items)-1].r.Right+px(16), halfLimit())
|
||||
}
|
||||
|
||||
// leftContent is the least the left half needs: Start, every app, and padding.
|
||||
func leftContent() int32 {
|
||||
return startWidth() + int32(len(apps))*px(36) + px(16)
|
||||
}
|
||||
|
||||
// leftHalf is the length of the left half.
|
||||
func leftHalf() int32 {
|
||||
lc := leftContent()
|
||||
var h int32
|
||||
switch {
|
||||
case leftPref < 0:
|
||||
h = lc
|
||||
case leftPref > 0:
|
||||
h = max(lc, leftPref)
|
||||
default:
|
||||
h = max(lc, rightHalf())
|
||||
}
|
||||
return min(h, halfLimit())
|
||||
}
|
||||
|
||||
// axisX is where the center line is, along the bar, measured from its start.
|
||||
func axisX(clientW int32) int32 { return leftHalf() }
|
||||
|
||||
// ---------- the drag handle ----------
|
||||
|
||||
func edgeZone(along int32) bool { return along >= 0 && along < px(10) }
|
||||
|
||||
func cursorAlong() int32 {
|
||||
var p point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||
if vertical {
|
||||
return p.Y
|
||||
}
|
||||
return p.X
|
||||
}
|
||||
|
||||
// overEdge reports whether the cursor is on the draggable far end of the pill.
|
||||
func overEdge(hwnd uintptr) bool {
|
||||
var p point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
if p.X < wr.Left || p.X >= wr.Right || p.Y < wr.Top || p.Y >= wr.Bottom {
|
||||
return false
|
||||
}
|
||||
if vertical {
|
||||
return edgeZone(p.Y - wr.Top)
|
||||
}
|
||||
return edgeZone(p.X - wr.Left)
|
||||
}
|
||||
|
||||
func beginResize(hwnd uintptr) {
|
||||
resizing = true
|
||||
resizeFrom = cursorAlong()
|
||||
resizeLen = leftHalf()
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
|
||||
func moveResize(hwnd uintptr) {
|
||||
newLen := resizeLen - (cursorAlong() - resizeFrom)
|
||||
if newLen <= leftContent()+px(10) {
|
||||
leftPref = -1 // pulled all the way in: hug the buttons
|
||||
} else {
|
||||
leftPref = min(newLen, halfLimit())
|
||||
}
|
||||
redraw(hwnd)
|
||||
}
|
||||
|
||||
func endResize(hwnd uintptr) {
|
||||
resizing = false
|
||||
pReleaseCapture.Call()
|
||||
saveLeftPref()
|
||||
redraw(hwnd)
|
||||
}
|
||||
|
||||
func sizeCursor() uintptr {
|
||||
id := uintptr(idcSizeWE)
|
||||
if vertical {
|
||||
id = idcSizeNS
|
||||
}
|
||||
c, _, _ := pLoadCursor.Call(0, id)
|
||||
return c
|
||||
}
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
package main
|
||||
|
||||
// Icon style: colorized or grayscale. It applies to the app
|
||||
// icons (their pixels are filtered) and to everything MirrorBar draws itself
|
||||
// (the logo, clock, battery, volume, wifi and arrow colors).
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
modeColor = 0
|
||||
modeGray = 1
|
||||
|
||||
menuStyleBase = 160
|
||||
)
|
||||
|
||||
var (
|
||||
pGetIconInfo = user32.NewProc("GetIconInfo")
|
||||
pCreateIconIndirect = user32.NewProc("CreateIconIndirect")
|
||||
pDestroyIcon = user32.NewProc("DestroyIcon")
|
||||
pGetObject = gdi32.NewProc("GetObjectW")
|
||||
pGetDIBits = gdi32.NewProc("GetDIBits")
|
||||
|
||||
iconMode = modeColor
|
||||
styleCache = map[styleKey]uintptr{}
|
||||
)
|
||||
|
||||
type styleKey struct {
|
||||
icon uintptr
|
||||
mode int
|
||||
}
|
||||
|
||||
type iconInfo struct {
|
||||
FIcon int32
|
||||
XHot uint32
|
||||
YHot uint32
|
||||
Mask uintptr
|
||||
Color uintptr
|
||||
}
|
||||
|
||||
type bitmapObj struct {
|
||||
Type int32
|
||||
Width int32
|
||||
Height int32
|
||||
WidthBytes int32
|
||||
Planes uint16
|
||||
BitsPixel uint16
|
||||
Bits uintptr
|
||||
}
|
||||
|
||||
var styleNames = []string{"Colorized", "Grayscale"}
|
||||
|
||||
func styleFile() string { return filepath.Join(dataDir(), "iconstyle.txt") }
|
||||
|
||||
func loadIconMode() {
|
||||
b, err := os.ReadFile(styleFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil && n >= 0 && n < len(styleNames) {
|
||||
iconMode = n
|
||||
}
|
||||
}
|
||||
|
||||
func saveIconMode() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(styleFile(), []byte(strconv.Itoa(iconMode)), 0o644)
|
||||
}
|
||||
|
||||
// styleCacheClear throws away the filtered copies of icons.
|
||||
func styleCacheClear() {
|
||||
for _, v := range styleCache {
|
||||
if v != 0 {
|
||||
pDestroyIcon.Call(v)
|
||||
}
|
||||
}
|
||||
styleCache = map[styleKey]uintptr{}
|
||||
}
|
||||
|
||||
// styledIcon is the icon as it should be drawn in the current style.
|
||||
func styledIcon(ic uintptr) uintptr {
|
||||
if ic == 0 || iconMode == modeColor {
|
||||
return ic
|
||||
}
|
||||
k := styleKey{ic, iconMode}
|
||||
if v, ok := styleCache[k]; ok {
|
||||
if v != 0 {
|
||||
return v
|
||||
}
|
||||
return ic
|
||||
}
|
||||
v := makeStyledIcon(ic, iconMode)
|
||||
if len(styleCache) > 300 {
|
||||
styleCacheClear()
|
||||
}
|
||||
styleCache[k] = v
|
||||
if v == 0 {
|
||||
return ic
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// makeStyledIcon returns a filtered copy of an icon, or 0 if it can't be done
|
||||
// (the original is then drawn as it is).
|
||||
func makeStyledIcon(ic uintptr, mode int) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
var ii iconInfo
|
||||
r, _, _ := pGetIconInfo.Call(ic, uintptr(unsafe.Pointer(&ii)))
|
||||
if r == 0 {
|
||||
return 0
|
||||
}
|
||||
defer func() {
|
||||
if ii.Mask != 0 {
|
||||
pDeleteObject.Call(ii.Mask)
|
||||
}
|
||||
if ii.Color != 0 {
|
||||
pDeleteObject.Call(ii.Color)
|
||||
}
|
||||
}()
|
||||
if ii.Color == 0 {
|
||||
return 0 // a two-color icon, leave it
|
||||
}
|
||||
var bm bitmapObj
|
||||
pGetObject.Call(ii.Color, unsafe.Sizeof(bm), uintptr(unsafe.Pointer(&bm)))
|
||||
w, h := int(bm.Width), int(bm.Height)
|
||||
if w <= 0 || h <= 0 || w > 512 || h > 512 {
|
||||
return 0
|
||||
}
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
defer pReleaseDC.Call(0, hdc)
|
||||
bmi := bitmapInfoHeader{Width: int32(w), Height: int32(-h), Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
pix := make([]uint32, w*h)
|
||||
n, _, _ := pGetDIBits.Call(hdc, ii.Color, 0, uintptr(h), uintptr(unsafe.Pointer(&pix[0])),
|
||||
uintptr(unsafe.Pointer(&bmi)), 0)
|
||||
if n == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
for i, p := range pix {
|
||||
a := p >> 24
|
||||
cr, cg, cb := p>>16&0xFF, p>>8&0xFF, p&0xFF
|
||||
y := (cr*299 + cg*587 + cb*114) / 1000 // works on premultiplied pixels too
|
||||
pix[i] = a<<24 | y<<16 | y<<8 | y
|
||||
}
|
||||
|
||||
var bits unsafe.Pointer
|
||||
hb, _, _ := pCreateDIBSection.Call(hdc, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if hb == 0 || bits == nil {
|
||||
return 0
|
||||
}
|
||||
copy(unsafe.Slice((*uint32)(bits), w*h), pix)
|
||||
ni := iconInfo{FIcon: 1, Mask: ii.Mask, Color: hb}
|
||||
nh, _, _ := pCreateIconIndirect.Call(uintptr(unsafe.Pointer(&ni)))
|
||||
pDeleteObject.Call(hb)
|
||||
return nh
|
||||
}
|
||||
|
||||
// styleColor applies the style to a color MirrorBar draws itself.
|
||||
func styleColor(r, g, b int) (int, int, int) {
|
||||
if iconMode == modeGray {
|
||||
y := (r*299 + g*587 + b*114) / 1000
|
||||
return y, y, y
|
||||
}
|
||||
return r, g, b
|
||||
}
|
||||
|
||||
func addStyleMenu(menu uintptr) {
|
||||
sub, _, _ := pCreatePopupMenu.Call()
|
||||
for i, name := range styleNames {
|
||||
var flags uintptr
|
||||
if i == iconMode {
|
||||
flags = mfChecked
|
||||
}
|
||||
pAppendMenu.Call(sub, flags, uintptr(menuStyleBase+i), uintptr(unsafe.Pointer(u16(name))))
|
||||
}
|
||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16("Icon style"))))
|
||||
}
|
||||
|
||||
func handleStyleCommand(cmd uintptr) bool {
|
||||
if cmd < menuStyleBase || cmd >= menuStyleBase+uintptr(len(styleNames)) {
|
||||
return false
|
||||
}
|
||||
iconMode = int(cmd - menuStyleBase)
|
||||
saveIconMode()
|
||||
styleCacheClear()
|
||||
return true
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -303,9 +302,10 @@ type trackMouseEvent struct {
|
||||
|
||||
// appWin is one open window shown as an icon button on the left side of the bar.
|
||||
type appWin struct {
|
||||
hwnd uintptr
|
||||
hwnd uintptr // 0 for a pinned program that has no window open right now
|
||||
title string
|
||||
icon uintptr
|
||||
exe string // full path of the program, "" when unknown
|
||||
}
|
||||
|
||||
type alphaLevel struct {
|
||||
@@ -515,58 +515,18 @@ func fetchIcon(hwnd uintptr) uintptr {
|
||||
return 0
|
||||
}
|
||||
|
||||
// refreshApps re-reads the open windows, keeping existing buttons in their
|
||||
// places and adding new windows at the far end. Returns true if anything changed.
|
||||
func refreshApps(refreshIcons bool) bool {
|
||||
enumFound = enumFound[:0]
|
||||
pEnumWindows.Call(enumCb, 0)
|
||||
|
||||
present := make(map[uintptr]appWin, len(enumFound))
|
||||
for _, f := range enumFound {
|
||||
present[f.hwnd] = f
|
||||
}
|
||||
var next []appWin
|
||||
for _, a := range apps {
|
||||
if f, ok := present[a.hwnd]; ok {
|
||||
a.title = f.title
|
||||
next = append(next, a)
|
||||
delete(present, a.hwnd)
|
||||
}
|
||||
}
|
||||
for _, f := range enumFound {
|
||||
if _, ok := present[f.hwnd]; ok {
|
||||
next = append(next, f)
|
||||
}
|
||||
}
|
||||
for i := range next {
|
||||
if next[i].icon == 0 || refreshIcons {
|
||||
if ic := fetchIcon(next[i].hwnd); ic != 0 {
|
||||
next[i].icon = ic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Titles change constantly (browser tabs, documents) but nothing on the
|
||||
// bar shows them, so only a change in which windows exist, or their icons,
|
||||
// counts as a change.
|
||||
changed := len(next) != len(apps)
|
||||
if !changed {
|
||||
for i := range next {
|
||||
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
apps = next
|
||||
return changed
|
||||
}
|
||||
|
||||
func activateApp(idx int) {
|
||||
if idx < 0 || idx >= len(apps) {
|
||||
return
|
||||
}
|
||||
h := apps[idx].hwnd
|
||||
if h == 0 {
|
||||
// A pinned program with no window: start it.
|
||||
if apps[idx].exe != "" {
|
||||
shellOpen(apps[idx].exe, "")
|
||||
}
|
||||
return
|
||||
}
|
||||
fg, _, _ := pGetForegroundWindow.Call()
|
||||
iconic, _, _ := pIsIconic.Call(h)
|
||||
switch {
|
||||
@@ -591,18 +551,11 @@ func screenSize() (int32, int32) {
|
||||
return int32(w), int32(h)
|
||||
}
|
||||
|
||||
// pillWidth is the width the bar needs: the wider of the two halves, doubled so
|
||||
// the bar stays a mirror image around the center, plus a little padding.
|
||||
// pillWidth is the width the bar needs: the left half plus the right half. By
|
||||
// default the left half is as long as the right one (a mirror image); pulling
|
||||
// the far left end changes that (see barwidth.go).
|
||||
func pillWidth() int32 {
|
||||
sw, _ := screenSize()
|
||||
left := startWidth() + int32(len(apps))*px(36)
|
||||
items := trayItems(0, 1)
|
||||
right := items[len(items)-1].r.Right
|
||||
half := max(left, right) + px(16)
|
||||
if limit := sw/2 - px(4); half > limit {
|
||||
half = limit
|
||||
}
|
||||
return half * 2
|
||||
return leftHalf() + rightHalf()
|
||||
}
|
||||
|
||||
// barGap is the space left under the pill so it stands off the screen edge.
|
||||
@@ -635,29 +588,17 @@ func positionBar(hwnd uintptr) {
|
||||
// too many to fit, the buttons shrink to a minimum width and the oldest run
|
||||
// off the left edge.
|
||||
func appRects(clientW, clientH int32) []rect {
|
||||
n := int32(len(apps))
|
||||
if n == 0 {
|
||||
if len(apps) == 0 {
|
||||
return nil
|
||||
}
|
||||
right := clientW/2 - startWidth()
|
||||
avail := right - px(8)
|
||||
bw := px(36)
|
||||
if avail/n < bw {
|
||||
bw = avail / n
|
||||
}
|
||||
if bw < px(24) {
|
||||
bw = px(24)
|
||||
}
|
||||
rects := make([]rect, n)
|
||||
for i := int32(0); i < n; i++ {
|
||||
r := right - i*bw
|
||||
rects[i] = rect{r - bw, 0, r, clientH}
|
||||
row := rowLayout(clientW, clientH)
|
||||
rects := make([]rect, len(apps))
|
||||
for i := range rects {
|
||||
rects[i] = row[seqOfApp(i)]
|
||||
}
|
||||
return rects
|
||||
}
|
||||
|
||||
// clientSize is the size of the bar in the horizontal layout (length, thickness),
|
||||
// whichever way the real window is turned.
|
||||
func clientSize(hwnd uintptr) (int32, int32) {
|
||||
var rc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||
@@ -677,10 +618,30 @@ func appIndexAt(hwnd uintptr, x int32) int {
|
||||
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) {
|
||||
b, _, _ := pCreateSolidBrush.Call(color)
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b)
|
||||
pDeleteObject.Call(b)
|
||||
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)
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&r)), b)
|
||||
pDeleteObject.Call(b)
|
||||
}
|
||||
}
|
||||
|
||||
func drawTextFmt(hdc uintptr, s string, r rect, format uintptr) {
|
||||
@@ -707,17 +668,17 @@ func drawLogo(hdc uintptr, r rect) {
|
||||
total := sq*2 + gap
|
||||
x := r.Left + (r.Right-r.Left-total)/2
|
||||
y := r.Top + (r.Bottom-r.Top-total)/2
|
||||
c := rgb(0, 120, 212)
|
||||
fill(hdc, rect{x, y, x + sq, y + sq}, c)
|
||||
fill(hdc, rect{x + sq + gap, y, x + total, y + sq}, c)
|
||||
fill(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)
|
||||
c := logoColor()
|
||||
fillFg(hdc, rect{x, y, x + sq, y + sq}, c)
|
||||
fillFg(hdc, rect{x + sq + gap, y, x + total, y + sq}, c)
|
||||
fillFg(hdc, rect{x, y + sq + gap, x + sq, y + total}, c)
|
||||
fillFg(hdc, rect{x + sq + gap, y + sq + gap, x + total, y + total}, c)
|
||||
}
|
||||
|
||||
func drawClock(hdc uintptr, r rect) {
|
||||
now := time.Now()
|
||||
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".
|
||||
old, _, _ := pSelectObject.Call(hdc, fontTime)
|
||||
drawText(hdc, now.Format("3:04 PM 1/2/2006"), r)
|
||||
@@ -744,7 +705,7 @@ func drawApps(hdc uintptr, w, h int32) {
|
||||
fill(hdc, inner, rgb(40, 40, 48))
|
||||
}
|
||||
|
||||
if !vertical {
|
||||
if !vertical && layerFg {
|
||||
drawAppGlyph(hdc, inner, a)
|
||||
}
|
||||
}
|
||||
@@ -756,7 +717,7 @@ func drawAppGlyph(hdc uintptr, r rect, a appWin) {
|
||||
isz := px(16) // the small taskbar icon size
|
||||
if a.icon != 0 {
|
||||
cx, cy := center(r)
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), a.icon, uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
} else if rs := []rune(a.title); len(rs) > 0 {
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
||||
@@ -773,156 +734,10 @@ func premul(c uint32, a uint32) uint32 {
|
||||
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 {
|
||||
w, _ := clientSize(hwnd)
|
||||
cx := w / 2
|
||||
return x >= cx-startWidth() && x < cx
|
||||
w, h := clientSize(hwnd)
|
||||
r := startRect(w, h)
|
||||
return x >= r.Left && x < r.Right
|
||||
}
|
||||
|
||||
func tapWinKey() {
|
||||
@@ -990,37 +805,62 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
add(mfGrayed, 0, strings.ReplaceAll(text, "&", "&&"))
|
||||
sep()
|
||||
|
||||
exe = windowExePath(target)
|
||||
if exe != "" {
|
||||
exe = apps[appIdx].exe
|
||||
if target != 0 && exe == "" {
|
||||
exe = windowExePath(target)
|
||||
}
|
||||
if target == 0 {
|
||||
// A pinned program that isn't running: only launcher options apply.
|
||||
add(0, menuLaunchID, "Open")
|
||||
if exe != "" {
|
||||
add(0, menuFileLocID, "Open file location")
|
||||
}
|
||||
sep()
|
||||
add(0, menuUnpinID, "Unpin from MirrorBar")
|
||||
sep()
|
||||
}
|
||||
if exe != "" && target != 0 {
|
||||
add(0, menuNewWindowID, "Open new window")
|
||||
add(0, menuFileLocID, "Open file location")
|
||||
switch {
|
||||
case isPinned(exe):
|
||||
add(0, menuUnpinID, "Unpin from MirrorBar")
|
||||
case canPin(exe):
|
||||
add(0, menuPinID, "Pin to MirrorBar")
|
||||
default:
|
||||
add(mfGrayed, 0, "Pin to MirrorBar (Store apps can't be pinned)")
|
||||
}
|
||||
sep()
|
||||
}
|
||||
|
||||
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
||||
iconic, _, _ := pIsIconic.Call(target)
|
||||
zoomed, _, _ := pIsZoomed.Call(target)
|
||||
normal := iconic == 0 && zoomed == 0
|
||||
enabled := func(ok bool) uintptr {
|
||||
if ok {
|
||||
return 0
|
||||
if target != 0 {
|
||||
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
||||
iconic, _, _ := pIsIconic.Call(target)
|
||||
zoomed, _, _ := pIsZoomed.Call(target)
|
||||
normal := iconic == 0 && zoomed == 0
|
||||
enabled := func(ok bool) uintptr {
|
||||
if ok {
|
||||
return 0
|
||||
}
|
||||
return mfGrayed
|
||||
}
|
||||
return mfGrayed
|
||||
add(enabled(!normal), menuRestoreID, "Restore")
|
||||
add(enabled(normal), menuMoveID, "Move")
|
||||
add(enabled(normal && style&wsThickFrame != 0), menuSizeID, "Size")
|
||||
add(enabled(iconic == 0 && style&wsMinimizeBox != 0), menuMinimizeID, "Minimize")
|
||||
add(enabled(zoomed == 0 && style&wsMaximizeBox != 0), menuMaximizeID, "Maximize")
|
||||
sep()
|
||||
add(0, menuCloseID, "Close window")
|
||||
sep()
|
||||
}
|
||||
add(enabled(!normal), menuRestoreID, "Restore")
|
||||
add(enabled(normal), menuMoveID, "Move")
|
||||
add(enabled(normal && style&wsThickFrame != 0), menuSizeID, "Size")
|
||||
add(enabled(iconic == 0 && style&wsMinimizeBox != 0), menuMinimizeID, "Minimize")
|
||||
add(enabled(zoomed == 0 && style&wsMaximizeBox != 0), menuMaximizeID, "Maximize")
|
||||
sep()
|
||||
add(0, menuCloseID, "Close window")
|
||||
sep()
|
||||
}
|
||||
|
||||
if appIdx < 0 {
|
||||
addTrayMenu(add, sep, trayKind)
|
||||
}
|
||||
|
||||
add(0, menuNotifyID, "Open notification center")
|
||||
sep()
|
||||
for i, l := range alphaLevels {
|
||||
var flags uintptr
|
||||
if bgAlpha == l.alpha {
|
||||
@@ -1029,6 +869,8 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
add(flags, uintptr(menuLevelBase+i), "Background: "+l.name)
|
||||
}
|
||||
sep()
|
||||
addColorMenus(menu)
|
||||
sep()
|
||||
orientText := "Switch to vertical"
|
||||
if vertical {
|
||||
orientText = "Switch to horizontal"
|
||||
@@ -1039,6 +881,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
posFlags = mfGrayed
|
||||
}
|
||||
add(posFlags, menuResetPosID, "Reset position to bottom center")
|
||||
add(0, menuResetWidthID, "Reset bar width")
|
||||
var autoFlags uintptr
|
||||
if autostartEnabled() {
|
||||
autoFlags = mfChecked
|
||||
@@ -1067,6 +910,12 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
case cmd == menuResetPosID:
|
||||
resetPos(hwnd)
|
||||
case cmd == menuResetWidthID:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwnd)
|
||||
case handleColorCommand(cmd):
|
||||
redraw(hwnd)
|
||||
case cmd == menuOrientID:
|
||||
vertical = !vertical
|
||||
saveOrient()
|
||||
@@ -1075,6 +924,18 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pPostMessage.Call(target, wmClose, 0, 0)
|
||||
case cmd == menuNewWindowID && exe != "":
|
||||
shellOpen(exe, "")
|
||||
case cmd == menuLaunchID && exe != "":
|
||||
shellOpen(exe, "")
|
||||
case cmd == menuPinID && exe != "":
|
||||
pinApp(exe)
|
||||
refreshApps(false)
|
||||
redraw(hwnd)
|
||||
case cmd == menuUnpinID && exe != "":
|
||||
unpinApp(exe)
|
||||
refreshApps(false)
|
||||
redraw(hwnd)
|
||||
case cmd == menuNotifyID:
|
||||
openNotifications()
|
||||
case cmd == menuFileLocID && exe != "":
|
||||
shellOpen("explorer.exe", `/select,"`+exe+`"`)
|
||||
case target != 0 && sysCommands[cmd] != 0:
|
||||
@@ -1109,6 +970,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||
return 0
|
||||
case wmTimer:
|
||||
if wparam == previewTimerID {
|
||||
previewTick()
|
||||
return 0
|
||||
}
|
||||
hideTaskbar()
|
||||
tick++
|
||||
changed := refreshApps(tick%16 == 0)
|
||||
@@ -1127,8 +992,66 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
}
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
case wmLButtonDown:
|
||||
previewSuppress()
|
||||
x := alongClient(lparam)
|
||||
if edgeZone(x) {
|
||||
beginResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
if inStart(hwnd, x) {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = seqOfApp(idx), false, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
} else if k := trayAt(hwnd, x); k != 0 {
|
||||
dragTray, dragTrayStart, dragTrayActive = k, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
return 0
|
||||
case wmCaptureChanged:
|
||||
resizing = false
|
||||
endIconDrag()
|
||||
dragTray, dragTrayActive = 0, false
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
if resizing {
|
||||
moveResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||
dragActive = true
|
||||
}
|
||||
if dragActive {
|
||||
if t := seqAt(hwnd, x); t >= 0 && t != dragSeq {
|
||||
moveSeq(dragSeq, t)
|
||||
dragSeq = t
|
||||
}
|
||||
hoverStart = dragIsStart
|
||||
hoverApp = -1
|
||||
if !dragIsStart {
|
||||
hoverApp = appOfSeq(dragSeq)
|
||||
}
|
||||
redraw(hwnd)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
if dragTray != 0 {
|
||||
if !dragTrayActive && abs32(x-dragTrayStart) > px(5) {
|
||||
dragTrayActive = true
|
||||
}
|
||||
if dragTrayActive {
|
||||
if t := trayKindAt(hwnd, x); t != 0 && t != dragTray {
|
||||
moveTray(dragTray, t)
|
||||
}
|
||||
hoverStart, hoverApp, hoverTray = false, -1, dragTray
|
||||
redraw(hwnd)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
overStart := inStart(hwnd, x)
|
||||
overApp := appIndexAt(hwnd, x)
|
||||
overTray := trayAt(hwnd, x)
|
||||
@@ -1138,6 +1061,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
hoverTray = overTray
|
||||
redraw(hwnd)
|
||||
}
|
||||
if overApp >= 0 {
|
||||
previewKick()
|
||||
}
|
||||
if !trackingMouse {
|
||||
tme := trackMouseEvent{Size: uint32(unsafe.Sizeof(trackMouseEvent{})), Flags: tmeLeave, HwndTrack: hwnd}
|
||||
pTrackMouseEvent.Call(uintptr(unsafe.Pointer(&tme)))
|
||||
@@ -1154,19 +1080,45 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
if resizing {
|
||||
endResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if inStart(hwnd, x) {
|
||||
tapWinKey()
|
||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||
activateApp(idx)
|
||||
if dragSeq >= 0 {
|
||||
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
||||
seq, wasStart, wasDrag := dragSeq, dragIsStart, dragActive
|
||||
endIconDrag()
|
||||
pReleaseCapture.Call()
|
||||
if wasDrag {
|
||||
saveStartSlot()
|
||||
saveOrder()
|
||||
} else if wasStart {
|
||||
tapWinKey()
|
||||
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
||||
activateApp(idx)
|
||||
}
|
||||
redraw(hwnd)
|
||||
} else if k := trayAt(hwnd, x); k != 0 {
|
||||
trayClick(k)
|
||||
} else if dragTray != 0 {
|
||||
// A press on a tray item: a click if it never moved, otherwise the drag ends here.
|
||||
k, wasDrag := dragTray, dragTrayActive
|
||||
dragTray, dragTrayActive = 0, false
|
||||
pReleaseCapture.Call()
|
||||
if wasDrag {
|
||||
saveTrayOrder()
|
||||
} else {
|
||||
trayClick(k)
|
||||
}
|
||||
redraw(hwnd)
|
||||
} else if inStart(hwnd, x) {
|
||||
tapWinKey()
|
||||
}
|
||||
return 0
|
||||
case wmRButtonUp:
|
||||
x := alongClient(lparam)
|
||||
previewBlock(true)
|
||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||
previewBlock(false)
|
||||
return 0
|
||||
case wmMouseWheel:
|
||||
// Scrolling over the volume icon changes the volume. The wheel
|
||||
@@ -1184,17 +1136,25 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
x := alongScreen(lparam, wr)
|
||||
if inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
||||
if edgeZone(x) || inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
||||
return htClient
|
||||
}
|
||||
return htCaption
|
||||
case wmSetCursor:
|
||||
// The far end of the pill shows the resize arrow.
|
||||
if resizing || (uint16(lparam&0xFFFF) == htClient && overEdge(hwnd)) {
|
||||
pSetCursor.Call(sizeCursor())
|
||||
return 1
|
||||
}
|
||||
case wmNcLButtonDblClk:
|
||||
return 0 // a double click on the drag area must not maximize the pill
|
||||
case wmNcRButtonUp:
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
x := alongScreen(lparam, wr)
|
||||
previewBlock(true)
|
||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||
previewBlock(false)
|
||||
return 0
|
||||
case wmEnterSizeMove:
|
||||
dragging = true
|
||||
@@ -1216,6 +1176,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmDestroy:
|
||||
previewShutdown()
|
||||
abd := appBarData{Hwnd: hwnd}
|
||||
appBar(abmRemove, &abd)
|
||||
pKillTimer.Call(hwnd, timerID)
|
||||
@@ -1269,7 +1230,13 @@ func main() {
|
||||
|
||||
loadAlpha()
|
||||
loadPos()
|
||||
loadStartSlot()
|
||||
loadTrayOrder()
|
||||
loadOrient()
|
||||
loadLeftPref()
|
||||
loadPinned()
|
||||
loadOrderKeys()
|
||||
loadIconMode()
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
||||
@@ -1281,6 +1248,8 @@ func main() {
|
||||
fontTime = makeFont(px(13), 400)
|
||||
fontDate = makeFont(px(11), 400)
|
||||
fontApp = makeFont(px(12), 600)
|
||||
initSuperFonts()
|
||||
loadColors()
|
||||
|
||||
autoQuit = autoQuitDef
|
||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||
@@ -1320,6 +1289,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
hwndMain = hwnd
|
||||
previewInit(inst)
|
||||
refreshAutostartPath()
|
||||
|
||||
// Hotkey: Ctrl+Alt+Q exits and restores.
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
package main
|
||||
|
||||
// Pinned apps and the saved icon order.
|
||||
//
|
||||
// A pinned app that has no open window still gets a button (a "launcher",
|
||||
// which is an appWin with hwnd 0). Clicking it starts the program. When the
|
||||
// program opens a window, the window takes over that very spot, and when its
|
||||
// last window closes the launcher comes back in the same place.
|
||||
//
|
||||
// The order of the icons is remembered by program, so it comes back after a
|
||||
// restart no matter which windows happen to be open.
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pSHGetFileInfo = shell32.NewProc("SHGetFileInfoW")
|
||||
|
||||
pinned []string // full paths of pinned programs
|
||||
orderKeys []string // programs in icon order, nearest the center first (lower case)
|
||||
winExe = map[uintptr]string{}
|
||||
exeIcons = map[string]uintptr{}
|
||||
)
|
||||
|
||||
const (
|
||||
menuPinID = 40
|
||||
menuUnpinID = 41
|
||||
menuNotifyID = 42
|
||||
menuLaunchID = 43
|
||||
|
||||
shgfiIcon = 0x100
|
||||
shgfiSmallIcon = 0x1
|
||||
vkN = 0x4E
|
||||
)
|
||||
|
||||
type shFileInfo struct {
|
||||
Icon uintptr
|
||||
IIcon int32
|
||||
Attrs uint32
|
||||
Display [260]uint16
|
||||
Type [80]uint16
|
||||
}
|
||||
|
||||
func pinnedFile() string { return filepath.Join(dataDir(), "pinned.txt") }
|
||||
func orderFile() string { return filepath.Join(dataDir(), "order.txt") }
|
||||
|
||||
func readLines(path string) []string {
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var out []string
|
||||
for _, l := range strings.Split(string(b), "\n") {
|
||||
if l = strings.TrimSpace(l); l != "" {
|
||||
out = append(out, l)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func writeLines(path string, lines []string) {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0o644)
|
||||
}
|
||||
|
||||
func loadPinned() { pinned = readLines(pinnedFile()) }
|
||||
func savePinned() { writeLines(pinnedFile(), pinned) }
|
||||
func loadOrderKeys() { orderKeys = readLines(orderFile()) }
|
||||
|
||||
func isPinned(exe string) bool {
|
||||
if exe == "" {
|
||||
return false
|
||||
}
|
||||
for _, p := range pinned {
|
||||
if strings.EqualFold(p, exe) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func pinApp(exe string) {
|
||||
if exe == "" || isPinned(exe) {
|
||||
return
|
||||
}
|
||||
pinned = append(pinned, exe)
|
||||
savePinned()
|
||||
saveOrder()
|
||||
}
|
||||
|
||||
func unpinApp(exe string) {
|
||||
var keep []string
|
||||
for _, p := range pinned {
|
||||
if !strings.EqualFold(p, exe) {
|
||||
keep = append(keep, p)
|
||||
}
|
||||
}
|
||||
pinned = keep
|
||||
savePinned()
|
||||
saveOrder()
|
||||
}
|
||||
|
||||
// canPin is false for Store and other packaged apps: their programs can't be
|
||||
// started again from a plain path.
|
||||
func canPin(exe string) bool {
|
||||
return exe != "" && !strings.Contains(strings.ToLower(exe), `\windowsapps\`)
|
||||
}
|
||||
|
||||
// ---------- order ----------
|
||||
|
||||
func orderRank(exe string) int {
|
||||
if exe == "" {
|
||||
return -1
|
||||
}
|
||||
for i, k := range orderKeys {
|
||||
if k == strings.ToLower(exe) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// saveOrder remembers the current icon order. Programs that aren't open right
|
||||
// now keep their place relative to their old neighbors.
|
||||
func saveOrder() {
|
||||
var cur []string
|
||||
have := map[string]bool{}
|
||||
for _, a := range apps {
|
||||
k := strings.ToLower(a.exe)
|
||||
if k == "" || have[k] {
|
||||
continue
|
||||
}
|
||||
have[k] = true
|
||||
cur = append(cur, k)
|
||||
}
|
||||
res := cur
|
||||
for i, k := range orderKeys {
|
||||
if have[k] {
|
||||
continue
|
||||
}
|
||||
pos := 0
|
||||
for j := i - 1; j >= 0; j-- {
|
||||
if p := indexOf(res, orderKeys[j]); p >= 0 {
|
||||
pos = p + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
res = append(res[:pos], append([]string{k}, res[pos:]...)...)
|
||||
have[k] = true
|
||||
}
|
||||
if len(res) > 200 {
|
||||
res = res[:200]
|
||||
}
|
||||
orderKeys = res
|
||||
writeLines(orderFile(), orderKeys)
|
||||
}
|
||||
|
||||
func indexOf(list []string, s string) int {
|
||||
for i, v := range list {
|
||||
if v == s {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func insertAt(list []appWin, i int, a appWin) []appWin {
|
||||
list = append(list, appWin{})
|
||||
copy(list[i+1:], list[i:])
|
||||
list[i] = a
|
||||
return list
|
||||
}
|
||||
|
||||
// addApp puts a new button into the list: into the spot of a waiting launcher
|
||||
// for the same program, else beside the program's other windows, else where
|
||||
// the saved order says, else at the far end.
|
||||
func addApp(list []appWin, f appWin) []appWin {
|
||||
if f.exe != "" {
|
||||
if f.hwnd != 0 {
|
||||
for i, a := range list {
|
||||
if a.hwnd == 0 && strings.EqualFold(a.exe, f.exe) {
|
||||
list[i] = f
|
||||
return list
|
||||
}
|
||||
}
|
||||
}
|
||||
last := -1
|
||||
for i, a := range list {
|
||||
if a.hwnd != 0 && strings.EqualFold(a.exe, f.exe) {
|
||||
last = i
|
||||
}
|
||||
}
|
||||
if last >= 0 {
|
||||
return insertAt(list, last+1, f)
|
||||
}
|
||||
if r := orderRank(f.exe); r >= 0 {
|
||||
for i, a := range list {
|
||||
if ra := orderRank(a.exe); ra < 0 || ra > r {
|
||||
return insertAt(list, i, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return append(list, f)
|
||||
}
|
||||
|
||||
// ---------- launchers and icons ----------
|
||||
|
||||
func launcher(exe string) appWin {
|
||||
name := filepath.Base(exe)
|
||||
name = strings.TrimSuffix(name, filepath.Ext(name))
|
||||
return appWin{title: name, exe: exe, icon: exeIcon(exe)}
|
||||
}
|
||||
|
||||
// exeIcon is the small icon of a program file, fetched once.
|
||||
func exeIcon(path string) uintptr {
|
||||
key := strings.ToLower(path)
|
||||
if ic, ok := exeIcons[key]; ok {
|
||||
return ic
|
||||
}
|
||||
var fi shFileInfo
|
||||
r, _, _ := pSHGetFileInfo.Call(uintptr(unsafe.Pointer(u16(path))), 0,
|
||||
uintptr(unsafe.Pointer(&fi)), unsafe.Sizeof(fi), shgfiIcon|shgfiSmallIcon)
|
||||
var ic uintptr
|
||||
if r != 0 {
|
||||
ic = fi.Icon
|
||||
}
|
||||
exeIcons[key] = ic
|
||||
return ic
|
||||
}
|
||||
|
||||
// refreshApps re-reads the open windows and merges them with the pinned
|
||||
// programs, keeping every button where it was. Returns true if anything changed.
|
||||
func refreshApps(refreshIcons bool) bool {
|
||||
enumFound = enumFound[:0]
|
||||
pEnumWindows.Call(enumCb, 0)
|
||||
|
||||
present := make(map[uintptr]appWin, len(enumFound))
|
||||
live := map[string]int{} // open windows per program
|
||||
for _, f := range enumFound {
|
||||
if _, ok := winExe[f.hwnd]; !ok {
|
||||
winExe[f.hwnd] = windowExePath(f.hwnd)
|
||||
}
|
||||
f.exe = winExe[f.hwnd]
|
||||
present[f.hwnd] = f
|
||||
if f.exe != "" {
|
||||
live[strings.ToLower(f.exe)]++
|
||||
}
|
||||
}
|
||||
for h := range winExe {
|
||||
if _, ok := present[h]; !ok {
|
||||
delete(winExe, h)
|
||||
}
|
||||
}
|
||||
|
||||
var next []appWin
|
||||
for _, a := range apps {
|
||||
if a.hwnd == 0 {
|
||||
next = append(next, a) // a waiting launcher; sorted out below
|
||||
continue
|
||||
}
|
||||
if f, ok := present[a.hwnd]; ok {
|
||||
a.title, a.exe = f.title, f.exe
|
||||
next = append(next, a)
|
||||
delete(present, a.hwnd)
|
||||
} else if isPinned(a.exe) && live[strings.ToLower(a.exe)] == 0 {
|
||||
// The last window of a pinned program closed: leave a launcher in its place.
|
||||
next = append(next, launcher(a.exe))
|
||||
}
|
||||
}
|
||||
for _, f := range enumFound {
|
||||
if _, ok := present[f.hwnd]; ok {
|
||||
next = addApp(next, f)
|
||||
}
|
||||
}
|
||||
|
||||
// Launchers for pinned programs that have neither a window nor a launcher yet.
|
||||
have := map[string]bool{}
|
||||
for _, a := range next {
|
||||
if a.exe != "" {
|
||||
have[strings.ToLower(a.exe)] = true
|
||||
}
|
||||
}
|
||||
for _, p := range pinned {
|
||||
if !have[strings.ToLower(p)] {
|
||||
next = addApp(next, launcher(p))
|
||||
have[strings.ToLower(p)] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Drop launchers that are no longer needed.
|
||||
var tidy []appWin
|
||||
seen := map[string]bool{}
|
||||
for _, a := range next {
|
||||
if a.hwnd == 0 {
|
||||
k := strings.ToLower(a.exe)
|
||||
if !isPinned(a.exe) || live[k] > 0 || seen[k] {
|
||||
continue
|
||||
}
|
||||
seen[k] = true
|
||||
}
|
||||
tidy = append(tidy, a)
|
||||
}
|
||||
next = tidy
|
||||
|
||||
for i := range next {
|
||||
if next[i].hwnd == 0 {
|
||||
if next[i].icon == 0 {
|
||||
next[i].icon = exeIcon(next[i].exe)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if next[i].icon == 0 || refreshIcons {
|
||||
if ic := fetchIcon(next[i].hwnd); ic != 0 {
|
||||
next[i].icon = ic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Titles change constantly (browser tabs, documents) but nothing on the
|
||||
// bar shows them, so only a change in which buttons exist, or their icons,
|
||||
// counts as a change.
|
||||
changed := len(next) != len(apps)
|
||||
if !changed {
|
||||
for i := range next {
|
||||
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
styleCacheClear() // icon handles can be reused by other icons
|
||||
}
|
||||
apps = next
|
||||
return changed
|
||||
}
|
||||
|
||||
// ---------- notification center ----------
|
||||
|
||||
// openNotifications presses Win+N, which opens the notification center and calendar.
|
||||
func openNotifications() {
|
||||
pKeybdEvent.Call(vkLWin, 0, 0, 0)
|
||||
pKeybdEvent.Call(vkN, 0, 0, 0)
|
||||
pKeybdEvent.Call(vkN, 0, keyUp, 0)
|
||||
pKeybdEvent.Call(vkLWin, 0, keyUp, 0)
|
||||
}
|
||||
@@ -128,17 +128,20 @@ func pillPos(pw, ph int32) (int32, int32) {
|
||||
return defaultPos(pw, ph)
|
||||
}
|
||||
sw, sh := screenSize()
|
||||
x := clampI(customCX-pw/2, 0, sw-pw)
|
||||
y := clampI(customY-ph/2, 0, sh-ph)
|
||||
return x, y
|
||||
l := leftHalf() // the center line stays at the remembered spot
|
||||
if vertical {
|
||||
return clampI(customCX-pw/2, 0, sw-pw), clampI(customY-l, 0, sh-ph)
|
||||
}
|
||||
return clampI(customCX-l, 0, sw-pw), clampI(customY-ph/2, 0, sh-ph)
|
||||
}
|
||||
|
||||
func defaultPos(pw, ph int32) (int32, int32) {
|
||||
sw, sh := screenSize()
|
||||
l := leftHalf() // the center line sits at the middle of the screen
|
||||
if vertical {
|
||||
return sw - pw - barGap(), (sh - ph) / 2
|
||||
return sw - pw - barGap(), sh/2 - l
|
||||
}
|
||||
return (sw - pw) / 2, sh - ph - barGap()
|
||||
return sw/2 - l, sh - ph - barGap()
|
||||
}
|
||||
|
||||
// finishDrag runs when a drag ends: remember the new spot, or snap back to the
|
||||
@@ -152,7 +155,12 @@ func finishDrag(hwnd uintptr) {
|
||||
resetPos(hwnd)
|
||||
return
|
||||
}
|
||||
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, (wr.Top+wr.Bottom)/2
|
||||
l := leftHalf()
|
||||
if vertical {
|
||||
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, wr.Top+l
|
||||
} else {
|
||||
customPos, customCX, customY = true, wr.Left+l, (wr.Top+wr.Bottom)/2
|
||||
}
|
||||
savePos()
|
||||
if appbarOn {
|
||||
// A floating bar no longer reserves screen space.
|
||||
@@ -180,3 +188,146 @@ func resetPos(hwnd uintptr) {
|
||||
}
|
||||
positionBar(hwnd)
|
||||
}
|
||||
|
||||
// ---------- the left row: Start button and app icons, all draggable ----------
|
||||
|
||||
var (
|
||||
pSetCapture = user32.NewProc("SetCapture")
|
||||
pReleaseCapture = user32.NewProc("ReleaseCapture")
|
||||
)
|
||||
|
||||
const (
|
||||
wmLButtonDown = 0x0201
|
||||
wmCaptureChanged = 0x0215
|
||||
)
|
||||
|
||||
var (
|
||||
startSlot int // where the Start button sits in the left row (0 is against the center line)
|
||||
dragSeq = -1 // row position of the item the mouse went down on, -1 for none
|
||||
dragIsStart bool // the item being pressed is the Start button
|
||||
dragStart int32 // where along the bar the mouse went down
|
||||
dragActive bool // true once the mouse has moved far enough to count as a drag
|
||||
)
|
||||
|
||||
func startSlotFile() string { return filepath.Join(dataDir(), "startslot.txt") }
|
||||
|
||||
func loadStartSlot() {
|
||||
b, err := os.ReadFile(startSlotFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil && n >= 0 {
|
||||
startSlot = n
|
||||
}
|
||||
}
|
||||
|
||||
func saveStartSlot() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(startSlotFile(), []byte(strconv.Itoa(startSlot)), 0o644)
|
||||
}
|
||||
|
||||
func endIconDrag() {
|
||||
dragSeq = -1
|
||||
dragIsStart = false
|
||||
dragActive = false
|
||||
}
|
||||
|
||||
// slot is the Start button's position, kept within the row.
|
||||
func slot() int {
|
||||
return max(0, min(startSlot, len(apps)))
|
||||
}
|
||||
|
||||
// The row is the Start button plus every app, from the center line leftward.
|
||||
// A "row position" counts those items; app i sits at seqOfApp(i).
|
||||
func seqOfApp(i int) int {
|
||||
if i < slot() {
|
||||
return i
|
||||
}
|
||||
return i + 1
|
||||
}
|
||||
|
||||
func appOfSeq(t int) int {
|
||||
if t < slot() {
|
||||
return t
|
||||
}
|
||||
return t - 1
|
||||
}
|
||||
|
||||
// rowLayout gives the rectangle of every row position (Start included).
|
||||
func rowLayout(clientW, clientH int32) []rect {
|
||||
n := int32(len(apps))
|
||||
sl := int32(slot())
|
||||
cx := axisX(clientW)
|
||||
bw := px(36)
|
||||
if n > 0 {
|
||||
avail := cx - startWidth() - px(8)
|
||||
if avail/n < bw {
|
||||
bw = avail / n
|
||||
}
|
||||
if bw < px(24) {
|
||||
bw = px(24)
|
||||
}
|
||||
}
|
||||
rects := make([]rect, n+1)
|
||||
x := cx
|
||||
for k := int32(0); k <= n; k++ {
|
||||
wd := bw
|
||||
if k == sl {
|
||||
wd = startWidth()
|
||||
}
|
||||
rects[k] = rect{x - wd, 0, x, clientH}
|
||||
x -= wd
|
||||
}
|
||||
return rects
|
||||
}
|
||||
|
||||
func startRect(clientW, clientH int32) rect {
|
||||
return rowLayout(clientW, clientH)[slot()]
|
||||
}
|
||||
|
||||
// seqAt is the row position under a spot along the bar, clamped to the ends.
|
||||
func seqAt(hwnd uintptr, x int32) int {
|
||||
w, h := clientSize(hwnd)
|
||||
rects := rowLayout(w, h)
|
||||
if x >= rects[0].Right {
|
||||
return 0
|
||||
}
|
||||
if x < rects[len(rects)-1].Left {
|
||||
return len(rects) - 1
|
||||
}
|
||||
for k, r := range rects {
|
||||
if x >= r.Left && x < r.Right {
|
||||
return k
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// moveSeq moves one item of the row to another position, shifting the rest.
|
||||
func moveSeq(from, to int) {
|
||||
n := len(apps)
|
||||
if from == to || from < 0 || to < 0 || from > n || to > n {
|
||||
return
|
||||
}
|
||||
sl := slot()
|
||||
seq := make([]int, 0, n+1) // -1 stands for the Start button, otherwise an app index
|
||||
for k := 0; k <= n; k++ {
|
||||
if k == sl {
|
||||
seq = append(seq, -1)
|
||||
} else {
|
||||
seq = append(seq, appOfSeq(k))
|
||||
}
|
||||
}
|
||||
v := seq[from]
|
||||
rest := append(append([]int{}, seq[:from]...), seq[from+1:]...)
|
||||
seq = append(append(append([]int{}, rest[:to]...), v), rest[to:]...)
|
||||
next := make([]appWin, 0, n)
|
||||
for k, a := range seq {
|
||||
if a == -1 {
|
||||
startSlot = k
|
||||
} else {
|
||||
next = append(next, apps[a])
|
||||
}
|
||||
}
|
||||
apps = next
|
||||
}
|
||||
|
||||
+385
@@ -0,0 +1,385 @@
|
||||
package main
|
||||
|
||||
// Hover preview: rest the mouse on an app icon and a small window with a live
|
||||
// picture of that app appears next to the bar. Windows draws the picture
|
||||
// itself (a DWM thumbnail), so it stays live and costs almost nothing. A
|
||||
// minimized window has nothing live to show, so it gets its icon instead.
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pDwmRegisterThumbnail = dwmapi.NewProc("DwmRegisterThumbnail")
|
||||
pDwmUnregisterThumbnail = dwmapi.NewProc("DwmUnregisterThumbnail")
|
||||
pDwmUpdateThumbnailProperties = dwmapi.NewProc("DwmUpdateThumbnailProperties")
|
||||
pDwmQueryThumbnailSourceSize = dwmapi.NewProc("DwmQueryThumbnailSourceSize")
|
||||
pSetWindowPos = user32.NewProc("SetWindowPos")
|
||||
pInvalidateRect = user32.NewProc("InvalidateRect")
|
||||
)
|
||||
|
||||
const (
|
||||
previewTimerID = 2
|
||||
previewDelay = 350 * time.Millisecond
|
||||
|
||||
hwndTopmost = ^uintptr(0) // HWND_TOPMOST is (HWND)-1
|
||||
swpNoActivate = 0x0010
|
||||
swpShowWindow = 0x0040
|
||||
wmMouseActivate = 0x0021
|
||||
maNoActivate = 3
|
||||
dtEndEllipsis = 0x8000
|
||||
vkLButton = 0x01
|
||||
|
||||
dwmTnpDest = 0x1
|
||||
dwmTnpOpacity = 0x4
|
||||
dwmTnpVisible = 0x8
|
||||
)
|
||||
|
||||
type dwmThumbProps struct {
|
||||
Flags uint32
|
||||
Dest rect
|
||||
Src rect
|
||||
Opacity byte
|
||||
_ [3]byte
|
||||
Visible int32
|
||||
ClientOnly int32
|
||||
}
|
||||
|
||||
var (
|
||||
pvHwnd uintptr // the preview window itself
|
||||
pvThumb uintptr // the live picture registered on it, if any
|
||||
pvSrc uintptr // the window being previewed; 0 means nothing is showing
|
||||
pvTitle string //
|
||||
pvIcon uintptr //
|
||||
pvIconic bool // true: no live picture, draw the icon instead
|
||||
pvThumbR rect // picture area, in the preview's own coordinates
|
||||
pvTitleR rect // title row
|
||||
pvCand uintptr // the icon the mouse has been resting on
|
||||
pvSince time.Time // since when
|
||||
pvSupp uintptr // an icon that was just clicked: no preview until the mouse leaves it
|
||||
pvTimer bool
|
||||
pvBlock bool // a menu is open
|
||||
)
|
||||
|
||||
func previewInit(inst uintptr) {
|
||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||
className := u16("MirrorBarPreview")
|
||||
wc := wndClassEx{
|
||||
WndProc: syscall.NewCallback(previewProc),
|
||||
Instance: inst,
|
||||
Cursor: cursor,
|
||||
ClassName: className,
|
||||
}
|
||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||
pvHwnd, _, _ = pCreateWindowEx.Call(
|
||||
wsExToolWindow|wsExTopmost|wsExNoActivate,
|
||||
uintptr(unsafe.Pointer(className)),
|
||||
uintptr(unsafe.Pointer(u16(""))),
|
||||
wsPopup,
|
||||
0, 0, 10, 10,
|
||||
0, 0, inst, 0)
|
||||
}
|
||||
|
||||
func previewProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0 // the preview is optional; never take the bar down with it
|
||||
}
|
||||
}()
|
||||
switch uint32(m) {
|
||||
case wmEraseBkgnd:
|
||||
return 1
|
||||
case wmMouseActivate:
|
||||
return maNoActivate
|
||||
case wmPaint:
|
||||
previewPaint(hwnd)
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
previewActivate()
|
||||
return 0
|
||||
}
|
||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||
return r
|
||||
}
|
||||
|
||||
func previewPaint(hwnd uintptr) {
|
||||
var ps paintStruct
|
||||
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||
var rc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||
|
||||
edge, _, _ := pCreateSolidBrush.Call(rgb(78, 78, 92))
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&rc)), edge)
|
||||
pDeleteObject.Call(edge)
|
||||
inner := rect{rc.Left + 1, rc.Top + 1, rc.Right - 1, rc.Bottom - 1}
|
||||
body, _, _ := pCreateSolidBrush.Call(rgb(28, 28, 34))
|
||||
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&inner)), body)
|
||||
pDeleteObject.Call(body)
|
||||
|
||||
isz := px(16)
|
||||
if pvIcon != 0 {
|
||||
y := pvTitleR.Top + (pvTitleR.Bottom-pvTitleR.Top-isz)/2
|
||||
pDrawIconEx.Call(hdc, uintptr(pvTitleR.Left), uintptr(y), styledIcon(pvIcon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||
}
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(240, 240, 245))
|
||||
old, _, _ := pSelectObject.Call(hdc, fontApp)
|
||||
tr := rect{pvTitleR.Left + isz + px(6), pvTitleR.Top, pvTitleR.Right, pvTitleR.Bottom}
|
||||
pDrawText.Call(hdc, uintptr(unsafe.Pointer(u16(pvTitle))), ^uintptr(0), uintptr(unsafe.Pointer(&tr)),
|
||||
dtLeft|dtVCenter|dtSingleLine|dtNoPrefix|dtEndEllipsis)
|
||||
pSelectObject.Call(hdc, old)
|
||||
|
||||
if pvIconic && pvIcon != 0 {
|
||||
big := px(48)
|
||||
cx := (pvThumbR.Left + pvThumbR.Right) / 2
|
||||
cy := (pvThumbR.Top + pvThumbR.Bottom) / 2
|
||||
pDrawIconEx.Call(hdc, uintptr(cx-big/2), uintptr(cy-big/2), styledIcon(pvIcon), uintptr(big), uintptr(big), 0, 0, diNormal)
|
||||
}
|
||||
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||
}
|
||||
|
||||
func previewDropThumb() {
|
||||
if pvThumb != 0 {
|
||||
pDwmUnregisterThumbnail.Call(pvThumb)
|
||||
pvThumb = 0
|
||||
}
|
||||
}
|
||||
|
||||
func previewHide() {
|
||||
previewDropThumb()
|
||||
if pvSrc != 0 && pvHwnd != 0 {
|
||||
pShowWindow.Call(pvHwnd, swHide)
|
||||
}
|
||||
pvSrc = 0
|
||||
}
|
||||
|
||||
// previewIconRect is where an app icon sits on the screen.
|
||||
func previewIconRect(idx int, wr rect) rect {
|
||||
w, h := clientSize(hwndMain)
|
||||
rs := appRects(w, h)
|
||||
if idx < 0 || idx >= len(rs) {
|
||||
return wr
|
||||
}
|
||||
r := rs[idx]
|
||||
if vertical {
|
||||
r = mapRect(r, barHeight)
|
||||
}
|
||||
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
||||
}
|
||||
|
||||
func previewShow(idx int) {
|
||||
if pvHwnd == 0 || idx < 0 || idx >= len(apps) {
|
||||
return
|
||||
}
|
||||
a := apps[idx]
|
||||
previewDropThumb()
|
||||
|
||||
iconic, _, _ := pIsIconic.Call(a.hwnd)
|
||||
pvIconic = iconic != 0
|
||||
var tw, th int32
|
||||
if !pvIconic {
|
||||
var t uintptr
|
||||
hr, _, _ := pDwmRegisterThumbnail.Call(pvHwnd, a.hwnd, uintptr(unsafe.Pointer(&t)))
|
||||
if hr == 0 && t != 0 {
|
||||
pvThumb = t
|
||||
var sz size
|
||||
hr2, _, _ := pDwmQueryThumbnailSourceSize.Call(t, uintptr(unsafe.Pointer(&sz)))
|
||||
if hr2 == 0 && sz.CX > 0 && sz.CY > 0 {
|
||||
f := min(float64(px(260))/float64(sz.CX), float64(px(160))/float64(sz.CY), 1.0)
|
||||
tw = max(int32(float64(sz.CX)*f), 1)
|
||||
th = max(int32(float64(sz.CY)*f), 1)
|
||||
} else {
|
||||
previewDropThumb()
|
||||
pvIconic = true
|
||||
}
|
||||
} else {
|
||||
pvIconic = true
|
||||
}
|
||||
}
|
||||
if pvIconic {
|
||||
tw, th = px(200), px(110)
|
||||
}
|
||||
|
||||
pad, titleH, gap := px(8), px(22), px(4)
|
||||
cw := max(px(180), tw+2*pad)
|
||||
ch := pad + titleH + gap + th + pad
|
||||
pvTitleR = rect{pad, pad, cw - pad, pad + titleH}
|
||||
tx, ty := (cw-tw)/2, pad+titleH+gap
|
||||
pvThumbR = rect{tx, ty, tx + tw, ty + th}
|
||||
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||
ir := previewIconRect(idx, wr)
|
||||
sw, sh := screenSize()
|
||||
space := px(8)
|
||||
var x, y int32
|
||||
if vertical {
|
||||
x = wr.Left - cw - space
|
||||
if x < 0 {
|
||||
x = wr.Right + space
|
||||
}
|
||||
y = (ir.Top+ir.Bottom)/2 - ch/2
|
||||
} else {
|
||||
x = (ir.Left+ir.Right)/2 - cw/2
|
||||
y = wr.Top - ch - space
|
||||
if y < 0 {
|
||||
y = wr.Bottom + space
|
||||
}
|
||||
}
|
||||
x = clampI(x, 0, sw-cw)
|
||||
y = clampI(y, 0, sh-ch)
|
||||
|
||||
pvSrc, pvTitle, pvIcon = a.hwnd, a.title, a.icon
|
||||
pSetWindowPos.Call(pvHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
||||
if pvThumb != 0 {
|
||||
props := dwmThumbProps{Flags: dwmTnpDest | dwmTnpOpacity | dwmTnpVisible, Dest: pvThumbR, Opacity: 255, Visible: 1}
|
||||
pDwmUpdateThumbnailProperties.Call(pvThumb, uintptr(unsafe.Pointer(&props)))
|
||||
}
|
||||
pInvalidateRect.Call(pvHwnd, 0, 1)
|
||||
}
|
||||
|
||||
func inRect(r rect, p point) bool {
|
||||
return p.X >= r.Left && p.X < r.Right && p.Y >= r.Top && p.Y < r.Bottom
|
||||
}
|
||||
|
||||
// previewKick starts the short timer that watches where the mouse is.
|
||||
func previewKick() {
|
||||
if pvHwnd == 0 || pvTimer {
|
||||
return
|
||||
}
|
||||
pSetTimer.Call(hwndMain, previewTimerID, 60, 0)
|
||||
pvTimer = true
|
||||
}
|
||||
|
||||
func previewStopTimer() {
|
||||
if pvTimer {
|
||||
pKillTimer.Call(hwndMain, previewTimerID)
|
||||
pvTimer = false
|
||||
}
|
||||
}
|
||||
|
||||
// previewTick decides what the preview should be doing right now, from where
|
||||
// the mouse is. It runs only while the mouse is near the bar.
|
||||
func previewTick() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
previewHide()
|
||||
}
|
||||
}()
|
||||
if pvHwnd == 0 {
|
||||
return
|
||||
}
|
||||
var cp point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||
overBar := inRect(wr, cp)
|
||||
|
||||
btn, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||
if btn&0x8000 != 0 || pvBlock || dragging {
|
||||
previewHide()
|
||||
pvCand = 0
|
||||
if !overBar {
|
||||
previewStopTimer()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
idx := -1
|
||||
var raw uintptr
|
||||
if overBar {
|
||||
x := cp.X - wr.Left
|
||||
if vertical {
|
||||
x = cp.Y - wr.Top
|
||||
}
|
||||
idx = appIndexAt(hwndMain, x)
|
||||
if idx >= 0 && idx < len(apps) {
|
||||
raw = apps[idx].hwnd
|
||||
}
|
||||
}
|
||||
target := raw
|
||||
if raw != 0 && raw == pvSupp {
|
||||
target = 0 // just clicked: stay quiet until the mouse moves off this icon
|
||||
} else {
|
||||
pvSupp = 0
|
||||
}
|
||||
|
||||
if target != 0 {
|
||||
if pvSrc == target {
|
||||
if apps[idx].title != pvTitle {
|
||||
pvTitle = apps[idx].title
|
||||
pInvalidateRect.Call(pvHwnd, 0, 1)
|
||||
}
|
||||
return
|
||||
}
|
||||
if pvCand != target {
|
||||
pvCand = target
|
||||
pvSince = time.Now()
|
||||
}
|
||||
if pvSrc != 0 || time.Since(pvSince) >= previewDelay {
|
||||
previewShow(idx)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
pvCand = 0
|
||||
if pvSrc != 0 {
|
||||
var pr rect
|
||||
pGetWindowRect.Call(pvHwnd, uintptr(unsafe.Pointer(&pr)))
|
||||
g := px(10) // covers the small gap between the icon and the preview
|
||||
pr = rect{pr.Left - g, pr.Top - g, pr.Right + g, pr.Bottom + g}
|
||||
if inRect(pr, cp) {
|
||||
return
|
||||
}
|
||||
previewHide()
|
||||
}
|
||||
if !overBar {
|
||||
previewStopTimer()
|
||||
}
|
||||
}
|
||||
|
||||
// previewSuppress hides the preview because the icon was clicked, and keeps it
|
||||
// away until the mouse leaves that icon.
|
||||
func previewSuppress() {
|
||||
if pvSrc != 0 {
|
||||
pvSupp = pvSrc
|
||||
} else {
|
||||
pvSupp = pvCand
|
||||
}
|
||||
pvCand = 0
|
||||
previewHide()
|
||||
}
|
||||
|
||||
// previewBlock keeps the preview down while a menu is open.
|
||||
func previewBlock(on bool) {
|
||||
pvBlock = on
|
||||
if on {
|
||||
previewSuppress()
|
||||
}
|
||||
}
|
||||
|
||||
// previewActivate runs when the preview itself is clicked: bring that window forward.
|
||||
func previewActivate() {
|
||||
h := pvSrc
|
||||
previewHide()
|
||||
if h == 0 {
|
||||
return
|
||||
}
|
||||
iconic, _, _ := pIsIconic.Call(h)
|
||||
if iconic != 0 {
|
||||
pShowWindow.Call(h, swRestore)
|
||||
}
|
||||
pSetForegroundWindow.Call(h)
|
||||
}
|
||||
|
||||
func previewShutdown() {
|
||||
previewStopTimer()
|
||||
previewHide()
|
||||
if pvHwnd != 0 {
|
||||
pDestroyWindow.Call(pvHwnd)
|
||||
pvHwnd = 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
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]
|
||||
r, g, b := styleColor(c.r, c.g, c.b)
|
||||
return rgb(r, g, 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")
|
||||
addStyleMenu(menu)
|
||||
}
|
||||
|
||||
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)
|
||||
case handleStyleCommand(cmd):
|
||||
return true
|
||||
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)
|
||||
sr := startRect(w, 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
|
||||
}
|
||||
@@ -5,6 +5,8 @@ package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
@@ -83,19 +85,30 @@ type trayItem struct {
|
||||
}
|
||||
|
||||
func trayItems(clientW, clientH int32) []trayItem {
|
||||
x := clientW / 2
|
||||
return trayItemsAt(axisX(clientW), clientH)
|
||||
}
|
||||
|
||||
// trayItemsAt lays the right-hand items out rightward from x.
|
||||
func trayItemsAt(x, clientH int32) []trayItem {
|
||||
var out []trayItem
|
||||
add := func(kind int, w int32) {
|
||||
for _, kind := range trayOrder {
|
||||
var w int32
|
||||
switch kind {
|
||||
case trayClock:
|
||||
w = clockWidth()
|
||||
case trayBattery:
|
||||
if battPct < 0 {
|
||||
continue // this PC has no battery
|
||||
}
|
||||
w = px(36)
|
||||
case trayVolume, trayWifi:
|
||||
w = px(36)
|
||||
case trayChevron:
|
||||
w = px(28)
|
||||
}
|
||||
out = append(out, trayItem{kind, rect{x, 0, x + w, clientH}})
|
||||
x += w
|
||||
}
|
||||
add(trayClock, clockWidth())
|
||||
if battPct >= 0 {
|
||||
add(trayBattery, px(36))
|
||||
}
|
||||
add(trayVolume, px(36))
|
||||
add(trayWifi, px(36))
|
||||
add(trayChevron, px(28))
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -145,13 +158,13 @@ func drawBattery(hdc uintptr, r rect) {
|
||||
t := px(1)
|
||||
left := cx - (bw+nubW)/2
|
||||
top := cy - bh/2
|
||||
white := rgb(245, 245, 245)
|
||||
white := iconColor()
|
||||
|
||||
fill(hdc, rect{left, top, left + bw, top + t}, white)
|
||||
fill(hdc, rect{left, top + bh - t, left + bw, top + bh}, white)
|
||||
fill(hdc, rect{left, top, left + t, top + bh}, white)
|
||||
fill(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, top, left + bw, top + t}, white)
|
||||
fillFg(hdc, rect{left, top + bh - t, left + bw, top + bh}, white)
|
||||
fillFg(hdc, rect{left, top, left + t, top + bh}, white)
|
||||
fillFg(hdc, rect{left + bw - t, top, left + bw, top + bh}, white)
|
||||
fillFg(hdc, rect{left + bw, cy - nubH/2, left + bw + nubW, cy + nubH/2}, white)
|
||||
|
||||
col := white
|
||||
switch {
|
||||
@@ -166,15 +179,15 @@ func drawBattery(hdc uintptr, r rect) {
|
||||
if battPct > 0 && 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) {
|
||||
cx, cy := center(r)
|
||||
white, dim := rgb(245, 245, 245), rgb(110, 110, 120)
|
||||
white, dim := iconColor(), iconDim()
|
||||
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{
|
||||
{x0 + px(3), cy - px(3)},
|
||||
{x0 + px(7), cy - px(6)},
|
||||
@@ -200,7 +213,7 @@ func drawVolume(hdc uintptr, r rect) {
|
||||
if i < active {
|
||||
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 {
|
||||
polyline(hdc, []point{{x0 + px(10), cy - px(4)}, {x0 + px(17), cy + px(4)}}, px(1), white)
|
||||
@@ -210,18 +223,18 @@ func drawVolume(hdc uintptr, r rect) {
|
||||
|
||||
func drawNetwork(hdc uintptr, r rect) {
|
||||
cx, cy := center(r)
|
||||
white, dim := rgb(245, 245, 245), rgb(110, 110, 120)
|
||||
white, dim := iconColor(), iconDim()
|
||||
|
||||
if netKind == netWired {
|
||||
t := px(1)
|
||||
l, tp := cx-px(7), cy-px(6)
|
||||
w, h := px(14), px(9)
|
||||
fill(hdc, rect{l, tp, l + w, tp + t}, white)
|
||||
fill(hdc, rect{l, tp + h - t, l + w, tp + h}, white)
|
||||
fill(hdc, rect{l, tp, l + t, tp + h}, white)
|
||||
fill(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)
|
||||
fill(hdc, rect{cx - px(4), tp + h + px(3), cx + px(4), tp + h + px(4)}, white)
|
||||
fillFg(hdc, rect{l, tp, l + w, tp + t}, white)
|
||||
fillFg(hdc, rect{l, tp + h - t, l + w, tp + h}, white)
|
||||
fillFg(hdc, rect{l, tp, l + t, tp + h}, white)
|
||||
fillFg(hdc, rect{l + w - t, tp, l + w, tp + h}, white)
|
||||
fillFg(hdc, rect{cx - px(1), tp + h, cx + px(1), tp + h + px(3)}, white)
|
||||
fillFg(hdc, rect{cx - px(4), tp + h + px(3), cx + px(4), tp + h + px(4)}, white)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -243,7 +256,7 @@ func drawNetwork(hdc uintptr, r rect) {
|
||||
if i < bars {
|
||||
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)
|
||||
}
|
||||
if netKind == netNone {
|
||||
@@ -255,7 +268,7 @@ func drawNetwork(hdc uintptr, r rect) {
|
||||
func drawChevron(hdc uintptr, r rect) {
|
||||
cx, cy := center(r)
|
||||
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) {
|
||||
@@ -263,7 +276,7 @@ func drawTray(hdc uintptr, w, h int32) {
|
||||
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))
|
||||
}
|
||||
if vertical && it.kind != trayClock {
|
||||
if !layerFg || (vertical && it.kind != trayClock) {
|
||||
continue // a vertical bar draws these upright, after turning
|
||||
}
|
||||
switch it.kind {
|
||||
@@ -534,6 +547,21 @@ func tapChord(mod, k uintptr) {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
switch kind {
|
||||
case trayClock:
|
||||
@@ -541,6 +569,12 @@ func trayClick(kind int) {
|
||||
case trayBattery, trayVolume, trayWifi:
|
||||
tapChord(vkLWin, 'A') // quick settings
|
||||
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.
|
||||
tapChord(vkLWin, 'B')
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
@@ -641,3 +675,85 @@ func handleTrayCommand(cmd uintptr) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------- the right row can be rearranged too ----------
|
||||
|
||||
// trayOrder is the left to right order of the items to the right of center.
|
||||
var trayOrder = []int{trayClock, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||
|
||||
var (
|
||||
dragTray int // the tray item the mouse went down on, 0 for none
|
||||
dragTrayStart int32 // where along the bar the mouse went down
|
||||
dragTrayActive bool // true once the mouse has moved far enough to count as a drag
|
||||
)
|
||||
|
||||
func trayOrderFile() string { return filepath.Join(dataDir(), "trayorder.txt") }
|
||||
|
||||
func loadTrayOrder() {
|
||||
b, err := os.ReadFile(trayOrderFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var order []int
|
||||
seen := map[int]bool{}
|
||||
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
|
||||
n, err := strconv.Atoi(strings.TrimSpace(p))
|
||||
if err != nil || n < trayClock || n > trayChevron || seen[n] {
|
||||
return
|
||||
}
|
||||
seen[n] = true
|
||||
order = append(order, n)
|
||||
}
|
||||
if len(order) == len(trayOrder) {
|
||||
trayOrder = order
|
||||
}
|
||||
}
|
||||
|
||||
func saveTrayOrder() {
|
||||
parts := make([]string, len(trayOrder))
|
||||
for i, k := range trayOrder {
|
||||
parts[i] = strconv.Itoa(k)
|
||||
}
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(trayOrderFile(), []byte(strings.Join(parts, ",")), 0o644)
|
||||
}
|
||||
|
||||
// trayKindAt is the tray item under a spot along the bar, clamped to the ends
|
||||
// of the right row.
|
||||
func trayKindAt(hwnd uintptr, x int32) int {
|
||||
w, h := clientSize(hwnd)
|
||||
items := trayItems(w, h)
|
||||
if len(items) == 0 {
|
||||
return 0
|
||||
}
|
||||
if x < items[0].r.Left {
|
||||
return items[0].kind
|
||||
}
|
||||
if x >= items[len(items)-1].r.Right {
|
||||
return items[len(items)-1].kind
|
||||
}
|
||||
for _, it := range items {
|
||||
if x >= it.r.Left && x < it.r.Right {
|
||||
return it.kind
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// moveTray puts one item where another one is, shifting the rest.
|
||||
func moveTray(kind, target int) {
|
||||
from, to := -1, -1
|
||||
for i, k := range trayOrder {
|
||||
if k == kind {
|
||||
from = i
|
||||
}
|
||||
if k == target {
|
||||
to = i
|
||||
}
|
||||
}
|
||||
if from < 0 || to < 0 || from == to {
|
||||
return
|
||||
}
|
||||
rest := append(append([]int{}, trayOrder[:from]...), trayOrder[from+1:]...)
|
||||
trayOrder = append(append(append([]int{}, rest[:to]...), kind), rest[to:]...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user