Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c58a4d8a5 | ||
|
|
7ffd3c5e22 | ||
|
|
eab5a47495 | ||
|
|
93f6b94d98 | ||
|
|
6ac9164755 | ||
|
|
9ea41cab49 | ||
|
|
2a76d1d9c9 | ||
|
|
fc1d82d790 | ||
|
|
c80267f81f | ||
|
|
e82ed224e8 | ||
|
|
8ab3cda02d | ||
|
|
b26879abdb | ||
|
|
2a68148183 | ||
|
|
3e0fc4e6ec | ||
|
|
75a88a4a91 | ||
|
|
40370fce29 | ||
|
|
4f05e6e411 | ||
|
|
968bc0ad22 | ||
|
|
f5d9389284 | ||
|
|
572d64c280 | ||
|
|
db0249bc14 | ||
|
|
ddcb334a10 | ||
|
|
6a84862b71 |
@@ -1,8 +1,8 @@
|
|||||||
# MirrorBar
|
# MirrorBar+
|
||||||
|
|
||||||
A small Windows 11 taskbar replacement, one exe, no installer, no dependencies.
|
MirrorBar+ is a small Windows 11 taskbar replacement, one exe, no installer, no dependencies.
|
||||||
|
|
||||||
The real taskbar is hidden and a see-through pill takes its place. The pill is a mirror image around its center line. To the left of center is the Start button, with your open apps as small icon-only buttons stretching further left. To the right of center is the clock (time and date on one line), then a little storm cloud for the weather, battery, volume, wifi and the ^ hidden-icons arrow stretching further right.
|
The real taskbar is hidden and a see-through pill takes its place. The pill is a mirror image around its center line. To the left of center is the Start button, with your open apps as small icon-only buttons stretching further left. To the right of center is the clock (time and date on one line), then a little sun-and-cloud for the weather, a little newspaper for local news, a little monitor for system stats, battery, volume, wifi and the ^ hidden-icons arrow stretching further right.
|
||||||
|
|
||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
@@ -11,15 +11,32 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
|||||||
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||||
- Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
- Windows of the same program share one icon. Four Brave windows show one Brave icon with a small red 4 in its top right corner. Click it to bring up the window you used last; click again while one of them is in front to step to the next. Hover shows a preview of the window you used last, and dragging the icon moves all of its windows together. Untick "Combine windows of the same program into one icon" in the settings window to get one icon per window again.
|
||||||
|
|
||||||
|
Tick "Hide the bar until the mouse touches the screen edge" in the settings window and the bar slides out of sight when the mouse is away from it (and stops reserving screen space, so maximized windows use the whole screen). Push the mouse against the screen edge where the bar lives (the bottom, or the right edge in vertical mode) and it comes back. It stays up while a panel, menu or preview is open.
|
||||||
|
|
||||||
|
Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
||||||
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
||||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
- 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.
|
- 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.
|
- "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.
|
- 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 weather ZIP code, vertical mode, start with Windows, and resetting the position and width. Changes apply as you make them.
|
- "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.
|
||||||
- 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, 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), 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.
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
- Click the little speech bubble and Google Messages for web opens in a small window above the bar, so you can read and answer texts without opening a browser tab. The first time, scan the QR code from the Messages app on your phone (Settings, Device pairing) and tick "Remember this computer"; after that it stays signed in. It runs Microsoft Edge in app mode (no tabs, no address bar) with its own private profile folder in `%LOCALAPPDATA%\MirrorBar\messages`, separate from your normal Edge, and goes only to messages.google.com. Once you have paired, MirrorBar quietly starts it in the background about 20 seconds after it launches, keeps the window just off the edge of the screen, and shows the unread count from the window title as a red number on the bubble. Click anywhere else and the window slides away again. Right-click the bubble and choose "Close Messages" to stop the background window and give the memory back. Messages for web only works while your phone is on and connected; that is how Google built it. A link someone texts you opens in your normal default browser, not in Edge: the Messages window is started with a debugging port that only listens on this PC (127.0.0.1), and MirrorBar hands any page that is not Messages or a Google sign-in page to the default browser and closes it. `messages-titles.txt` in the MirrorBar data folder keeps the first 25 different window titles it has seen, only so the unread badge can be tuned; delete it any time.
|
||||||
|
|
||||||
|
- "Show weather on the bar", "Show local news on the bar", "Show system stats on the bar" and "Show Google Messages on the bar" in the settings window turn each feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back.
|
||||||
|
|
||||||
|
- The weather, news and system stats panels are as see-through as the bar itself: set the bar to Clear and the panels go clear too, with only their text, pictures and outline staying solid. Untick "Panels match the bar's transparency" in the settings window to keep the panels solid.
|
||||||
|
|
||||||
|
- Click the little monitor and a panel opens with the usual neofetch information: OS, host, kernel, uptime, resolution, CPU, GPU, memory, each fixed disk, battery and local IP. Click any line to copy it to the clipboard, or click the top of the panel to copy everything as plain text you can paste into other programs. Nothing leaves your PC; it is all read from Windows.
|
||||||
- Pick the color of the Windows logo, the clock, and the battery/volume/wifi/arrow icons from the right-click menu (white, blue, sky blue, green, yellow, orange, red, pink, purple, black).
|
- Pick the color of the Windows logo, the clock, and the battery/volume/wifi/arrow icons from the right-click menu (white, blue, sky blue, green, yellow, orange, red, pink, purple, black).
|
||||||
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
||||||
- Background see-through level: Clear, Light, Medium or Solid.
|
- Background see-through level: Clear, Light, Medium or Solid.
|
||||||
@@ -36,7 +53,7 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
|||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
Grab `mirrorbar.zip` from the Releases page. If Windows shows a "protected your PC" warning, right-click the zip, choose Properties, check Unblock, and unzip it after that.
|
Grab `MirrorBarPlus.zip` from the Releases page. If Windows shows a "protected your PC" warning, right-click the zip, choose Properties, check Unblock, and unzip it after that.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
@@ -47,3 +64,4 @@ GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-H=windowsgui -s -w"
|
|||||||
```
|
```
|
||||||
|
|
||||||
Settings are kept in `%LOCALAPPDATA%\MirrorBar`.
|
Settings are kept in `%LOCALAPPDATA%\MirrorBar`.
|
||||||
|
|
||||||
|
|||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Auto-hide: the bar slides out of sight when the mouse is away from it and
|
||||||
|
// comes back when the mouse touches the screen edge where it lives.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ahTimerID = 9
|
||||||
|
ahDelay = 700 * time.Millisecond
|
||||||
|
ahEdgeSlack = 24 // device-independent pixels of leeway along the edge
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
autoHide bool
|
||||||
|
ahHidden bool
|
||||||
|
ahLeftAt = time.Now()
|
||||||
|
menuOpen bool // a right-click menu of the bar is showing
|
||||||
|
)
|
||||||
|
|
||||||
|
// ahStart / ahStop run the quick mouse check only while auto-hide is on.
|
||||||
|
func ahStart() { pSetTimer.Call(hwndMain, ahTimerID, 60, 0) }
|
||||||
|
func ahStop() { pKillTimer.Call(hwndMain, ahTimerID) }
|
||||||
|
|
||||||
|
// ahBusy is true while something on screen depends on the bar staying put.
|
||||||
|
func ahBusy() bool {
|
||||||
|
if wxShown || newsShown || sysShown || gmShown || dragging || dragActive || menuOpen {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if pvHwnd != 0 {
|
||||||
|
if v, _, _ := pIsWindowVisible.Call(pvHwnd); v != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func ahTick(hwnd uintptr) {
|
||||||
|
if !autoHide {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
sw, sh := screenSize()
|
||||||
|
pw, ph := pillSize()
|
||||||
|
x, y := pillPos(pw, ph)
|
||||||
|
slack := px(ahEdgeSlack)
|
||||||
|
|
||||||
|
if ahHidden {
|
||||||
|
var hot bool
|
||||||
|
if vertical {
|
||||||
|
hot = cp.X >= sw-2 && cp.Y >= y-slack && cp.Y <= y+ph+slack
|
||||||
|
} else {
|
||||||
|
hot = cp.Y >= sh-2 && cp.X >= x-slack && cp.X <= x+pw+slack
|
||||||
|
}
|
||||||
|
if hot {
|
||||||
|
ahHidden = false
|
||||||
|
ahLeftAt = time.Now()
|
||||||
|
positionBar(hwnd)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
near := cp.X >= x-px(6) && cp.X <= x+pw+px(6) && cp.Y >= y-px(6) && cp.Y <= y+ph+px(6)
|
||||||
|
if near || ahBusy() {
|
||||||
|
ahLeftAt = time.Now()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if time.Since(ahLeftAt) > ahDelay {
|
||||||
|
ahHidden = true
|
||||||
|
positionBar(hwnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setAutoHide is called by the settings window.
|
||||||
|
func setAutoHide(on bool) {
|
||||||
|
if autoHide == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
autoHide = on
|
||||||
|
saveFeatures()
|
||||||
|
ahHidden = false
|
||||||
|
ahLeftAt = time.Now()
|
||||||
|
if on {
|
||||||
|
if appbarOn { // a bar that hides must not keep screen space reserved
|
||||||
|
abd := appBarData{Hwnd: hwndMain}
|
||||||
|
appBar(abmRemove, &abd)
|
||||||
|
appbarOn = false
|
||||||
|
}
|
||||||
|
ahStart()
|
||||||
|
} else {
|
||||||
|
ahStop()
|
||||||
|
if !customPos && !appbarOn {
|
||||||
|
abd := appBarData{Hwnd: hwndMain, CallbackMsg: callbackMsg}
|
||||||
|
appBar(abmNew, &abd)
|
||||||
|
appbarOn = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
+14
-3
@@ -65,7 +65,18 @@ func saveLeftPref() {
|
|||||||
// halfLimit is the longest either half may be.
|
// halfLimit is the longest either half may be.
|
||||||
func halfLimit() int32 {
|
func halfLimit() int32 {
|
||||||
sw, _ := screenSize()
|
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.
|
// 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:
|
case leftPref < 0:
|
||||||
h = lc
|
h = lc
|
||||||
case leftPref > 0:
|
case leftPref > 0:
|
||||||
h = max(lc, leftPref)
|
h = max(lc, leftPref*layerMul())
|
||||||
default:
|
default:
|
||||||
h = max(lc, rightHalf())
|
h = max(lc, rightHalf())
|
||||||
}
|
}
|
||||||
@@ -128,7 +139,7 @@ func overEdge(hwnd uintptr) bool {
|
|||||||
func beginResize(hwnd uintptr) {
|
func beginResize(hwnd uintptr) {
|
||||||
resizing = true
|
resizing = true
|
||||||
resizeFrom = cursorAlong()
|
resizeFrom = cursorAlong()
|
||||||
resizeLen = leftHalf()
|
resizeLen = leftHalf() // always measured at real size here
|
||||||
pSetCapture.Call(hwnd)
|
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)
|
||||||
|
}
|
||||||
+185
@@ -0,0 +1,185 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// The two optional features, weather and local news. Each can be turned off in
|
||||||
|
// the settings window: its icon leaves the bar, its panel is closed, and nothing
|
||||||
|
// is downloaded for it. Both are on until switched off.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
showWeather = true
|
||||||
|
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") }
|
||||||
|
|
||||||
|
func loadFeatures() {
|
||||||
|
b, err := os.ReadFile(featuresFile())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, ln := range strings.Split(string(b), "\n") {
|
||||||
|
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
on := strings.TrimSpace(v) != "0"
|
||||||
|
switch strings.TrimSpace(k) {
|
||||||
|
case "weather":
|
||||||
|
showWeather = on
|
||||||
|
case "news":
|
||||||
|
showNews = on
|
||||||
|
case "sys":
|
||||||
|
showSys = on
|
||||||
|
case "messages":
|
||||||
|
showGM = on
|
||||||
|
case "panelfade":
|
||||||
|
flyMatchBar = on
|
||||||
|
case "group":
|
||||||
|
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) + "\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)
|
||||||
|
}
|
||||||
|
|
||||||
|
func b01(b bool) string {
|
||||||
|
if b {
|
||||||
|
return "1"
|
||||||
|
}
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
// setShowWeather is called by the settings window.
|
||||||
|
func setShowWeather(on bool) {
|
||||||
|
if showWeather == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showWeather = on
|
||||||
|
saveFeatures()
|
||||||
|
if on {
|
||||||
|
weatherRefresh(false)
|
||||||
|
} else {
|
||||||
|
weatherHide()
|
||||||
|
}
|
||||||
|
featuresChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setShowNews is called by the settings window.
|
||||||
|
func setShowNews(on bool) {
|
||||||
|
if showNews == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showNews = on
|
||||||
|
saveFeatures()
|
||||||
|
if on {
|
||||||
|
newsRefresh(false)
|
||||||
|
} else {
|
||||||
|
newsHide()
|
||||||
|
}
|
||||||
|
featuresChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setShowSys is called by the settings window.
|
||||||
|
func setShowSys(on bool) {
|
||||||
|
if showSys == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showSys = on
|
||||||
|
saveFeatures()
|
||||||
|
if !on {
|
||||||
|
sysHide()
|
||||||
|
}
|
||||||
|
featuresChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setShowGM is called by the settings window.
|
||||||
|
func setShowGM(on bool) {
|
||||||
|
if showGM == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showGM = on
|
||||||
|
saveFeatures()
|
||||||
|
if on {
|
||||||
|
gmAutoTried = false // let the background check start Messages again
|
||||||
|
} else {
|
||||||
|
gmClose()
|
||||||
|
}
|
||||||
|
featuresChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setFlyMatchBar is called by the settings window: should the panels be as
|
||||||
|
// see-through as the bar?
|
||||||
|
func setFlyMatchBar(on bool) {
|
||||||
|
if flyMatchBar == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
flyMatchBar = on
|
||||||
|
saveFeatures()
|
||||||
|
flyRefreshAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
func featuresChanged() {
|
||||||
|
settingsZipStatusUpdate()
|
||||||
|
redraw(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// zipStatusText is the one line the settings window shows under the ZIP box.
|
||||||
|
func zipStatusText() string {
|
||||||
|
switch {
|
||||||
|
case !showWeather && !showNews:
|
||||||
|
return "Weather and news are both turned off."
|
||||||
|
case wxZip == "":
|
||||||
|
return "Type a 5 digit ZIP code to turn on weather and local news."
|
||||||
|
case showWeather:
|
||||||
|
return weatherStatusText()
|
||||||
|
}
|
||||||
|
return newsStatusText()
|
||||||
|
}
|
||||||
|
|
||||||
|
// setGroupWins is called by the settings window: one icon per program, with a
|
||||||
|
// count, or one icon per window.
|
||||||
|
func setGroupWins(on bool) {
|
||||||
|
if groupWins == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
groupWins = on
|
||||||
|
saveFeatures()
|
||||||
|
styleCacheClear()
|
||||||
|
apps = groupApps(allApps)
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
@@ -26,9 +26,11 @@ var (
|
|||||||
const (
|
const (
|
||||||
wxLayoutW = 340.0 // panel width, in 96 dpi units
|
wxLayoutW = 340.0 // panel width, in 96 dpi units
|
||||||
wxFullH = 428.0 // panel height when there is a forecast to show
|
wxFullH = 428.0 // panel height when there is a forecast to show
|
||||||
|
wxRadarH = 158.0 // extra height when the radar picture fits on the screen
|
||||||
wxShortH = 150.0 // panel height for the "add a ZIP code" and error messages
|
wxShortH = 150.0 // panel height for the "add a ZIP code" and error messages
|
||||||
|
|
||||||
wxPollTimerID = 1
|
wxPollTimerID = 1
|
||||||
|
wxAnimTimerID = 2
|
||||||
vkRButton = 0x02
|
vkRButton = 0x02
|
||||||
srcCopy = 0x00CC0020
|
srcCopy = 0x00CC0020
|
||||||
halftone = 4
|
halftone = 4
|
||||||
@@ -41,8 +43,10 @@ var (
|
|||||||
wxShown bool
|
wxShown bool
|
||||||
wxPrevBtn bool // a mouse button was down at the last look
|
wxPrevBtn bool // a mouse button was down at the last look
|
||||||
|
|
||||||
wxFontsMade bool
|
wxFontsMade bool
|
||||||
fBig, fMed, fText, fBold, fSmall uintptr
|
fBig, fMed, fText, fBold, fSmall, fTiny uintptr
|
||||||
|
|
||||||
|
rdHold int // how many beats the newest radar frame has been held for
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------- the button on the bar ----------
|
// ---------- the button on the bar ----------
|
||||||
@@ -102,7 +106,7 @@ func weatherInit(inst uintptr) {
|
|||||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
wxHwnd, _, _ = pCreateWindowEx.Call(
|
wxHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
wsExToolWindow|wsExTopmost|wsExNoActivate,
|
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
||||||
uintptr(unsafe.Pointer(className)),
|
uintptr(unsafe.Pointer(className)),
|
||||||
uintptr(unsafe.Pointer(u16(""))),
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
wsPopup,
|
wsPopup,
|
||||||
@@ -125,6 +129,10 @@ func weatherProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
wxPaint(hwnd)
|
wxPaint(hwnd)
|
||||||
return 0
|
return 0
|
||||||
case wmTimer:
|
case wmTimer:
|
||||||
|
if wparam == wxAnimTimerID {
|
||||||
|
radarAdvance()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
weatherPoll()
|
weatherPoll()
|
||||||
return 0
|
return 0
|
||||||
case wmLButtonUp:
|
case wmLButtonUp:
|
||||||
@@ -141,15 +149,21 @@ func weatherToggle() {
|
|||||||
weatherHide()
|
weatherHide()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if wxHwnd == 0 {
|
if wxHwnd == 0 || !showWeather {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
previewHide()
|
previewHide()
|
||||||
|
newsHide() // one panel at a time
|
||||||
|
sysHide()
|
||||||
|
gmHide()
|
||||||
|
webFlyHideAll()
|
||||||
weatherRefresh(false)
|
weatherRefresh(false)
|
||||||
wxShown = true
|
wxShown = true
|
||||||
wxPrevBtn = true // ignore a button that is still held from the click that opened this
|
wxPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||||
weatherPlace()
|
weatherPlace()
|
||||||
pSetTimer.Call(wxHwnd, wxPollTimerID, 80, 0)
|
pSetTimer.Call(wxHwnd, wxPollTimerID, 80, 0)
|
||||||
|
pSetTimer.Call(wxHwnd, wxAnimTimerID, 450, 0)
|
||||||
|
radarEnsure(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func weatherHide() {
|
func weatherHide() {
|
||||||
@@ -158,6 +172,7 @@ func weatherHide() {
|
|||||||
}
|
}
|
||||||
wxShown = false
|
wxShown = false
|
||||||
pKillTimer.Call(wxHwnd, wxPollTimerID)
|
pKillTimer.Call(wxHwnd, wxPollTimerID)
|
||||||
|
pKillTimer.Call(wxHwnd, wxAnimTimerID)
|
||||||
pShowWindow.Call(wxHwnd, swHide)
|
pShowWindow.Call(wxHwnd, swHide)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,21 +185,7 @@ func weatherShutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// weatherAnchor is where the cloud sits on the screen.
|
// weatherAnchor is where the cloud sits on the screen.
|
||||||
func weatherAnchor() rect {
|
func weatherAnchor() rect { return trayAnchor(trayWeather) }
|
||||||
var wr rect
|
|
||||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
|
||||||
w, h := clientSize(hwndMain)
|
|
||||||
for _, it := range trayItems(w, h) {
|
|
||||||
if it.kind == trayWeather {
|
|
||||||
r := it.r
|
|
||||||
if vertical {
|
|
||||||
r = mapRect(r, h)
|
|
||||||
}
|
|
||||||
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return wr
|
|
||||||
}
|
|
||||||
|
|
||||||
// weatherPlace sizes the panel for what it has to show and puts it next to the
|
// weatherPlace sizes the panel for what it has to show and puts it next to the
|
||||||
// cloud: above a horizontal bar, to the left of a vertical one.
|
// cloud: above a horizontal bar, to the left of a vertical one.
|
||||||
@@ -196,6 +197,9 @@ func weatherPlace() {
|
|||||||
lh := wxShortH
|
lh := wxShortH
|
||||||
if s.ok && wxZip != "" {
|
if s.ok && wxZip != "" {
|
||||||
lh = wxFullH
|
lh = wxFullH
|
||||||
|
if wxRadarFits() {
|
||||||
|
lh += wxRadarH
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cw, ch := px(wxLayoutW), px(lh)
|
cw, ch := px(wxLayoutW), px(lh)
|
||||||
|
|
||||||
@@ -221,7 +225,7 @@ func weatherPlace() {
|
|||||||
x = clampI(x, 0, sw-cw)
|
x = clampI(x, 0, sw-cw)
|
||||||
y = clampI(y, 0, sh-ch)
|
y = clampI(y, 0, sh-ch)
|
||||||
pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
pSetWindowPos.Call(wxHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
||||||
pInvalidateRect.Call(wxHwnd, 0, 1)
|
flyRefresh(wxHwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// weatherPoll closes the panel when a mouse button goes down anywhere outside
|
// weatherPoll closes the panel when a mouse button goes down anywhere outside
|
||||||
@@ -257,8 +261,10 @@ func weatherClick() {
|
|||||||
|
|
||||||
// weatherDone runs when a lookup finishes.
|
// weatherDone runs when a lookup finishes.
|
||||||
func weatherDone() {
|
func weatherDone() {
|
||||||
|
newsDone()
|
||||||
if wxShown {
|
if wxShown {
|
||||||
weatherPlace()
|
weatherPlace()
|
||||||
|
radarEnsure(false)
|
||||||
}
|
}
|
||||||
settingsZipStatusUpdate()
|
settingsZipStatusUpdate()
|
||||||
}
|
}
|
||||||
@@ -292,50 +298,23 @@ func wxMakeFonts() {
|
|||||||
fText = makeFont(px(13), 400)
|
fText = makeFont(px(13), 400)
|
||||||
fBold = makeFont(px(13), 600)
|
fBold = makeFont(px(13), 600)
|
||||||
fSmall = makeFont(px(11), 400)
|
fSmall = makeFont(px(11), 400)
|
||||||
|
fTiny = makeFont(px(9), 400)
|
||||||
wxFontsMade = true
|
wxFontsMade = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func wxPaint(hwnd uintptr) {
|
func wxPaint(hwnd uintptr) { flyPaint(hwnd, wxDraw) }
|
||||||
|
|
||||||
|
// flyPaint answers a paint request: the panel is rendered see-through (see
|
||||||
|
// flyrender.go) instead of being painted by Windows.
|
||||||
|
func flyPaint(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
|
||||||
var ps paintStruct
|
var ps paintStruct
|
||||||
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
defer pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
|
flyRender(hwnd, draw)
|
||||||
var rc rect
|
|
||||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
|
||||||
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
|
|
||||||
if W <= 0 || H <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const ss = 2
|
|
||||||
|
|
||||||
mem, _, _ := pCreateCompatibleDC.Call(hdc)
|
|
||||||
defer pDeleteDC.Call(mem)
|
|
||||||
bmi := bitmapInfoHeader{Width: W * ss, Height: -(H * ss), Planes: 1, BitCount: 32}
|
|
||||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
|
||||||
var bits unsafe.Pointer
|
|
||||||
bmp, _, _ := pCreateDIBSection.Call(hdc, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
|
|
||||||
if bmp == 0 || bits == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer pDeleteObject.Call(bmp)
|
|
||||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
|
||||||
defer pSelectObject.Call(mem, old)
|
|
||||||
|
|
||||||
saved := scale
|
|
||||||
defer func() { scale = saved }()
|
|
||||||
scale *= ss
|
|
||||||
wxMakeFonts()
|
|
||||||
wxDraw(mem, W*ss, H*ss)
|
|
||||||
scale = saved
|
|
||||||
|
|
||||||
pSetStretchBltMode.Call(hdc, halftone)
|
|
||||||
pSetBrushOrgEx.Call(hdc, 0, 0, 0)
|
|
||||||
pStretchBlt.Call(hdc, 0, 0, uintptr(W), uintptr(H), mem, 0, 0, uintptr(W*ss), uintptr(H*ss), srcCopy)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
colBack = rgb(28, 28, 34)
|
colBack = rgb(28, 28, 34)
|
||||||
colEdge = rgb(78, 78, 92)
|
|
||||||
colRule = rgb(52, 52, 62)
|
colRule = rgb(52, 52, 62)
|
||||||
colText = rgb(240, 240, 245)
|
colText = rgb(240, 240, 245)
|
||||||
colDim = rgb(150, 150, 165)
|
colDim = rgb(150, 150, 165)
|
||||||
@@ -354,8 +333,7 @@ func wxText(hdc uintptr, s string, r rect, font, col, flags uintptr) {
|
|||||||
// here is a double size distance.
|
// here is a double size distance.
|
||||||
func wxDraw(hdc uintptr, W, H int32) {
|
func wxDraw(hdc uintptr, W, H int32) {
|
||||||
u := px
|
u := px
|
||||||
fillRaw(hdc, rect{0, 0, W, H}, colEdge)
|
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
||||||
fillRaw(hdc, rect{u(1), u(1), W - u(1), H - u(1)}, colBack)
|
|
||||||
|
|
||||||
pad := u(14)
|
pad := u(14)
|
||||||
inner := W - 2*pad
|
inner := W - 2*pad
|
||||||
@@ -431,6 +409,15 @@ func wxDraw(hdc uintptr, W, H int32) {
|
|||||||
cell(2, 1, "UV index", strconv.Itoa(int(math.Round(today.uv))))
|
cell(2, 1, "UV index", strconv.Itoa(int(math.Round(today.uv))))
|
||||||
rule(u(218))
|
rule(u(218))
|
||||||
|
|
||||||
|
// Radar, when the panel is tall enough to have room for it. Everything below it
|
||||||
|
// is drawn the same way, just moved down.
|
||||||
|
if H >= u(wxFullH+wxRadarH-1) {
|
||||||
|
radarDraw(hdc, rect{pad, u(226), W - pad, u(226) + u(150)})
|
||||||
|
rule(u(382))
|
||||||
|
pSetViewportOrgEx.Call(hdc, 0, uintptr(u(wxRadarH)), 0)
|
||||||
|
defer pSetViewportOrgEx.Call(hdc, 0, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
// Moon.
|
// Moon.
|
||||||
moon := moonAt(time.Now())
|
moon := moonAt(time.Now())
|
||||||
wxMoonDraw(hdc, pad+u(24), u(254), u(22), moon, s.lat >= 0)
|
wxMoonDraw(hdc, pad+u(24), u(254), u(22), moon, s.lat >= 0)
|
||||||
@@ -495,8 +482,40 @@ func wxSunGlyph(hdc uintptr, cx, cy, s float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func wxCrescent(hdc uintptr, cx, cy, rad float64) {
|
func wxCrescent(hdc uintptr, cx, cy, rad float64) {
|
||||||
wxCircle(hdc, cx, cy, rad, rgb(235, 232, 205))
|
brush, _, _ := pCreateSolidBrush.Call(rgb(235, 232, 205))
|
||||||
wxCircle(hdc, cx+0.45*rad, cy-0.25*rad, 0.85*rad, colBack)
|
defer pDeleteObject.Call(brush)
|
||||||
|
ix, iy, ir := cx+0.45*rad, cy-0.25*rad, 0.85*rad // the circle that is cut out
|
||||||
|
top := int32(math.Round(cy))
|
||||||
|
r := int32(math.Ceil(rad))
|
||||||
|
for dy := -r; dy <= r; dy++ {
|
||||||
|
y := top + dy
|
||||||
|
oh2 := rad*rad - float64(dy)*float64(dy)
|
||||||
|
if oh2 <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
oh := math.Sqrt(oh2)
|
||||||
|
x0, x1 := cx-oh, cx+oh
|
||||||
|
var segs [][2]float64
|
||||||
|
fy := float64(y) + 0.5 - iy
|
||||||
|
if ih2 := ir*ir - fy*fy; ih2 > 0 {
|
||||||
|
ih := math.Sqrt(ih2)
|
||||||
|
if l := ix - ih; l > x0 {
|
||||||
|
segs = append(segs, [2]float64{x0, math.Min(l, x1)})
|
||||||
|
}
|
||||||
|
if rr := ix + ih; rr < x1 {
|
||||||
|
segs = append(segs, [2]float64{math.Max(rr, x0), x1})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
segs = append(segs, [2]float64{x0, x1})
|
||||||
|
}
|
||||||
|
for _, sg := range segs {
|
||||||
|
if sg[1]-sg[0] < 0.5 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
line := rect{int32(math.Round(sg[0])), y, int32(math.Round(sg[1])), y + 1}
|
||||||
|
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&line)), brush)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// wxIcon draws the picture for a kind of weather inside the square r.
|
// wxIcon draws the picture for a kind of weather inside the square r.
|
||||||
|
|||||||
+166
@@ -0,0 +1,166 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Painting the three panels (weather, news, system stats) as see-through
|
||||||
|
// windows that follow the bar's own background opacity. The panels are painted
|
||||||
|
// the same way the bar is: the content (text, pictures, lines) is drawn twice at
|
||||||
|
// double size, once on black and once on white; comparing the two copies shows
|
||||||
|
// how solid every pixel is. The panel's background color is then added back at
|
||||||
|
// the bar's see-through level, and the result is handed to Windows as a layered
|
||||||
|
// window with a transparency value for every pixel.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// flyMatchBar is the "panels match the bar's transparency" setting. When it is
|
||||||
|
// off the panels are solid, as they were before.
|
||||||
|
var flyMatchBar = true
|
||||||
|
|
||||||
|
func flyBgAlpha() uint32 {
|
||||||
|
if flyMatchBar {
|
||||||
|
return uint32(bgAlpha)
|
||||||
|
}
|
||||||
|
return 255
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyFrame draws the one pixel outline around a panel, in the tray icon color.
|
||||||
|
// The background inside it is not painted here; flyRender adds it.
|
||||||
|
func flyFrame(hdc uintptr, W, H int32) {
|
||||||
|
t, col := px(1), iconColor()
|
||||||
|
fillRaw(hdc, rect{0, 0, W, t}, col)
|
||||||
|
fillRaw(hdc, rect{0, H - t, W, H}, col)
|
||||||
|
fillRaw(hdc, rect{0, 0, t, H}, col)
|
||||||
|
fillRaw(hdc, rect{W - t, 0, W, H}, col)
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyLayer paints the content onto a flat color and returns its pixels.
|
||||||
|
func flyLayer(screen uintptr, w, h int32, base uintptr, draw func(hdc uintptr, W, H int32)) []uint32 {
|
||||||
|
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)
|
||||||
|
draw(mem, w, h)
|
||||||
|
pGdiFlush.Call()
|
||||||
|
out := make([]uint32, int(w)*int(h))
|
||||||
|
copy(out, unsafe.Slice((*uint32)(bits), len(out)))
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyRender paints one panel and puts it on the screen.
|
||||||
|
func flyRender(hwnd uintptr, draw func(hdc uintptr, W, H int32)) {
|
||||||
|
if hwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v, _, _ := pIsWindowVisible.Call(hwnd); v == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var rc rect
|
||||||
|
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||||
|
W, H := rc.Right-rc.Left, rc.Bottom-rc.Top
|
||||||
|
if W <= 0 || H <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const ss = 2
|
||||||
|
|
||||||
|
screen, _, _ := pGetDC.Call(0)
|
||||||
|
defer pReleaseDC.Call(0, screen)
|
||||||
|
|
||||||
|
saved := scale
|
||||||
|
scale *= ss
|
||||||
|
wxMakeFonts()
|
||||||
|
onBlack := flyLayer(screen, W*ss, H*ss, rgb(0, 0, 0), draw)
|
||||||
|
onWhite := flyLayer(screen, W*ss, H*ss, rgb(255, 255, 255), draw)
|
||||||
|
scale = saved
|
||||||
|
n := int(W) * int(H)
|
||||||
|
if len(onBlack) != n*ss*ss || len(onWhite) != len(onBlack) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
|
defer pDeleteDC.Call(mem)
|
||||||
|
bmi := bitmapInfoHeader{Width: W, Height: -H, Planes: 1, BitCount: 32}
|
||||||
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
|
var bits unsafe.Pointer
|
||||||
|
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0, uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||||
|
if bmp == 0 || bits == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer pDeleteObject.Call(bmp)
|
||||||
|
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||||
|
defer pSelectObject.Call(mem, old)
|
||||||
|
pix := unsafe.Slice((*uint32)(bits), n)
|
||||||
|
|
||||||
|
a := flyBgAlpha()
|
||||||
|
bgR, bgG, bgB := uint32(28)*a/255, uint32(28)*a/255, uint32(34)*a/255 // colBack at its see-through level
|
||||||
|
stride := int(W) * ss
|
||||||
|
for i := range pix {
|
||||||
|
x, y := i%int(W), i/int(W)
|
||||||
|
var br, bg, bb, wr, wg, wb uint32
|
||||||
|
for dy := 0; dy < ss; dy++ {
|
||||||
|
for dx := 0; dx < ss; dx++ {
|
||||||
|
k := (y*ss+dy)*stride + x*ss + dx
|
||||||
|
c, w := onBlack[k], onWhite[k]
|
||||||
|
br += c >> 16 & 0xFF
|
||||||
|
bg += c >> 8 & 0xFF
|
||||||
|
bb += c & 0xFF
|
||||||
|
wr += w >> 16 & 0xFF
|
||||||
|
wg += w >> 8 & 0xFF
|
||||||
|
wb += w & 0xFF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const cnt = ss * ss
|
||||||
|
br, bg, bb, wr, wg, wb = br/cnt, bg/cnt, bb/cnt, wr/cnt, wg/cnt, wb/cnt
|
||||||
|
d := (sub0(wr, br) + sub0(wg, bg) + sub0(wb, bb)) / 3
|
||||||
|
fa := 255 - min(d, 255) // how solid the content is here
|
||||||
|
fr, fg, fb := min(br, fa), min(bg, fa), min(bb, fa)
|
||||||
|
inv := 255 - fa
|
||||||
|
oa := fa + a*inv/255
|
||||||
|
pix[i] = oa<<24 | (fr+bgR*inv/255)<<16 | (fg+bgG*inv/255)<<8 | (fb + bgB*inv/255)
|
||||||
|
}
|
||||||
|
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
dst := point{wr.Left, wr.Top}
|
||||||
|
sz := size{W, H}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyRefresh repaints one of the panels.
|
||||||
|
func flyRefresh(hwnd uintptr) {
|
||||||
|
switch hwnd {
|
||||||
|
case wxHwnd:
|
||||||
|
flyRender(hwnd, wxDraw)
|
||||||
|
case newsHwnd:
|
||||||
|
flyRender(hwnd, newsDraw)
|
||||||
|
case sysHwnd:
|
||||||
|
flyRender(hwnd, sysDraw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyRefreshAll repaints whichever panel is open (after a setting changed).
|
||||||
|
func flyRefreshAll() {
|
||||||
|
if wxShown {
|
||||||
|
flyRefresh(wxHwnd)
|
||||||
|
}
|
||||||
|
if newsShown {
|
||||||
|
flyRefresh(newsHwnd)
|
||||||
|
}
|
||||||
|
if sysShown {
|
||||||
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
+559
@@ -0,0 +1,559 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// The Google Messages flyout: a speech bubble on the bar that opens Messages for
|
||||||
|
// web (messages.google.com) in a small window above the bar, so you can read and
|
||||||
|
// answer texts without opening a browser tab.
|
||||||
|
//
|
||||||
|
// How it works: MirrorBar starts Microsoft Edge in "app" mode (no tabs, no address
|
||||||
|
// bar) with its own private profile folder, so the sign-in from pairing your phone
|
||||||
|
// is remembered and never touches your normal Edge. Edge is already on every
|
||||||
|
// Windows 11 PC, so there is nothing to install. The window is kept just off the
|
||||||
|
// edge of the screen while the flyout is closed; clicking the bubble slides it
|
||||||
|
// above the bar, clicking anywhere else slides it away again. Because the page
|
||||||
|
// keeps running, the unread number in its window title can be shown on the bubble.
|
||||||
|
//
|
||||||
|
// Messages for web only works while the phone is on and connected; that is how
|
||||||
|
// Google built it, not something MirrorBar can change.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
gmURL = "https://messages.google.com/web/conversations"
|
||||||
|
|
||||||
|
gmW = 780.0 // flyout size, in 96 dpi units
|
||||||
|
gmH = 580.0
|
||||||
|
|
||||||
|
gmTimerID = 3 // on the main window: watches for clicks outside the flyout
|
||||||
|
gmParkX = -32000
|
||||||
|
gmParkY = -32000
|
||||||
|
gmAutoDelay = 20 * time.Second // wait this long after start before opening Messages in the background
|
||||||
|
gmLaunchMax = 45 * time.Second // give up looking for the window after this long
|
||||||
|
|
||||||
|
gmSwpNoSize = 0x0001
|
||||||
|
gmSwpNoMove = 0x0002
|
||||||
|
gmSwpNoZOrder = 0x0004
|
||||||
|
gmSwpFrameChanged = 0x0020
|
||||||
|
gmSwShowNoActive = 4
|
||||||
|
gmWsExAppWindow = 0x00040000
|
||||||
|
gmGaRootOwner = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pIsWindow = user32.NewProc("IsWindow")
|
||||||
|
pWindowFromPoint = user32.NewProc("WindowFromPoint")
|
||||||
|
pGetAncestor = user32.NewProc("GetAncestor")
|
||||||
|
pSetWindowLongPtr = user32.NewProc("SetWindowLongPtrW")
|
||||||
|
pSetWindowPlace = user32.NewProc("SetWindowPlacement")
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
gmHwnd uintptr
|
||||||
|
gmPid uint32
|
||||||
|
gmShown bool
|
||||||
|
gmPrevBtn bool
|
||||||
|
gmPrevFg uintptr
|
||||||
|
gmShownAt time.Time
|
||||||
|
gmLaunching bool
|
||||||
|
gmLaunchedAt time.Time
|
||||||
|
gmWantOpen bool // the bubble was clicked while the window was still starting
|
||||||
|
gmAutoTried bool
|
||||||
|
gmUnread int
|
||||||
|
gmEnumCb uintptr
|
||||||
|
gmFound uintptr
|
||||||
|
gmLogged = map[string]bool{}
|
||||||
|
gmLoggedN int
|
||||||
|
)
|
||||||
|
|
||||||
|
type gmPlacementT struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
ShowCmd uint32
|
||||||
|
MinPos point
|
||||||
|
MaxPos point
|
||||||
|
Normal rect
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
|
func drawGMIcon(hdc uintptr, r rect) {
|
||||||
|
if !layerFg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
col := iconColor()
|
||||||
|
cx, cy := center(r)
|
||||||
|
e := px(1)
|
||||||
|
l, t, rt, b := cx-px(6.5), cy-px(5.5), cx+px(6.5), cy+px(3)
|
||||||
|
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 little tail at the bottom left
|
||||||
|
polyline(hdc, []point{{cx - px(3.5), b}, {cx - px(3.5), cy + px(6)}, {cx - px(0.5), b}}, e, col)
|
||||||
|
// two lines of "text" in the bubble
|
||||||
|
fillRaw(hdc, rect{cx - px(4), cy - px(3), cx + px(4), cy - px(3) + e}, col)
|
||||||
|
fillRaw(hdc, rect{cx - px(4), cy - px(0.5), cx + px(1.5), cy - px(0.5) + e}, col)
|
||||||
|
|
||||||
|
if gmUnread > 0 {
|
||||||
|
br, bg, bb := styleColor(235, 70, 70)
|
||||||
|
bx, by, rad := cx+px(6.5), cy-px(5.5), px(5)
|
||||||
|
circleRaw(hdc, bx, by, rad, rgb(br, bg, bb))
|
||||||
|
txt := strconv.Itoa(gmUnread)
|
||||||
|
if gmUnread > 9 {
|
||||||
|
txt = "9+"
|
||||||
|
}
|
||||||
|
f := makeFont(px(8), 700)
|
||||||
|
old, _, _ := pSelectObject.Call(hdc, f)
|
||||||
|
pSetBkMode.Call(hdc, transparent)
|
||||||
|
pSetTextColor.Call(hdc, rgb(255, 255, 255))
|
||||||
|
drawText(hdc, txt, rect{bx - rad, by - rad, bx + rad + 1, by + rad + 1})
|
||||||
|
pSelectObject.Call(hdc, old)
|
||||||
|
pDeleteObject.Call(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- finding and starting the browser window ----------
|
||||||
|
|
||||||
|
func gmProfileDir() string { return filepath.Join(dataDir(), "messages") }
|
||||||
|
|
||||||
|
func gmProfileExists() bool {
|
||||||
|
_, err := os.Stat(filepath.Join(gmProfileDir(), "Local State"))
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmBrowserPath is Edge (always there on Windows 11), or Chrome if Edge is gone.
|
||||||
|
func gmBrowserPath() string {
|
||||||
|
type cand struct{ env, vendor, app, exe string }
|
||||||
|
for _, c := range []cand{
|
||||||
|
{"ProgramFiles(x86)", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"ProgramFiles", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"LOCALAPPDATA", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"ProgramFiles", "Google", "Chrome", "chrome.exe"},
|
||||||
|
{"ProgramFiles(x86)", "Google", "Chrome", "chrome.exe"},
|
||||||
|
{"LOCALAPPDATA", "Google", "Chrome", "chrome.exe"},
|
||||||
|
} {
|
||||||
|
base := os.Getenv(c.env)
|
||||||
|
if base == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p := filepath.Join(base, c.vendor, c.app, "Application", c.exe)
|
||||||
|
if _, err := os.Stat(p); err == nil {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmLaunch starts the app window. Started in the background it opens minimized
|
||||||
|
// and is never given focus, so it does not interrupt whatever is being typed.
|
||||||
|
func gmLaunch(visible bool) bool {
|
||||||
|
exe := gmBrowserPath()
|
||||||
|
if exe == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
prof := gmProfileDir()
|
||||||
|
if err := os.MkdirAll(prof, 0o755); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
args := []string{
|
||||||
|
exe,
|
||||||
|
"--app=" + gmURL,
|
||||||
|
"--user-data-dir=" + prof,
|
||||||
|
// lets MirrorBar send clicked links to the default browser (this PC only)
|
||||||
|
"--remote-debugging-port=" + gmDebugPort,
|
||||||
|
"--remote-debugging-address=127.0.0.1",
|
||||||
|
"--no-first-run",
|
||||||
|
"--no-default-browser-check",
|
||||||
|
// keep the page awake while its window is parked off the screen
|
||||||
|
"--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} // STARTF_USESHOWWINDOW
|
||||||
|
si.Cb = uint32(unsafe.Sizeof(si))
|
||||||
|
si.ShowWindow = 7 // SW_SHOWMINNOACTIVE
|
||||||
|
if visible {
|
||||||
|
si.ShowWindow = 1 // SW_SHOWNORMAL
|
||||||
|
}
|
||||||
|
var pi syscall.ProcessInformation
|
||||||
|
err := syscall.CreateProcess(u16(exe), u16(strings.Join(parts, " ")), nil, nil, false, 0, nil, nil, &si, &pi)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
gmPid = pi.ProcessId
|
||||||
|
gmStartLinkWatch()
|
||||||
|
syscall.CloseHandle(pi.Process)
|
||||||
|
syscall.CloseHandle(pi.Thread)
|
||||||
|
gmLaunching = true
|
||||||
|
gmLaunchedAt = time.Now()
|
||||||
|
gmWantOpen = visible
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmWindowTitle(hwnd uintptr) string {
|
||||||
|
var tb [512]uint16
|
||||||
|
n, _, _ := pGetWindowText.Call(hwnd, uintptr(unsafe.Pointer(&tb[0])), 512)
|
||||||
|
return syscall.UTF16ToString(tb[:n])
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmTitleMatch is true for the app window's title ("Messages for web", maybe
|
||||||
|
// with a count in front) and false for ordinary browser windows.
|
||||||
|
func gmTitleMatch(t string) bool {
|
||||||
|
l := strings.ToLower(t)
|
||||||
|
if strings.Contains(l, "microsoft edge") || strings.Contains(l, "google chrome") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.Contains(l, "messages")
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmEnumProc(hwnd, lparam uintptr) uintptr {
|
||||||
|
var cls [64]uint16
|
||||||
|
n, _, _ := pGetClassName.Call(hwnd, uintptr(unsafe.Pointer(&cls[0])), 64)
|
||||||
|
if syscall.UTF16ToString(cls[:n]) != "Chrome_WidgetWin_1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if !gmTitleMatch(gmWindowTitle(hwnd)) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
var pid uint32
|
||||||
|
pGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
||||||
|
if gmPid != 0 && pid == gmPid {
|
||||||
|
gmFound = hwnd
|
||||||
|
return 0 // exactly the window we started
|
||||||
|
}
|
||||||
|
if gmFound == 0 {
|
||||||
|
gmFound = hwnd
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmFindWindow() uintptr {
|
||||||
|
if gmEnumCb == 0 {
|
||||||
|
gmEnumCb = syscall.NewCallback(gmEnumProc)
|
||||||
|
}
|
||||||
|
gmFound = 0
|
||||||
|
pEnumWindows.Call(gmEnumCb, 0)
|
||||||
|
return gmFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmWindowOK() bool {
|
||||||
|
if gmHwnd == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ok, _, _ := pIsWindow.Call(gmHwnd)
|
||||||
|
return ok != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmAdopt takes charge of the window once it exists: it stays out of the app
|
||||||
|
// list and Alt+Tab, and sits off screen until the bubble is clicked.
|
||||||
|
func gmAdopt(h uintptr) {
|
||||||
|
gmHwnd = h
|
||||||
|
var pid uint32
|
||||||
|
pGetWindowThreadProcessId.Call(h, uintptr(unsafe.Pointer(&pid)))
|
||||||
|
if pid != 0 {
|
||||||
|
gmPid = 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)
|
||||||
|
}
|
||||||
|
gmLaunching = false
|
||||||
|
gmStartLinkWatch()
|
||||||
|
if gmWantOpen {
|
||||||
|
gmWantOpen = false
|
||||||
|
gmShow()
|
||||||
|
} else {
|
||||||
|
gmPark()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- moving the window ----------
|
||||||
|
|
||||||
|
func gmSize() (int32, int32) {
|
||||||
|
sw, sh := screenSize()
|
||||||
|
cw := min(px(gmW), sw-px(16))
|
||||||
|
ch := min(px(gmH), sh-px(24))
|
||||||
|
return cw, ch
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmMove puts the window at x, y, w, h. A minimized window is first brought back
|
||||||
|
// to that spot without taking focus.
|
||||||
|
func gmMove(x, y, w, h int32, topmost, activate bool) {
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if z, _, _ := pIsZoomed.Call(gmHwnd); z != 0 {
|
||||||
|
pShowWindow.Call(gmHwnd, swRestore)
|
||||||
|
}
|
||||||
|
if ic, _, _ := pIsIconic.Call(gmHwnd); 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(gmHwnd, uintptr(unsafe.Pointer(&wp)))
|
||||||
|
}
|
||||||
|
after := ^uintptr(1) // HWND_NOTOPMOST
|
||||||
|
if topmost {
|
||||||
|
after = hwndTopmost
|
||||||
|
}
|
||||||
|
var flags uintptr
|
||||||
|
if !activate {
|
||||||
|
flags = swpNoActivate
|
||||||
|
}
|
||||||
|
pSetWindowPos.Call(gmHwnd, after, uintptr(x), uintptr(y), uintptr(w), uintptr(h), flags|swpShowWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmPark() {
|
||||||
|
cw, ch := gmSize()
|
||||||
|
gmMove(gmParkX, gmParkY, cw, ch, false, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmPlace is where the flyout goes: above a horizontal bar, to the left of a
|
||||||
|
// vertical one, centered on the bubble and always on the screen.
|
||||||
|
func gmPlace() (x, y, w, h int32) {
|
||||||
|
cw, ch := gmSize()
|
||||||
|
ar := trayAnchor(trayGM)
|
||||||
|
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 gmFocus() {
|
||||||
|
// This program just received the click, so Windows lets it hand the focus on.
|
||||||
|
pSetForegroundWindow.Call(gmHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- open, close, click ----------
|
||||||
|
|
||||||
|
func gmToggle() {
|
||||||
|
if !showGM {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if gmShown {
|
||||||
|
gmHide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewHide()
|
||||||
|
weatherHide() // one panel at a time
|
||||||
|
newsHide()
|
||||||
|
sysHide()
|
||||||
|
webFlyHideAll()
|
||||||
|
if gmWindowOK() {
|
||||||
|
gmShow()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
if gmLaunching {
|
||||||
|
gmWantOpen = true // it is still starting; open it the moment it exists
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !gmLaunch(true) {
|
||||||
|
shellOpen(gmURL, "") // no Edge or Chrome found: use the default browser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmShow() {
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
if fg != gmHwnd {
|
||||||
|
gmPrevFg = fg
|
||||||
|
}
|
||||||
|
gmShown = true
|
||||||
|
gmPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||||
|
gmShownAt = time.Now()
|
||||||
|
x, y, w, h := gmPlace()
|
||||||
|
gmMove(x, y, w, h, true, true)
|
||||||
|
gmFocus()
|
||||||
|
pSetTimer.Call(hwndMain, gmTimerID, 80, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmHide() {
|
||||||
|
if !gmShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
gmPark()
|
||||||
|
if fg == gmHwnd && gmPrevFg != 0 && gmPrevFg != hwndMain && gmPrevFg != gmHwnd {
|
||||||
|
if ok, _, _ := pIsWindow.Call(gmPrevFg); ok != 0 {
|
||||||
|
pSetForegroundWindow.Call(gmPrevFg) // give the keyboard back to what you were doing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmClose shuts the Messages window down (right-click, "Close Messages").
|
||||||
|
func gmClose() {
|
||||||
|
gmHide()
|
||||||
|
if gmWindowOK() {
|
||||||
|
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
gmLaunching = false
|
||||||
|
gmWantOpen = false
|
||||||
|
gmAutoTried = true // do not bring it back by itself
|
||||||
|
gmUnread = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmShutdown() {
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
if gmWindowOK() {
|
||||||
|
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmPoll runs every 80 ms while the flyout is open and closes it when a mouse
|
||||||
|
// button goes down anywhere outside it (the bubble itself is left alone, so
|
||||||
|
// clicking it can close the flyout).
|
||||||
|
func gmPoll() {
|
||||||
|
if !gmShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !gmWindowOK() {
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
|
down := (l|r)&0x8000 != 0
|
||||||
|
if down && !gmPrevBtn && time.Since(gmShownAt) > 300*time.Millisecond {
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var fr rect
|
||||||
|
pGetWindowRect.Call(gmHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
|
inside := inRect(fr, cp)
|
||||||
|
if !inside {
|
||||||
|
// a dialog or menu that belongs to the Messages window counts as inside
|
||||||
|
h, _, _ := pWindowFromPoint.Call(uintptr(uint32(cp.X)) | uintptr(uint32(cp.Y))<<32)
|
||||||
|
if h != 0 {
|
||||||
|
root, _, _ := pGetAncestor.Call(h, gmGaRootOwner)
|
||||||
|
inside = root == gmHwnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !inside && !inRect(trayAnchor(trayGM), cp) {
|
||||||
|
gmHide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gmPrevBtn = down
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the background check ----------
|
||||||
|
|
||||||
|
var gmCountRe = regexp.MustCompile(`[\(\[](\d{1,3})\+?[\)\]]`)
|
||||||
|
|
||||||
|
func gmParseUnread(title string) int {
|
||||||
|
m := gmCountRe.FindStringSubmatch(title)
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
n, _ := strconv.Atoi(m[1])
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmLogTitle keeps the first few different window titles in titles.txt next to
|
||||||
|
// the Messages profile, so the unread badge can be tuned if Google words it
|
||||||
|
// differently than expected. It stops after 25 so it never grows.
|
||||||
|
func gmLogTitle(t string) {
|
||||||
|
if t == "" || gmLogged[t] || gmLoggedN >= 25 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmLogged[t] = true
|
||||||
|
gmLoggedN++
|
||||||
|
f, err := os.OpenFile(filepath.Join(dataDir(), "messages-titles.txt"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if len(t) > 80 {
|
||||||
|
t = t[:80]
|
||||||
|
}
|
||||||
|
_, _ = f.WriteString(time.Now().Format("2006-01-02 15:04:05") + "\t" + t + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmTick runs from the bar's 250 ms timer. It starts Messages in the background
|
||||||
|
// once you have paired a phone, notices when the window goes away, and reads
|
||||||
|
// the unread count from the window title. Returns true when the bar needs a
|
||||||
|
// repaint.
|
||||||
|
func gmTick(tick int) (changed bool) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
changed = false // optional feature; never take the bar down with it
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if !showGM {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if gmHwnd != 0 && !gmWindowOK() {
|
||||||
|
gmHwnd = 0
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
changed = gmUnread != 0
|
||||||
|
gmUnread = 0
|
||||||
|
}
|
||||||
|
if gmHwnd == 0 {
|
||||||
|
switch {
|
||||||
|
case gmLaunching:
|
||||||
|
if h := gmFindWindow(); h != 0 {
|
||||||
|
gmAdopt(h)
|
||||||
|
} else if time.Since(gmLaunchedAt) > gmLaunchMax {
|
||||||
|
gmLaunching = false
|
||||||
|
gmWantOpen = false
|
||||||
|
}
|
||||||
|
case !gmAutoTried && time.Since(startedAt) > gmAutoDelay:
|
||||||
|
gmAutoTried = true
|
||||||
|
if h := gmFindWindow(); h != 0 {
|
||||||
|
gmAdopt(h) // left over from an earlier run of MirrorBar
|
||||||
|
} else if gmProfileExists() {
|
||||||
|
gmLaunch(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gmHwnd != 0 && tick%8 == 0 {
|
||||||
|
t := gmWindowTitle(gmHwnd)
|
||||||
|
gmLogTitle(t)
|
||||||
|
if n := gmParseUnread(t); n != gmUnread {
|
||||||
|
gmUnread = n
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed
|
||||||
|
}
|
||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Links clicked inside Google Messages open in the Windows default browser.
|
||||||
|
//
|
||||||
|
// Edge opens a clicked link in a new Edge window of the Messages profile. To
|
||||||
|
// hand those to the default browser, the Messages window is started with a
|
||||||
|
// debugging port that listens on this PC only (127.0.0.1). A small background
|
||||||
|
// loop looks at the list of open pages, and any page that is not Messages or
|
||||||
|
// a Google sign-in page is opened with the default browser and then closed.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const gmDebugPort = "9341"
|
||||||
|
|
||||||
|
var gmLinkOnce bool
|
||||||
|
|
||||||
|
type gmTarget struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmOwnHost reports whether a page belongs to Messages itself (including the
|
||||||
|
// Google sign-in pages used while pairing), which must stay where they are.
|
||||||
|
func gmOwnHost(host string) bool {
|
||||||
|
host = strings.ToLower(host)
|
||||||
|
for _, ok := range []string{"messages.google.com", "accounts.google.com", "gstatic.com", "googleusercontent.com"} {
|
||||||
|
if host == ok || strings.HasSuffix(host, "."+ok) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmStartLinkWatch() {
|
||||||
|
if gmLinkOnce {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmLinkOnce = true
|
||||||
|
go func() {
|
||||||
|
defer func() { recover() }()
|
||||||
|
runtime.LockOSThread()
|
||||||
|
pCoInitializeEx.Call(0, 2)
|
||||||
|
client := &http.Client{Timeout: 1500 * time.Millisecond, Transport: &http.Transport{DisableKeepAlives: true}}
|
||||||
|
base := "http://127.0.0.1:" + gmDebugPort
|
||||||
|
for {
|
||||||
|
time.Sleep(80 * time.Millisecond)
|
||||||
|
if gmHwnd == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resp, err := client.Get(base + "/json/list")
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var ts []gmTarget
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&ts)
|
||||||
|
resp.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, t := range ts {
|
||||||
|
if t.Type != "page" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
u, err := url.Parse(t.URL)
|
||||||
|
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if gmOwnHost(u.Hostname()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// close the Edge window first so it is on screen as briefly as possible
|
||||||
|
if r, err := client.Get(base + "/json/close/" + url.PathEscape(t.ID)); err == nil {
|
||||||
|
r.Body.Close()
|
||||||
|
}
|
||||||
|
pShellExecute.Call(0, uintptr(unsafe.Pointer(u16("open"))), uintptr(unsafe.Pointer(u16(t.URL))), 0, 0, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Combining windows: when "Combine windows of the same program" is on, all the
|
||||||
|
// open windows of one program (four Brave windows, say) share a single icon on
|
||||||
|
// the bar with a small red count in its top right corner. `allApps` is the full
|
||||||
|
// list of windows and launchers in bar order; `apps` is what the bar shows.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
groupWins = true
|
||||||
|
allApps []appWin
|
||||||
|
winActiveAt = map[uintptr]time.Time{} // when each window was last the front one
|
||||||
|
)
|
||||||
|
|
||||||
|
// noteForeground remembers which window is in front, so a combined icon knows
|
||||||
|
// which of its windows you were using last.
|
||||||
|
func noteForeground(present map[uintptr]appWin) {
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
if _, ok := present[fg]; ok {
|
||||||
|
winActiveAt[fg] = time.Now()
|
||||||
|
}
|
||||||
|
for h := range winActiveAt {
|
||||||
|
if _, ok := present[h]; !ok {
|
||||||
|
delete(winActiveAt, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// groupApps turns the full window list into the icons the bar shows.
|
||||||
|
func groupApps(list []appWin) []appWin {
|
||||||
|
out := make([]appWin, 0, len(list))
|
||||||
|
idx := map[string]int{}
|
||||||
|
for _, a := range list {
|
||||||
|
a.count, a.members = 1, nil
|
||||||
|
if a.hwnd == 0 {
|
||||||
|
out = append(out, a)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
a.members = []uintptr{a.hwnd}
|
||||||
|
if groupWins && a.exe != "" {
|
||||||
|
k := strings.ToLower(a.exe)
|
||||||
|
if i, ok := idx[k]; ok {
|
||||||
|
out[i].members = append(out[i].members, a.hwnd)
|
||||||
|
out[i].count++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
idx[k] = len(out)
|
||||||
|
}
|
||||||
|
out = append(out, a)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// memberHwnd is the window a combined icon acts on: the one used most recently.
|
||||||
|
func memberHwnd(a appWin) uintptr {
|
||||||
|
if len(a.members) <= 1 {
|
||||||
|
return a.hwnd
|
||||||
|
}
|
||||||
|
best := a.members[0]
|
||||||
|
for _, m := range a.members[1:] {
|
||||||
|
if winActiveAt[m].After(winActiveAt[best]) {
|
||||||
|
best = m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best
|
||||||
|
}
|
||||||
|
|
||||||
|
// syncAllFromGrouped puts allApps back in step after the icons were dragged
|
||||||
|
// into a new order: each icon brings all of its windows along.
|
||||||
|
func syncAllFromGrouped() {
|
||||||
|
byHwnd := map[uintptr]appWin{}
|
||||||
|
for _, a := range allApps {
|
||||||
|
if a.hwnd != 0 {
|
||||||
|
byHwnd[a.hwnd] = a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out := make([]appWin, 0, len(allApps))
|
||||||
|
for _, g := range apps {
|
||||||
|
if g.hwnd == 0 {
|
||||||
|
g.count, g.members = 0, nil
|
||||||
|
out = append(out, g)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, m := range g.members {
|
||||||
|
if w, ok := byHwnd[m]; ok {
|
||||||
|
out = append(out, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
allApps = out
|
||||||
|
}
|
||||||
|
|
||||||
|
// activateGroup handles a click on a combined icon: bring up the window used
|
||||||
|
// most recently, or, if one of them is already in front, step to the next.
|
||||||
|
func activateGroup(a appWin) {
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
target := memberHwnd(a)
|
||||||
|
for i, m := range a.members {
|
||||||
|
if m == fg {
|
||||||
|
target = a.members[(i+1)%len(a.members)]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if iconic, _, _ := pIsIconic.Call(target); iconic != 0 {
|
||||||
|
pShowWindow.Call(target, swRestore)
|
||||||
|
}
|
||||||
|
pSetForegroundWindow.Call(target)
|
||||||
|
}
|
||||||
|
|
||||||
|
// drawCountBadge draws the little red number in the top right corner of an icon.
|
||||||
|
func drawCountBadge(hdc uintptr, cx, cy, isz int32, n int) {
|
||||||
|
br, bg, bb := styleColor(235, 70, 70)
|
||||||
|
bx, by, rad := cx+isz/2, cy-isz/2, px(5)
|
||||||
|
circleRaw(hdc, bx, by, rad, rgb(br, bg, bb))
|
||||||
|
txt := strconv.Itoa(n)
|
||||||
|
if n > 9 {
|
||||||
|
txt = "9+"
|
||||||
|
}
|
||||||
|
f := makeFont(px(8), 700)
|
||||||
|
old, _, _ := pSelectObject.Call(hdc, f)
|
||||||
|
pSetBkMode.Call(hdc, transparent)
|
||||||
|
pSetTextColor.Call(hdc, rgb(255, 255, 255))
|
||||||
|
drawText(hdc, txt, rect{bx - rad, by - rad, bx + rad + 1, by + rad + 1})
|
||||||
|
pSelectObject.Call(hdc, old)
|
||||||
|
pDeleteObject.Call(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = unsafe.Pointer(nil)
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -306,6 +306,9 @@ type appWin struct {
|
|||||||
title string
|
title string
|
||||||
icon uintptr
|
icon uintptr
|
||||||
exe string // full path of the program, "" when unknown
|
exe string // full path of the program, "" when unknown
|
||||||
|
|
||||||
|
count int // windows combined into this icon (1 when alone)
|
||||||
|
members []uintptr // every window behind this icon
|
||||||
}
|
}
|
||||||
|
|
||||||
type alphaLevel struct {
|
type alphaLevel struct {
|
||||||
@@ -328,6 +331,7 @@ var (
|
|||||||
hoverApp = -1
|
hoverApp = -1
|
||||||
trackingMouse bool
|
trackingMouse bool
|
||||||
scale float64 = 1
|
scale float64 = 1
|
||||||
|
realScale float64 = 1 // scale as the screen really is; scale itself is doubled while the icon layers are drawn
|
||||||
barHeight int32
|
barHeight int32
|
||||||
fontTime uintptr
|
fontTime uintptr
|
||||||
fontDate uintptr
|
fontDate uintptr
|
||||||
@@ -437,6 +441,17 @@ func setTaskbarState(owner uintptr, state uintptr) {
|
|||||||
appBar(abmSetState, &abd)
|
appBar(abmSetState, &abd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keepOnTop puts the bar back in the topmost band if Windows or another program
|
||||||
|
// has knocked it out of it, which otherwise sinks it under every other window.
|
||||||
|
func keepOnTop(hwnd uintptr) {
|
||||||
|
ex, _, _ := pGetWindowLongPtr.Call(hwnd, neg(-20))
|
||||||
|
if ex&wsExTopmost != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const swpNoSize, swpNoMove = 0x0001, 0x0002
|
||||||
|
pSetWindowPos.Call(hwnd, hwndTopmost, 0, 0, 0, 0, swpNoSize|swpNoMove|swpNoActivate)
|
||||||
|
}
|
||||||
|
|
||||||
func hideTaskbar() {
|
func hideTaskbar() {
|
||||||
tb := findTaskbar()
|
tb := findTaskbar()
|
||||||
if tb == 0 {
|
if tb == 0 {
|
||||||
@@ -462,7 +477,7 @@ func restoreAll() {
|
|||||||
// ---------- open windows ----------
|
// ---------- open windows ----------
|
||||||
|
|
||||||
func collectWindow(hwnd uintptr) {
|
func collectWindow(hwnd uintptr) {
|
||||||
if hwnd == hwndMain {
|
if hwnd == hwndMain || (gmHwnd != 0 && hwnd == gmHwnd) || webFlyOwns(hwnd) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vis, _, _ := pIsWindowVisible.Call(hwnd)
|
vis, _, _ := pIsWindowVisible.Call(hwnd)
|
||||||
@@ -527,6 +542,10 @@ func activateApp(idx int) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if apps[idx].count > 1 {
|
||||||
|
activateGroup(apps[idx])
|
||||||
|
return
|
||||||
|
}
|
||||||
fg, _, _ := pGetForegroundWindow.Call()
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
iconic, _, _ := pIsIconic.Call(h)
|
iconic, _, _ := pIsIconic.Call(h)
|
||||||
switch {
|
switch {
|
||||||
@@ -543,7 +562,6 @@ func activateApp(idx int) {
|
|||||||
// ---------- our bar ----------
|
// ---------- our bar ----------
|
||||||
|
|
||||||
func startWidth() int32 { return px(52) }
|
func startWidth() int32 { return px(52) }
|
||||||
func clockWidth() int32 { return px(140) }
|
|
||||||
|
|
||||||
func screenSize() (int32, int32) {
|
func screenSize() (int32, int32) {
|
||||||
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
||||||
@@ -563,7 +581,7 @@ func barGap() int32 { return px(6) }
|
|||||||
|
|
||||||
func positionBar(hwnd uintptr) {
|
func positionBar(hwnd uintptr) {
|
||||||
pw, ph := pillSize()
|
pw, ph := pillSize()
|
||||||
if !customPos {
|
if !customPos && !autoHide {
|
||||||
sw, sh := screenSize()
|
sw, sh := screenSize()
|
||||||
edge := uintptr(abeBottom)
|
edge := uintptr(abeBottom)
|
||||||
if vertical {
|
if vertical {
|
||||||
@@ -579,6 +597,14 @@ func positionBar(hwnd uintptr) {
|
|||||||
appBar(abmSetPos, &abd)
|
appBar(abmSetPos, &abd)
|
||||||
}
|
}
|
||||||
x, y := pillPos(pw, ph)
|
x, y := pillPos(pw, ph)
|
||||||
|
if autoHide && ahHidden {
|
||||||
|
sw, sh := screenSize()
|
||||||
|
if vertical {
|
||||||
|
x = sw // just past the right edge
|
||||||
|
} else {
|
||||||
|
y = sh // just below the bottom edge
|
||||||
|
}
|
||||||
|
}
|
||||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 1)
|
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 1)
|
||||||
redraw(hwnd)
|
redraw(hwnd)
|
||||||
}
|
}
|
||||||
@@ -656,13 +682,25 @@ func drawText(hdc uintptr, s string, r rect) {
|
|||||||
// makeFont uses plain antialiasing (not ClearType) because ClearType's colored
|
// makeFont uses plain antialiasing (not ClearType) because ClearType's colored
|
||||||
// edges look wrong on a transparent window.
|
// edges look wrong on a transparent window.
|
||||||
func makeFont(height int32, weight int) uintptr {
|
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(
|
f, _, _ := pCreateFont.Call(
|
||||||
uintptr(-height), 0, 0, 0, uintptr(weight), 0, 0, 0,
|
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
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func drawLogo(hdc uintptr, r rect) {
|
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)
|
sq := px(8)
|
||||||
gap := px(2)
|
gap := px(2)
|
||||||
total := sq*2 + gap
|
total := sq*2 + gap
|
||||||
@@ -718,6 +756,9 @@ func drawAppGlyph(hdc uintptr, r rect, a appWin) {
|
|||||||
if a.icon != 0 {
|
if a.icon != 0 {
|
||||||
cx, cy := center(r)
|
cx, cy := center(r)
|
||||||
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||||
|
if a.count > 1 {
|
||||||
|
drawCountBadge(hdc, cx, cy, isz, a.count)
|
||||||
|
}
|
||||||
} else if rs := []rune(a.title); len(rs) > 0 {
|
} else if rs := []rune(a.title); len(rs) > 0 {
|
||||||
pSetBkMode.Call(hdc, transparent)
|
pSetBkMode.Call(hdc, transparent)
|
||||||
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
||||||
@@ -795,7 +836,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
var target uintptr
|
var target uintptr
|
||||||
var exe string
|
var exe string
|
||||||
if appIdx >= 0 && appIdx < len(apps) {
|
if appIdx >= 0 && appIdx < len(apps) {
|
||||||
target = apps[appIdx].hwnd
|
target = memberHwnd(apps[appIdx])
|
||||||
|
|
||||||
title := []rune(apps[appIdx].title)
|
title := []rune(apps[appIdx].title)
|
||||||
text := string(title)
|
text := string(title)
|
||||||
@@ -861,6 +902,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
|
|
||||||
add(0, menuSettingsID, "MirrorBar settings...")
|
add(0, menuSettingsID, "MirrorBar settings...")
|
||||||
add(0, menuNotifyID, "Open notification center")
|
add(0, menuNotifyID, "Open notification center")
|
||||||
|
add(0, menuEmojiID, "Open emoji panel")
|
||||||
sep()
|
sep()
|
||||||
for i, l := range alphaLevels {
|
for i, l := range alphaLevels {
|
||||||
var flags uintptr
|
var flags uintptr
|
||||||
@@ -894,8 +936,11 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
var pt point
|
var pt point
|
||||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&pt)))
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&pt)))
|
||||||
pSetForegroundWindow.Call(hwnd)
|
pSetForegroundWindow.Call(hwnd)
|
||||||
|
menuOpen = true
|
||||||
cmd, _, _ := pTrackPopupMenu.Call(menu, tpmRightButton|tpmBottomAlign|tpmReturnCmd,
|
cmd, _, _ := pTrackPopupMenu.Call(menu, tpmRightButton|tpmBottomAlign|tpmReturnCmd,
|
||||||
uintptr(pt.X), uintptr(pt.Y), 0, hwnd, 0)
|
uintptr(pt.X), uintptr(pt.Y), 0, hwnd, 0)
|
||||||
|
menuOpen = false
|
||||||
|
ahLeftAt = time.Now()
|
||||||
pDestroyMenu.Call(menu)
|
pDestroyMenu.Call(menu)
|
||||||
|
|
||||||
sysCommands := map[uintptr]uintptr{
|
sysCommands := map[uintptr]uintptr{
|
||||||
@@ -974,13 +1019,29 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
return 0
|
return 0
|
||||||
case wmTimer:
|
case wmTimer:
|
||||||
|
if wparam == gmTimerID {
|
||||||
|
gmPoll()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if webFlyTimer(wparam) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if wparam == ahTimerID {
|
||||||
|
ahTick(hwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if wparam == previewTimerID {
|
if wparam == previewTimerID {
|
||||||
previewTick()
|
previewTick()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
hideTaskbar()
|
hideTaskbar()
|
||||||
|
keepOnTop(hwnd)
|
||||||
tick++
|
tick++
|
||||||
changed := refreshApps(tick%16 == 0)
|
changed := refreshApps(tick%16 == 0)
|
||||||
|
if gmTick(tick) {
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
webFlyTick()
|
||||||
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
|
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
@@ -1188,6 +1249,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
case wmDestroy:
|
case wmDestroy:
|
||||||
previewShutdown()
|
previewShutdown()
|
||||||
weatherShutdown()
|
weatherShutdown()
|
||||||
|
newsShutdown()
|
||||||
|
sysShutdown()
|
||||||
|
gmShutdown()
|
||||||
|
webFlyShutdown()
|
||||||
abd := appBarData{Hwnd: hwnd}
|
abd := appBarData{Hwnd: hwnd}
|
||||||
appBar(abmRemove, &abd)
|
appBar(abmRemove, &abd)
|
||||||
pKillTimer.Call(hwnd, timerID)
|
pKillTimer.Call(hwnd, timerID)
|
||||||
@@ -1249,6 +1314,7 @@ func main() {
|
|||||||
loadOrderKeys()
|
loadOrderKeys()
|
||||||
loadIconMode()
|
loadIconMode()
|
||||||
loadZip()
|
loadZip()
|
||||||
|
loadFeatures()
|
||||||
|
|
||||||
hdc, _, _ := pGetDC.Call(0)
|
hdc, _, _ := pGetDC.Call(0)
|
||||||
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
||||||
@@ -1256,12 +1322,15 @@ func main() {
|
|||||||
if dpi > 0 {
|
if dpi > 0 {
|
||||||
scale = float64(dpi) / 96.0
|
scale = float64(dpi) / 96.0
|
||||||
}
|
}
|
||||||
|
realScale = scale
|
||||||
barHeight = px(36)
|
barHeight = px(36)
|
||||||
fontTime = makeFont(px(13), 400)
|
fontTime = makeFont(px(13), 400)
|
||||||
fontDate = makeFont(px(11), 400)
|
fontDate = makeFont(px(11), 400)
|
||||||
fontApp = makeFont(px(12), 600)
|
fontApp = makeFont(px(12), 600)
|
||||||
initSuperFonts()
|
initSuperFonts()
|
||||||
loadColors()
|
loadColors()
|
||||||
|
loadLook()
|
||||||
|
rebuildClockFonts()
|
||||||
|
|
||||||
autoQuit = autoQuitDef
|
autoQuit = autoQuitDef
|
||||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||||
@@ -1303,6 +1372,8 @@ func main() {
|
|||||||
hwndMain = hwnd
|
hwndMain = hwnd
|
||||||
previewInit(inst)
|
previewInit(inst)
|
||||||
weatherInit(inst)
|
weatherInit(inst)
|
||||||
|
newsInit(inst)
|
||||||
|
sysInit(inst)
|
||||||
enableFileDrop(hwnd)
|
enableFileDrop(hwnd)
|
||||||
refreshAutostartPath()
|
refreshAutostartPath()
|
||||||
|
|
||||||
@@ -1319,7 +1390,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Register as an app bar so maximized windows stop above us.
|
// Register as an app bar so maximized windows stop above us.
|
||||||
if customPos {
|
if customPos || autoHide {
|
||||||
appbarOn = false
|
appbarOn = false
|
||||||
} else {
|
} else {
|
||||||
abd := appBarData{Hwnd: hwnd, CallbackMsg: callbackMsg}
|
abd := appBarData{Hwnd: hwnd, CallbackMsg: callbackMsg}
|
||||||
@@ -1331,7 +1402,11 @@ func main() {
|
|||||||
refreshApps(true)
|
refreshApps(true)
|
||||||
positionBar(hwnd)
|
positionBar(hwnd)
|
||||||
pSetTimer.Call(hwnd, timerID, 250, 0)
|
pSetTimer.Call(hwnd, timerID, 250, 0)
|
||||||
|
if autoHide {
|
||||||
|
ahStart()
|
||||||
|
}
|
||||||
weatherRefresh(false) // have the forecast ready before the cloud is first clicked
|
weatherRefresh(false) // have the forecast ready before the cloud is first clicked
|
||||||
|
newsRefresh(false)
|
||||||
|
|
||||||
var m msg
|
var m msg
|
||||||
for {
|
for {
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Local news state and downloading. The place comes from the same ZIP code as
|
||||||
|
// the weather. Like the weather, the download runs on its own goroutine and the
|
||||||
|
// bar is told with a posted message when it finishes.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const newsFresh = 10 * time.Minute
|
||||||
|
|
||||||
|
type newsState struct {
|
||||||
|
zip string
|
||||||
|
place string
|
||||||
|
items []newsItem
|
||||||
|
ok bool
|
||||||
|
loading bool
|
||||||
|
err string
|
||||||
|
fetched time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
newsMu sync.Mutex
|
||||||
|
news newsState
|
||||||
|
newsGen int
|
||||||
|
)
|
||||||
|
|
||||||
|
func newsSnapshot() newsState {
|
||||||
|
newsMu.Lock()
|
||||||
|
defer newsMu.Unlock()
|
||||||
|
s := news
|
||||||
|
s.items = append([]newsItem(nil), news.items...)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsRefresh starts a download if there are no headlines for this ZIP code yet
|
||||||
|
// or they are old (or force is set). Safe to call as often as you like.
|
||||||
|
func newsRefresh(force bool) {
|
||||||
|
if !showNews {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
zip := wxZip
|
||||||
|
newsMu.Lock()
|
||||||
|
if len(zip) != 5 {
|
||||||
|
news = newsState{}
|
||||||
|
newsGen++
|
||||||
|
newsMu.Unlock()
|
||||||
|
weatherNotify()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
same := news.zip == zip
|
||||||
|
switch {
|
||||||
|
case same && news.loading && !force:
|
||||||
|
newsMu.Unlock()
|
||||||
|
return
|
||||||
|
case same && news.ok && time.Since(news.fetched) < newsFresh && !force:
|
||||||
|
newsMu.Unlock()
|
||||||
|
return
|
||||||
|
case same && !news.ok && news.err != "" && time.Since(news.fetched) < 30*time.Second && !force:
|
||||||
|
newsMu.Unlock() // it just failed; don't hammer the service
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !same {
|
||||||
|
news = newsState{zip: zip}
|
||||||
|
}
|
||||||
|
news.loading = true
|
||||||
|
news.err = ""
|
||||||
|
newsGen++
|
||||||
|
gen := newsGen
|
||||||
|
newsMu.Unlock()
|
||||||
|
weatherNotify()
|
||||||
|
go newsFetch(zip, gen)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newsFetch(zip string, gen int) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
newsFinish(gen, zip, "", nil, "The news lookup failed.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
_, _, place, err := wxLocate(zip)
|
||||||
|
if err != nil {
|
||||||
|
newsFinish(gen, zip, "", nil, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("GET", newsFeedURL(place), nil)
|
||||||
|
if err != nil {
|
||||||
|
newsFinish(gen, zip, place, nil, "The news lookup failed.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Header.Set("User-Agent", "MirrorBar news flyout")
|
||||||
|
resp, err := wxClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
newsFinish(gen, zip, place, nil, "Can't reach the news service. Check your internet connection.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
newsFinish(gen, zip, place, nil, fmt.Sprintf("The news service said HTTP %d.", resp.StatusCode))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||||
|
if err != nil {
|
||||||
|
newsFinish(gen, zip, place, nil, "The news download was cut off.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
items, err := newsParse(data)
|
||||||
|
if err != nil {
|
||||||
|
newsFinish(gen, zip, place, nil, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(items) == 0 {
|
||||||
|
newsFinish(gen, zip, place, nil, "No local headlines found for "+place+".")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newsFinish(gen, zip, place, items, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsFinish stores a result, unless the ZIP code changed while it was loading.
|
||||||
|
func newsFinish(gen int, zip, place string, items []newsItem, errText string) {
|
||||||
|
newsMu.Lock()
|
||||||
|
if gen != newsGen {
|
||||||
|
newsMu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
news.loading = false
|
||||||
|
news.fetched = time.Now()
|
||||||
|
if place != "" {
|
||||||
|
news.place = place
|
||||||
|
}
|
||||||
|
if items != nil {
|
||||||
|
news.items, news.ok, news.err = items, true, ""
|
||||||
|
} else {
|
||||||
|
news.err = errText // keep older headlines on screen if there are any
|
||||||
|
}
|
||||||
|
newsMu.Unlock()
|
||||||
|
weatherNotify()
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsStatusText is the line the settings window shows when only news is on.
|
||||||
|
func newsStatusText() string {
|
||||||
|
s := newsSnapshot()
|
||||||
|
switch {
|
||||||
|
case s.ok && s.place != "":
|
||||||
|
return "Showing local news for " + s.place
|
||||||
|
case s.loading:
|
||||||
|
return "Looking up " + wxZip + "..."
|
||||||
|
case s.err != "":
|
||||||
|
return s.err
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
+98
@@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Reading a news feed. Only the standard library, no Windows calls, so it can
|
||||||
|
// be tested on its own.
|
||||||
|
//
|
||||||
|
// Local headlines come from Google News' place feed: it takes a place name such
|
||||||
|
// as "Huntington, Indiana" and returns what local papers, TV and radio stations
|
||||||
|
// near it are publishing. The place name comes from the ZIP code (the weather
|
||||||
|
// lookup already finds it), so the same ZIP code serves both panels.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
|
"html"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type newsItem struct {
|
||||||
|
title string
|
||||||
|
source string
|
||||||
|
link string
|
||||||
|
when time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
const newsKeep = 30 // headlines kept per lookup
|
||||||
|
|
||||||
|
func newsFeedURL(place string) string {
|
||||||
|
return "https://news.google.com/rss/headlines/section/geo/" + url.PathEscape(place) + "?hl=en-US&gl=US&ceid=US:en"
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsParse turns the feed into headlines, newest first. Only web links are
|
||||||
|
// kept, so nothing odd can be opened from the panel.
|
||||||
|
func newsParse(data []byte) ([]newsItem, error) {
|
||||||
|
var feed struct {
|
||||||
|
Items []struct {
|
||||||
|
Title string `xml:"title"`
|
||||||
|
Link string `xml:"link"`
|
||||||
|
PubDate string `xml:"pubDate"`
|
||||||
|
Source string `xml:"source"`
|
||||||
|
} `xml:"channel>item"`
|
||||||
|
}
|
||||||
|
if err := xml.Unmarshal(data, &feed); err != nil {
|
||||||
|
return nil, fmt.Errorf("The news feed could not be read.")
|
||||||
|
}
|
||||||
|
var out []newsItem
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for _, it := range feed.Items {
|
||||||
|
link := strings.TrimSpace(it.Link)
|
||||||
|
if !strings.HasPrefix(link, "https://") && !strings.HasPrefix(link, "http://") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
title := strings.TrimSpace(html.UnescapeString(it.Title))
|
||||||
|
src := strings.TrimSpace(html.UnescapeString(it.Source))
|
||||||
|
// Titles end with " - Source Name"; the source is shown on its own line.
|
||||||
|
if src != "" && strings.HasSuffix(title, " - "+src) {
|
||||||
|
title = strings.TrimSuffix(title, " - "+src)
|
||||||
|
} else if src == "" {
|
||||||
|
if i := strings.LastIndex(title, " - "); i > 0 {
|
||||||
|
src = strings.TrimSpace(title[i+3:])
|
||||||
|
title = strings.TrimSpace(title[:i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
key := strings.ToLower(title)
|
||||||
|
if title == "" || seen[key] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[key] = true
|
||||||
|
when, _ := time.Parse(time.RFC1123, strings.TrimSpace(it.PubDate))
|
||||||
|
out = append(out, newsItem{title: title, source: src, link: link, when: when})
|
||||||
|
}
|
||||||
|
sort.SliceStable(out, func(i, j int) bool { return out[i].when.After(out[j].when) })
|
||||||
|
if len(out) > newsKeep {
|
||||||
|
out = out[:newsKeep]
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsAge says how old a headline is: "12 min ago", "3 hr ago", "2 days ago".
|
||||||
|
func newsAge(t time.Time, now time.Time) string {
|
||||||
|
if t.IsZero() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
d := now.Sub(t)
|
||||||
|
switch {
|
||||||
|
case d < 0, d < time.Minute:
|
||||||
|
return "just now"
|
||||||
|
case d < time.Hour:
|
||||||
|
return fmt.Sprintf("%d min ago", int(d.Minutes()))
|
||||||
|
case d < 24*time.Hour:
|
||||||
|
return fmt.Sprintf("%d hr ago", int(d.Hours()))
|
||||||
|
case d < 48*time.Hour:
|
||||||
|
return "yesterday"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%d days ago", int(d.Hours()/24))
|
||||||
|
}
|
||||||
+361
@@ -0,0 +1,361 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// The local news flyout: a little newspaper on the bar that opens a panel above
|
||||||
|
// it with a list of local headlines. Each headline is a link; clicking one opens
|
||||||
|
// it in the default browser. The panel is its own window that never takes focus,
|
||||||
|
// it goes away when you click the newspaper again or click anywhere else, and it
|
||||||
|
// is painted at double size and shrunk down, the same way the weather panel is.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
newsW = 380.0 // panel width, in 96 dpi units
|
||||||
|
newsHead = 44.0 // header height
|
||||||
|
newsRow = 58.0 // height of one headline
|
||||||
|
newsFoot = 8.0
|
||||||
|
newsMaxRows = 10
|
||||||
|
|
||||||
|
idcHandCursor = 32649
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
newsHwnd uintptr
|
||||||
|
newsShown bool
|
||||||
|
newsPrevBtn bool
|
||||||
|
newsHover = -1 // the headline under the mouse, -1 for none
|
||||||
|
newsVisible int // how many headlines the panel is showing
|
||||||
|
)
|
||||||
|
|
||||||
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
|
// drawNewsIcon draws the little newspaper on the bar.
|
||||||
|
func drawNewsIcon(hdc uintptr, r rect) {
|
||||||
|
if !layerFg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
col := iconColor()
|
||||||
|
cx, cy := center(r)
|
||||||
|
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(5.5)
|
||||||
|
e := px(1)
|
||||||
|
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)
|
||||||
|
fillRaw(hdc, rect{l + px(2.5), t + px(2.5), l + px(6), t + px(5.5)}, col) // the main headline
|
||||||
|
fillRaw(hdc, rect{l + px(7.5), t + px(2.5), rt - px(2.5), t + px(3.5)}, col)
|
||||||
|
fillRaw(hdc, rect{l + px(7.5), t + px(4.5), rt - px(2.5), t + px(5.5)}, col)
|
||||||
|
fillRaw(hdc, rect{l + px(2.5), t + px(7), rt - px(2.5), t + px(8)}, col) // lines of text
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the panel window ----------
|
||||||
|
|
||||||
|
func newsInit(inst uintptr) {
|
||||||
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
|
className := u16("MirrorBarNews")
|
||||||
|
wc := wndClassEx{
|
||||||
|
WndProc: syscall.NewCallback(newsProc),
|
||||||
|
Instance: inst,
|
||||||
|
Cursor: cursor,
|
||||||
|
ClassName: className,
|
||||||
|
}
|
||||||
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
|
newsHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
|
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
||||||
|
uintptr(unsafe.Pointer(className)),
|
||||||
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
|
wsPopup,
|
||||||
|
0, 0, 10, 10,
|
||||||
|
0, 0, inst, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
result = 0 // the flyout is optional; never take the bar down with it
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
switch uint32(m) {
|
||||||
|
case wmEraseBkgnd:
|
||||||
|
return 1
|
||||||
|
case wmMouseActivate:
|
||||||
|
return maNoActivate
|
||||||
|
case wmPaint:
|
||||||
|
flyPaint(hwnd, newsDraw)
|
||||||
|
return 0
|
||||||
|
case wmTimer:
|
||||||
|
newsPoll()
|
||||||
|
return 0
|
||||||
|
case wmSetCursor:
|
||||||
|
if newsHover >= 0 {
|
||||||
|
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
||||||
|
pSetCursor.Call(h)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
case wmLButtonUp:
|
||||||
|
newsClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsToggle is what clicking the newspaper does.
|
||||||
|
func newsToggle() {
|
||||||
|
if !showNews {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if newsShown {
|
||||||
|
newsHide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if newsHwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewHide()
|
||||||
|
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
|
||||||
|
newsHover = -1
|
||||||
|
newsPlace()
|
||||||
|
pSetTimer.Call(newsHwnd, wxPollTimerID, 80, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newsHide() {
|
||||||
|
if !newsShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newsShown = false
|
||||||
|
newsHover = -1
|
||||||
|
pKillTimer.Call(newsHwnd, wxPollTimerID)
|
||||||
|
pShowWindow.Call(newsHwnd, swHide)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newsShutdown() {
|
||||||
|
newsHide()
|
||||||
|
if newsHwnd != 0 {
|
||||||
|
pDestroyWindow.Call(newsHwnd)
|
||||||
|
newsHwnd = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsVisibleRows is how many headlines fit on the screen, up to ten.
|
||||||
|
func newsVisibleRows(n int) int {
|
||||||
|
_, sh := screenSize()
|
||||||
|
avail := sh - px(90) - px(newsHead+newsFoot)
|
||||||
|
m := int(avail / px(newsRow))
|
||||||
|
m = max(3, min(m, newsMaxRows))
|
||||||
|
return min(n, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsPlace sizes the panel for what it has to show and puts it next to the
|
||||||
|
// newspaper: above a horizontal bar, to the left of a vertical one.
|
||||||
|
func newsPlace() {
|
||||||
|
if newsHwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s := newsSnapshot()
|
||||||
|
lh := wxShortH
|
||||||
|
newsVisible = 0
|
||||||
|
if wxZip != "" && len(s.items) > 0 {
|
||||||
|
newsVisible = newsVisibleRows(len(s.items))
|
||||||
|
lh = newsHead + float64(newsVisible)*newsRow + newsFoot
|
||||||
|
}
|
||||||
|
flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh))
|
||||||
|
flyRefresh(newsHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsDone runs when a download finishes.
|
||||||
|
func newsDone() {
|
||||||
|
if newsShown {
|
||||||
|
newsPlace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsPoll closes the panel when a mouse button goes down anywhere outside it
|
||||||
|
// (the newspaper itself is left alone, so clicking it can close the panel) and
|
||||||
|
// keeps track of which headline the mouse is over.
|
||||||
|
func newsPoll() {
|
||||||
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
|
down := (l|r)&0x8000 != 0
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var fr rect
|
||||||
|
pGetWindowRect.Call(newsHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
|
if down && !newsPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(trayNews), cp) {
|
||||||
|
newsHide()
|
||||||
|
newsPrevBtn = down
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newsPrevBtn = down
|
||||||
|
|
||||||
|
h := -1
|
||||||
|
if inRect(fr, cp) {
|
||||||
|
h = newsRowAt(cp.X-fr.Left, cp.Y-fr.Top)
|
||||||
|
}
|
||||||
|
if h != newsHover {
|
||||||
|
newsHover = h
|
||||||
|
flyRefresh(newsHwnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsRowAt is the headline under a spot in the panel (real pixels), or -1.
|
||||||
|
func newsRowAt(x, y int32) int {
|
||||||
|
ry := y - px(newsHead)
|
||||||
|
if ry < 0 || x < 0 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
i := int(ry / px(newsRow))
|
||||||
|
if i >= newsVisible {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
// newsClick runs when the panel is clicked: a headline opens in the browser, the
|
||||||
|
// header refreshes, and the messages in an empty panel are buttons.
|
||||||
|
func newsClick(x, y int32) {
|
||||||
|
s := newsSnapshot()
|
||||||
|
switch {
|
||||||
|
case wxZip == "":
|
||||||
|
newsHide()
|
||||||
|
openSettings()
|
||||||
|
return
|
||||||
|
case len(s.items) == 0:
|
||||||
|
if !s.loading {
|
||||||
|
newsRefresh(true)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case y < px(newsHead):
|
||||||
|
newsRefresh(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if i := newsRowAt(x, y); i >= 0 && i < len(s.items) {
|
||||||
|
link := s.items[i].link
|
||||||
|
newsHide()
|
||||||
|
shellOpen(link, "") // only web links were kept when the feed was read
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- painting ----------
|
||||||
|
|
||||||
|
func newsDraw(hdc uintptr, W, H int32) {
|
||||||
|
u := px
|
||||||
|
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
||||||
|
|
||||||
|
pad := u(14)
|
||||||
|
s := newsSnapshot()
|
||||||
|
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
||||||
|
|
||||||
|
title := "Local news"
|
||||||
|
if s.place != "" && wxZip != "" {
|
||||||
|
title = s.place + " news"
|
||||||
|
}
|
||||||
|
wxText(hdc, title, rect{pad, u(10), W - pad - u(108), u(34)}, fMed, colText, line)
|
||||||
|
status := ""
|
||||||
|
switch {
|
||||||
|
case s.loading:
|
||||||
|
status = "Updating..."
|
||||||
|
case s.ok && s.err != "":
|
||||||
|
status = "Couldn't update"
|
||||||
|
case s.ok:
|
||||||
|
status = "Updated " + s.fetched.Format("3:04 PM")
|
||||||
|
}
|
||||||
|
wxText(hdc, status, rect{W - pad - u(108), u(12), W - pad, u(32)}, fSmall, colDim, dtRight|dtVCenter|dtSingleLine)
|
||||||
|
|
||||||
|
// Nothing to show yet: say why. These messages are clickable.
|
||||||
|
if wxZip == "" || len(s.items) == 0 {
|
||||||
|
var head, sub string
|
||||||
|
switch {
|
||||||
|
case wxZip == "":
|
||||||
|
head, sub = "No ZIP code yet", "Click here to open the settings and type your ZIP code."
|
||||||
|
case s.loading:
|
||||||
|
head, sub = "Getting the headlines...", ""
|
||||||
|
default:
|
||||||
|
head, sub = "No news right now", s.err+" Click here to try again."
|
||||||
|
}
|
||||||
|
wxText(hdc, head, rect{pad, u(48), W - pad, u(74)}, fMed, colText, dtCenter|dtVCenter|dtSingleLine)
|
||||||
|
if sub != "" {
|
||||||
|
wxText(hdc, sub, rect{pad, u(78), W - pad, H - pad}, fText, colDim, dtCenter|dtWordBreak)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fillRaw(hdc, rect{pad, u(newsHead) - u(2), W - pad, u(newsHead) - u(1)}, colRule)
|
||||||
|
now := time.Now()
|
||||||
|
for i := 0; i < newsVisible && i < len(s.items); i++ {
|
||||||
|
it := s.items[i]
|
||||||
|
y := u(newsHead) + int32(i)*u(newsRow)
|
||||||
|
head := colText
|
||||||
|
if i == newsHover {
|
||||||
|
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(newsRow)}, rgb(40, 40, 48))
|
||||||
|
head = colAccent
|
||||||
|
}
|
||||||
|
wxText(hdc, it.title, rect{pad, y + u(6), W - pad, y + u(42)}, fBold, head, dtLeft|dtWordBreak|dtEndEllipsis)
|
||||||
|
meta := it.source
|
||||||
|
if age := newsAge(it.when, now); age != "" {
|
||||||
|
if meta != "" {
|
||||||
|
meta += " · "
|
||||||
|
}
|
||||||
|
meta += age
|
||||||
|
}
|
||||||
|
wxText(hdc, meta, rect{pad, y + u(42), W - pad, y + u(56)}, fSmall, colDim, line)
|
||||||
|
if i < newsVisible-1 && i != newsHover && i+1 != newsHover {
|
||||||
|
fillRaw(hdc, rect{pad, y + u(newsRow) - u(1), W - pad, y + u(newsRow)}, colRule)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- shared by both panels ----------
|
||||||
|
|
||||||
|
// trayAnchor is where an icon on the bar sits on the screen.
|
||||||
|
func trayAnchor(kind int) rect {
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
w, h := clientSize(hwndMain)
|
||||||
|
for _, it := range trayItems(w, h) {
|
||||||
|
if it.kind == kind {
|
||||||
|
r := it.r
|
||||||
|
if vertical {
|
||||||
|
r = mapRect(r, h)
|
||||||
|
}
|
||||||
|
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wr
|
||||||
|
}
|
||||||
|
|
||||||
|
// flyPlace puts a panel of size cw by ch next to an icon: above a horizontal
|
||||||
|
// bar, to the left of a vertical one, and always on the screen.
|
||||||
|
func flyPlace(hwnd uintptr, ar rect, cw, ch int32) {
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
sw, sh := screenSize()
|
||||||
|
space := px(8)
|
||||||
|
var x, y int32
|
||||||
|
if vertical {
|
||||||
|
x = wr.Left - cw - space
|
||||||
|
if x < 0 {
|
||||||
|
x = wr.Right + space
|
||||||
|
}
|
||||||
|
y = (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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x = clampI(x, 0, sw-cw)
|
||||||
|
y = clampI(y, 0, sh-ch)
|
||||||
|
pSetWindowPos.Call(hwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
||||||
|
}
|
||||||
@@ -257,8 +257,12 @@ func refreshApps(refreshIcons bool) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
present0 := make(map[uintptr]appWin, len(present))
|
||||||
|
for h, w := range present {
|
||||||
|
present0[h] = w
|
||||||
|
}
|
||||||
var next []appWin
|
var next []appWin
|
||||||
for _, a := range apps {
|
for _, a := range allApps {
|
||||||
if a.hwnd == 0 {
|
if a.hwnd == 0 {
|
||||||
next = append(next, a) // a waiting launcher; sorted out below
|
next = append(next, a) // a waiting launcher; sorted out below
|
||||||
continue
|
continue
|
||||||
@@ -321,13 +325,17 @@ func refreshApps(refreshIcons bool) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noteForeground(present0)
|
||||||
|
allApps = next
|
||||||
|
grouped := groupApps(next)
|
||||||
|
|
||||||
// Titles change constantly (browser tabs, documents) but nothing on the
|
// Titles change constantly (browser tabs, documents) but nothing on the
|
||||||
// bar shows them, so only a change in which buttons exist, or their icons,
|
// bar shows them, so only a change in which buttons exist, their icons, or
|
||||||
// counts as a change.
|
// how many windows an icon stands for counts as a change.
|
||||||
changed := len(next) != len(apps)
|
changed := len(grouped) != len(apps)
|
||||||
if !changed {
|
if !changed {
|
||||||
for i := range next {
|
for i := range grouped {
|
||||||
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
if grouped[i].hwnd != apps[i].hwnd || grouped[i].icon != apps[i].icon || grouped[i].count != apps[i].count {
|
||||||
changed = true
|
changed = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -336,7 +344,7 @@ func refreshApps(refreshIcons bool) bool {
|
|||||||
if changed {
|
if changed {
|
||||||
styleCacheClear() // icon handles can be reused by other icons
|
styleCacheClear() // icon handles can be reused by other icons
|
||||||
}
|
}
|
||||||
apps = next
|
apps = grouped
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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>`
|
||||||
@@ -330,4 +330,5 @@ func moveSeq(from, to int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
apps = next
|
apps = next
|
||||||
|
syncAllFromGrouped()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -175,6 +175,7 @@ func previewShow(idx int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
a := apps[idx]
|
a := apps[idx]
|
||||||
|
a.hwnd = memberHwnd(a)
|
||||||
previewDropThumb()
|
previewDropThumb()
|
||||||
|
|
||||||
iconic, _, _ := pIsIconic.Call(a.hwnd)
|
iconic, _, _ := pIsIconic.Call(a.hwnd)
|
||||||
@@ -297,7 +298,7 @@ func previewTick() {
|
|||||||
}
|
}
|
||||||
idx = appIndexAt(hwndMain, x)
|
idx = appIndexAt(hwndMain, x)
|
||||||
if idx >= 0 && idx < len(apps) {
|
if idx >= 0 && idx < len(apps) {
|
||||||
raw = apps[idx].hwnd
|
raw = memberHwnd(apps[idx])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target := raw
|
target := raw
|
||||||
|
|||||||
@@ -0,0 +1,277 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Radar for the weather flyout: a small map centered on the ZIP code with the
|
||||||
|
// last hour or so of rain radar over it, played as a loop.
|
||||||
|
//
|
||||||
|
// Radar pictures come from RainViewer (rainviewer.com, free, no account): a list
|
||||||
|
// of the latest frames, then one picture tile per frame. The map under them is
|
||||||
|
// Esri's dark gray map (gray base plus a layer of place names). Both are lists
|
||||||
|
// of square tiles on the same world grid, so a window around the ZIP code is
|
||||||
|
// cut out of the tiles and each radar frame is laid over the map.
|
||||||
|
//
|
||||||
|
// Nothing here runs until the panel is opened, and it all happens on a
|
||||||
|
// background goroutine; the finished frames are plain pixel arrays that the
|
||||||
|
// panel draws straight to the screen.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
_ "image/jpeg"
|
||||||
|
_ "image/png"
|
||||||
|
"math"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
radarW = 520 // pixels in a finished frame; 520 by 250 matches the panel's 312 by 150 picture
|
||||||
|
radarH = 250
|
||||||
|
radarFrames = 8 // the newest eight frames, 10 minutes apart
|
||||||
|
radarFresh = 5 * time.Minute
|
||||||
|
|
||||||
|
// One world pixel grid serves everything: 65536 pixels around the globe. That is
|
||||||
|
// RainViewer's 512 pixel tiles at zoom 7 and Esri's 256 pixel tiles at zoom 8.
|
||||||
|
radarWorld = 65536.0
|
||||||
|
radarTileRV = 512
|
||||||
|
radarZoomRV = 7
|
||||||
|
radarTileMap = 256
|
||||||
|
radarZoomMap = 8
|
||||||
|
)
|
||||||
|
|
||||||
|
type radarState struct {
|
||||||
|
key string // the place these frames are for
|
||||||
|
frames [][]byte
|
||||||
|
times []time.Time
|
||||||
|
loading bool
|
||||||
|
err string
|
||||||
|
fetched time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
rdMu sync.Mutex
|
||||||
|
rd radarState
|
||||||
|
rdGen int
|
||||||
|
rdIdx int // which frame is on screen; touched only by the panel's own thread
|
||||||
|
)
|
||||||
|
|
||||||
|
func radarSnapshot() radarState {
|
||||||
|
rdMu.Lock()
|
||||||
|
defer rdMu.Unlock()
|
||||||
|
return rd
|
||||||
|
}
|
||||||
|
|
||||||
|
// radarEnsure starts a radar download if there is none for this place yet, or
|
||||||
|
// the one we have is old. Called when the panel opens and when a forecast lands.
|
||||||
|
func radarEnsure(force bool) {
|
||||||
|
s := wxSnapshot()
|
||||||
|
if !s.ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
key := fmt.Sprintf("%.3f,%.3f", s.lat, s.lon)
|
||||||
|
rdMu.Lock()
|
||||||
|
same := rd.key == key
|
||||||
|
switch {
|
||||||
|
case same && rd.loading && !force:
|
||||||
|
rdMu.Unlock()
|
||||||
|
return
|
||||||
|
case same && len(rd.frames) > 0 && time.Since(rd.fetched) < radarFresh && !force:
|
||||||
|
rdMu.Unlock()
|
||||||
|
return
|
||||||
|
case same && rd.err != "" && len(rd.frames) == 0 && time.Since(rd.fetched) < time.Minute && !force:
|
||||||
|
rdMu.Unlock() // it just failed; don't hammer the service
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !same {
|
||||||
|
rd = radarState{key: key}
|
||||||
|
}
|
||||||
|
rd.loading = true
|
||||||
|
rd.err = ""
|
||||||
|
rdGen++
|
||||||
|
gen := rdGen
|
||||||
|
rdMu.Unlock()
|
||||||
|
go radarFetch(key, s.lat, s.lon, gen)
|
||||||
|
}
|
||||||
|
|
||||||
|
func radarFinish(gen int, key string, frames [][]byte, times []time.Time, errText string) {
|
||||||
|
rdMu.Lock()
|
||||||
|
if gen != rdGen || rd.key != key {
|
||||||
|
rdMu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rd.loading = false
|
||||||
|
rd.fetched = time.Now()
|
||||||
|
if frames != nil {
|
||||||
|
rd.frames, rd.times, rd.err = frames, times, ""
|
||||||
|
} else {
|
||||||
|
rd.err = errText
|
||||||
|
}
|
||||||
|
rdMu.Unlock()
|
||||||
|
weatherNotify()
|
||||||
|
}
|
||||||
|
|
||||||
|
// worldPixel is where a place falls on the 65536 pixel world grid (Web Mercator).
|
||||||
|
func worldPixel(lat, lon float64) (x, y float64) {
|
||||||
|
x = (lon + 180) / 360 * radarWorld
|
||||||
|
r := lat * math.Pi / 180
|
||||||
|
y = (1 - math.Log(math.Tan(r)+1/math.Cos(r))/math.Pi) / 2 * radarWorld
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type tileJob struct {
|
||||||
|
url string
|
||||||
|
img image.Image
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchTiles downloads a set of tile pictures, a few at a time.
|
||||||
|
func fetchTiles(jobs []*tileJob) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
sem := make(chan struct{}, 6)
|
||||||
|
for _, j := range jobs {
|
||||||
|
wg.Add(1)
|
||||||
|
sem <- struct{}{}
|
||||||
|
go func(j *tileJob) {
|
||||||
|
defer wg.Done()
|
||||||
|
defer func() { <-sem }()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
j.err = fmt.Errorf("tile failed")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
b, err := wxGetBytes(j.url)
|
||||||
|
if err != nil {
|
||||||
|
j.err = err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
j.img, _, j.err = image.Decode(bytes.NewReader(b))
|
||||||
|
}(j)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func radarFetch(key string, lat, lon float64, gen int) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
radarFinish(gen, key, nil, nil, "The radar lookup failed.")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 1. The list of radar frames.
|
||||||
|
var idx struct {
|
||||||
|
Host string `json:"host"`
|
||||||
|
Radar struct {
|
||||||
|
Past []struct {
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
} `json:"past"`
|
||||||
|
} `json:"radar"`
|
||||||
|
}
|
||||||
|
if _, err := wxGetJSON("https://api.rainviewer.com/public/weather-maps.json", &idx); err != nil || idx.Host == "" || len(idx.Radar.Past) == 0 {
|
||||||
|
radarFinish(gen, key, nil, nil, "Radar isn't available right now.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
past := idx.Radar.Past
|
||||||
|
if len(past) > radarFrames {
|
||||||
|
past = past[len(past)-radarFrames:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Which tiles cover a window centered on the place.
|
||||||
|
cx, cy := worldPixel(lat, lon)
|
||||||
|
x0 := int(math.Floor(cx - radarW/2))
|
||||||
|
y0 := int(math.Floor(cy - radarH/2))
|
||||||
|
span := func(a, b int, size int) (lo, hi int) {
|
||||||
|
lo = int(math.Floor(float64(a) / float64(size)))
|
||||||
|
hi = int(math.Floor(float64(b) / float64(size)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. The map: gray base plus place names, from tiles 256 pixels wide at zoom 8.
|
||||||
|
base := image.NewRGBA(image.Rect(0, 0, radarW, radarH))
|
||||||
|
draw.Draw(base, base.Bounds(), image.NewUniform(color.RGBA{34, 34, 38, 255}), image.Point{}, draw.Src)
|
||||||
|
mx0, mx1 := span(x0, x0+radarW-1, radarTileMap)
|
||||||
|
my0, my1 := span(y0, y0+radarH-1, radarTileMap)
|
||||||
|
type placed struct {
|
||||||
|
job *tileJob
|
||||||
|
ox, oy int
|
||||||
|
}
|
||||||
|
var mapTiles []placed
|
||||||
|
var jobs []*tileJob
|
||||||
|
for _, layer := range []string{"World_Dark_Gray_Base", "World_Dark_Gray_Reference"} {
|
||||||
|
for ty := my0; ty <= my1; ty++ {
|
||||||
|
for tx := mx0; tx <= mx1; tx++ {
|
||||||
|
j := &tileJob{url: fmt.Sprintf("https://server.arcgisonline.com/ArcGIS/rest/services/Canvas/%s/MapServer/tile/%d/%d/%d",
|
||||||
|
layer, radarZoomMap, ty, tx)}
|
||||||
|
mapTiles = append(mapTiles, placed{j, tx*radarTileMap - x0, ty*radarTileMap - y0})
|
||||||
|
jobs = append(jobs, j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Every radar frame's tiles, 512 pixels wide at zoom 7.
|
||||||
|
rx0, rx1 := span(x0, x0+radarW-1, radarTileRV)
|
||||||
|
ry0, ry1 := span(y0, y0+radarH-1, radarTileRV)
|
||||||
|
type frameTiles struct {
|
||||||
|
t time.Time
|
||||||
|
tiles []placed
|
||||||
|
}
|
||||||
|
frames := make([]frameTiles, len(past))
|
||||||
|
for i, p := range past {
|
||||||
|
frames[i].t = time.Unix(p.Time, 0)
|
||||||
|
for ty := ry0; ty <= ry1; ty++ {
|
||||||
|
for tx := rx0; tx <= rx1; tx++ {
|
||||||
|
j := &tileJob{url: fmt.Sprintf("%s%s/%d/%d/%d/%d/2/1_1.png", idx.Host, p.Path, radarTileRV, radarZoomRV, tx, ty)}
|
||||||
|
frames[i].tiles = append(frames[i].tiles, placed{j, tx*radarTileRV - x0, ty*radarTileRV - y0})
|
||||||
|
jobs = append(jobs, j)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchTiles(jobs)
|
||||||
|
|
||||||
|
// The map must have come through; a missing radar frame is just skipped.
|
||||||
|
for _, m := range mapTiles {
|
||||||
|
if m.job.err != nil || m.job.img == nil {
|
||||||
|
radarFinish(gen, key, nil, nil, "The map for radar didn't load.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b := m.job.img.Bounds()
|
||||||
|
draw.Draw(base, image.Rect(m.ox, m.oy, m.ox+b.Dx(), m.oy+b.Dy()), m.job.img, b.Min, draw.Over)
|
||||||
|
}
|
||||||
|
|
||||||
|
alpha := &image.Uniform{color.Alpha{A: 215}}
|
||||||
|
var out [][]byte
|
||||||
|
var times []time.Time
|
||||||
|
for _, f := range frames {
|
||||||
|
layer := image.NewRGBA(base.Bounds())
|
||||||
|
good := true
|
||||||
|
for _, t := range f.tiles {
|
||||||
|
if t.job.err != nil || t.job.img == nil {
|
||||||
|
good = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
b := t.job.img.Bounds()
|
||||||
|
draw.Draw(layer, image.Rect(t.ox, t.oy, t.ox+b.Dx(), t.oy+b.Dy()), t.job.img, b.Min, draw.Over)
|
||||||
|
}
|
||||||
|
if !good {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
comp := image.NewRGBA(base.Bounds())
|
||||||
|
copy(comp.Pix, base.Pix)
|
||||||
|
draw.DrawMask(comp, comp.Bounds(), layer, image.Point{}, alpha, image.Point{}, draw.Over)
|
||||||
|
|
||||||
|
// Windows wants blue, green, red order.
|
||||||
|
bgra := make([]byte, len(comp.Pix))
|
||||||
|
for i := 0; i+3 < len(comp.Pix); i += 4 {
|
||||||
|
bgra[i], bgra[i+1], bgra[i+2], bgra[i+3] = comp.Pix[i+2], comp.Pix[i+1], comp.Pix[i], 255
|
||||||
|
}
|
||||||
|
out = append(out, bgra)
|
||||||
|
times = append(times, f.t)
|
||||||
|
}
|
||||||
|
if len(out) == 0 {
|
||||||
|
radarFinish(gen, key, nil, nil, "Radar isn't available right now.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
radarFinish(gen, key, out, times, "")
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Drawing the radar picture inside the weather panel, and stepping the loop.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pStretchDIBits = gdi32.NewProc("StretchDIBits")
|
||||||
|
pSetViewportOrgEx = gdi32.NewProc("SetViewportOrgEx")
|
||||||
|
)
|
||||||
|
|
||||||
|
// wxRadarFits reports whether the panel with its radar picture fits on the
|
||||||
|
// screen, with some room left for the bar. On a small or heavily scaled screen
|
||||||
|
// the radar is left out and the rest of the panel stays as it was.
|
||||||
|
func wxRadarFits() bool {
|
||||||
|
_, sh := screenSize()
|
||||||
|
return px(wxFullH+wxRadarH) <= sh-px(90)
|
||||||
|
}
|
||||||
|
|
||||||
|
// radarAdvance moves the loop to its next frame. The newest frame is held for a
|
||||||
|
// few beats before it starts over.
|
||||||
|
func radarAdvance() {
|
||||||
|
if !wxShown || !wxRadarFits() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rs := radarSnapshot()
|
||||||
|
n := len(rs.frames)
|
||||||
|
if n < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rdIdx %= n
|
||||||
|
if rdIdx == n-1 && rdHold < 3 {
|
||||||
|
rdHold++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rdHold = 0
|
||||||
|
rdIdx = (rdIdx + 1) % n
|
||||||
|
flyRefresh(wxHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func radarBox(hdc uintptr, r rect) {
|
||||||
|
t := px(1)
|
||||||
|
fillRaw(hdc, rect{r.Left, r.Top, r.Right, r.Top + t}, colRule)
|
||||||
|
fillRaw(hdc, rect{r.Left, r.Bottom - t, r.Right, r.Bottom}, colRule)
|
||||||
|
fillRaw(hdc, rect{r.Left, r.Top, r.Left + t, r.Bottom}, colRule)
|
||||||
|
fillRaw(hdc, rect{r.Right - t, r.Top, r.Right, r.Bottom}, colRule)
|
||||||
|
}
|
||||||
|
|
||||||
|
// radarDraw paints the radar picture (or a short message while there isn't one)
|
||||||
|
// into the rectangle r. The panel is painted at double size, so px() here is
|
||||||
|
// already the double size distance.
|
||||||
|
func radarDraw(hdc uintptr, r rect) {
|
||||||
|
rs := radarSnapshot()
|
||||||
|
w, h := r.Right-r.Left, r.Bottom-r.Top
|
||||||
|
|
||||||
|
if len(rs.frames) == 0 {
|
||||||
|
fillRaw(hdc, r, rgb(22, 22, 27))
|
||||||
|
msg := "Loading radar..."
|
||||||
|
if rs.err != "" {
|
||||||
|
msg = rs.err
|
||||||
|
}
|
||||||
|
wxText(hdc, msg, r, fText, colDim, dtCenter|dtVCenter|dtSingleLine)
|
||||||
|
radarBox(hdc, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
i := rdIdx % len(rs.frames)
|
||||||
|
bmi := bitmapInfoHeader{Width: radarW, Height: -radarH, Planes: 1, BitCount: 32}
|
||||||
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
|
pSetStretchBltMode.Call(hdc, halftone)
|
||||||
|
pSetBrushOrgEx.Call(hdc, 0, 0, 0)
|
||||||
|
pStretchDIBits.Call(hdc,
|
||||||
|
uintptr(r.Left), uintptr(r.Top), uintptr(w), uintptr(h),
|
||||||
|
0, 0, radarW, radarH,
|
||||||
|
uintptr(unsafe.Pointer(&rs.frames[i][0])), uintptr(unsafe.Pointer(&bmi)), 0, srcCopy)
|
||||||
|
|
||||||
|
// You are here.
|
||||||
|
cx, cy := center(r)
|
||||||
|
circleRaw(hdc, cx, cy, px(5), rgb(245, 245, 245))
|
||||||
|
circleRaw(hdc, cx, cy, px(3), rgb(235, 70, 70))
|
||||||
|
|
||||||
|
// When this frame is from.
|
||||||
|
back := rgb(22, 22, 27)
|
||||||
|
label := "Radar"
|
||||||
|
if i < len(rs.times) {
|
||||||
|
label += " " + rs.times[i].Format("3:04 PM")
|
||||||
|
}
|
||||||
|
fillRaw(hdc, rect{r.Left, r.Top, r.Left + px(104), r.Top + px(19)}, back)
|
||||||
|
wxText(hdc, label, rect{r.Left + px(6), r.Top, r.Left + px(104), r.Top + px(19)}, fSmall, colText, dtLeft|dtVCenter|dtSingleLine)
|
||||||
|
|
||||||
|
// Where the pictures come from.
|
||||||
|
fillRaw(hdc, rect{r.Right - px(92), r.Bottom - px(14), r.Right, r.Bottom}, back)
|
||||||
|
wxText(hdc, "RainViewer, Esri", rect{r.Right - px(92), r.Bottom - px(14), r.Right - px(4), r.Bottom}, fTiny, colDim, dtRight|dtVCenter|dtSingleLine)
|
||||||
|
|
||||||
|
radarBox(hdc, r)
|
||||||
|
}
|
||||||
@@ -22,9 +22,9 @@ const (
|
|||||||
superSample = 2
|
superSample = 2
|
||||||
mfPopup = 0x0010
|
mfPopup = 0x0010
|
||||||
|
|
||||||
menuLogoColorBase = 100
|
menuLogoColorBase = 300 // 40 apart so the color menus can grow past 20 colors
|
||||||
menuClockColorBase = 120
|
menuClockColorBase = 340
|
||||||
menuIconColorBase = 140
|
menuIconColorBase = 380
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -58,6 +58,20 @@ var palette = []namedColor{
|
|||||||
{"Pink", 255, 125, 195},
|
{"Pink", 255, 125, 195},
|
||||||
{"Purple", 175, 115, 240},
|
{"Purple", 175, 115, 240},
|
||||||
{"Black", 0, 0, 0},
|
{"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 (
|
var (
|
||||||
@@ -215,6 +229,9 @@ func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fg {
|
if fg {
|
||||||
|
if logoStyle != 0 {
|
||||||
|
drawLogoStyle(memV, mapRect(sr, h))
|
||||||
|
}
|
||||||
for i, r := range appRects(w, h) {
|
for i, r := range appRects(w, h) {
|
||||||
if i < len(apps) {
|
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])
|
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||||
@@ -233,6 +250,20 @@ func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uin
|
|||||||
drawChevron(memV, r)
|
drawChevron(memV, r)
|
||||||
case trayWeather:
|
case trayWeather:
|
||||||
drawWeatherIcon(memV, r)
|
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()
|
pGdiFlush.Call()
|
||||||
@@ -318,6 +349,8 @@ func redraw(hwnd uintptr) {
|
|||||||
|
|
||||||
a := uint32(bgAlpha)
|
a := uint32(bgAlpha)
|
||||||
hoverA := max(a, 120)
|
hoverA := max(a, 120)
|
||||||
|
barC := barRGB()
|
||||||
|
lightBar := barIsLight()
|
||||||
length := float64(max(fw, fh))
|
length := float64(max(fw, fh))
|
||||||
rad := float64(min(fw, fh)) / 2
|
rad := float64(min(fw, fh)) / 2
|
||||||
stride := int(fw) * superSample
|
stride := int(fw) * superSample
|
||||||
@@ -330,6 +363,9 @@ func redraw(hwnd uintptr) {
|
|||||||
bgA := a
|
bgA := a
|
||||||
if c != colBg {
|
if c != colBg {
|
||||||
bgA = hoverA
|
bgA = hoverA
|
||||||
|
c = hoverTint(c, lightBar)
|
||||||
|
} else {
|
||||||
|
c = barC
|
||||||
}
|
}
|
||||||
bgR := (c >> 16 & 0xFF) * bgA / 255
|
bgR := (c >> 16 & 0xFF) * bgA / 255
|
||||||
bgG := (c >> 8 & 0xFF) * bgA / 255
|
bgG := (c >> 8 & 0xFF) * bgA / 255
|
||||||
|
|||||||
+170
-21
@@ -55,19 +55,40 @@ const (
|
|||||||
tbEndTrack = 8
|
tbEndTrack = 8
|
||||||
colorBtnFace = 15
|
colorBtnFace = 15
|
||||||
|
|
||||||
idAlpha = 200
|
idAlpha = 200
|
||||||
idAlphaValue = 201
|
idAlphaValue = 201
|
||||||
idLogo = 202
|
idLogo = 202
|
||||||
idClock = 203
|
idClock = 203
|
||||||
idTrayIcons = 204
|
idTrayIcons = 204
|
||||||
idStyle = 205
|
idStyle = 205
|
||||||
idVertical = 206
|
idVertical = 206
|
||||||
idAutostart = 207
|
idAutostart = 207
|
||||||
idResetPos = 208
|
idResetPos = 208
|
||||||
idResetWidth = 209
|
idResetWidth = 209
|
||||||
idClose = 210
|
idClose = 210
|
||||||
idZip = 211
|
idZip = 211
|
||||||
idZipStatus = 212
|
idZipStatus = 212
|
||||||
|
idShowWeather = 213
|
||||||
|
idShowNews = 214
|
||||||
|
idShowSys = 215
|
||||||
|
idPanelFade = 216
|
||||||
|
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 (
|
var (
|
||||||
@@ -78,6 +99,12 @@ var (
|
|||||||
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
||||||
ctlVertical, ctlAutostart uintptr
|
ctlVertical, ctlAutostart uintptr
|
||||||
ctlZip, ctlZipStatus uintptr
|
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
|
zipSyncing bool // true while the program itself is filling in the ZIP box
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,7 +156,7 @@ func openSettings() {
|
|||||||
settingsFont = makeFont(px(13), 400)
|
settingsFont = makeFont(px(13), 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := rect{0, 0, px(400), px(376)}
|
r := rect{0, 0, px(800), px(572)}
|
||||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||||
sw, sh := screenSize()
|
sw, sh := screenSize()
|
||||||
@@ -171,17 +198,71 @@ func openSettings() {
|
|||||||
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||||
}
|
}
|
||||||
|
|
||||||
label("Weather ZIP code", 204)
|
label("ZIP code", 204)
|
||||||
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
|
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
|
||||||
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
|
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
|
||||||
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
|
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
|
||||||
|
|
||||||
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idVertical)
|
ctlShowWeather = makeControl(hw, inst, "BUTTON", "Show weather on the bar", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idShowWeather)
|
||||||
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 290, 368, 22, idAutostart)
|
ctlShowNews = makeControl(hw, inst, "BUTTON", "Show local news on the bar", bsAutoCheckBox|wsTabStop, 16, 290, 368, 22, idShowNews)
|
||||||
|
ctlShowSys = makeControl(hw, inst, "BUTTON", "Show system stats on the bar", bsAutoCheckBox|wsTabStop, 16, 318, 368, 22, idShowSys)
|
||||||
|
ctlShowGM = makeControl(hw, inst, "BUTTON", "Show Google Messages on the bar", bsAutoCheckBox|wsTabStop, 16, 346, 368, 22, idShowGM)
|
||||||
|
ctlPanelFade = makeControl(hw, inst, "BUTTON", "Panels match the bar's transparency", bsAutoCheckBox|wsTabStop, 16, 374, 368, 22, idPanelFade)
|
||||||
|
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 402, 368, 22, idVertical)
|
||||||
|
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 430, 368, 22, idAutostart)
|
||||||
|
|
||||||
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 330, 116, 28, idResetPos)
|
ctlGroup = makeControl(hw, inst, "BUTTON", "Combine windows of the same program into one icon", bsAutoCheckBox|wsTabStop, 16, 458, 368, 22, idGroup)
|
||||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 330, 116, 28, idResetWidth)
|
ctlAutoHide = makeControl(hw, inst, "BUTTON", "Hide the bar until the mouse touches the screen edge", bsAutoCheckBox|wsTabStop, 16, 486, 368, 22, idAutoHide)
|
||||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 330, 92, 28, idClose)
|
|
||||||
|
// 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)
|
||||||
|
|
||||||
hwndSettings = hw
|
hwndSettings = hw
|
||||||
settingsSync()
|
settingsSync()
|
||||||
@@ -200,8 +281,28 @@ func settingsSync() {
|
|||||||
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
||||||
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 0)
|
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 0)
|
||||||
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
|
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
|
||||||
|
pSendMessage.Call(ctlShowWeather, bmSetCheck, boolWP(showWeather), 0)
|
||||||
|
pSendMessage.Call(ctlShowNews, bmSetCheck, boolWP(showNews), 0)
|
||||||
|
pSendMessage.Call(ctlShowSys, bmSetCheck, boolWP(showSys), 0)
|
||||||
|
pSendMessage.Call(ctlShowGM, bmSetCheck, boolWP(showGM), 0)
|
||||||
|
pSendMessage.Call(ctlPanelFade, bmSetCheck, boolWP(flyMatchBar), 0)
|
||||||
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
|
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
|
||||||
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
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.
|
// Leave the ZIP box alone while the person is typing in it.
|
||||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||||
@@ -224,7 +325,7 @@ func settingsZipStatusUpdate() {
|
|||||||
if hwndSettings == 0 || ctlZipStatus == 0 {
|
if hwndSettings == 0 || ctlZipStatus == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(weatherStatusText()))))
|
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(zipStatusText()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
||||||
@@ -279,6 +380,7 @@ func settingsCommand(id, note uintptr) {
|
|||||||
}
|
}
|
||||||
saveColors()
|
saveColors()
|
||||||
redraw(hwndMain)
|
redraw(hwndMain)
|
||||||
|
flyRefreshAll()
|
||||||
case idStyle:
|
case idStyle:
|
||||||
if note != cbnSelChange {
|
if note != cbnSelChange {
|
||||||
return
|
return
|
||||||
@@ -293,10 +395,56 @@ func settingsCommand(id, note uintptr) {
|
|||||||
if note == enChange && !zipSyncing {
|
if note == enChange && !zipSyncing {
|
||||||
zipEdited()
|
zipEdited()
|
||||||
}
|
}
|
||||||
|
case idShowWeather:
|
||||||
|
setShowWeather(checked(ctlShowWeather))
|
||||||
|
case idShowNews:
|
||||||
|
setShowNews(checked(ctlShowNews))
|
||||||
|
case idShowSys:
|
||||||
|
setShowSys(checked(ctlShowSys))
|
||||||
|
case idShowGM:
|
||||||
|
setShowGM(checked(ctlShowGM))
|
||||||
|
case idPanelFade:
|
||||||
|
setFlyMatchBar(checked(ctlPanelFade))
|
||||||
case idVertical:
|
case idVertical:
|
||||||
vertical = checked(ctlVertical)
|
vertical = checked(ctlVertical)
|
||||||
saveOrient()
|
saveOrient()
|
||||||
resetPos(hwndMain)
|
resetPos(hwndMain)
|
||||||
|
case idGroup:
|
||||||
|
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:
|
case idAutostart:
|
||||||
setAutostart(checked(ctlAutostart))
|
setAutostart(checked(ctlAutostart))
|
||||||
settingsSync()
|
settingsSync()
|
||||||
@@ -327,6 +475,7 @@ func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
bgAlpha = n
|
bgAlpha = n
|
||||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||||
redraw(hwndMain)
|
redraw(hwndMain)
|
||||||
|
flyRefreshAll()
|
||||||
}
|
}
|
||||||
if wparam&0xFFFF == tbEndTrack {
|
if wparam&0xFFFF == tbEndTrack {
|
||||||
saveAlpha()
|
saveAlpha()
|
||||||
|
|||||||
+272
@@ -0,0 +1,272 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// The system stats flyout: a little monitor on the bar that opens a panel with
|
||||||
|
// the sort of thing neofetch prints (OS, CPU, memory, disks, uptime...). Click a
|
||||||
|
// line to copy it, or click the header to copy everything as plain text that can
|
||||||
|
// be pasted into any other program.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
sysW = 420.0
|
||||||
|
sysHead = 44.0
|
||||||
|
sysRow_ = 24.0
|
||||||
|
sysFoot = 26.0
|
||||||
|
|
||||||
|
sysRefreshTimerID = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sysHwnd uintptr
|
||||||
|
sysShown bool
|
||||||
|
sysPrevBtn bool
|
||||||
|
sysHover = -1
|
||||||
|
sysRows []sysRow
|
||||||
|
sysCopied string // what the header says after a copy: "Copied" or "Copy failed"
|
||||||
|
sysCopiedAt time.Time
|
||||||
|
sysTick int
|
||||||
|
)
|
||||||
|
|
||||||
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
|
func drawSysIcon(hdc uintptr, r rect) {
|
||||||
|
if !layerFg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
col := iconColor()
|
||||||
|
cx, cy := center(r)
|
||||||
|
e := px(1)
|
||||||
|
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(2.5)
|
||||||
|
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)
|
||||||
|
fillRaw(hdc, rect{cx - px(1), b, cx + px(1), cy + px(4.5)}, col) // stand
|
||||||
|
fillRaw(hdc, rect{cx - px(3), cy + px(4.5), cx + px(3), cy + px(5.5)}, col)
|
||||||
|
fillRaw(hdc, rect{cx - px(3.5), cy - px(0.5), cx - px(2), cy + px(1.5)}, col) // little bars on the screen
|
||||||
|
fillRaw(hdc, rect{cx - px(1), cy - px(2.5), cx + px(0.5), cy + px(1.5)}, col)
|
||||||
|
fillRaw(hdc, rect{cx + px(2), cy - px(1.5), cx + px(3.5), cy + px(1.5)}, col)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the panel window ----------
|
||||||
|
|
||||||
|
func sysInit(inst uintptr) {
|
||||||
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
|
className := u16("MirrorBarSys")
|
||||||
|
wc := wndClassEx{
|
||||||
|
WndProc: syscall.NewCallback(sysProc),
|
||||||
|
Instance: inst,
|
||||||
|
Cursor: cursor,
|
||||||
|
ClassName: className,
|
||||||
|
}
|
||||||
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
|
sysHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
|
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
||||||
|
uintptr(unsafe.Pointer(className)),
|
||||||
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
|
wsPopup,
|
||||||
|
0, 0, 10, 10,
|
||||||
|
0, 0, inst, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
result = 0 // the flyout is optional; never take the bar down with it
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
switch uint32(m) {
|
||||||
|
case wmEraseBkgnd:
|
||||||
|
return 1
|
||||||
|
case wmMouseActivate:
|
||||||
|
return maNoActivate
|
||||||
|
case wmPaint:
|
||||||
|
flyPaint(hwnd, sysDraw)
|
||||||
|
return 0
|
||||||
|
case wmTimer:
|
||||||
|
if wparam == sysRefreshTimerID {
|
||||||
|
sysRows = sysGather() // uptime and memory move
|
||||||
|
flyRefresh(sysHwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
sysPoll()
|
||||||
|
return 0
|
||||||
|
case wmSetCursor:
|
||||||
|
if sysOverButton() {
|
||||||
|
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
||||||
|
pSetCursor.Call(h)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
case wmLButtonUp:
|
||||||
|
sysClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// sysOverButton is true when the mouse is on something clickable: a line or the header.
|
||||||
|
func sysOverButton() bool {
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var fr rect
|
||||||
|
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
|
if !inRect(fr, cp) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
y := cp.Y - fr.Top
|
||||||
|
return y < px(sysHead) || sysRowAt(y) >= 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysToggle() {
|
||||||
|
if !showSys {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sysShown {
|
||||||
|
sysHide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sysHwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewHide()
|
||||||
|
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
|
||||||
|
sysHover = -1
|
||||||
|
sysCopied = ""
|
||||||
|
sysPlace()
|
||||||
|
pSetTimer.Call(sysHwnd, wxPollTimerID, 80, 0)
|
||||||
|
pSetTimer.Call(sysHwnd, sysRefreshTimerID, 1500, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysHide() {
|
||||||
|
if !sysShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sysShown = false
|
||||||
|
sysHover = -1
|
||||||
|
pKillTimer.Call(sysHwnd, wxPollTimerID)
|
||||||
|
pKillTimer.Call(sysHwnd, sysRefreshTimerID)
|
||||||
|
pShowWindow.Call(sysHwnd, swHide)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysShutdown() {
|
||||||
|
sysHide()
|
||||||
|
if sysHwnd != 0 {
|
||||||
|
pDestroyWindow.Call(sysHwnd)
|
||||||
|
sysHwnd = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysPlace() {
|
||||||
|
if sysHwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot
|
||||||
|
flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh))
|
||||||
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sysRowAt is the line under a height in the panel (real pixels), or -1.
|
||||||
|
func sysRowAt(y int32) int {
|
||||||
|
ry := y - px(sysHead)
|
||||||
|
if ry < 0 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
i := int(ry / px(sysRow_))
|
||||||
|
if i >= len(sysRows) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysPoll() {
|
||||||
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
|
down := (l|r)&0x8000 != 0
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var fr rect
|
||||||
|
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
|
if down && !sysPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(traySys), cp) {
|
||||||
|
sysHide()
|
||||||
|
sysPrevBtn = down
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sysPrevBtn = down
|
||||||
|
|
||||||
|
h := -1
|
||||||
|
if inRect(fr, cp) {
|
||||||
|
h = sysRowAt(cp.Y - fr.Top)
|
||||||
|
}
|
||||||
|
changed := h != sysHover
|
||||||
|
sysHover = h
|
||||||
|
if sysCopied != "" && time.Since(sysCopiedAt) > 1500*time.Millisecond {
|
||||||
|
sysCopied = ""
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
if changed {
|
||||||
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysCopy(text, what string) {
|
||||||
|
if clipboardSet(text) {
|
||||||
|
sysCopied = what
|
||||||
|
} else {
|
||||||
|
sysCopied = "Copy failed"
|
||||||
|
}
|
||||||
|
sysCopiedAt = time.Now()
|
||||||
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysClick(x, y int32) {
|
||||||
|
if y < px(sysHead) {
|
||||||
|
sysCopy(sysText(sysRows), "Copied everything")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if i := sysRowAt(y); i >= 0 {
|
||||||
|
sysCopy(sysRows[i].label+": "+sysRows[i].value, "Copied "+sysRows[i].label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- painting ----------
|
||||||
|
|
||||||
|
func sysDraw(hdc uintptr, W, H int32) {
|
||||||
|
u := px
|
||||||
|
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
||||||
|
|
||||||
|
pad := u(14)
|
||||||
|
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
||||||
|
wxText(hdc, sysUserHost(), rect{pad, u(10), W - pad - u(150), u(34)}, fMed, colText, line)
|
||||||
|
btn, col := "Copy all", colAccent
|
||||||
|
if sysCopied != "" {
|
||||||
|
btn, col = sysCopied, colDim
|
||||||
|
}
|
||||||
|
wxText(hdc, btn, rect{W - pad - u(150), u(12), W - pad, u(32)}, fBold, col, dtRight|dtVCenter|dtSingleLine|dtEndEllipsis)
|
||||||
|
fillRaw(hdc, rect{pad, u(sysHead) - u(2), W - pad, u(sysHead) - u(1)}, colRule)
|
||||||
|
|
||||||
|
labelW := u(96)
|
||||||
|
for i, r := range sysRows {
|
||||||
|
y := u(sysHead) + int32(i)*u(sysRow_)
|
||||||
|
val := colText
|
||||||
|
if i == sysHover {
|
||||||
|
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(sysRow_)}, rgb(40, 40, 48))
|
||||||
|
val = colAccent
|
||||||
|
}
|
||||||
|
wxText(hdc, r.label, rect{pad, y, pad + labelW, y + u(sysRow_)}, fBold, colAccent, line)
|
||||||
|
wxText(hdc, r.value, rect{pad + labelW, y, W - pad, y + u(sysRow_)}, fText, val, line)
|
||||||
|
}
|
||||||
|
y := u(sysHead) + int32(len(sysRows))*u(sysRow_)
|
||||||
|
wxText(hdc, "Click a line to copy it, or the top to copy everything.", rect{pad, y + u(4), W - pad, H - u(2)}, fTiny, colDim, line)
|
||||||
|
}
|
||||||
+298
@@ -0,0 +1,298 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// System information for the stats panel: the kind of thing neofetch prints.
|
||||||
|
// Everything is read from Windows itself (the registry and a few kernel calls);
|
||||||
|
// nothing goes over the network.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pGlobalMemoryStatusEx = kern32t.NewProc("GlobalMemoryStatusEx")
|
||||||
|
pGetTickCount64 = kern32t.NewProc("GetTickCount64")
|
||||||
|
pGetLogicalDrives = kern32t.NewProc("GetLogicalDrives")
|
||||||
|
pGetDriveType = kern32t.NewProc("GetDriveTypeW")
|
||||||
|
pGetDiskFreeSpaceEx = kern32t.NewProc("GetDiskFreeSpaceExW")
|
||||||
|
pGlobalAlloc = kern32t.NewProc("GlobalAlloc")
|
||||||
|
pGlobalLock = kern32t.NewProc("GlobalLock")
|
||||||
|
pGlobalUnlock = kern32t.NewProc("GlobalUnlock")
|
||||||
|
pMoveMemory = kern32t.NewProc("RtlMoveMemory")
|
||||||
|
pOpenClipboard = user32.NewProc("OpenClipboard")
|
||||||
|
pEmptyClipboard = user32.NewProc("EmptyClipboard")
|
||||||
|
pSetClipboardData = user32.NewProc("SetClipboardData")
|
||||||
|
pCloseClipboard = user32.NewProc("CloseClipboard")
|
||||||
|
)
|
||||||
|
|
||||||
|
type sysRow struct{ label, value string }
|
||||||
|
|
||||||
|
// ---------- the registry ----------
|
||||||
|
|
||||||
|
func regRead(path, name string) (buf []byte, ok bool) {
|
||||||
|
var k syscall.Handle
|
||||||
|
if syscall.RegOpenKeyEx(syscall.HKEY_LOCAL_MACHINE, u16(path), 0, syscall.KEY_READ, &k) != nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
defer syscall.RegCloseKey(k)
|
||||||
|
var n, typ uint32
|
||||||
|
if syscall.RegQueryValueEx(k, u16(name), nil, &typ, nil, &n) != nil || n == 0 {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
buf = make([]byte, n)
|
||||||
|
if syscall.RegQueryValueEx(k, u16(name), nil, &typ, &buf[0], &n) != nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return buf[:n], true
|
||||||
|
}
|
||||||
|
|
||||||
|
func regString(path, name string) string {
|
||||||
|
b, ok := regRead(path, name)
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
w := make([]uint16, 0, len(b)/2)
|
||||||
|
for i := 0; i+1 < len(b); i += 2 {
|
||||||
|
c := binary.LittleEndian.Uint16(b[i:])
|
||||||
|
if c == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
w = append(w, c)
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(syscall.UTF16ToString(w))
|
||||||
|
}
|
||||||
|
|
||||||
|
func regDword(path, name string) (uint32, bool) {
|
||||||
|
b, ok := regRead(path, name)
|
||||||
|
if !ok || len(b) < 4 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return binary.LittleEndian.Uint32(b), true
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- gathering ----------
|
||||||
|
|
||||||
|
type memStatusEx struct {
|
||||||
|
Length uint32
|
||||||
|
MemoryLoad uint32
|
||||||
|
TotalPhys, AvailPhys uint64
|
||||||
|
TotalPage, AvailPage uint64
|
||||||
|
TotalVirt, AvailVirt uint64
|
||||||
|
AvailExtendedVirtual uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
func gib(b uint64) string { return fmt.Sprintf("%.1f GiB", float64(b)/(1<<30)) }
|
||||||
|
|
||||||
|
func sysUptime() string {
|
||||||
|
ms, _, _ := pGetTickCount64.Call()
|
||||||
|
d := time.Duration(ms) * time.Millisecond
|
||||||
|
days := int(d.Hours()) / 24
|
||||||
|
hrs := int(d.Hours()) % 24
|
||||||
|
mins := int(d.Minutes()) % 60
|
||||||
|
var parts []string
|
||||||
|
if days > 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("%d day%s", days, plural(days)))
|
||||||
|
}
|
||||||
|
if days > 0 || hrs > 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("%d hour%s", hrs, plural(hrs)))
|
||||||
|
}
|
||||||
|
parts = append(parts, fmt.Sprintf("%d min%s", mins, plural(mins)))
|
||||||
|
return strings.Join(parts, ", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func plural(n int) string {
|
||||||
|
if n == 1 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "s"
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysGather() []sysRow {
|
||||||
|
var rows []sysRow
|
||||||
|
add := func(l, v string) {
|
||||||
|
if strings.TrimSpace(v) != "" {
|
||||||
|
rows = append(rows, sysRow{l, v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const cv = `SOFTWARE\Microsoft\Windows NT\CurrentVersion`
|
||||||
|
build := regString(cv, "CurrentBuild")
|
||||||
|
bn := 0
|
||||||
|
fmt.Sscanf(build, "%d", &bn)
|
||||||
|
name := regString(cv, "ProductName")
|
||||||
|
if bn >= 22000 {
|
||||||
|
name = strings.Replace(name, "Windows 10", "Windows 11", 1) // Windows 11 still says 10 here
|
||||||
|
}
|
||||||
|
ver := regString(cv, "DisplayVersion")
|
||||||
|
arch := map[string]string{"amd64": "x86_64", "arm64": "arm64", "386": "x86"}[runtime.GOARCH]
|
||||||
|
osText := name
|
||||||
|
if ver != "" {
|
||||||
|
osText += " " + ver
|
||||||
|
}
|
||||||
|
if arch != "" {
|
||||||
|
osText += " " + arch
|
||||||
|
}
|
||||||
|
add("OS", osText)
|
||||||
|
|
||||||
|
const bios = `HARDWARE\DESCRIPTION\System\BIOS`
|
||||||
|
host := strings.TrimSpace(regString(bios, "SystemManufacturer") + " " + regString(bios, "SystemProductName"))
|
||||||
|
add("Host", host)
|
||||||
|
|
||||||
|
if build != "" {
|
||||||
|
k := "NT 10.0." + build
|
||||||
|
if ubr, ok := regDword(cv, "UBR"); ok {
|
||||||
|
k += fmt.Sprintf(".%d", ubr)
|
||||||
|
}
|
||||||
|
add("Kernel", k)
|
||||||
|
}
|
||||||
|
add("Uptime", sysUptime())
|
||||||
|
add("Shell", "MirrorBar")
|
||||||
|
|
||||||
|
sw, sh := screenSize()
|
||||||
|
res := fmt.Sprintf("%dx%d", sw, sh)
|
||||||
|
if s := int(scale*100 + 0.5); s != 100 {
|
||||||
|
res += fmt.Sprintf(" (%d%% scaling)", s)
|
||||||
|
}
|
||||||
|
add("Resolution", res)
|
||||||
|
|
||||||
|
const cpuKey = `HARDWARE\DESCRIPTION\System\CentralProcessor\0`
|
||||||
|
cpu := strings.Join(strings.Fields(regString(cpuKey, "ProcessorNameString")), " ")
|
||||||
|
if cpu != "" {
|
||||||
|
cpu += fmt.Sprintf(" (%d threads)", runtime.NumCPU())
|
||||||
|
}
|
||||||
|
add("CPU", cpu)
|
||||||
|
|
||||||
|
// Graphics adapters: the display class lists them as 0000, 0001, ...
|
||||||
|
n := 0
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
d := regString(fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Class\{4d36e968-e325-11ce-bfc1-08002be10318}\%04d`, i), "DriverDesc")
|
||||||
|
if d == "" || seen[d] || strings.Contains(d, "Basic Display") || strings.Contains(d, "Remote Display") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[d] = true
|
||||||
|
n++
|
||||||
|
l := "GPU"
|
||||||
|
if n > 1 {
|
||||||
|
l = fmt.Sprintf("GPU %d", n)
|
||||||
|
}
|
||||||
|
add(l, d)
|
||||||
|
}
|
||||||
|
|
||||||
|
var ms memStatusEx
|
||||||
|
ms.Length = uint32(unsafe.Sizeof(ms))
|
||||||
|
if r, _, _ := pGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&ms))); r != 0 && ms.TotalPhys > 0 {
|
||||||
|
used := ms.TotalPhys - ms.AvailPhys
|
||||||
|
add("Memory", fmt.Sprintf("%s / %s (%d%%)", gib(used), gib(ms.TotalPhys), used*100/ms.TotalPhys))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixed drives only; a sleeping network drive could make this wait.
|
||||||
|
mask, _, _ := pGetLogicalDrives.Call()
|
||||||
|
for i := 0; i < 26; i++ {
|
||||||
|
if mask&(1<<uint(i)) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
root := string(rune('A'+i)) + `:\`
|
||||||
|
if t, _, _ := pGetDriveType.Call(uintptr(unsafe.Pointer(u16(root)))); t != 3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var free, total, totalFree uint64
|
||||||
|
r, _, _ := pGetDiskFreeSpaceEx.Call(uintptr(unsafe.Pointer(u16(root))),
|
||||||
|
uintptr(unsafe.Pointer(&free)), uintptr(unsafe.Pointer(&total)), uintptr(unsafe.Pointer(&totalFree)))
|
||||||
|
if r == 0 || total == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
used := total - totalFree
|
||||||
|
add("Disk ("+root[:2]+")", fmt.Sprintf("%s / %s (%d%%)", gib(used), gib(total), used*100/total))
|
||||||
|
}
|
||||||
|
|
||||||
|
if battPct >= 0 {
|
||||||
|
b := fmt.Sprintf("%d%%", battPct)
|
||||||
|
switch {
|
||||||
|
case battCharging:
|
||||||
|
b += ", charging"
|
||||||
|
case battAC:
|
||||||
|
b += ", plugged in"
|
||||||
|
}
|
||||||
|
add("Battery", b)
|
||||||
|
}
|
||||||
|
add("Local IP", localIP())
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
// localIP is this PC's first private IPv4 address.
|
||||||
|
func localIP() string {
|
||||||
|
addrs, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
for _, a := range addrs {
|
||||||
|
if ipn, ok := a.(*net.IPNet); ok && !ipn.IP.IsLoopback() {
|
||||||
|
if v4 := ipn.IP.To4(); v4 != nil && v4.IsPrivate() {
|
||||||
|
return v4.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func sysUserHost() string {
|
||||||
|
u := os.Getenv("USERNAME")
|
||||||
|
h, _ := os.Hostname()
|
||||||
|
if u == "" {
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
return u + "@" + h
|
||||||
|
}
|
||||||
|
|
||||||
|
// sysText is everything as plain text, ready to paste.
|
||||||
|
func sysText(rows []sysRow) string {
|
||||||
|
head := sysUserHost()
|
||||||
|
var sb strings.Builder
|
||||||
|
sb.WriteString(head + "\r\n" + strings.Repeat("-", len([]rune(head))) + "\r\n")
|
||||||
|
for _, r := range rows {
|
||||||
|
sb.WriteString(r.label + ": " + r.value + "\r\n")
|
||||||
|
}
|
||||||
|
return sb.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the clipboard ----------
|
||||||
|
|
||||||
|
// clipboardSet puts plain text on the clipboard. Returns false if it couldn't.
|
||||||
|
func clipboardSet(text string) bool {
|
||||||
|
w, err := syscall.UTF16FromString(text)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i < 5; i++ { // another program may have it open for a moment
|
||||||
|
if r, _, _ := pOpenClipboard.Call(hwndMain); r != 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if i == 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
time.Sleep(30 * time.Millisecond)
|
||||||
|
}
|
||||||
|
defer pCloseClipboard.Call()
|
||||||
|
pEmptyClipboard.Call()
|
||||||
|
const gmemMoveable, cfUnicodeText = 0x0002, 13
|
||||||
|
h, _, _ := pGlobalAlloc.Call(gmemMoveable, uintptr(len(w)*2))
|
||||||
|
if h == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
p, _, _ := pGlobalLock.Call(h)
|
||||||
|
if p == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
pMoveMemory.Call(p, uintptr(unsafe.Pointer(&w[0])), uintptr(len(w)*2))
|
||||||
|
pGlobalUnlock.Call(h)
|
||||||
|
r, _, _ := pSetClipboardData.Call(cfUnicodeText, h)
|
||||||
|
return r != 0 // the system owns the memory now
|
||||||
|
}
|
||||||
@@ -21,6 +21,13 @@ const (
|
|||||||
trayWifi
|
trayWifi
|
||||||
trayChevron
|
trayChevron
|
||||||
trayWeather // added after the others so saved orders from older versions still mean the same thing
|
trayWeather // added after the others so saved orders from older versions still mean the same thing
|
||||||
|
trayNews
|
||||||
|
traySys
|
||||||
|
trayGM // Google Messages
|
||||||
|
trayEmoji // the emoji panel button
|
||||||
|
trayClip // the clipboard history button
|
||||||
|
trayAI // Claude or Grok
|
||||||
|
trayMusic // the mp3 player
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -45,6 +52,13 @@ const (
|
|||||||
|
|
||||||
menuWeatherID = 26
|
menuWeatherID = 26
|
||||||
menuWeatherZipID = 27
|
menuWeatherZipID = 27
|
||||||
|
menuNewsID = 28
|
||||||
|
menuNewsZipID = 29
|
||||||
|
menuSysID = 34
|
||||||
|
menuSysCopyID = 35
|
||||||
|
menuGMID = 36
|
||||||
|
menuGMCloseID = 37
|
||||||
|
menuEmojiID = 38
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -101,11 +115,59 @@ func trayItemsAt(x, clientH int32) []trayItem {
|
|||||||
case trayClock:
|
case trayClock:
|
||||||
w = clockWidth()
|
w = clockWidth()
|
||||||
case trayBattery:
|
case trayBattery:
|
||||||
if battPct < 0 {
|
if battPct < 0 || !showBattery {
|
||||||
continue // this PC has no battery
|
continue // this PC has no battery, or it was turned off in the settings
|
||||||
}
|
}
|
||||||
w = px(36)
|
w = px(36)
|
||||||
case trayVolume, trayWifi, trayWeather:
|
case trayVolume:
|
||||||
|
if !showVolume {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayWifi:
|
||||||
|
if !showWifi {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayWeather:
|
||||||
|
if !showWeather {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayNews:
|
||||||
|
if !showNews {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case traySys:
|
||||||
|
if !showSys {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayGM:
|
||||||
|
if !showGM {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayEmoji:
|
||||||
|
if !showEmoji {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayClip:
|
||||||
|
if !showClip {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayAI:
|
||||||
|
if !showAI {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayMusic:
|
||||||
|
if !showMusic {
|
||||||
|
continue
|
||||||
|
}
|
||||||
w = px(36)
|
w = px(36)
|
||||||
case trayChevron:
|
case trayChevron:
|
||||||
w = px(28)
|
w = px(28)
|
||||||
@@ -173,7 +235,7 @@ func drawBattery(hdc uintptr, r rect) {
|
|||||||
col := white
|
col := white
|
||||||
switch {
|
switch {
|
||||||
case battCharging || battAC:
|
case battCharging || battAC:
|
||||||
col = rgb(90, 205, 120)
|
col = chargeColor()
|
||||||
case battPct <= 15:
|
case battPct <= 15:
|
||||||
col = rgb(235, 80, 80)
|
col = rgb(235, 80, 80)
|
||||||
}
|
}
|
||||||
@@ -296,6 +358,20 @@ func drawTray(hdc uintptr, w, h int32) {
|
|||||||
drawChevron(hdc, it.r)
|
drawChevron(hdc, it.r)
|
||||||
case trayWeather:
|
case trayWeather:
|
||||||
drawWeatherIcon(hdc, it.r)
|
drawWeatherIcon(hdc, it.r)
|
||||||
|
case trayNews:
|
||||||
|
drawNewsIcon(hdc, it.r)
|
||||||
|
case traySys:
|
||||||
|
drawSysIcon(hdc, it.r)
|
||||||
|
case trayGM:
|
||||||
|
drawGMIcon(hdc, it.r)
|
||||||
|
case trayEmoji:
|
||||||
|
drawEmojiIcon(hdc, it.r)
|
||||||
|
case trayClip:
|
||||||
|
drawClipIcon(hdc, it.r)
|
||||||
|
case trayAI:
|
||||||
|
drawAIIcon(hdc, it.r)
|
||||||
|
case trayMusic:
|
||||||
|
drawMusicIcon(hdc, it.r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -555,6 +631,9 @@ func tapChord(mod, k uintptr) {
|
|||||||
// trayClick opens the matching Windows panel with its keyboard shortcut.
|
// trayClick opens the matching Windows panel with its keyboard shortcut.
|
||||||
const vkEscape = 0x1B
|
const vkEscape = 0x1B
|
||||||
|
|
||||||
|
// vkPeriod is the . key; Win+. opens the Windows emoji panel.
|
||||||
|
const vkPeriod = 0xBE
|
||||||
|
|
||||||
// overflowOpen reports whether the hidden icons flyout is on screen.
|
// overflowOpen reports whether the hidden icons flyout is on screen.
|
||||||
func overflowOpen() bool {
|
func overflowOpen() bool {
|
||||||
for _, class := range []string{"TopLevelWindowForOverflowXamlIsland", "NotifyIconOverflowWindow"} {
|
for _, class := range []string{"TopLevelWindowForOverflowXamlIsland", "NotifyIconOverflowWindow"} {
|
||||||
@@ -576,6 +655,20 @@ func trayClick(kind int) {
|
|||||||
tapChord(vkLWin, 'A') // quick settings
|
tapChord(vkLWin, 'A') // quick settings
|
||||||
case trayWeather:
|
case trayWeather:
|
||||||
weatherToggle()
|
weatherToggle()
|
||||||
|
case trayNews:
|
||||||
|
newsToggle()
|
||||||
|
case traySys:
|
||||||
|
sysToggle()
|
||||||
|
case trayGM:
|
||||||
|
gmToggle()
|
||||||
|
case trayEmoji:
|
||||||
|
tapChord(vkLWin, vkPeriod) // Win+. opens the emoji panel
|
||||||
|
case trayClip:
|
||||||
|
tapChord(vkLWin, 'V') // Win+V opens the clipboard history
|
||||||
|
case trayAI:
|
||||||
|
aiClick()
|
||||||
|
case trayMusic:
|
||||||
|
flyPlayer.toggle()
|
||||||
case trayChevron:
|
case trayChevron:
|
||||||
// If the hidden icons are already showing, a second click closes them. Sending
|
// If the hidden icons are already showing, a second click closes them. Sending
|
||||||
// Win+B and Enter again would instead press Enter on the highlighted icon.
|
// Win+B and Enter again would instead press Enter on the highlighted icon.
|
||||||
@@ -662,6 +755,20 @@ func addTrayMenu(add func(flags uintptr, id uintptr, text string), sep func(), k
|
|||||||
add(0, menuWeatherID, "Show weather")
|
add(0, menuWeatherID, "Show weather")
|
||||||
add(0, menuWeatherZipID, "Weather ZIP code...")
|
add(0, menuWeatherZipID, "Weather ZIP code...")
|
||||||
sep()
|
sep()
|
||||||
|
case trayNews:
|
||||||
|
add(0, menuNewsID, "Show local news")
|
||||||
|
add(0, menuNewsZipID, "News ZIP code...")
|
||||||
|
sep()
|
||||||
|
case traySys:
|
||||||
|
add(0, menuSysID, "Show system stats")
|
||||||
|
add(0, menuSysCopyID, "Copy system stats")
|
||||||
|
sep()
|
||||||
|
case trayGM:
|
||||||
|
add(0, menuGMID, "Show Messages")
|
||||||
|
add(0, menuGMCloseID, "Close Messages (stop checking for texts)")
|
||||||
|
sep()
|
||||||
|
case trayAI, trayMusic, trayClip:
|
||||||
|
webFlyMenu(add, sep, kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -680,7 +787,29 @@ func handleTrayCommand(cmd uintptr) bool {
|
|||||||
if !wxShown {
|
if !wxShown {
|
||||||
weatherToggle()
|
weatherToggle()
|
||||||
}
|
}
|
||||||
case menuWeatherZipID:
|
case menuNewsID:
|
||||||
|
if !newsShown {
|
||||||
|
newsToggle()
|
||||||
|
}
|
||||||
|
case menuSysID:
|
||||||
|
if !sysShown {
|
||||||
|
sysToggle()
|
||||||
|
}
|
||||||
|
case menuGMID:
|
||||||
|
if !gmShown {
|
||||||
|
gmToggle()
|
||||||
|
}
|
||||||
|
case menuGMCloseID:
|
||||||
|
gmClose()
|
||||||
|
redraw(hwndMain)
|
||||||
|
case menuEmojiID:
|
||||||
|
tapChord(vkLWin, vkPeriod)
|
||||||
|
case menuSysCopyID:
|
||||||
|
if clipboardSet(sysText(sysGather())) {
|
||||||
|
sysCopied = "Copied everything"
|
||||||
|
sysCopiedAt = time.Now()
|
||||||
|
}
|
||||||
|
case menuWeatherZipID, menuNewsZipID:
|
||||||
openSettings()
|
openSettings()
|
||||||
case menuAutostartID:
|
case menuAutostartID:
|
||||||
setAutostart(!autostartEnabled())
|
setAutostart(!autostartEnabled())
|
||||||
@@ -689,7 +818,7 @@ func handleTrayCommand(cmd uintptr) bool {
|
|||||||
time.Sleep(60 * time.Millisecond)
|
time.Sleep(60 * time.Millisecond)
|
||||||
refreshStatus(false)
|
refreshStatus(false)
|
||||||
default:
|
default:
|
||||||
return false
|
return webFlyCommand(cmd)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -697,7 +826,7 @@ func handleTrayCommand(cmd uintptr) bool {
|
|||||||
// ---------- the right row can be rearranged too ----------
|
// ---------- the right row can be rearranged too ----------
|
||||||
|
|
||||||
// trayOrder is the left to right order of the items to the right of center.
|
// trayOrder is the left to right order of the items to the right of center.
|
||||||
var trayOrder = []int{trayClock, trayWeather, trayBattery, trayVolume, trayWifi, trayChevron}
|
var trayOrder = []int{trayClock, trayWeather, trayNews, traySys, trayGM, trayEmoji, trayClip, trayAI, trayMusic, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dragTray int // the tray item the mouse went down on, 0 for none
|
dragTray int // the tray item the mouse went down on, 0 for none
|
||||||
@@ -716,22 +845,48 @@ func loadTrayOrder() {
|
|||||||
seen := map[int]bool{}
|
seen := map[int]bool{}
|
||||||
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
|
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
|
||||||
n, err := strconv.Atoi(strings.TrimSpace(p))
|
n, err := strconv.Atoi(strings.TrimSpace(p))
|
||||||
if err != nil || n < trayClock || n > trayWeather || seen[n] {
|
if err != nil || n < trayClock || n > trayMusic || seen[n] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
seen[n] = true
|
seen[n] = true
|
||||||
order = append(order, n)
|
order = append(order, n)
|
||||||
}
|
}
|
||||||
// An order saved before the weather cloud existed: put the cloud next to the clock.
|
// An order saved before the weather cloud or the newspaper existed: put the new
|
||||||
if !seen[trayWeather] {
|
// icon next to the clock (the newspaper goes after the cloud).
|
||||||
withCloud := make([]int, 0, len(order)+1)
|
insertAfter := func(after, kind int) {
|
||||||
|
out := make([]int, 0, len(order)+1)
|
||||||
for _, k := range order {
|
for _, k := range order {
|
||||||
withCloud = append(withCloud, k)
|
out = append(out, k)
|
||||||
if k == trayClock {
|
if k == after {
|
||||||
withCloud = append(withCloud, trayWeather)
|
out = append(out, kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
order = withCloud
|
order = out
|
||||||
|
seen[kind] = true
|
||||||
|
}
|
||||||
|
if !seen[trayWeather] {
|
||||||
|
insertAfter(trayClock, trayWeather)
|
||||||
|
}
|
||||||
|
if !seen[trayNews] {
|
||||||
|
insertAfter(trayWeather, trayNews)
|
||||||
|
}
|
||||||
|
if !seen[traySys] {
|
||||||
|
insertAfter(trayNews, traySys)
|
||||||
|
}
|
||||||
|
if !seen[trayGM] {
|
||||||
|
insertAfter(traySys, trayGM)
|
||||||
|
}
|
||||||
|
if !seen[trayEmoji] {
|
||||||
|
insertAfter(trayGM, trayEmoji)
|
||||||
|
}
|
||||||
|
if !seen[trayClip] {
|
||||||
|
insertAfter(trayEmoji, trayClip)
|
||||||
|
}
|
||||||
|
if !seen[trayAI] {
|
||||||
|
insertAfter(trayClip, trayAI)
|
||||||
|
}
|
||||||
|
if !seen[trayMusic] {
|
||||||
|
insertAfter(trayAI, trayMusic)
|
||||||
}
|
}
|
||||||
if len(order) == len(trayOrder) {
|
if len(order) == len(trayOrder) {
|
||||||
trayOrder = order
|
trayOrder = order
|
||||||
|
|||||||
+22
@@ -123,11 +123,15 @@ func weatherSetZip(z string) {
|
|||||||
_ = os.Remove(locCacheFile())
|
_ = os.Remove(locCacheFile())
|
||||||
}
|
}
|
||||||
weatherRefresh(true)
|
weatherRefresh(true)
|
||||||
|
newsRefresh(true) // the local news follows the same ZIP code
|
||||||
}
|
}
|
||||||
|
|
||||||
// weatherRefresh starts a fetch if the forecast is missing or old (or force is
|
// weatherRefresh starts a fetch if the forecast is missing or old (or force is
|
||||||
// set). Safe to call as often as you like.
|
// set). Safe to call as often as you like.
|
||||||
func weatherRefresh(force bool) {
|
func weatherRefresh(force bool) {
|
||||||
|
if !showWeather {
|
||||||
|
return
|
||||||
|
}
|
||||||
zip := wxZip
|
zip := wxZip
|
||||||
wxMu.Lock()
|
wxMu.Lock()
|
||||||
if len(zip) != 5 {
|
if len(zip) != 5 {
|
||||||
@@ -230,6 +234,24 @@ func wxGetJSON(u string, v any) (status int, err error) {
|
|||||||
return resp.StatusCode, json.NewDecoder(io.LimitReader(resp.Body, 2<<20)).Decode(v)
|
return resp.StatusCode, json.NewDecoder(io.LimitReader(resp.Body, 2<<20)).Decode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// wxGetBytes downloads one file (a picture tile), up to 4 MB.
|
||||||
|
func wxGetBytes(u string) ([]byte, error) {
|
||||||
|
req, err := http.NewRequest("GET", u, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("User-Agent", "MirrorBar weather flyout")
|
||||||
|
resp, err := wxClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("HTTP %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
return io.ReadAll(io.LimitReader(resp.Body, 4<<20))
|
||||||
|
}
|
||||||
|
|
||||||
// wxLocate turns a ZIP code into a place. The answer is kept in a small file so
|
// wxLocate turns a ZIP code into a place. The answer is kept in a small file so
|
||||||
// the lookup happens once per ZIP code, not every time the bar starts.
|
// the lookup happens once per ZIP code, not every time the bar starts.
|
||||||
func wxLocate(zip string) (lat, lon float64, place string, err error) {
|
func wxLocate(zip string) (lat, lon float64, place string, err error) {
|
||||||
|
|||||||
@@ -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