Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c58a4d8a5 | ||
|
|
7ffd3c5e22 | ||
|
|
eab5a47495 | ||
|
|
93f6b94d98 | ||
|
|
6ac9164755 | ||
|
|
9ea41cab49 | ||
|
|
2a76d1d9c9 | ||
|
|
fc1d82d790 | ||
|
|
c80267f81f | ||
|
|
e82ed224e8 | ||
|
|
8ab3cda02d | ||
|
|
b26879abdb |
@@ -20,9 +20,12 @@ Drag the app icons and the Windows logo along the left row to reorder them. Mirr
|
||||
- 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.
|
||||
- Click the little smiley, or right-click and choose "Open emoji panel", and the Windows emoji panel opens (the same as pressing Win+.). Pick an emoji and it is typed into the window you were just in. Tick or untick "Emoji panel button" under "Show on the bar" in the settings window to put the smiley on the bar or take it off; it can be dragged along the right row like the other icons.
|
||||
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
||||
- "MirrorBar settings..." in the right-click menu opens one window for background opacity, the three colors, icon style, the ZIP code, tickboxes to show or hide the weather, the local news and the system stats, vertical mode, start with Windows, and resetting the position and width. Changes apply as you make them.
|
||||
- Smooth, outline-free icons and text, even when the pill is see-through.
|
||||
- In "MirrorBar settings..." you can also change how the bar looks. "Bar color" turns the pill dark (the default), black, white, red, dark green, navy, purple, gray, charcoal, slate, burgundy, forest, brown, teal, olive or midnight. "Windows logo shape" swaps the four squares for rounded squares, four dots, squares tilted right or left, diamonds, a waving flag, a single circle, a hexagon, a plus sign, three bars, pills or a triangle. "Clock text size" makes the time and date Normal, Large, Larger or Largest, and "Bold clock text" makes them heavier; the bar grows to fit. Under "Show on the bar" you can take the battery, volume and wifi icons off the bar and bring them back. The logo, clock and tray icon colors have twenty-four choices, including dark green, teal, navy, maroon, gray, lime, brown, mint, lavender, gold, coral, silver, slate and olive. A light bar needs a dark clock and icon color to be readable. "Clock font" picks the typeface for the time and date from sixteen fonts that come with Windows or Office (a font that is not installed on your PC shows as a default one). "Battery charging color" changes the color of the filled part of the battery while it charges or is plugged in: the old bright green is the default, and there are softer, muted ones and one that simply matches the icon color.
|
||||
|
||||
Smooth, outline-free icons and text, even when the pill is see-through.
|
||||
- Click the storm cloud and a weather panel opens above the bar: the temperature in Fahrenheit, what it feels like, the high and low, humidity, wind, chance of rain, sunrise, sunset, UV index, the moon phase, a looping radar picture of the last hour or so centered on your ZIP code, and the next five days. Click the cloud again, or click anywhere else, and it closes. It needs a ZIP code: type it in "MirrorBar settings..." (a 5 digit US ZIP code) and the weather turns on at once. The forecast comes from Open-Meteo (open-meteo.com, free, no account), the radar map comes from RainViewer and Esri and is only downloaded when you open the panel, and MirrorBar only goes to the internet when a ZIP code is set. The cloud can be dragged along the right row like the other icons.
|
||||
|
||||
- Click the newspaper and a panel of local headlines opens above the bar, newest first, with the outlet and how long ago each ran. Click a headline and it opens in your default browser. It uses the same ZIP code as the weather: the ZIP code is turned into a town name and the headlines are Google News' feed for that town, so someone in 43220 gets Columbus stations and papers and someone in 46750 gets Fort Wayne and Huntington ones. The headlines are only downloaded when a ZIP code is set. Small towns have fewer stories than cities.
|
||||
|
||||
+14
-3
@@ -65,7 +65,18 @@ func saveLeftPref() {
|
||||
// halfLimit is the longest either half may be.
|
||||
func halfLimit() int32 {
|
||||
sw, _ := screenSize()
|
||||
return sw/2 - px(4)
|
||||
return sw*layerMul()/2 - px(4)
|
||||
}
|
||||
|
||||
// layerMul is how much bigger the layer being drawn is than the real bar (2
|
||||
// while the icons are drawn at double size, otherwise 1). Lengths kept in real
|
||||
// pixels, like the chosen bar width and the screen size, are scaled by it so
|
||||
// the icons land on the same spots the mouse tests.
|
||||
func layerMul() int32 {
|
||||
if realScale <= 0 {
|
||||
return 1
|
||||
}
|
||||
return int32(scale/realScale + 0.5)
|
||||
}
|
||||
|
||||
// rightHalf is the length of the right half: the tray items plus a little padding.
|
||||
@@ -87,7 +98,7 @@ func leftHalf() int32 {
|
||||
case leftPref < 0:
|
||||
h = lc
|
||||
case leftPref > 0:
|
||||
h = max(lc, leftPref)
|
||||
h = max(lc, leftPref*layerMul())
|
||||
default:
|
||||
h = max(lc, rightHalf())
|
||||
}
|
||||
@@ -128,7 +139,7 @@ func overEdge(hwnd uintptr) bool {
|
||||
func beginResize(hwnd uintptr) {
|
||||
resizing = true
|
||||
resizeFrom = cursorAlong()
|
||||
resizeLen = leftHalf()
|
||||
resizeLen = leftHalf() // always measured at real size here
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
// The little smiley on the bar. Clicking it presses Win+. which opens the
|
||||
// Windows emoji panel (emoji, GIFs, symbols and the clipboard history), so
|
||||
// whatever you pick is pasted into the window you were just typing in.
|
||||
|
||||
import "math"
|
||||
|
||||
func drawEmojiIcon(hdc uintptr, r rect) {
|
||||
if !layerFg {
|
||||
return
|
||||
}
|
||||
cx, cy := center(r)
|
||||
col := iconColor()
|
||||
rad := float64(px(7.5))
|
||||
|
||||
// the face
|
||||
face := make([]point, 0, 33)
|
||||
for k := 0; k <= 32; k++ {
|
||||
a := float64(k) * 2 * math.Pi / 32
|
||||
face = append(face, point{cx + int32(math.Round(rad*math.Cos(a))), cy + int32(math.Round(rad*math.Sin(a)))})
|
||||
}
|
||||
polyline(hdc, face, px(1.3), col)
|
||||
|
||||
// the eyes
|
||||
eye := px(1.1)
|
||||
circleRaw(hdc, cx-px(2.7), cy-px(2), eye, col)
|
||||
circleRaw(hdc, cx+px(2.7), cy-px(2), eye, col)
|
||||
|
||||
// the smile
|
||||
smile := make([]point, 0, 9)
|
||||
sr := float64(px(4.2))
|
||||
for k := 0; k <= 8; k++ {
|
||||
a := (25 + float64(k)*130/8) * math.Pi / 180
|
||||
smile = append(smile, point{cx + int32(math.Round(sr*math.Cos(a))), cy + int32(math.Round(sr*math.Sin(a))) - px(0.5)})
|
||||
}
|
||||
polyline(hdc, smile, px(1.2), col)
|
||||
}
|
||||
+23
-1
@@ -15,6 +15,14 @@ var (
|
||||
showNews = true
|
||||
showSys = true
|
||||
showGM = true // the Google Messages bubble
|
||||
|
||||
showBattery = true
|
||||
showVolume = true
|
||||
showWifi = true
|
||||
showEmoji = true // the emoji panel button
|
||||
showClip = true // the clipboard history button
|
||||
showAI = true // the Claude and Grok button
|
||||
showMusic = true // the mp3 player button
|
||||
)
|
||||
|
||||
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
||||
@@ -45,12 +53,26 @@ func loadFeatures() {
|
||||
groupWins = on
|
||||
case "autohide":
|
||||
autoHide = on
|
||||
case "battery":
|
||||
showBattery = on
|
||||
case "volume":
|
||||
showVolume = on
|
||||
case "wifi":
|
||||
showWifi = on
|
||||
case "emoji":
|
||||
showEmoji = on
|
||||
case "clip":
|
||||
showClip = on
|
||||
case "ai":
|
||||
showAI = on
|
||||
case "music":
|
||||
showMusic = on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveFeatures() {
|
||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\ngroup=" + b01(groupWins) + "\nautohide=" + b01(autoHide) + "\n"
|
||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\ngroup=" + b01(groupWins) + "\nautohide=" + b01(autoHide) + "\nbattery=" + b01(showBattery) + "\nvolume=" + b01(showVolume) + "\nwifi=" + b01(showWifi) + "\nemoji=" + b01(showEmoji) + "\nclip=" + b01(showClip) + "\nai=" + b01(showAI) + "\nmusic=" + b01(showMusic) + "\n"
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ func weatherToggle() {
|
||||
newsHide() // one panel at a time
|
||||
sysHide()
|
||||
gmHide()
|
||||
webFlyHideAll()
|
||||
weatherRefresh(false)
|
||||
wxShown = true
|
||||
wxPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||
|
||||
@@ -369,6 +369,7 @@ func gmToggle() {
|
||||
weatherHide() // one panel at a time
|
||||
newsHide()
|
||||
sysHide()
|
||||
webFlyHideAll()
|
||||
if gmWindowOK() {
|
||||
gmShow()
|
||||
return
|
||||
|
||||
@@ -0,0 +1,518 @@
|
||||
package main
|
||||
|
||||
// How the bar looks: the color of the bar itself, the shape of the Windows
|
||||
// logo, the size and weight of the clock text, and which of the battery, volume
|
||||
// and wifi icons are on the bar. All of it is changed in the settings window.
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pRoundRect = gdi32.NewProc("RoundRect")
|
||||
pGetTextExtentW = gdi32.NewProc("GetTextExtentPoint32W")
|
||||
)
|
||||
|
||||
// ---------- the color of the bar ----------
|
||||
|
||||
type barColor struct {
|
||||
name string
|
||||
r, g, b int
|
||||
}
|
||||
|
||||
// New colors go on the end so a saved choice keeps meaning the same color.
|
||||
var barPalette = []barColor{
|
||||
{"Dark (default)", 22, 22, 26},
|
||||
{"Black", 0, 0, 0},
|
||||
{"White", 245, 245, 245},
|
||||
{"Red", 190, 35, 35},
|
||||
{"Dark green", 20, 72, 42},
|
||||
{"Navy", 16, 36, 92},
|
||||
{"Purple", 72, 38, 112},
|
||||
{"Gray", 92, 92, 100},
|
||||
{"Charcoal", 44, 44, 50},
|
||||
{"Slate", 52, 64, 80},
|
||||
{"Burgundy", 92, 24, 40},
|
||||
{"Forest", 30, 56, 30},
|
||||
{"Brown", 84, 52, 30},
|
||||
{"Teal", 16, 82, 86},
|
||||
{"Olive", 74, 80, 32},
|
||||
{"Midnight", 10, 14, 40},
|
||||
}
|
||||
|
||||
var (
|
||||
barIdx = 0
|
||||
logoStyle = 0
|
||||
clockSizeIx = 0
|
||||
clockBold = false
|
||||
clockFontIx = 0
|
||||
chargeIx = 0
|
||||
|
||||
clockMeasured float64 // the width the time and date need in a font other than Segoe UI, at 96 dpi so it scales with the bar
|
||||
)
|
||||
|
||||
var logoStyleNames = []string{
|
||||
"Classic squares",
|
||||
"Rounded squares",
|
||||
"Four dots",
|
||||
"Tilted right",
|
||||
"Tilted left",
|
||||
"Diamonds",
|
||||
"Waving flag",
|
||||
"Single circle",
|
||||
"Hexagon",
|
||||
"Plus sign",
|
||||
"Three bars",
|
||||
"Pills",
|
||||
"Triangle",
|
||||
}
|
||||
|
||||
// The clock fonts. New ones go on the end so a saved choice keeps meaning the same font.
|
||||
// A font that is not installed on this PC quietly shows as a default font.
|
||||
var clockFonts = []string{
|
||||
"Segoe UI",
|
||||
"Tahoma",
|
||||
"Verdana",
|
||||
"Arial",
|
||||
"Calibri",
|
||||
"Cambria",
|
||||
"Consolas",
|
||||
"Cascadia Mono",
|
||||
"Courier New",
|
||||
"Georgia",
|
||||
"Trebuchet MS",
|
||||
"Bahnschrift",
|
||||
"Tw Cen MT",
|
||||
"Segoe Script",
|
||||
"Impact",
|
||||
"Comic Sans MS",
|
||||
}
|
||||
|
||||
// The color of the filled part of the battery icon while it charges. New ones go on the end.
|
||||
type chargeChoice struct {
|
||||
name string
|
||||
r, g, b int
|
||||
}
|
||||
|
||||
var chargeColors = []chargeChoice{
|
||||
{"Bright green (default)", 90, 205, 120},
|
||||
{"Soft green", 105, 165, 120},
|
||||
{"Dark green", 40, 115, 70},
|
||||
{"Muted teal", 80, 145, 150},
|
||||
{"Slate blue", 110, 135, 170},
|
||||
{"Dim gold", 190, 160, 80},
|
||||
{"Gray", 150, 150, 158},
|
||||
{"Same as the icon color", -1, -1, -1},
|
||||
}
|
||||
|
||||
// chargeColor is the fill color of the battery icon while it is charging or plugged in.
|
||||
func chargeColor() uintptr {
|
||||
i := chargeIx
|
||||
if i < 0 || i >= len(chargeColors) {
|
||||
i = 0
|
||||
}
|
||||
c := chargeColors[i]
|
||||
if c.r < 0 {
|
||||
return iconColor()
|
||||
}
|
||||
return rgb(c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
type clockSizeChoice struct {
|
||||
name string
|
||||
px int
|
||||
}
|
||||
|
||||
var clockSizes = []clockSizeChoice{
|
||||
{"Normal", 13},
|
||||
{"Large", 15},
|
||||
{"Larger", 17},
|
||||
{"Largest", 19},
|
||||
}
|
||||
|
||||
// barRGB is the bar color as it sits in a bitmap (0xRRGGBB).
|
||||
func barRGB() uint32 {
|
||||
i := barIdx
|
||||
if i < 0 || i >= len(barPalette) {
|
||||
i = 0
|
||||
}
|
||||
c := barPalette[i]
|
||||
return uint32(c.r)<<16 | uint32(c.g)<<8 | uint32(c.b)
|
||||
}
|
||||
|
||||
// barIsLight is true for a bar bright enough that the dark hover fills would look wrong on it.
|
||||
func barIsLight() bool {
|
||||
i := barIdx
|
||||
if i < 0 || i >= len(barPalette) {
|
||||
i = 0
|
||||
}
|
||||
c := barPalette[i]
|
||||
return (c.r*299+c.g*587+c.b*114)/1000 > 140
|
||||
}
|
||||
|
||||
// hoverTint is the fill used for a hovered button, matched to the bar color.
|
||||
func hoverTint(c uint32, light bool) uint32 {
|
||||
if light {
|
||||
return 200<<16 | 200<<8 | 208
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// ---------- the clock text ----------
|
||||
|
||||
func clockPx() int {
|
||||
i := clockSizeIx
|
||||
if i < 0 || i >= len(clockSizes) {
|
||||
i = 0
|
||||
}
|
||||
return clockSizes[i].px
|
||||
}
|
||||
|
||||
// clockWidth is the room the time and date need, which grows with the text.
|
||||
func clockWidth() int32 {
|
||||
if clockFontIx > 0 && clockMeasured > 0 {
|
||||
return px(clockMeasured + 24)
|
||||
}
|
||||
w := 140.0 * float64(clockPx()) / 13.0
|
||||
if clockBold {
|
||||
w *= 1.08
|
||||
}
|
||||
return px(w)
|
||||
}
|
||||
|
||||
// rebuildClockFonts makes the clock fonts again (the normal one and the double
|
||||
// size one used for the smooth pass) after the size or weight changed.
|
||||
func rebuildClockFonts() {
|
||||
weight := 400
|
||||
if clockBold {
|
||||
weight = 700
|
||||
}
|
||||
face := clockFonts[0]
|
||||
if clockFontIx > 0 && clockFontIx < len(clockFonts) {
|
||||
face = clockFonts[clockFontIx]
|
||||
}
|
||||
oldA, oldB := fontTime, fontTime2
|
||||
fontTime = makeFontFace(face, px(float64(clockPx())), weight)
|
||||
scale *= superSample
|
||||
fontTime2 = makeFontFace(face, px(float64(clockPx())), weight)
|
||||
scale /= superSample
|
||||
clockMeasured = float64(measureClockText()) / scale
|
||||
if oldA != 0 {
|
||||
pDeleteObject.Call(oldA)
|
||||
}
|
||||
if oldB != 0 {
|
||||
pDeleteObject.Call(oldB)
|
||||
}
|
||||
}
|
||||
|
||||
// measureClockText is how wide the longest time and date are in the clock font, in real pixels.
|
||||
func measureClockText() int32 {
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
if hdc == 0 {
|
||||
return 0
|
||||
}
|
||||
old, _, _ := pSelectObject.Call(hdc, fontTime)
|
||||
var sz struct{ cx, cy int32 }
|
||||
sample := "12:59 PM 12/30/2026"
|
||||
pGetTextExtentW.Call(hdc, uintptr(unsafe.Pointer(u16(sample))), uintptr(len(sample)), uintptr(unsafe.Pointer(&sz)))
|
||||
pSelectObject.Call(hdc, old)
|
||||
pReleaseDC.Call(0, hdc)
|
||||
return sz.cx
|
||||
}
|
||||
|
||||
// ---------- remembering the choices ----------
|
||||
|
||||
func lookFile() string { return filepath.Join(dataDir(), "look.txt") }
|
||||
|
||||
func loadLook() {
|
||||
b, err := os.ReadFile(lookFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, ln := range strings.Split(string(b), "\n") {
|
||||
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
n, err := strconv.Atoi(strings.TrimSpace(v))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
switch strings.TrimSpace(k) {
|
||||
case "barcolor":
|
||||
if n >= 0 && n < len(barPalette) {
|
||||
barIdx = n
|
||||
}
|
||||
case "logostyle":
|
||||
if n >= 0 && n < len(logoStyleNames) {
|
||||
logoStyle = n
|
||||
}
|
||||
case "clocksize":
|
||||
if n >= 0 && n < len(clockSizes) {
|
||||
clockSizeIx = n
|
||||
}
|
||||
case "clockbold":
|
||||
clockBold = n != 0
|
||||
case "clockfont":
|
||||
if n >= 0 && n < len(clockFonts) {
|
||||
clockFontIx = n
|
||||
}
|
||||
case "chargecolor":
|
||||
if n >= 0 && n < len(chargeColors) {
|
||||
chargeIx = n
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveLook() {
|
||||
s := "barcolor=" + strconv.Itoa(barIdx) +
|
||||
"\nlogostyle=" + strconv.Itoa(logoStyle) +
|
||||
"\nclocksize=" + strconv.Itoa(clockSizeIx) +
|
||||
"\nclockbold=" + b01(clockBold) +
|
||||
"\nclockfont=" + strconv.Itoa(clockFontIx) +
|
||||
"\nchargecolor=" + strconv.Itoa(chargeIx) + "\n"
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(lookFile(), []byte(s), 0o644)
|
||||
}
|
||||
|
||||
// ---------- the settings window calls these ----------
|
||||
|
||||
func setBarColor(i int) {
|
||||
if i < 0 || i >= len(barPalette) || i == barIdx {
|
||||
return
|
||||
}
|
||||
barIdx = i
|
||||
saveLook()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
|
||||
func setLogoStyle(i int) {
|
||||
if i < 0 || i >= len(logoStyleNames) || i == logoStyle {
|
||||
return
|
||||
}
|
||||
logoStyle = i
|
||||
saveLook()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
|
||||
func setClockSize(i int) {
|
||||
if i < 0 || i >= len(clockSizes) || i == clockSizeIx {
|
||||
return
|
||||
}
|
||||
clockSizeIx = i
|
||||
rebuildClockFonts()
|
||||
saveLook()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setClockBold(on bool) {
|
||||
if clockBold == on {
|
||||
return
|
||||
}
|
||||
clockBold = on
|
||||
rebuildClockFonts()
|
||||
saveLook()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setClockFont(i int) {
|
||||
if i < 0 || i >= len(clockFonts) || i == clockFontIx {
|
||||
return
|
||||
}
|
||||
clockFontIx = i
|
||||
rebuildClockFonts()
|
||||
saveLook()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setChargeColor(i int) {
|
||||
if i < 0 || i >= len(chargeColors) || i == chargeIx {
|
||||
return
|
||||
}
|
||||
chargeIx = i
|
||||
saveLook()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
|
||||
func setShowEmoji(on bool) {
|
||||
if showEmoji == on {
|
||||
return
|
||||
}
|
||||
showEmoji = on
|
||||
saveFeatures()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowClip(on bool) {
|
||||
if showClip == on {
|
||||
return
|
||||
}
|
||||
showClip = on
|
||||
saveFeatures()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowAI(on bool) {
|
||||
if showAI == on {
|
||||
return
|
||||
}
|
||||
showAI = on
|
||||
saveFeatures()
|
||||
if !on {
|
||||
flyClaude.closeWindow()
|
||||
flyGrok.closeWindow()
|
||||
}
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowMusic(on bool) {
|
||||
if showMusic == on {
|
||||
return
|
||||
}
|
||||
showMusic = on
|
||||
saveFeatures()
|
||||
if !on {
|
||||
flyPlayer.closeWindow()
|
||||
}
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowBattery(on bool) {
|
||||
if showBattery == on {
|
||||
return
|
||||
}
|
||||
showBattery = on
|
||||
saveFeatures()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowVolume(on bool) {
|
||||
if showVolume == on {
|
||||
return
|
||||
}
|
||||
showVolume = on
|
||||
saveFeatures()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
func setShowWifi(on bool) {
|
||||
if showWifi == on {
|
||||
return
|
||||
}
|
||||
showWifi = on
|
||||
saveFeatures()
|
||||
positionBar(hwndMain)
|
||||
}
|
||||
|
||||
// ---------- the Windows logo ----------
|
||||
|
||||
// roundRectRaw paints a filled rounded square with no outline.
|
||||
func roundRectRaw(hdc uintptr, l, t, r, b, rad int32, color uintptr) {
|
||||
brush, _, _ := pCreateSolidBrush.Call(color)
|
||||
nullPen, _, _ := pGetStockObject.Call(8) // NULL_PEN
|
||||
oldBrush, _, _ := pSelectObject.Call(hdc, brush)
|
||||
oldPen, _, _ := pSelectObject.Call(hdc, nullPen)
|
||||
pRoundRect.Call(hdc, uintptr(l), uintptr(t), uintptr(r), uintptr(b), uintptr(rad*2), uintptr(rad*2))
|
||||
pSelectObject.Call(hdc, oldPen)
|
||||
pSelectObject.Call(hdc, oldBrush)
|
||||
pDeleteObject.Call(brush)
|
||||
}
|
||||
|
||||
// drawLogoStyle draws the Windows logo in one of the shapes other than the
|
||||
// classic four squares. The four panes are laid out around the center of r.
|
||||
func drawLogoStyle(hdc uintptr, r rect) {
|
||||
if !layerFg {
|
||||
return
|
||||
}
|
||||
cx, cy := center(r)
|
||||
c := logoColor()
|
||||
|
||||
sq := float64(px(8)) // one pane
|
||||
gap := float64(px(2)) // the space between panes
|
||||
if logoStyle == 5 {
|
||||
sq, gap = float64(px(6)), float64(px(2)) // a diamond is wider than it looks, so shrink it
|
||||
}
|
||||
o := (sq + gap) / 2 // how far each pane's middle is from the logo's middle
|
||||
h := sq / 2
|
||||
offs := [4][2]float64{{-o, -o}, {o, -o}, {-o, o}, {o, o}}
|
||||
|
||||
// pane builds one pane's corners, moved by the transform for this style.
|
||||
pane := func(ox, oy float64, tf func(x, y float64) (float64, float64)) []point {
|
||||
corners := [4][2]float64{{ox - h, oy - h}, {ox + h, oy - h}, {ox + h, oy + h}, {ox - h, oy + h}}
|
||||
pts := make([]point, 4)
|
||||
for i, p := range corners {
|
||||
x, y := tf(p[0], p[1])
|
||||
pts[i] = point{cx + int32(math.Round(x)), cy + int32(math.Round(y))}
|
||||
}
|
||||
return pts
|
||||
}
|
||||
turn := func(deg float64) func(x, y float64) (float64, float64) {
|
||||
a := deg * math.Pi / 180
|
||||
s, co := math.Sin(a), math.Cos(a)
|
||||
return func(x, y float64) (float64, float64) { return x*co - y*s, x*s + y*co }
|
||||
}
|
||||
|
||||
switch logoStyle {
|
||||
case 1: // rounded squares
|
||||
rad := px(2)
|
||||
for _, f := range offs {
|
||||
l, t := cx+int32(math.Round(f[0]-h)), cy+int32(math.Round(f[1]-h))
|
||||
roundRectRaw(hdc, l, t, l+int32(sq), t+int32(sq), rad, c)
|
||||
}
|
||||
case 2: // four dots
|
||||
rad := int32(math.Round(sq * 0.46))
|
||||
for _, f := range offs {
|
||||
circleRaw(hdc, cx+int32(math.Round(f[0])), cy+int32(math.Round(f[1])), rad, c)
|
||||
}
|
||||
case 3: // tilted right
|
||||
for _, f := range offs {
|
||||
polygon(hdc, pane(f[0], f[1], turn(15)), c)
|
||||
}
|
||||
case 4: // tilted left
|
||||
for _, f := range offs {
|
||||
polygon(hdc, pane(f[0], f[1], turn(-15)), c)
|
||||
}
|
||||
case 5: // diamonds
|
||||
for _, f := range offs {
|
||||
polygon(hdc, pane(f[0], f[1], turn(45)), c)
|
||||
}
|
||||
case 6: // waving flag: every pane leans, and the left side sits lower than the right
|
||||
wave := func(x, y float64) (float64, float64) {
|
||||
return x, y - 0.22*x + 0.9*math.Sin(x*0.55)
|
||||
}
|
||||
for _, f := range offs {
|
||||
polygon(hdc, pane(f[0], f[1], wave), c)
|
||||
}
|
||||
case 7: // single circle
|
||||
circleRaw(hdc, cx, cy, px(9), c)
|
||||
case 8: // hexagon
|
||||
pts := make([]point, 6)
|
||||
for k := range pts {
|
||||
a := (float64(k)*60 - 30) * math.Pi / 180
|
||||
pts[k] = point{cx + int32(math.Round(float64(px(10))*math.Cos(a))), cy + int32(math.Round(float64(px(10))*math.Sin(a)))}
|
||||
}
|
||||
polygon(hdc, pts, c)
|
||||
case 9: // plus sign
|
||||
l, t := px(10), px(3)
|
||||
fillRaw(hdc, rect{cx - l, cy - t, cx + l, cy + t}, c)
|
||||
fillRaw(hdc, rect{cx - t, cy - l, cx + t, cy + l}, c)
|
||||
case 10: // three bars
|
||||
for _, dy := range []int32{-px(6), 0, px(6)} {
|
||||
fillRaw(hdc, rect{cx - px(9), cy + dy - px(1.5), cx + px(9), cy + dy + px(1.5)}, c)
|
||||
}
|
||||
case 11: // pills, two by two
|
||||
for _, ox := range []int32{-px(10), px(1)} {
|
||||
for _, oy := range []int32{-px(7), px(1)} {
|
||||
roundRectRaw(hdc, cx+ox, cy+oy, cx+ox+px(9), cy+oy+px(6), px(3), c)
|
||||
}
|
||||
}
|
||||
case 12: // triangle
|
||||
polygon(hdc, []point{{cx, cy - px(9)}, {cx + px(10), cy + px(8)}, {cx - px(10), cy + px(8)}}, c)
|
||||
}
|
||||
}
|
||||
@@ -331,6 +331,7 @@ var (
|
||||
hoverApp = -1
|
||||
trackingMouse bool
|
||||
scale float64 = 1
|
||||
realScale float64 = 1 // scale as the screen really is; scale itself is doubled while the icon layers are drawn
|
||||
barHeight int32
|
||||
fontTime uintptr
|
||||
fontDate uintptr
|
||||
@@ -476,7 +477,7 @@ func restoreAll() {
|
||||
// ---------- open windows ----------
|
||||
|
||||
func collectWindow(hwnd uintptr) {
|
||||
if hwnd == hwndMain || (gmHwnd != 0 && hwnd == gmHwnd) {
|
||||
if hwnd == hwndMain || (gmHwnd != 0 && hwnd == gmHwnd) || webFlyOwns(hwnd) {
|
||||
return
|
||||
}
|
||||
vis, _, _ := pIsWindowVisible.Call(hwnd)
|
||||
@@ -561,7 +562,6 @@ func activateApp(idx int) {
|
||||
// ---------- our bar ----------
|
||||
|
||||
func startWidth() int32 { return px(52) }
|
||||
func clockWidth() int32 { return px(140) }
|
||||
|
||||
func screenSize() (int32, int32) {
|
||||
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
||||
@@ -682,13 +682,25 @@ func drawText(hdc uintptr, s string, r rect) {
|
||||
// makeFont uses plain antialiasing (not ClearType) because ClearType's colored
|
||||
// edges look wrong on a transparent window.
|
||||
func makeFont(height int32, weight int) uintptr {
|
||||
return makeFontFace("Segoe UI", height, weight)
|
||||
}
|
||||
|
||||
// makeFontFace is makeFont for any installed font. A font that is not installed
|
||||
// quietly falls back to a default one.
|
||||
func makeFontFace(face string, height int32, weight int) uintptr {
|
||||
f, _, _ := pCreateFont.Call(
|
||||
uintptr(-height), 0, 0, 0, uintptr(weight), 0, 0, 0,
|
||||
1, 0, 0, 4, 0, uintptr(unsafe.Pointer(u16("Segoe UI"))))
|
||||
1, 0, 0, 4, 0, uintptr(unsafe.Pointer(u16(face))))
|
||||
return f
|
||||
}
|
||||
|
||||
func drawLogo(hdc uintptr, r rect) {
|
||||
if logoStyle != 0 {
|
||||
if !vertical { // a vertical bar draws it upright after turning (see renderLayer)
|
||||
drawLogoStyle(hdc, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
sq := px(8)
|
||||
gap := px(2)
|
||||
total := sq*2 + gap
|
||||
@@ -890,6 +902,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
|
||||
add(0, menuSettingsID, "MirrorBar settings...")
|
||||
add(0, menuNotifyID, "Open notification center")
|
||||
add(0, menuEmojiID, "Open emoji panel")
|
||||
sep()
|
||||
for i, l := range alphaLevels {
|
||||
var flags uintptr
|
||||
@@ -1010,6 +1023,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
gmPoll()
|
||||
return 0
|
||||
}
|
||||
if webFlyTimer(wparam) {
|
||||
return 0
|
||||
}
|
||||
if wparam == ahTimerID {
|
||||
ahTick(hwnd)
|
||||
return 0
|
||||
@@ -1025,6 +1041,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
if gmTick(tick) {
|
||||
changed = true
|
||||
}
|
||||
webFlyTick()
|
||||
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
|
||||
changed = true
|
||||
}
|
||||
@@ -1235,6 +1252,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
newsShutdown()
|
||||
sysShutdown()
|
||||
gmShutdown()
|
||||
webFlyShutdown()
|
||||
abd := appBarData{Hwnd: hwnd}
|
||||
appBar(abmRemove, &abd)
|
||||
pKillTimer.Call(hwnd, timerID)
|
||||
@@ -1304,12 +1322,15 @@ func main() {
|
||||
if dpi > 0 {
|
||||
scale = float64(dpi) / 96.0
|
||||
}
|
||||
realScale = scale
|
||||
barHeight = px(36)
|
||||
fontTime = makeFont(px(13), 400)
|
||||
fontDate = makeFont(px(11), 400)
|
||||
fontApp = makeFont(px(12), 600)
|
||||
initSuperFonts()
|
||||
loadColors()
|
||||
loadLook()
|
||||
rebuildClockFonts()
|
||||
|
||||
autoQuit = autoQuitDef
|
||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||
|
||||
@@ -120,6 +120,7 @@ func newsToggle() {
|
||||
weatherHide() // one panel at a time
|
||||
sysHide()
|
||||
gmHide()
|
||||
webFlyHideAll()
|
||||
newsRefresh(false)
|
||||
newsShown = true
|
||||
newsPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
package main
|
||||
|
||||
// The mp3 and audiobook player. MirrorBar runs a tiny web server that listens
|
||||
// only on this PC (127.0.0.1), serves the player page and the audio files from
|
||||
// the folder you picked, and remembers where you were: which file, how far in,
|
||||
// the volume and the speed, separately for every folder or file you have played.
|
||||
// The window itself is a small Edge app window (see webfly.go).
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"mime"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var audioExts = map[string]string{
|
||||
".mp3": "audio/mpeg", ".m4a": "audio/mp4", ".m4b": "audio/mp4", ".aac": "audio/aac",
|
||||
".ogg": "audio/ogg", ".oga": "audio/ogg", ".opus": "audio/ogg", ".wav": "audio/wav", ".flac": "audio/flac",
|
||||
}
|
||||
|
||||
type playSpot struct {
|
||||
Index int `json:"index"`
|
||||
Pos float64 `json:"pos"`
|
||||
}
|
||||
|
||||
type playerState struct {
|
||||
Source string `json:"source"` // folder or single file
|
||||
Vol float64 `json:"vol"`
|
||||
Rate float64 `json:"rate"`
|
||||
Spots map[string]playSpot `json:"spots"`
|
||||
}
|
||||
|
||||
var (
|
||||
plMu sync.Mutex
|
||||
plState = playerState{Vol: 1, Rate: 1, Spots: map[string]playSpot{}}
|
||||
plFiles []string // full paths, in play order
|
||||
plLoaded bool
|
||||
plPort int
|
||||
plStart sync.Once
|
||||
)
|
||||
|
||||
func playerStateFile() string { return filepath.Join(dataDir(), "player.json") }
|
||||
|
||||
func playerLoad() {
|
||||
if plLoaded {
|
||||
return
|
||||
}
|
||||
plLoaded = true
|
||||
if b, err := os.ReadFile(playerStateFile()); err == nil {
|
||||
var s playerState
|
||||
if json.Unmarshal(b, &s) == nil {
|
||||
if s.Spots == nil {
|
||||
s.Spots = map[string]playSpot{}
|
||||
}
|
||||
if s.Vol <= 0 || s.Vol > 1 {
|
||||
s.Vol = 1
|
||||
}
|
||||
if s.Rate < 0.5 || s.Rate > 3 {
|
||||
s.Rate = 1
|
||||
}
|
||||
plState = s
|
||||
}
|
||||
}
|
||||
plFiles = scanAudio(plState.Source)
|
||||
}
|
||||
|
||||
func playerSave() {
|
||||
b, err := json.Marshal(plState)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(playerStateFile(), b, 0o644)
|
||||
}
|
||||
|
||||
func isAudio(p string) bool {
|
||||
_, ok := audioExts[strings.ToLower(filepath.Ext(p))]
|
||||
return ok
|
||||
}
|
||||
|
||||
// scanAudio lists the audio in a folder (sub folders too) in natural order, so
|
||||
// "Chapter 2" comes before "Chapter 10", or returns the one file itself.
|
||||
func scanAudio(src string) []string {
|
||||
if src == "" {
|
||||
return nil
|
||||
}
|
||||
st, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if !st.IsDir() {
|
||||
if isAudio(src) {
|
||||
return []string{src}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var out []string
|
||||
_ = filepath.WalkDir(src, func(p string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if !d.IsDir() && isAudio(p) && len(out) < 5000 {
|
||||
out = append(out, p)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
sort.SliceStable(out, func(i, j int) bool { return naturalLess(out[i], out[j]) })
|
||||
return out
|
||||
}
|
||||
|
||||
func naturalLess(a, b string) bool {
|
||||
a, b = strings.ToLower(a), strings.ToLower(b)
|
||||
i, j := 0, 0
|
||||
for i < len(a) && j < len(b) {
|
||||
if unicode.IsDigit(rune(a[i])) && unicode.IsDigit(rune(b[j])) {
|
||||
si := i
|
||||
for i < len(a) && unicode.IsDigit(rune(a[i])) {
|
||||
i++
|
||||
}
|
||||
sj := j
|
||||
for j < len(b) && unicode.IsDigit(rune(b[j])) {
|
||||
j++
|
||||
}
|
||||
na, nb := strings.TrimLeft(a[si:i], "0"), strings.TrimLeft(b[sj:j], "0")
|
||||
if len(na) != len(nb) {
|
||||
return len(na) < len(nb)
|
||||
}
|
||||
if na != nb {
|
||||
return na < nb
|
||||
}
|
||||
continue
|
||||
}
|
||||
if a[i] != b[j] {
|
||||
return a[i] < b[j]
|
||||
}
|
||||
i++
|
||||
j++
|
||||
}
|
||||
return len(a)-i < len(b)-j
|
||||
}
|
||||
|
||||
func trackName(src, p string) string {
|
||||
rel := p
|
||||
if st, err := os.Stat(src); err == nil && st.IsDir() {
|
||||
if r, err := filepath.Rel(src, p); err == nil {
|
||||
rel = r
|
||||
}
|
||||
} else {
|
||||
rel = filepath.Base(p)
|
||||
}
|
||||
rel = strings.TrimSuffix(rel, filepath.Ext(rel))
|
||||
return strings.ReplaceAll(rel, string(filepath.Separator), " / ")
|
||||
}
|
||||
|
||||
type playerView struct {
|
||||
Source string `json:"source"`
|
||||
Name string `json:"name"`
|
||||
Tracks []string `json:"tracks"`
|
||||
Index int `json:"index"`
|
||||
Pos float64 `json:"pos"`
|
||||
Vol float64 `json:"vol"`
|
||||
Rate float64 `json:"rate"`
|
||||
}
|
||||
|
||||
func playerViewNow() playerView {
|
||||
v := playerView{Source: plState.Source, Vol: plState.Vol, Rate: plState.Rate, Tracks: []string{}}
|
||||
if plState.Source != "" {
|
||||
v.Name = filepath.Base(plState.Source)
|
||||
if v.Name == "" || v.Name == "." || v.Name == string(filepath.Separator) {
|
||||
v.Name = plState.Source
|
||||
}
|
||||
}
|
||||
for _, p := range plFiles {
|
||||
v.Tracks = append(v.Tracks, trackName(plState.Source, p))
|
||||
}
|
||||
if sp, ok := plState.Spots[plState.Source]; ok && sp.Index >= 0 && sp.Index < len(plFiles) {
|
||||
v.Index, v.Pos = sp.Index, sp.Pos
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func playerURL() string {
|
||||
plStart.Do(playerServe)
|
||||
return fmt.Sprintf("http://127.0.0.1:%d/", plPort)
|
||||
}
|
||||
|
||||
func playerServe() {
|
||||
plMu.Lock()
|
||||
playerLoad()
|
||||
plMu.Unlock()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
plPort = ln.Addr().(*net.TCPAddr).Port
|
||||
mux := http.NewServeMux()
|
||||
guard := func(h http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// only this program's own page may talk to the server
|
||||
if r.Host != fmt.Sprintf("127.0.0.1:%d", plPort) {
|
||||
http.Error(w, "no", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
h(w, r)
|
||||
}
|
||||
}
|
||||
mux.HandleFunc("/", guard(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_, _ = w.Write([]byte(playerPage))
|
||||
}))
|
||||
mux.HandleFunc("/api/state", guard(func(w http.ResponseWriter, r *http.Request) {
|
||||
plMu.Lock()
|
||||
v := playerViewNow()
|
||||
plMu.Unlock()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
_ = json.NewEncoder(w).Encode(v)
|
||||
}))
|
||||
mux.HandleFunc("/api/file", guard(func(w http.ResponseWriter, r *http.Request) {
|
||||
var i int
|
||||
fmt.Sscanf(r.URL.Query().Get("i"), "%d", &i)
|
||||
plMu.Lock()
|
||||
var p string
|
||||
if i >= 0 && i < len(plFiles) {
|
||||
p = plFiles[i]
|
||||
}
|
||||
plMu.Unlock()
|
||||
if p == "" {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
f, err := os.Open(p)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
st, err := f.Stat()
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
ct := audioExts[strings.ToLower(filepath.Ext(p))]
|
||||
if ct == "" {
|
||||
ct = mime.TypeByExtension(filepath.Ext(p))
|
||||
}
|
||||
w.Header().Set("Content-Type", ct)
|
||||
http.ServeContent(w, r, filepath.Base(p), st.ModTime(), f)
|
||||
}))
|
||||
mux.HandleFunc("/api/save", guard(func(w http.ResponseWriter, r *http.Request) {
|
||||
var in struct {
|
||||
Index int `json:"index"`
|
||||
Pos float64 `json:"pos"`
|
||||
Vol float64 `json:"vol"`
|
||||
Rate float64 `json:"rate"`
|
||||
}
|
||||
if json.NewDecoder(http.MaxBytesReader(w, r.Body, 4096)).Decode(&in) != nil {
|
||||
http.Error(w, "bad", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
plMu.Lock()
|
||||
if plState.Source != "" {
|
||||
plState.Spots[plState.Source] = playSpot{Index: in.Index, Pos: in.Pos}
|
||||
}
|
||||
if in.Vol >= 0 && in.Vol <= 1 {
|
||||
plState.Vol = in.Vol
|
||||
}
|
||||
if in.Rate >= 0.5 && in.Rate <= 3 {
|
||||
plState.Rate = in.Rate
|
||||
}
|
||||
playerSave()
|
||||
plMu.Unlock()
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
mux.HandleFunc("/api/pick", guard(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "no", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
playerPick(r.URL.Query().Get("kind") == "folder")
|
||||
plMu.Lock()
|
||||
v := playerViewNow()
|
||||
plMu.Unlock()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(v)
|
||||
}))
|
||||
go func() { _ = http.Serve(ln, mux) }()
|
||||
}
|
||||
|
||||
// playerPick opens a standard Windows folder or file dialog (through PowerShell,
|
||||
// which is on every Windows 11 PC), then loads what was picked.
|
||||
func playerPick(folder bool) {
|
||||
if !pickBusy.CompareAndSwap(false, true) {
|
||||
return
|
||||
}
|
||||
defer pickBusy.Store(false)
|
||||
script := `Add-Type -AssemblyName System.Windows.Forms
|
||||
$o = New-Object System.Windows.Forms.Form
|
||||
$o.TopMost = $true
|
||||
$o.ShowInTaskbar = $false
|
||||
$o.StartPosition = 'CenterScreen'
|
||||
$o.Size = New-Object System.Drawing.Size(1,1)
|
||||
$o.Opacity = 0
|
||||
$o.Show()
|
||||
$o.Activate()
|
||||
`
|
||||
if folder {
|
||||
script += `$d = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$d.Description = 'Pick the folder with your music or audiobook'
|
||||
$d.ShowNewFolderButton = $false
|
||||
if ($d.ShowDialog($o) -eq 'OK') { [Console]::Out.Write($d.SelectedPath) }`
|
||||
} else {
|
||||
script += `$d = New-Object System.Windows.Forms.OpenFileDialog
|
||||
$d.Title = 'Pick an audio file'
|
||||
$d.Filter = 'Audio files|*.mp3;*.m4a;*.m4b;*.aac;*.ogg;*.oga;*.opus;*.wav;*.flac|All files|*.*'
|
||||
if ($d.ShowDialog($o) -eq 'OK') { [Console]::Out.Write($d.FileName) }`
|
||||
}
|
||||
script += "\n$o.Close()"
|
||||
cmd := exec.Command("powershell.exe", "-NoProfile", "-STA", "-WindowStyle", "Hidden", "-Command", script)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
src := strings.TrimSpace(string(out))
|
||||
if src == "" {
|
||||
return
|
||||
}
|
||||
files := scanAudio(src)
|
||||
plMu.Lock()
|
||||
defer plMu.Unlock()
|
||||
if len(files) == 0 {
|
||||
return
|
||||
}
|
||||
plState.Source = src
|
||||
plFiles = files
|
||||
playerSave()
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package main
|
||||
|
||||
// The page shown in the player flyout.
|
||||
|
||||
const playerPage = `<!DOCTYPE html>
|
||||
<html><head><meta charset="utf-8"><title>MirrorBar Player</title>
|
||||
<style>
|
||||
*{box-sizing:border-box;border-radius:0}
|
||||
html,body{margin:0;height:100%;background:#1b1b22;color:#e8e8ee;font:14px "Segoe UI",sans-serif;overflow:hidden}
|
||||
#app{display:flex;flex-direction:column;height:100%;padding:12px;gap:10px}
|
||||
#src{font-size:12px;color:#9a9aa8;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
#now{font-size:17px;font-weight:600;line-height:1.25;min-height:44px;overflow:hidden}
|
||||
button,select{background:#2c2c38;color:#e8e8ee;border:1px solid #444456;padding:7px 10px;font:inherit;cursor:pointer}
|
||||
button:hover,select:hover{background:#3a3a4a}
|
||||
button.main{background:#5b6ee1;border-color:#5b6ee1;min-width:64px;font-size:16px}
|
||||
button.main:hover{background:#6e80ee}
|
||||
#ctl{display:flex;gap:6px;align-items:center;justify-content:center}
|
||||
#seekrow{display:flex;gap:8px;align-items:center;font-size:12px;color:#b8b8c6}
|
||||
#seek{flex:1}
|
||||
input[type=range]{accent-color:#5b6ee1}
|
||||
#opts{display:flex;gap:8px;align-items:center;font-size:12px;color:#b8b8c6}
|
||||
#vol{width:90px}
|
||||
#opts .sp{flex:1}
|
||||
#list{flex:1;overflow-y:auto;border:1px solid #333344;background:#15151b}
|
||||
.t{padding:6px 10px;cursor:pointer;border-bottom:1px solid #222230;font-size:13px}
|
||||
.t:hover{background:#262633}
|
||||
.t.on{background:#333a66;color:#fff}
|
||||
#empty{padding:20px;color:#9a9aa8;text-align:center;line-height:1.6}
|
||||
</style></head>
|
||||
<body><div id="app">
|
||||
<div id="src">No folder picked</div>
|
||||
<div id="now">Pick a music or audiobook folder to start.</div>
|
||||
<div id="seekrow"><span id="cur">0:00</span><input id="seek" type="range" min="0" max="1000" value="0"><span id="dur">0:00</span></div>
|
||||
<div id="ctl">
|
||||
<button id="prev" title="Previous file">⏮</button>
|
||||
<button id="back" title="Back 15 seconds">-15</button>
|
||||
<button id="play" class="main" title="Play or pause (space)">▶</button>
|
||||
<button id="fwd" title="Forward 30 seconds">+30</button>
|
||||
<button id="next" title="Next file">⏭</button>
|
||||
</div>
|
||||
<div id="opts">
|
||||
<span>Speed</span>
|
||||
<select id="rate"><option>0.75</option><option>1</option><option>1.25</option><option>1.5</option><option>1.75</option><option>2</option></select>
|
||||
<span class="sp"></span>
|
||||
<span>Volume</span><input id="vol" type="range" min="0" max="100" value="100">
|
||||
</div>
|
||||
<div id="opts">
|
||||
<button id="pickf">Folder...</button><button id="pickx">File...</button>
|
||||
</div>
|
||||
<div id="list"></div>
|
||||
<audio id="au" preload="auto"></audio>
|
||||
</div>
|
||||
<script>
|
||||
var au=document.getElementById('au'),tracks=[],idx=0,source='',loaded=false,seeking=false,lastSave=0;
|
||||
function $(i){return document.getElementById(i)}
|
||||
function fmt(s){if(!isFinite(s)||s<0)s=0;s=Math.floor(s);var h=Math.floor(s/3600),m=Math.floor(s%3600/60),c=s%60;
|
||||
return (h?h+':'+(m<10?'0':''):'')+m+':'+(c<10?'0':'')+c}
|
||||
function save(){
|
||||
if(!source)return;
|
||||
lastSave=Date.now();
|
||||
try{fetch('/api/save',{method:'POST',body:JSON.stringify({index:idx,pos:au.currentTime||0,vol:au.volume,rate:au.playbackRate}),keepalive:true})}catch(e){}
|
||||
}
|
||||
function render(){
|
||||
var L=$('list');L.innerHTML='';
|
||||
if(!tracks.length){
|
||||
var e=document.createElement('div');e.id='empty';
|
||||
e.textContent=source?'No audio files found in that folder.':'Use Folder... for a folder of mp3s or an audiobook, or File... for one file.';
|
||||
L.appendChild(e);return}
|
||||
tracks.forEach(function(n,i){
|
||||
var d=document.createElement('div');d.className='t'+(i==idx?' on':'');d.textContent=(i+1)+'. '+n;
|
||||
d.onclick=function(){go(i,0,true)};L.appendChild(d)});
|
||||
var on=L.querySelector('.on');if(on)on.scrollIntoView({block:'nearest'});
|
||||
}
|
||||
function go(i,pos,play){
|
||||
if(i<0||i>=tracks.length)return;
|
||||
idx=i;au.src='/api/file?i='+i;
|
||||
var p=pos||0;
|
||||
au.onloadedmetadata=function(){if(p>0&&p<au.duration-1)au.currentTime=p;au.onloadedmetadata=null};
|
||||
$('now').textContent=tracks[i];
|
||||
render();
|
||||
if(play){au.play().catch(function(){})}
|
||||
save();
|
||||
}
|
||||
function apply(v,keepPlaying){
|
||||
source=v.source;tracks=v.tracks||[];
|
||||
$('src').textContent=source?v.name+' ('+tracks.length+' files)':'No folder picked';
|
||||
au.volume=v.vol;$('vol').value=Math.round(v.vol*100);
|
||||
au.playbackRate=v.rate;
|
||||
var r=$('rate'),f=false;for(var k=0;k<r.options.length;k++){if(parseFloat(r.options[k].value)==v.rate){r.selectedIndex=k;f=true}}
|
||||
if(!f){var o=document.createElement('option');o.text=v.rate;r.add(o);r.value=o.text}
|
||||
if(tracks.length){go(Math.min(v.index,tracks.length-1),v.pos,false)}else{idx=0;au.removeAttribute('src');$('now').textContent='Pick a music or audiobook folder to start.';render()}
|
||||
}
|
||||
function load(){
|
||||
fetch('/api/state').then(function(r){return r.json()}).then(function(v){apply(v);loaded=true})
|
||||
}
|
||||
function toggle(){if(!tracks.length)return;if(au.paused)au.play().catch(function(){});else au.pause()}
|
||||
$('play').onclick=toggle;
|
||||
$('prev').onclick=function(){if(au.currentTime>5)au.currentTime=0;else go(idx-1,0,!au.paused)};
|
||||
$('next').onclick=function(){go(idx+1,0,!au.paused)};
|
||||
$('back').onclick=function(){au.currentTime=Math.max(0,au.currentTime-15)};
|
||||
$('fwd').onclick=function(){au.currentTime=Math.min(au.duration||1e9,au.currentTime+30)};
|
||||
$('rate').onchange=function(){au.playbackRate=parseFloat($('rate').value);save()};
|
||||
$('vol').oninput=function(){au.volume=$('vol').value/100;save()};
|
||||
$('pickf').onclick=function(){pick('folder')};
|
||||
$('pickx').onclick=function(){pick('file')};
|
||||
function pick(k){fetch('/api/pick?kind='+k,{method:'POST'}).then(function(r){return r.json()}).then(function(v){if(v.source!==source){au.pause();apply(v)}})}
|
||||
$('seek').oninput=function(){seeking=true;$('cur').textContent=fmt($('seek').value/1000*(au.duration||0))};
|
||||
$('seek').onchange=function(){if(au.duration)au.currentTime=$('seek').value/1000*au.duration;seeking=false;save()};
|
||||
au.ontimeupdate=function(){
|
||||
if(!seeking&&au.duration){$('seek').value=Math.round(au.currentTime/au.duration*1000);$('cur').textContent=fmt(au.currentTime)}
|
||||
$('dur').textContent=fmt(au.duration);
|
||||
if(Date.now()-lastSave>5000&&!au.paused)save();
|
||||
};
|
||||
au.onplay=function(){$('play').innerHTML='❚❚'};
|
||||
au.onpause=function(){$('play').innerHTML='▶';save()};
|
||||
au.onended=function(){if(idx+1<tracks.length)go(idx+1,0,true);else{$('play').innerHTML='▶';save()}};
|
||||
au.onerror=function(){if(au.src&&idx+1<tracks.length)go(idx+1,0,true)};
|
||||
document.onkeydown=function(e){
|
||||
if(e.target.tagName==='SELECT')return;
|
||||
if(e.code==='Space'){e.preventDefault();toggle()}
|
||||
else if(e.code==='ArrowLeft'&&e.target.tagName!=='INPUT'){au.currentTime=Math.max(0,au.currentTime-15)}
|
||||
else if(e.code==='ArrowRight'&&e.target.tagName!=='INPUT'){au.currentTime+=30}
|
||||
};
|
||||
document.addEventListener('visibilitychange',save);
|
||||
window.addEventListener('pagehide',save);
|
||||
setInterval(function(){
|
||||
if(!loaded)return;
|
||||
fetch('/api/state').then(function(r){return r.json()}).then(function(v){if(v.source!==source){au.pause();apply(v)}}).catch(function(){});
|
||||
},2000);
|
||||
load();
|
||||
</script></body></html>`
|
||||
@@ -1,392 +1,422 @@
|
||||
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)
|
||||
case trayWeather:
|
||||
drawWeatherIcon(memV, r)
|
||||
case trayNews:
|
||||
drawNewsIcon(memV, r)
|
||||
case traySys:
|
||||
drawSysIcon(memV, r)
|
||||
case trayGM:
|
||||
drawGMIcon(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
|
||||
}
|
||||
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 = 300 // 40 apart so the color menus can grow past 20 colors
|
||||
menuClockColorBase = 340
|
||||
menuIconColorBase = 380
|
||||
)
|
||||
|
||||
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},
|
||||
{"Dark green", 20, 120, 55},
|
||||
{"Teal", 0, 160, 160},
|
||||
{"Navy", 30, 60, 160},
|
||||
{"Maroon", 140, 30, 50},
|
||||
{"Gray", 140, 140, 150},
|
||||
{"Lime", 150, 220, 40},
|
||||
{"Brown", 150, 100, 60},
|
||||
{"Mint", 150, 230, 200},
|
||||
{"Lavender", 190, 170, 240},
|
||||
{"Gold", 210, 170, 50},
|
||||
{"Coral", 255, 120, 100},
|
||||
{"Silver", 200, 200, 210},
|
||||
{"Slate", 90, 105, 125},
|
||||
{"Olive", 130, 140, 50},
|
||||
}
|
||||
|
||||
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 {
|
||||
if logoStyle != 0 {
|
||||
drawLogoStyle(memV, mapRect(sr, h))
|
||||
}
|
||||
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)
|
||||
case trayWeather:
|
||||
drawWeatherIcon(memV, r)
|
||||
case trayNews:
|
||||
drawNewsIcon(memV, r)
|
||||
case traySys:
|
||||
drawSysIcon(memV, r)
|
||||
case trayGM:
|
||||
drawGMIcon(memV, r)
|
||||
case trayEmoji:
|
||||
drawEmojiIcon(memV, r)
|
||||
case trayClip:
|
||||
drawClipIcon(memV, r)
|
||||
case trayAI:
|
||||
drawAIIcon(memV, r)
|
||||
case trayMusic:
|
||||
drawMusicIcon(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)
|
||||
barC := barRGB()
|
||||
lightBar := barIsLight()
|
||||
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
|
||||
c = hoverTint(c, lightBar)
|
||||
} else {
|
||||
c = barC
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
+110
-1
@@ -75,6 +75,20 @@ const (
|
||||
idShowGM = 217
|
||||
idGroup = 218
|
||||
idAutoHide = 219
|
||||
|
||||
idBarColor = 220
|
||||
idLogoStyle = 221
|
||||
idClockSize = 222
|
||||
idClockBold = 223
|
||||
idShowBattery = 224
|
||||
idShowVolume = 225
|
||||
idShowWifi = 226
|
||||
idShowEmoji = 227
|
||||
idClockFont = 228
|
||||
idChargeColor = 229
|
||||
idShowClip = 230
|
||||
idShowAI = 231
|
||||
idShowMusic = 232
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -87,6 +101,10 @@ var (
|
||||
ctlZip, ctlZipStatus uintptr
|
||||
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
|
||||
ctlGroup, ctlAutoHide uintptr
|
||||
ctlBarColor, ctlLogoStyle, ctlClockSize, ctlClockBold uintptr
|
||||
ctlShowBattery, ctlShowVolume, ctlShowWifi uintptr
|
||||
ctlShowEmoji, ctlClockFont, ctlChargeColor uintptr
|
||||
ctlShowClip, ctlShowAI, ctlShowMusic uintptr
|
||||
zipSyncing bool // true while the program itself is filling in the ZIP box
|
||||
)
|
||||
|
||||
@@ -138,7 +156,7 @@ func openSettings() {
|
||||
settingsFont = makeFont(px(13), 400)
|
||||
}
|
||||
|
||||
r := rect{0, 0, px(400), px(572)}
|
||||
r := rect{0, 0, px(800), px(572)}
|
||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||
sw, sh := screenSize()
|
||||
@@ -196,6 +214,52 @@ func openSettings() {
|
||||
ctlGroup = makeControl(hw, inst, "BUTTON", "Combine windows of the same program into one icon", bsAutoCheckBox|wsTabStop, 16, 458, 368, 22, idGroup)
|
||||
ctlAutoHide = makeControl(hw, inst, "BUTTON", "Hide the bar until the mouse touches the screen edge", bsAutoCheckBox|wsTabStop, 16, 486, 368, 22, idAutoHide)
|
||||
|
||||
// The right-hand column: how the bar looks, and what is on it.
|
||||
combo2 := func(y int, id uintptr) uintptr {
|
||||
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 560, y, 224, 200, id)
|
||||
}
|
||||
label2 := func(text string, y int) {
|
||||
makeControl(hw, inst, "STATIC", text, 0, 416, y+4, 140, 20, 0)
|
||||
}
|
||||
label2("Bar color", 16)
|
||||
ctlBarColor = combo2(16, idBarColor)
|
||||
label2("Windows logo shape", 52)
|
||||
ctlLogoStyle = combo2(52, idLogoStyle)
|
||||
label2("Clock font", 88)
|
||||
ctlClockFont = combo2(88, idClockFont)
|
||||
label2("Clock text size", 124)
|
||||
ctlClockSize = combo2(124, idClockSize)
|
||||
ctlClockBold = makeControl(hw, inst, "BUTTON", "Bold clock text", bsAutoCheckBox|wsTabStop, 416, 160, 368, 22, idClockBold)
|
||||
label2("Battery charging color", 196)
|
||||
ctlChargeColor = combo2(196, idChargeColor)
|
||||
makeControl(hw, inst, "STATIC", "Show on the bar:", 0, 416, 244, 368, 20, 0)
|
||||
ctlShowBattery = makeControl(hw, inst, "BUTTON", "Battery", bsAutoCheckBox|wsTabStop, 416, 270, 368, 22, idShowBattery)
|
||||
ctlShowVolume = makeControl(hw, inst, "BUTTON", "Volume", bsAutoCheckBox|wsTabStop, 416, 298, 368, 22, idShowVolume)
|
||||
ctlShowWifi = makeControl(hw, inst, "BUTTON", "Wifi", bsAutoCheckBox|wsTabStop, 416, 326, 368, 22, idShowWifi)
|
||||
ctlShowEmoji = makeControl(hw, inst, "BUTTON", "Emoji panel button", bsAutoCheckBox|wsTabStop, 416, 354, 368, 22, idShowEmoji)
|
||||
ctlShowClip = makeControl(hw, inst, "BUTTON", "Clipboard history button", bsAutoCheckBox|wsTabStop, 416, 382, 368, 22, idShowClip)
|
||||
ctlShowAI = makeControl(hw, inst, "BUTTON", "Claude and Grok button", bsAutoCheckBox|wsTabStop, 416, 410, 368, 22, idShowAI)
|
||||
ctlShowMusic = makeControl(hw, inst, "BUTTON", "MP3 player button", bsAutoCheckBox|wsTabStop, 416, 438, 368, 22, idShowMusic)
|
||||
for _, b := range barPalette {
|
||||
pSendMessage.Call(ctlBarColor, cbAddString, 0, uintptr(unsafe.Pointer(u16(b.name))))
|
||||
}
|
||||
for _, n := range logoStyleNames {
|
||||
pSendMessage.Call(ctlLogoStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||
}
|
||||
for _, c := range clockSizes {
|
||||
pSendMessage.Call(ctlClockSize, cbAddString, 0, uintptr(unsafe.Pointer(u16(c.name))))
|
||||
}
|
||||
for i, f := range clockFonts {
|
||||
name := f
|
||||
if i == 0 {
|
||||
name = f + " (default)"
|
||||
}
|
||||
pSendMessage.Call(ctlClockFont, cbAddString, 0, uintptr(unsafe.Pointer(u16(name))))
|
||||
}
|
||||
for _, c := range chargeColors {
|
||||
pSendMessage.Call(ctlChargeColor, cbAddString, 0, uintptr(unsafe.Pointer(u16(c.name))))
|
||||
}
|
||||
|
||||
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 526, 116, 28, idResetPos)
|
||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 526, 116, 28, idResetWidth)
|
||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 526, 92, 28, idClose)
|
||||
@@ -226,6 +290,19 @@ func settingsSync() {
|
||||
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
||||
pSendMessage.Call(ctlGroup, bmSetCheck, boolWP(groupWins), 0)
|
||||
pSendMessage.Call(ctlAutoHide, bmSetCheck, boolWP(autoHide), 0)
|
||||
pSendMessage.Call(ctlBarColor, cbSetCurSel, uintptr(barIdx), 0)
|
||||
pSendMessage.Call(ctlLogoStyle, cbSetCurSel, uintptr(logoStyle), 0)
|
||||
pSendMessage.Call(ctlClockSize, cbSetCurSel, uintptr(clockSizeIx), 0)
|
||||
pSendMessage.Call(ctlClockBold, bmSetCheck, boolWP(clockBold), 0)
|
||||
pSendMessage.Call(ctlClockFont, cbSetCurSel, uintptr(clockFontIx), 0)
|
||||
pSendMessage.Call(ctlChargeColor, cbSetCurSel, uintptr(chargeIx), 0)
|
||||
pSendMessage.Call(ctlShowEmoji, bmSetCheck, boolWP(showEmoji), 0)
|
||||
pSendMessage.Call(ctlShowClip, bmSetCheck, boolWP(showClip), 0)
|
||||
pSendMessage.Call(ctlShowAI, bmSetCheck, boolWP(showAI), 0)
|
||||
pSendMessage.Call(ctlShowMusic, bmSetCheck, boolWP(showMusic), 0)
|
||||
pSendMessage.Call(ctlShowBattery, bmSetCheck, boolWP(showBattery), 0)
|
||||
pSendMessage.Call(ctlShowVolume, bmSetCheck, boolWP(showVolume), 0)
|
||||
pSendMessage.Call(ctlShowWifi, bmSetCheck, boolWP(showWifi), 0)
|
||||
|
||||
// Leave the ZIP box alone while the person is typing in it.
|
||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||
@@ -336,6 +413,38 @@ func settingsCommand(id, note uintptr) {
|
||||
setGroupWins(checked(ctlGroup))
|
||||
case idAutoHide:
|
||||
setAutoHide(checked(ctlAutoHide))
|
||||
case idBarColor, idLogoStyle, idClockSize, idClockFont, idChargeColor:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
case idBarColor:
|
||||
setBarColor(comboChoice(ctlBarColor))
|
||||
case idLogoStyle:
|
||||
setLogoStyle(comboChoice(ctlLogoStyle))
|
||||
case idClockSize:
|
||||
setClockSize(comboChoice(ctlClockSize))
|
||||
case idClockFont:
|
||||
setClockFont(comboChoice(ctlClockFont))
|
||||
case idChargeColor:
|
||||
setChargeColor(comboChoice(ctlChargeColor))
|
||||
}
|
||||
case idClockBold:
|
||||
setClockBold(checked(ctlClockBold))
|
||||
case idShowBattery:
|
||||
setShowBattery(checked(ctlShowBattery))
|
||||
case idShowVolume:
|
||||
setShowVolume(checked(ctlShowVolume))
|
||||
case idShowWifi:
|
||||
setShowWifi(checked(ctlShowWifi))
|
||||
case idShowEmoji:
|
||||
setShowEmoji(checked(ctlShowEmoji))
|
||||
case idShowClip:
|
||||
setShowClip(checked(ctlShowClip))
|
||||
case idShowAI:
|
||||
setShowAI(checked(ctlShowAI))
|
||||
case idShowMusic:
|
||||
setShowMusic(checked(ctlShowMusic))
|
||||
case idAutostart:
|
||||
setAutostart(checked(ctlAutostart))
|
||||
settingsSync()
|
||||
|
||||
@@ -138,6 +138,7 @@ func sysToggle() {
|
||||
weatherHide() // one panel at a time
|
||||
newsHide()
|
||||
gmHide()
|
||||
webFlyHideAll()
|
||||
sysRows = sysGather()
|
||||
sysShown = true
|
||||
sysPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||
|
||||
@@ -0,0 +1,580 @@
|
||||
package main
|
||||
|
||||
// Small browser-window flyouts: the AI button (Claude and Grok) and the mp3
|
||||
// player. They work like the Messages flyout: Microsoft Edge is started in "app"
|
||||
// mode (no tabs, no address bar) with its own private profile folder, the window
|
||||
// is kept just off the edge of the screen while the flyout is closed, clicking
|
||||
// the button on the bar slides it above the bar, and clicking anywhere else
|
||||
// slides it away again. Because the page keeps running while parked, music keeps
|
||||
// playing after the player flyout is closed.
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type webFly struct {
|
||||
name string // "Claude", "Grok", "Player"
|
||||
kind int // the tray item that opens it
|
||||
timerID uintptr
|
||||
w, h float64 // size in 96 dpi units
|
||||
profile string // folder name under the MirrorBar data folder
|
||||
url func() string
|
||||
title string // lower case text that the window title contains
|
||||
hwnd uintptr
|
||||
pid uint32
|
||||
shown bool
|
||||
prevBtn bool
|
||||
prevFg uintptr
|
||||
shownAt time.Time
|
||||
launched time.Time
|
||||
starting bool
|
||||
wantOpen bool
|
||||
}
|
||||
|
||||
var (
|
||||
flyClaude = &webFly{name: "Claude", kind: trayAI, timerID: 4, w: 480, h: 720, profile: "claude",
|
||||
url: func() string { return "https://claude.ai/new" }, title: "claude"}
|
||||
flyGrok = &webFly{name: "Grok", kind: trayAI, timerID: 5, w: 480, h: 720, profile: "grok",
|
||||
url: func() string { return "https://grok.com/" }, title: "grok"}
|
||||
flyPlayer = &webFly{name: "Player", kind: trayMusic, timerID: 6, w: 440, h: 640, profile: "player",
|
||||
url: playerURL, title: "mirrorbar player"}
|
||||
|
||||
allWebFlies = []*webFly{flyClaude, flyGrok, flyPlayer}
|
||||
|
||||
wfEnumCb uintptr
|
||||
wfTarget *webFly
|
||||
wfFound uintptr
|
||||
pickBusy atomic.Bool // true while the player's folder or file dialog is open
|
||||
)
|
||||
|
||||
func (f *webFly) profileDir() string { return filepath.Join(dataDir(), f.profile) }
|
||||
|
||||
func (f *webFly) windowOK() bool {
|
||||
if f.hwnd == 0 {
|
||||
return false
|
||||
}
|
||||
ok, _, _ := pIsWindow.Call(f.hwnd)
|
||||
return ok != 0
|
||||
}
|
||||
|
||||
// launch starts the app window, visible, because it only starts when the button is clicked.
|
||||
func (f *webFly) launch() bool {
|
||||
exe := gmBrowserPath()
|
||||
if exe == "" {
|
||||
return false
|
||||
}
|
||||
prof := f.profileDir()
|
||||
if err := os.MkdirAll(prof, 0o755); err != nil {
|
||||
return false
|
||||
}
|
||||
args := []string{
|
||||
exe,
|
||||
"--app=" + f.url(),
|
||||
"--user-data-dir=" + prof,
|
||||
"--no-first-run",
|
||||
"--no-default-browser-check",
|
||||
"--autoplay-policy=no-user-gesture-required",
|
||||
"--disable-features=CalculateNativeWinOcclusion",
|
||||
"--disable-renderer-backgrounding",
|
||||
"--disable-background-timer-throttling",
|
||||
"--disable-backgrounding-occluded-windows",
|
||||
}
|
||||
parts := make([]string, len(args))
|
||||
for i, a := range args {
|
||||
parts[i] = syscall.EscapeArg(a)
|
||||
}
|
||||
si := syscall.StartupInfo{Flags: 1}
|
||||
si.Cb = uint32(unsafe.Sizeof(si))
|
||||
si.ShowWindow = 1
|
||||
var pi syscall.ProcessInformation
|
||||
if err := syscall.CreateProcess(u16(exe), u16(strings.Join(parts, " ")), nil, nil, false, 0, nil, nil, &si, &pi); err != nil {
|
||||
return false
|
||||
}
|
||||
f.pid = pi.ProcessId
|
||||
syscall.CloseHandle(pi.Process)
|
||||
syscall.CloseHandle(pi.Thread)
|
||||
f.starting = true
|
||||
f.launched = time.Now()
|
||||
f.wantOpen = true
|
||||
return true
|
||||
}
|
||||
|
||||
func wfEnumProc(hwnd, lparam uintptr) uintptr {
|
||||
f := wfTarget
|
||||
var cls [64]uint16
|
||||
n, _, _ := pGetClassName.Call(hwnd, uintptr(unsafe.Pointer(&cls[0])), 64)
|
||||
if syscall.UTF16ToString(cls[:n]) != "Chrome_WidgetWin_1" {
|
||||
return 1
|
||||
}
|
||||
var pid uint32
|
||||
pGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
||||
t := strings.ToLower(gmWindowTitle(hwnd))
|
||||
if f.pid != 0 && pid == f.pid && t != "" {
|
||||
wfFound = hwnd
|
||||
return 0
|
||||
}
|
||||
// Not the process we started (Edge handed the window to a copy that was already
|
||||
// running with this profile): accept it only if it is Edge or Chrome and its
|
||||
// title fits, so the Claude desktop app is never mistaken for it.
|
||||
if wfFound == 0 && strings.Contains(t, f.title) && !strings.Contains(t, "microsoft edge") && !strings.Contains(t, "google chrome") {
|
||||
exe := strings.ToLower(filepath.Base(windowExePath(hwnd)))
|
||||
if exe == "msedge.exe" || exe == "chrome.exe" {
|
||||
wfFound = hwnd
|
||||
}
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
func (f *webFly) find() uintptr {
|
||||
if wfEnumCb == 0 {
|
||||
wfEnumCb = syscall.NewCallback(wfEnumProc)
|
||||
}
|
||||
wfTarget = f
|
||||
wfFound = 0
|
||||
pEnumWindows.Call(wfEnumCb, 0)
|
||||
return wfFound
|
||||
}
|
||||
|
||||
// adopt takes charge of the window once it exists: out of the app list and
|
||||
// Alt+Tab, then shown above the bar.
|
||||
func (f *webFly) adopt(h uintptr) {
|
||||
f.hwnd = h
|
||||
var pid uint32
|
||||
pGetWindowThreadProcessId.Call(h, uintptr(unsafe.Pointer(&pid)))
|
||||
if pid != 0 {
|
||||
f.pid = pid
|
||||
}
|
||||
ex, _, _ := pGetWindowLongPtr.Call(h, neg(-20))
|
||||
want := (ex | wsExToolWindow) &^ gmWsExAppWindow
|
||||
if want != ex {
|
||||
pSetWindowLongPtr.Call(h, neg(-20), want)
|
||||
pSetWindowPos.Call(h, 0, 0, 0, 0, 0, gmSwpNoMove|gmSwpNoSize|gmSwpNoZOrder|swpNoActivate|gmSwpFrameChanged)
|
||||
}
|
||||
f.starting = false
|
||||
if f.wantOpen {
|
||||
f.wantOpen = false
|
||||
f.show()
|
||||
} else {
|
||||
f.park()
|
||||
}
|
||||
}
|
||||
|
||||
func (f *webFly) size() (int32, int32) {
|
||||
sw, sh := screenSize()
|
||||
return min(px(f.w), sw-px(16)), min(px(f.h), sh-px(24))
|
||||
}
|
||||
|
||||
func (f *webFly) move(x, y, w, h int32, topmost, activate bool) {
|
||||
if !f.windowOK() {
|
||||
return
|
||||
}
|
||||
if z, _, _ := pIsZoomed.Call(f.hwnd); z != 0 {
|
||||
pShowWindow.Call(f.hwnd, swRestore)
|
||||
}
|
||||
if ic, _, _ := pIsIconic.Call(f.hwnd); ic != 0 {
|
||||
cmd := uint32(gmSwShowNoActive)
|
||||
if activate {
|
||||
cmd = swRestore
|
||||
}
|
||||
wp := gmPlacementT{ShowCmd: cmd, Normal: rect{x, y, x + w, y + h}}
|
||||
wp.Length = uint32(unsafe.Sizeof(wp))
|
||||
pSetWindowPlace.Call(f.hwnd, uintptr(unsafe.Pointer(&wp)))
|
||||
}
|
||||
after := ^uintptr(1) // HWND_NOTOPMOST
|
||||
if topmost {
|
||||
after = hwndTopmost
|
||||
}
|
||||
var flags uintptr
|
||||
if !activate {
|
||||
flags = swpNoActivate
|
||||
}
|
||||
pSetWindowPos.Call(f.hwnd, after, uintptr(x), uintptr(y), uintptr(w), uintptr(h), flags|swpShowWindow)
|
||||
}
|
||||
|
||||
func (f *webFly) park() {
|
||||
cw, ch := f.size()
|
||||
f.move(gmParkX, gmParkY, cw, ch, false, false)
|
||||
}
|
||||
|
||||
func (f *webFly) place() (x, y, w, h int32) {
|
||||
cw, ch := f.size()
|
||||
ar := trayAnchor(f.kind)
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||
sw, sh := screenSize()
|
||||
space := px(8)
|
||||
if vertical {
|
||||
x = wr.Left - cw - space
|
||||
if x < 0 {
|
||||
x = wr.Right + space
|
||||
}
|
||||
y = (ar.Top+ar.Bottom)/2 - ch/2
|
||||
} else {
|
||||
x = (ar.Left+ar.Right)/2 - cw/2
|
||||
y = wr.Top - ch - space
|
||||
if y < 0 {
|
||||
y = wr.Bottom + space
|
||||
}
|
||||
}
|
||||
return clampI(x, 0, sw-cw), clampI(y, 0, sh-ch), cw, ch
|
||||
}
|
||||
|
||||
func (f *webFly) show() {
|
||||
if !f.windowOK() {
|
||||
return
|
||||
}
|
||||
webFlyHideOthers(f)
|
||||
fg, _, _ := pGetForegroundWindow.Call()
|
||||
if fg != f.hwnd {
|
||||
f.prevFg = fg
|
||||
}
|
||||
f.shown = true
|
||||
f.prevBtn = true
|
||||
f.shownAt = time.Now()
|
||||
x, y, w, h := f.place()
|
||||
f.move(x, y, w, h, true, true)
|
||||
pSetForegroundWindow.Call(f.hwnd)
|
||||
pSetTimer.Call(hwndMain, f.timerID, 80, 0)
|
||||
}
|
||||
|
||||
func (f *webFly) hide() {
|
||||
if !f.shown {
|
||||
return
|
||||
}
|
||||
f.shown = false
|
||||
pKillTimer.Call(hwndMain, f.timerID)
|
||||
if !f.windowOK() {
|
||||
return
|
||||
}
|
||||
fg, _, _ := pGetForegroundWindow.Call()
|
||||
f.park()
|
||||
if fg == f.hwnd && f.prevFg != 0 && f.prevFg != hwndMain && f.prevFg != f.hwnd {
|
||||
if ok, _, _ := pIsWindow.Call(f.prevFg); ok != 0 {
|
||||
pSetForegroundWindow.Call(f.prevFg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// open shows the flyout, starting the browser window first if needed.
|
||||
func (f *webFly) open() {
|
||||
webFlyHideOthers(f)
|
||||
if f.windowOK() {
|
||||
f.show()
|
||||
return
|
||||
}
|
||||
f.hwnd = 0
|
||||
if f.starting {
|
||||
f.wantOpen = true
|
||||
return
|
||||
}
|
||||
if h := f.find(); h != 0 {
|
||||
f.wantOpen = true
|
||||
f.adopt(h)
|
||||
return
|
||||
}
|
||||
if !f.launch() {
|
||||
shellOpen(f.url(), "") // no Edge or Chrome found: use the default browser
|
||||
}
|
||||
}
|
||||
|
||||
func (f *webFly) toggle() {
|
||||
if f.shown {
|
||||
f.hide()
|
||||
return
|
||||
}
|
||||
f.open()
|
||||
}
|
||||
|
||||
// closeWindow shuts the browser window down (right-click, "Close ...").
|
||||
func (f *webFly) closeWindow() {
|
||||
f.hide()
|
||||
if f.windowOK() {
|
||||
pPostMessage.Call(f.hwnd, wmClose, 0, 0)
|
||||
}
|
||||
f.hwnd = 0
|
||||
f.starting = false
|
||||
f.wantOpen = false
|
||||
}
|
||||
|
||||
func (f *webFly) poll() {
|
||||
if !f.shown {
|
||||
return
|
||||
}
|
||||
if !f.windowOK() {
|
||||
f.shown = false
|
||||
pKillTimer.Call(hwndMain, f.timerID)
|
||||
return
|
||||
}
|
||||
if pickBusy.Load() && f == flyPlayer {
|
||||
f.shownAt = time.Now() // a folder or file dialog is open; keep the player up
|
||||
return
|
||||
}
|
||||
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||
down := (l|r)&0x8000 != 0
|
||||
if down && !f.prevBtn && time.Since(f.shownAt) > 300*time.Millisecond {
|
||||
var cp point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||
var fr rect
|
||||
pGetWindowRect.Call(f.hwnd, uintptr(unsafe.Pointer(&fr)))
|
||||
inside := inRect(fr, cp)
|
||||
if !inside {
|
||||
h, _, _ := pWindowFromPoint.Call(uintptr(uint32(cp.X)) | uintptr(uint32(cp.Y))<<32)
|
||||
if h != 0 {
|
||||
root, _, _ := pGetAncestor.Call(h, gmGaRootOwner)
|
||||
inside = root == f.hwnd
|
||||
}
|
||||
}
|
||||
if !inside && !inRect(trayAnchor(f.kind), cp) {
|
||||
f.hide()
|
||||
}
|
||||
}
|
||||
f.prevBtn = down
|
||||
}
|
||||
|
||||
// tick runs from the bar's 250 ms timer: it adopts a window that has just
|
||||
// appeared and forgets one that was closed.
|
||||
func (f *webFly) tick() {
|
||||
if f.hwnd != 0 && !f.windowOK() {
|
||||
f.hwnd = 0
|
||||
f.shown = false
|
||||
pKillTimer.Call(hwndMain, f.timerID)
|
||||
}
|
||||
if f.hwnd == 0 && f.starting {
|
||||
if h := f.find(); h != 0 {
|
||||
f.adopt(h)
|
||||
} else if time.Since(f.launched) > gmLaunchMax {
|
||||
f.starting = false
|
||||
f.wantOpen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- shared hooks ----------
|
||||
|
||||
func webFlyTick() {
|
||||
defer func() { _ = recover() }()
|
||||
for _, f := range allWebFlies {
|
||||
f.tick()
|
||||
}
|
||||
}
|
||||
|
||||
func webFlyHideAll() {
|
||||
for _, f := range allWebFlies {
|
||||
f.hide()
|
||||
}
|
||||
}
|
||||
|
||||
func webFlyHideOthers(except *webFly) {
|
||||
previewHide()
|
||||
weatherHide()
|
||||
newsHide()
|
||||
sysHide()
|
||||
gmHide()
|
||||
for _, f := range allWebFlies {
|
||||
if f != except {
|
||||
f.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func webFlyTimer(id uintptr) bool {
|
||||
for _, f := range allWebFlies {
|
||||
if f.timerID == id {
|
||||
f.poll()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func webFlyOwns(h uintptr) bool {
|
||||
for _, f := range allWebFlies {
|
||||
if f.hwnd != 0 && f.hwnd == h {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func webFlyShutdown() {
|
||||
for _, f := range allWebFlies {
|
||||
pKillTimer.Call(hwndMain, f.timerID)
|
||||
if f.windowOK() {
|
||||
pPostMessage.Call(f.hwnd, wmClose, 0, 0)
|
||||
}
|
||||
f.hwnd = 0
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- the AI button: a choice between Claude and Grok ----------
|
||||
|
||||
const (
|
||||
menuAIClaudeID = 700
|
||||
menuAIGrokID = 701
|
||||
menuAICloseClaudeID = 702
|
||||
menuAICloseGrokID = 703
|
||||
menuPlayerShowID = 704
|
||||
menuPlayerFolderID = 705
|
||||
menuPlayerFileID = 706
|
||||
menuPlayerCloseID = 707
|
||||
menuClipID = 708
|
||||
tpmCenterAlign = 0x0004
|
||||
tpmRightAlign = 0x0008
|
||||
tpmVCenterAlign = 0x0010
|
||||
)
|
||||
|
||||
// aiClick: if one of the two is open, close it; otherwise pop up the choice.
|
||||
func aiClick() {
|
||||
if flyClaude.shown {
|
||||
flyClaude.hide()
|
||||
return
|
||||
}
|
||||
if flyGrok.shown {
|
||||
flyGrok.hide()
|
||||
return
|
||||
}
|
||||
menu, _, _ := pCreatePopupMenu.Call()
|
||||
pAppendMenu.Call(menu, 0, menuAIClaudeID, uintptr(unsafe.Pointer(u16("Claude"))))
|
||||
pAppendMenu.Call(menu, 0, menuAIGrokID, uintptr(unsafe.Pointer(u16("Grok"))))
|
||||
ar := trayAnchor(trayAI)
|
||||
flags := uintptr(tpmRightButton | tpmReturnCmd)
|
||||
x, y := (ar.Left+ar.Right)/2, ar.Top
|
||||
if vertical {
|
||||
flags |= tpmRightAlign | tpmVCenterAlign
|
||||
x, y = ar.Left, (ar.Top+ar.Bottom)/2
|
||||
} else {
|
||||
flags |= tpmBottomAlign | tpmCenterAlign
|
||||
}
|
||||
pSetForegroundWindow.Call(hwndMain)
|
||||
menuOpen = true
|
||||
cmd, _, _ := pTrackPopupMenu.Call(menu, flags, uintptr(x), uintptr(y), 0, hwndMain, 0)
|
||||
menuOpen = false
|
||||
ahLeftAt = time.Now()
|
||||
pDestroyMenu.Call(menu)
|
||||
switch cmd {
|
||||
case menuAIClaudeID:
|
||||
flyClaude.open()
|
||||
case menuAIGrokID:
|
||||
flyGrok.open()
|
||||
}
|
||||
}
|
||||
|
||||
func webFlyMenu(add func(flags uintptr, id uintptr, text string), sep func(), kind int) {
|
||||
switch kind {
|
||||
case trayAI:
|
||||
add(0, menuAIClaudeID, "Open Claude")
|
||||
add(0, menuAIGrokID, "Open Grok")
|
||||
add(0, menuAICloseClaudeID, "Close Claude (sign-in is kept)")
|
||||
add(0, menuAICloseGrokID, "Close Grok (sign-in is kept)")
|
||||
sep()
|
||||
case trayMusic:
|
||||
add(0, menuPlayerShowID, "Show player")
|
||||
add(0, menuPlayerFolderID, "Choose a music or audiobook folder...")
|
||||
add(0, menuPlayerFileID, "Choose a single file...")
|
||||
add(0, menuPlayerCloseID, "Close player (stops the music)")
|
||||
sep()
|
||||
case trayClip:
|
||||
add(0, menuClipID, "Open clipboard history")
|
||||
sep()
|
||||
}
|
||||
}
|
||||
|
||||
func webFlyCommand(cmd uintptr) bool {
|
||||
switch cmd {
|
||||
case menuAIClaudeID:
|
||||
flyClaude.open()
|
||||
case menuAIGrokID:
|
||||
flyGrok.open()
|
||||
case menuAICloseClaudeID:
|
||||
flyClaude.closeWindow()
|
||||
case menuAICloseGrokID:
|
||||
flyGrok.closeWindow()
|
||||
case menuPlayerShowID:
|
||||
flyPlayer.open()
|
||||
case menuPlayerFolderID:
|
||||
flyPlayer.open()
|
||||
go playerPick(true)
|
||||
case menuPlayerFileID:
|
||||
flyPlayer.open()
|
||||
go playerPick(false)
|
||||
case menuPlayerCloseID:
|
||||
flyPlayer.closeWindow()
|
||||
case menuClipID:
|
||||
tapChord(vkLWin, 'V')
|
||||
default:
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------- icons ----------
|
||||
|
||||
// drawAIIcon: a four pointed sparkle with a small one beside it.
|
||||
func drawAIIcon(hdc uintptr, r rect) {
|
||||
if !layerFg {
|
||||
return
|
||||
}
|
||||
col := iconColor()
|
||||
cx, cy := center(r)
|
||||
sparkle := func(x, y int32, rad, inner float64, w int32) {
|
||||
pts := make([]point, 0, 9)
|
||||
for k := 0; k <= 8; k++ {
|
||||
a := float64(k) * math.Pi / 4
|
||||
rr := rad
|
||||
if k%2 == 1 {
|
||||
rr = inner
|
||||
}
|
||||
pts = append(pts, point{x + int32(math.Round(rr*math.Sin(a))), y - int32(math.Round(rr*math.Cos(a)))})
|
||||
}
|
||||
polyline(hdc, pts, w, col)
|
||||
}
|
||||
sparkle(cx-px(1.5), cy+px(1.5), float64(px(7.5)), float64(px(2)), px(1.2))
|
||||
sparkle(cx+px(5.5), cy-px(5), float64(px(3.2)), float64(px(1)), px(1))
|
||||
}
|
||||
|
||||
// drawClipIcon: a clipboard with a clip at the top and two lines of text.
|
||||
func drawClipIcon(hdc uintptr, r rect) {
|
||||
if !layerFg {
|
||||
return
|
||||
}
|
||||
col := iconColor()
|
||||
cx, cy := center(r)
|
||||
e := px(1)
|
||||
l, t, rt, b := cx-px(5.5), cy-px(5.5), cx+px(5.5), cy+px(7)
|
||||
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
||||
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
||||
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
||||
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
||||
// the clip
|
||||
fillRaw(hdc, rect{cx - px(2.5), t - px(2), cx + px(2.5), t + px(1.5)}, col)
|
||||
// lines of text
|
||||
fillRaw(hdc, rect{cx - px(3), cy - px(0.5), cx + px(3), cy - px(0.5) + e}, col)
|
||||
fillRaw(hdc, rect{cx - px(3), cy + px(2.5), cx + px(1), cy + px(2.5) + e}, col)
|
||||
}
|
||||
|
||||
// drawMusicIcon: two beamed notes.
|
||||
func drawMusicIcon(hdc uintptr, r rect) {
|
||||
if !layerFg {
|
||||
return
|
||||
}
|
||||
col := iconColor()
|
||||
cx, cy := center(r)
|
||||
e := px(1.2)
|
||||
h1x, h1y := cx-px(3.5), cy+px(4.5)
|
||||
h2x, h2y := cx+px(4), cy+px(2.5)
|
||||
circleRaw(hdc, h1x, h1y, px(2.4), col)
|
||||
circleRaw(hdc, h2x, h2y, px(2.4), col)
|
||||
s1x, s2x := h1x+px(2), h2x+px(2)
|
||||
t1, t2 := cy-px(6.5), cy-px(8.5)
|
||||
fillRaw(hdc, rect{s1x - e/2, t1, s1x - e/2 + e, h1y}, col)
|
||||
fillRaw(hdc, rect{s2x - e/2, t2, s2x - e/2 + e, h2y}, col)
|
||||
polyline(hdc, []point{{s1x, t1 + px(0.5)}, {s2x, t2 + px(0.5)}}, px(2), col)
|
||||
}
|
||||
Reference in New Issue
Block a user