Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ea41cab49 | ||
|
|
2a76d1d9c9 | ||
|
|
fc1d82d790 | ||
|
|
c80267f81f | ||
|
|
e82ed224e8 | ||
|
|
8ab3cda02d | ||
|
|
b26879abdb | ||
|
|
2a68148183 | ||
|
|
3e0fc4e6ec | ||
|
|
75a88a4a91 |
@@ -1,60 +1,66 @@
|
||||
# MirrorBar+
|
||||
|
||||
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 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
|
||||
|
||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
||||
- Drag it anywhere by its background. It remembers where you put it. Right-click and choose "Reset position to bottom center" to send it home.
|
||||
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||
- Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
||||
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
||||
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
||||
- "Open notification center" is in the right-click menu.
|
||||
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
||||
- "MirrorBar settings..." in the right-click menu opens one window for background opacity, the three colors, icon style, the ZIP code, tickboxes to show or hide the weather, the local news and the system stats, vertical mode, start with Windows, and resetting the position and width. Changes apply as you make them.
|
||||
- Smooth, outline-free icons and text, even when the pill is see-through.
|
||||
- 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. `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).
|
||||
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
||||
- Background see-through level: Clear, Light, Medium or Solid.
|
||||
- "Start MirrorBar when I sign in" in the right-click menu.
|
||||
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
||||
|
||||
## Safety
|
||||
|
||||
- `mirrorbar.exe` quits by itself after 10 minutes and brings the normal taskbar back. `mirrorbar_forever.exe` (or any copy started with `--forever`) does not.
|
||||
- Ctrl+Alt+Q quits and restores the taskbar.
|
||||
- Right-click, "Exit MirrorBar and restore taskbar".
|
||||
- Hold Shift while it launches and it exits at once without touching anything.
|
||||
- `restore_taskbar.exe` (the same program, renamed) or `--restore` puts the normal taskbar back.
|
||||
|
||||
## Download
|
||||
|
||||
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
|
||||
|
||||
Go 1.24 or newer, standard library only:
|
||||
|
||||
```
|
||||
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-H=windowsgui -s -w" -o mirrorbar.exe .
|
||||
```
|
||||
|
||||
Settings are kept in `%LOCALAPPDATA%\MirrorBar`.
|
||||
|
||||
# MirrorBar+
|
||||
|
||||
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 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
|
||||
|
||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
||||
- Drag it anywhere by its background. It remembers where you put it. Right-click and choose "Reset position to bottom center" to send it home.
|
||||
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||
- 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.
|
||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
||||
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
||||
- "Open notification center" is in the right-click menu.
|
||||
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
||||
- "MirrorBar settings..." in the right-click menu opens one window for background opacity, the three colors, icon style, the ZIP code, tickboxes to show or hide the weather, the local news and the system stats, vertical mode, start with Windows, and resetting the position and width. Changes apply as you make them.
|
||||
- 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 or gray. "Windows logo shape" swaps the four squares for rounded squares, four dots, squares tilted right or left, diamonds or a waving flag. "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 now have sixteen choices, including dark green, teal, navy, maroon, gray and lime. A light bar needs a dark clock and icon color to be readable.
|
||||
|
||||
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).
|
||||
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
||||
- Background see-through level: Clear, Light, Medium or Solid.
|
||||
- "Start MirrorBar when I sign in" in the right-click menu.
|
||||
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
||||
|
||||
## Safety
|
||||
|
||||
- `mirrorbar.exe` quits by itself after 10 minutes and brings the normal taskbar back. `mirrorbar_forever.exe` (or any copy started with `--forever`) does not.
|
||||
- Ctrl+Alt+Q quits and restores the taskbar.
|
||||
- Right-click, "Exit MirrorBar and restore taskbar".
|
||||
- Hold Shift while it launches and it exits at once without touching anything.
|
||||
- `restore_taskbar.exe` (the same program, renamed) or `--restore` puts the normal taskbar back.
|
||||
|
||||
## Download
|
||||
|
||||
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
|
||||
|
||||
Go 1.24 or newer, standard library only:
|
||||
|
||||
```
|
||||
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-H=windowsgui -s -w" -o mirrorbar.exe .
|
||||
```
|
||||
|
||||
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)
|
||||
}
|
||||
+173
-146
@@ -1,146 +1,173 @@
|
||||
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
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveFeatures() {
|
||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\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()
|
||||
}
|
||||
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
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) + "\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)
|
||||
}
|
||||
|
||||
+558
-553
File diff suppressed because it is too large
Load Diff
+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,325 @@
|
||||
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"
|
||||
)
|
||||
|
||||
var pRoundRect = gdi32.NewProc("RoundRect")
|
||||
|
||||
// ---------- 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},
|
||||
}
|
||||
|
||||
var (
|
||||
barIdx = 0
|
||||
logoStyle = 0
|
||||
clockSizeIx = 0
|
||||
clockBold = false
|
||||
)
|
||||
|
||||
var logoStyleNames = []string{
|
||||
"Classic squares",
|
||||
"Rounded squares",
|
||||
"Four dots",
|
||||
"Tilted right",
|
||||
"Tilted left",
|
||||
"Diamonds",
|
||||
"Waving flag",
|
||||
}
|
||||
|
||||
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 {
|
||||
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
|
||||
}
|
||||
oldA, oldB := fontTime, fontTime2
|
||||
fontTime = makeFont(px(float64(clockPx())), weight)
|
||||
scale *= superSample
|
||||
fontTime2 = makeFont(px(float64(clockPx())), weight)
|
||||
scale /= superSample
|
||||
if oldA != 0 {
|
||||
pDeleteObject.Call(oldA)
|
||||
}
|
||||
if oldB != 0 {
|
||||
pDeleteObject.Call(oldB)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func saveLook() {
|
||||
s := "barcolor=" + strconv.Itoa(barIdx) +
|
||||
"\nlogostyle=" + strconv.Itoa(logoStyle) +
|
||||
"\nclocksize=" + strconv.Itoa(clockSizeIx) +
|
||||
"\nclockbold=" + b01(clockBold) + "\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 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,6 +306,9 @@ type appWin struct {
|
||||
title string
|
||||
icon uintptr
|
||||
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 {
|
||||
@@ -538,6 +541,10 @@ func activateApp(idx int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if apps[idx].count > 1 {
|
||||
activateGroup(apps[idx])
|
||||
return
|
||||
}
|
||||
fg, _, _ := pGetForegroundWindow.Call()
|
||||
iconic, _, _ := pIsIconic.Call(h)
|
||||
switch {
|
||||
@@ -554,7 +561,6 @@ func activateApp(idx int) {
|
||||
// ---------- our bar ----------
|
||||
|
||||
func startWidth() int32 { return px(52) }
|
||||
func clockWidth() int32 { return px(140) }
|
||||
|
||||
func screenSize() (int32, int32) {
|
||||
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
||||
@@ -574,7 +580,7 @@ func barGap() int32 { return px(6) }
|
||||
|
||||
func positionBar(hwnd uintptr) {
|
||||
pw, ph := pillSize()
|
||||
if !customPos {
|
||||
if !customPos && !autoHide {
|
||||
sw, sh := screenSize()
|
||||
edge := uintptr(abeBottom)
|
||||
if vertical {
|
||||
@@ -590,6 +596,14 @@ func positionBar(hwnd uintptr) {
|
||||
appBar(abmSetPos, &abd)
|
||||
}
|
||||
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)
|
||||
redraw(hwnd)
|
||||
}
|
||||
@@ -674,6 +688,12 @@ func makeFont(height int32, weight int) uintptr {
|
||||
}
|
||||
|
||||
func drawLogo(hdc uintptr, r rect) {
|
||||
if logoStyle != 0 {
|
||||
if !vertical { // a vertical bar draws it upright after turning (see renderLayer)
|
||||
drawLogoStyle(hdc, r)
|
||||
}
|
||||
return
|
||||
}
|
||||
sq := px(8)
|
||||
gap := px(2)
|
||||
total := sq*2 + gap
|
||||
@@ -729,6 +749,9 @@ func drawAppGlyph(hdc uintptr, r rect, a appWin) {
|
||||
if a.icon != 0 {
|
||||
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)
|
||||
if a.count > 1 {
|
||||
drawCountBadge(hdc, cx, cy, isz, a.count)
|
||||
}
|
||||
} else if rs := []rune(a.title); len(rs) > 0 {
|
||||
pSetBkMode.Call(hdc, transparent)
|
||||
pSetTextColor.Call(hdc, rgb(245, 245, 245))
|
||||
@@ -806,7 +829,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
var target uintptr
|
||||
var exe string
|
||||
if appIdx >= 0 && appIdx < len(apps) {
|
||||
target = apps[appIdx].hwnd
|
||||
target = memberHwnd(apps[appIdx])
|
||||
|
||||
title := []rune(apps[appIdx].title)
|
||||
text := string(title)
|
||||
@@ -905,8 +928,11 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
var pt point
|
||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&pt)))
|
||||
pSetForegroundWindow.Call(hwnd)
|
||||
menuOpen = true
|
||||
cmd, _, _ := pTrackPopupMenu.Call(menu, tpmRightButton|tpmBottomAlign|tpmReturnCmd,
|
||||
uintptr(pt.X), uintptr(pt.Y), 0, hwnd, 0)
|
||||
menuOpen = false
|
||||
ahLeftAt = time.Now()
|
||||
pDestroyMenu.Call(menu)
|
||||
|
||||
sysCommands := map[uintptr]uintptr{
|
||||
@@ -989,6 +1015,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
gmPoll()
|
||||
return 0
|
||||
}
|
||||
if wparam == ahTimerID {
|
||||
ahTick(hwnd)
|
||||
return 0
|
||||
}
|
||||
if wparam == previewTimerID {
|
||||
previewTick()
|
||||
return 0
|
||||
@@ -1285,6 +1315,8 @@ func main() {
|
||||
fontApp = makeFont(px(12), 600)
|
||||
initSuperFonts()
|
||||
loadColors()
|
||||
loadLook()
|
||||
rebuildClockFonts()
|
||||
|
||||
autoQuit = autoQuitDef
|
||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||
@@ -1344,7 +1376,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Register as an app bar so maximized windows stop above us.
|
||||
if customPos {
|
||||
if customPos || autoHide {
|
||||
appbarOn = false
|
||||
} else {
|
||||
abd := appBarData{Hwnd: hwnd, CallbackMsg: callbackMsg}
|
||||
@@ -1356,6 +1388,9 @@ func main() {
|
||||
refreshApps(true)
|
||||
positionBar(hwnd)
|
||||
pSetTimer.Call(hwnd, timerID, 250, 0)
|
||||
if autoHide {
|
||||
ahStart()
|
||||
}
|
||||
weatherRefresh(false) // have the forecast ready before the cloud is first clicked
|
||||
newsRefresh(false)
|
||||
|
||||
|
||||
@@ -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
|
||||
for _, a := range apps {
|
||||
for _, a := range allApps {
|
||||
if a.hwnd == 0 {
|
||||
next = append(next, a) // a waiting launcher; sorted out below
|
||||
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
|
||||
// bar shows them, so only a change in which buttons exist, or their icons,
|
||||
// counts as a change.
|
||||
changed := len(next) != len(apps)
|
||||
// bar shows them, so only a change in which buttons exist, their icons, or
|
||||
// how many windows an icon stands for counts as a change.
|
||||
changed := len(grouped) != len(apps)
|
||||
if !changed {
|
||||
for i := range next {
|
||||
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
||||
for i := range grouped {
|
||||
if grouped[i].hwnd != apps[i].hwnd || grouped[i].icon != apps[i].icon || grouped[i].count != apps[i].count {
|
||||
changed = true
|
||||
break
|
||||
}
|
||||
@@ -336,7 +344,7 @@ func refreshApps(refreshIcons bool) bool {
|
||||
if changed {
|
||||
styleCacheClear() // icon handles can be reused by other icons
|
||||
}
|
||||
apps = next
|
||||
apps = grouped
|
||||
return changed
|
||||
}
|
||||
|
||||
|
||||
@@ -330,4 +330,5 @@ func moveSeq(from, to int) {
|
||||
}
|
||||
}
|
||||
apps = next
|
||||
syncAllFromGrouped()
|
||||
}
|
||||
|
||||
+2
-1
@@ -175,6 +175,7 @@ func previewShow(idx int) {
|
||||
return
|
||||
}
|
||||
a := apps[idx]
|
||||
a.hwnd = memberHwnd(a)
|
||||
previewDropThumb()
|
||||
|
||||
iconic, _, _ := pIsIconic.Call(a.hwnd)
|
||||
@@ -297,7 +298,7 @@ func previewTick() {
|
||||
}
|
||||
idx = appIndexAt(hwndMain, x)
|
||||
if idx >= 0 && idx < len(apps) {
|
||||
raw = apps[idx].hwnd
|
||||
raw = memberHwnd(apps[idx])
|
||||
}
|
||||
}
|
||||
target := raw
|
||||
|
||||
@@ -1,392 +1,406 @@
|
||||
package main
|
||||
|
||||
// Painting the bar smoothly on a see-through background.
|
||||
//
|
||||
// Drawing icons and text straight onto a dark bitmap leaves a dark fringe
|
||||
// around them once the background is made see-through. So the bar is painted
|
||||
// in layers: one layer with only the backgrounds, and the icons, text and
|
||||
// symbols drawn twice (once on black, once on white) at double size. Comparing
|
||||
// the two copies shows exactly how see-through every edge pixel is, and
|
||||
// shrinking back down gives smooth edges with no dark outline.
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
superSample = 2
|
||||
mfPopup = 0x0010
|
||||
|
||||
menuLogoColorBase = 100
|
||||
menuClockColorBase = 120
|
||||
menuIconColorBase = 140
|
||||
)
|
||||
|
||||
var (
|
||||
fontTime2 uintptr
|
||||
fontApp2 uintptr
|
||||
)
|
||||
|
||||
// initSuperFonts makes the double size fonts used for the smooth pass.
|
||||
func initSuperFonts() {
|
||||
scale *= superSample
|
||||
fontTime2 = makeFont(px(13), 400)
|
||||
fontApp2 = makeFont(px(12), 600)
|
||||
scale /= superSample
|
||||
}
|
||||
|
||||
// ---------- colors ----------
|
||||
|
||||
type namedColor struct {
|
||||
name string
|
||||
r, g, b int
|
||||
}
|
||||
|
||||
var palette = []namedColor{
|
||||
{"White", 245, 245, 245},
|
||||
{"Blue", 0, 120, 212},
|
||||
{"Sky blue", 90, 190, 255},
|
||||
{"Green", 70, 200, 110},
|
||||
{"Yellow", 255, 205, 60},
|
||||
{"Orange", 255, 140, 40},
|
||||
{"Red", 235, 70, 70},
|
||||
{"Pink", 255, 125, 195},
|
||||
{"Purple", 175, 115, 240},
|
||||
{"Black", 0, 0, 0},
|
||||
}
|
||||
|
||||
var (
|
||||
logoIdx = 1 // Blue, like the real Windows logo
|
||||
clockIdx = 0 // White
|
||||
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
||||
)
|
||||
|
||||
func colorOf(i int) uintptr {
|
||||
if i < 0 || i >= len(palette) {
|
||||
i = 0
|
||||
}
|
||||
c := palette[i]
|
||||
r, g, b := styleColor(c.r, c.g, c.b)
|
||||
return rgb(r, g, b)
|
||||
}
|
||||
|
||||
func logoColor() uintptr { return colorOf(logoIdx) }
|
||||
func clockColor() uintptr { return colorOf(clockIdx) }
|
||||
func iconColor() uintptr { return colorOf(iconIdx) }
|
||||
|
||||
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
||||
func iconDim() uintptr {
|
||||
c := palette[iconIdx]
|
||||
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
||||
return rgb(140, 140, 150)
|
||||
}
|
||||
return rgb(110, 110, 120)
|
||||
}
|
||||
|
||||
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
||||
|
||||
func loadColors() {
|
||||
b, err := os.ReadFile(colorsFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
||||
if len(parts) < 2 || len(parts) > 3 {
|
||||
return
|
||||
}
|
||||
vals := []int{0, 0, 0}
|
||||
for i, p := range parts {
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil || n < 0 || n >= len(palette) {
|
||||
return
|
||||
}
|
||||
vals[i] = n
|
||||
}
|
||||
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
||||
}
|
||||
|
||||
func saveColors() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
||||
}
|
||||
|
||||
// addColorMenus adds the two color pickers as sub menus.
|
||||
func addColorMenus(menu uintptr) {
|
||||
build := func(base uintptr, cur int, title string) {
|
||||
sub, _, _ := pCreatePopupMenu.Call()
|
||||
for i, c := range palette {
|
||||
var flags uintptr
|
||||
if i == cur {
|
||||
flags = mfChecked
|
||||
}
|
||||
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
||||
}
|
||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
||||
}
|
||||
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
||||
build(menuClockColorBase, clockIdx, "Clock color")
|
||||
build(menuIconColorBase, iconIdx, "Tray icon color")
|
||||
addStyleMenu(menu)
|
||||
}
|
||||
|
||||
func handleColorCommand(cmd uintptr) bool {
|
||||
n := uintptr(len(palette))
|
||||
switch {
|
||||
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
||||
logoIdx = int(cmd - menuLogoColorBase)
|
||||
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
||||
clockIdx = int(cmd - menuClockColorBase)
|
||||
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
||||
iconIdx = int(cmd - menuIconColorBase)
|
||||
case handleStyleCommand(cmd):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
saveColors()
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------- painting ----------
|
||||
|
||||
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
|
||||
// and returns its pixels at the real orientation. fills and fg choose which
|
||||
// parts are painted; base is the color everything is painted onto.
|
||||
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
||||
layerFills, layerFg = fills, fg
|
||||
defer func() { layerFills, layerFg = true, true }()
|
||||
|
||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(mem)
|
||||
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
var bits unsafe.Pointer
|
||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if bmp == 0 || bits == nil {
|
||||
return nil
|
||||
}
|
||||
defer pDeleteObject.Call(bmp)
|
||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||
defer pSelectObject.Call(mem, old)
|
||||
|
||||
fillRaw(mem, rect{0, 0, w, h}, base)
|
||||
sr := startRect(w, h)
|
||||
if hoverStart {
|
||||
fill(mem, sr, rgb(58, 58, 68))
|
||||
}
|
||||
drawLogo(mem, sr)
|
||||
drawApps(mem, w, h)
|
||||
drawTray(mem, w, h)
|
||||
pGdiFlush.Call()
|
||||
|
||||
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
||||
if !vertical {
|
||||
out := make([]uint32, len(src))
|
||||
copy(out, src)
|
||||
return out
|
||||
}
|
||||
|
||||
// Turn a quarter turn, then put the icons and symbols back on upright.
|
||||
fw, fh := h, w
|
||||
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
||||
var bitsV unsafe.Pointer
|
||||
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
||||
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
||||
if bmpV == 0 || bitsV == nil {
|
||||
return nil
|
||||
}
|
||||
defer pDeleteObject.Call(bmpV)
|
||||
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(memV)
|
||||
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
||||
defer pSelectObject.Call(memV, oldV)
|
||||
|
||||
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
||||
for y := int32(0); y < h; y++ {
|
||||
for x := int32(0); x < w; x++ {
|
||||
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
||||
}
|
||||
}
|
||||
if fg {
|
||||
for i, r := range appRects(w, h) {
|
||||
if i < len(apps) {
|
||||
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||
}
|
||||
}
|
||||
for _, it := range trayItems(w, h) {
|
||||
r := mapRect(it.r, h)
|
||||
switch it.kind {
|
||||
case trayBattery:
|
||||
drawBattery(memV, r)
|
||||
case trayVolume:
|
||||
drawVolume(memV, r)
|
||||
case trayWifi:
|
||||
drawNetwork(memV, r)
|
||||
case trayChevron:
|
||||
drawChevron(memV, r)
|
||||
case trayWeather:
|
||||
drawWeatherIcon(memV, r)
|
||||
case trayNews:
|
||||
drawNewsIcon(memV, r)
|
||||
case traySys:
|
||||
drawSysIcon(memV, r)
|
||||
case trayGM:
|
||||
drawGMIcon(memV, r)
|
||||
}
|
||||
}
|
||||
pGdiFlush.Call()
|
||||
}
|
||||
out := make([]uint32, len(dst))
|
||||
copy(out, dst)
|
||||
return out
|
||||
}
|
||||
|
||||
// avg4 averages the superSample x superSample block of pixels that makes up
|
||||
// one real pixel, one color channel at a time.
|
||||
func avg4(p []uint32, stride, x, y int) (r, g, b uint32) {
|
||||
var sr, sg, sb uint32
|
||||
for dy := 0; dy < superSample; dy++ {
|
||||
for dx := 0; dx < superSample; dx++ {
|
||||
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
||||
sr += c >> 16 & 0xFF
|
||||
sg += c >> 8 & 0xFF
|
||||
sb += c & 0xFF
|
||||
}
|
||||
}
|
||||
n := uint32(superSample * superSample)
|
||||
return sr / n, sg / n, sb / n
|
||||
}
|
||||
|
||||
// redraw paints the whole bar and hands it to Windows as a layered window
|
||||
// with a transparency value for every pixel.
|
||||
func redraw(hwnd uintptr) {
|
||||
if hwnd == 0 {
|
||||
return
|
||||
}
|
||||
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
||||
pw, ph := pillSize()
|
||||
var crc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
||||
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
||||
x, y := pillPos(pw, ph)
|
||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
||||
}
|
||||
w, h := clientSize(hwnd)
|
||||
if w <= 0 || h <= 0 {
|
||||
return
|
||||
}
|
||||
fw, fh := w, h
|
||||
if vertical {
|
||||
fw, fh = h, w
|
||||
}
|
||||
|
||||
screen, _, _ := pGetDC.Call(0)
|
||||
defer pReleaseDC.Call(0, screen)
|
||||
|
||||
// Layer 1: backgrounds, at real size.
|
||||
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
||||
|
||||
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
||||
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
||||
scale *= superSample
|
||||
fontTime, fontApp = fontTime2, fontApp2
|
||||
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
|
||||
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
|
||||
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
||||
|
||||
n := int(fw) * int(fh)
|
||||
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
|
||||
return
|
||||
}
|
||||
|
||||
// The finished bitmap that Windows will show.
|
||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(mem)
|
||||
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
var bits unsafe.Pointer
|
||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if bmp == 0 || bits == nil {
|
||||
return
|
||||
}
|
||||
defer pDeleteObject.Call(bmp)
|
||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||
defer pSelectObject.Call(mem, old)
|
||||
pix := unsafe.Slice((*uint32)(bits), n)
|
||||
|
||||
a := uint32(bgAlpha)
|
||||
hoverA := max(a, 120)
|
||||
length := float64(max(fw, fh))
|
||||
rad := float64(min(fw, fh)) / 2
|
||||
stride := int(fw) * superSample
|
||||
|
||||
for i := range pix {
|
||||
x, y := i%int(fw), i/int(fw)
|
||||
|
||||
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
||||
c := bgPix[i] & 0x00FFFFFF
|
||||
bgA := a
|
||||
if c != colBg {
|
||||
bgA = hoverA
|
||||
}
|
||||
bgR := (c >> 16 & 0xFF) * bgA / 255
|
||||
bgG := (c >> 8 & 0xFF) * bgA / 255
|
||||
bgB := (c & 0xFF) * bgA / 255
|
||||
|
||||
// Foreground: how solid is this pixel, and what color is it.
|
||||
br, bgn, bb := avg4(onBlack, stride, x, y)
|
||||
wr, wg, wb := avg4(onWhite, stride, x, y)
|
||||
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
|
||||
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
|
||||
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
||||
|
||||
// Foreground over background.
|
||||
inv := 255 - fa
|
||||
oa := fa + bgA*inv/255
|
||||
or := fr + bgR*inv/255
|
||||
og := fg + bgG*inv/255
|
||||
ob := fb + bgB*inv/255
|
||||
|
||||
// Rounded ends: how much of this pixel is inside the pill.
|
||||
along := float64(x) + 0.5
|
||||
across := float64(y) + 0.5
|
||||
if vertical {
|
||||
along, across = across, along
|
||||
}
|
||||
da := 0.0
|
||||
if along < rad {
|
||||
da = rad - along
|
||||
} else if along > length-rad {
|
||||
da = along - (length - rad)
|
||||
}
|
||||
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
|
||||
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
|
||||
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
|
||||
}
|
||||
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
dst := point{wr.Left, wr.Top}
|
||||
sz := size{fw, fh}
|
||||
src := point{0, 0}
|
||||
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
||||
pUpdateLayeredWindow.Call(hwnd, screen,
|
||||
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
|
||||
mem, uintptr(unsafe.Pointer(&src)), 0,
|
||||
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
||||
}
|
||||
|
||||
func sub0(a, b uint32) uint32 {
|
||||
if a > b {
|
||||
return a - b
|
||||
}
|
||||
return 0
|
||||
}
|
||||
package main
|
||||
|
||||
// Painting the bar smoothly on a see-through background.
|
||||
//
|
||||
// Drawing icons and text straight onto a dark bitmap leaves a dark fringe
|
||||
// around them once the background is made see-through. So the bar is painted
|
||||
// in layers: one layer with only the backgrounds, and the icons, text and
|
||||
// symbols drawn twice (once on black, once on white) at double size. Comparing
|
||||
// the two copies shows exactly how see-through every edge pixel is, and
|
||||
// shrinking back down gives smooth edges with no dark outline.
|
||||
|
||||
import (
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
superSample = 2
|
||||
mfPopup = 0x0010
|
||||
|
||||
menuLogoColorBase = 100
|
||||
menuClockColorBase = 120
|
||||
menuIconColorBase = 140
|
||||
)
|
||||
|
||||
var (
|
||||
fontTime2 uintptr
|
||||
fontApp2 uintptr
|
||||
)
|
||||
|
||||
// initSuperFonts makes the double size fonts used for the smooth pass.
|
||||
func initSuperFonts() {
|
||||
scale *= superSample
|
||||
fontTime2 = makeFont(px(13), 400)
|
||||
fontApp2 = makeFont(px(12), 600)
|
||||
scale /= superSample
|
||||
}
|
||||
|
||||
// ---------- colors ----------
|
||||
|
||||
type namedColor struct {
|
||||
name string
|
||||
r, g, b int
|
||||
}
|
||||
|
||||
var palette = []namedColor{
|
||||
{"White", 245, 245, 245},
|
||||
{"Blue", 0, 120, 212},
|
||||
{"Sky blue", 90, 190, 255},
|
||||
{"Green", 70, 200, 110},
|
||||
{"Yellow", 255, 205, 60},
|
||||
{"Orange", 255, 140, 40},
|
||||
{"Red", 235, 70, 70},
|
||||
{"Pink", 255, 125, 195},
|
||||
{"Purple", 175, 115, 240},
|
||||
{"Black", 0, 0, 0},
|
||||
{"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},
|
||||
}
|
||||
|
||||
var (
|
||||
logoIdx = 1 // Blue, like the real Windows logo
|
||||
clockIdx = 0 // White
|
||||
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
||||
)
|
||||
|
||||
func colorOf(i int) uintptr {
|
||||
if i < 0 || i >= len(palette) {
|
||||
i = 0
|
||||
}
|
||||
c := palette[i]
|
||||
r, g, b := styleColor(c.r, c.g, c.b)
|
||||
return rgb(r, g, b)
|
||||
}
|
||||
|
||||
func logoColor() uintptr { return colorOf(logoIdx) }
|
||||
func clockColor() uintptr { return colorOf(clockIdx) }
|
||||
func iconColor() uintptr { return colorOf(iconIdx) }
|
||||
|
||||
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
||||
func iconDim() uintptr {
|
||||
c := palette[iconIdx]
|
||||
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
||||
return rgb(140, 140, 150)
|
||||
}
|
||||
return rgb(110, 110, 120)
|
||||
}
|
||||
|
||||
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
||||
|
||||
func loadColors() {
|
||||
b, err := os.ReadFile(colorsFile())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
||||
if len(parts) < 2 || len(parts) > 3 {
|
||||
return
|
||||
}
|
||||
vals := []int{0, 0, 0}
|
||||
for i, p := range parts {
|
||||
n, err := strconv.Atoi(p)
|
||||
if err != nil || n < 0 || n >= len(palette) {
|
||||
return
|
||||
}
|
||||
vals[i] = n
|
||||
}
|
||||
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
||||
}
|
||||
|
||||
func saveColors() {
|
||||
_ = os.MkdirAll(dataDir(), 0o755)
|
||||
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
||||
}
|
||||
|
||||
// addColorMenus adds the two color pickers as sub menus.
|
||||
func addColorMenus(menu uintptr) {
|
||||
build := func(base uintptr, cur int, title string) {
|
||||
sub, _, _ := pCreatePopupMenu.Call()
|
||||
for i, c := range palette {
|
||||
var flags uintptr
|
||||
if i == cur {
|
||||
flags = mfChecked
|
||||
}
|
||||
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
||||
}
|
||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
||||
}
|
||||
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
||||
build(menuClockColorBase, clockIdx, "Clock color")
|
||||
build(menuIconColorBase, iconIdx, "Tray icon color")
|
||||
addStyleMenu(menu)
|
||||
}
|
||||
|
||||
func handleColorCommand(cmd uintptr) bool {
|
||||
n := uintptr(len(palette))
|
||||
switch {
|
||||
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
||||
logoIdx = int(cmd - menuLogoColorBase)
|
||||
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
||||
clockIdx = int(cmd - menuClockColorBase)
|
||||
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
||||
iconIdx = int(cmd - menuIconColorBase)
|
||||
case handleStyleCommand(cmd):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
saveColors()
|
||||
return true
|
||||
}
|
||||
|
||||
// ---------- painting ----------
|
||||
|
||||
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
|
||||
// and returns its pixels at the real orientation. fills and fg choose which
|
||||
// parts are painted; base is the color everything is painted onto.
|
||||
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
||||
layerFills, layerFg = fills, fg
|
||||
defer func() { layerFills, layerFg = true, true }()
|
||||
|
||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(mem)
|
||||
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
var bits unsafe.Pointer
|
||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if bmp == 0 || bits == nil {
|
||||
return nil
|
||||
}
|
||||
defer pDeleteObject.Call(bmp)
|
||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||
defer pSelectObject.Call(mem, old)
|
||||
|
||||
fillRaw(mem, rect{0, 0, w, h}, base)
|
||||
sr := startRect(w, h)
|
||||
if hoverStart {
|
||||
fill(mem, sr, rgb(58, 58, 68))
|
||||
}
|
||||
drawLogo(mem, sr)
|
||||
drawApps(mem, w, h)
|
||||
drawTray(mem, w, h)
|
||||
pGdiFlush.Call()
|
||||
|
||||
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
||||
if !vertical {
|
||||
out := make([]uint32, len(src))
|
||||
copy(out, src)
|
||||
return out
|
||||
}
|
||||
|
||||
// Turn a quarter turn, then put the icons and symbols back on upright.
|
||||
fw, fh := h, w
|
||||
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
||||
var bitsV unsafe.Pointer
|
||||
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
||||
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
||||
if bmpV == 0 || bitsV == nil {
|
||||
return nil
|
||||
}
|
||||
defer pDeleteObject.Call(bmpV)
|
||||
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(memV)
|
||||
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
||||
defer pSelectObject.Call(memV, oldV)
|
||||
|
||||
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
||||
for y := int32(0); y < h; y++ {
|
||||
for x := int32(0); x < w; x++ {
|
||||
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
||||
}
|
||||
}
|
||||
if fg {
|
||||
if logoStyle != 0 {
|
||||
drawLogoStyle(memV, mapRect(sr, h))
|
||||
}
|
||||
for i, r := range appRects(w, h) {
|
||||
if i < len(apps) {
|
||||
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||
}
|
||||
}
|
||||
for _, it := range trayItems(w, h) {
|
||||
r := mapRect(it.r, h)
|
||||
switch it.kind {
|
||||
case trayBattery:
|
||||
drawBattery(memV, r)
|
||||
case trayVolume:
|
||||
drawVolume(memV, r)
|
||||
case trayWifi:
|
||||
drawNetwork(memV, r)
|
||||
case trayChevron:
|
||||
drawChevron(memV, r)
|
||||
case trayWeather:
|
||||
drawWeatherIcon(memV, r)
|
||||
case trayNews:
|
||||
drawNewsIcon(memV, r)
|
||||
case traySys:
|
||||
drawSysIcon(memV, r)
|
||||
case trayGM:
|
||||
drawGMIcon(memV, r)
|
||||
}
|
||||
}
|
||||
pGdiFlush.Call()
|
||||
}
|
||||
out := make([]uint32, len(dst))
|
||||
copy(out, dst)
|
||||
return out
|
||||
}
|
||||
|
||||
// avg4 averages the superSample x superSample block of pixels that makes up
|
||||
// one real pixel, one color channel at a time.
|
||||
func avg4(p []uint32, stride, x, y int) (r, g, b uint32) {
|
||||
var sr, sg, sb uint32
|
||||
for dy := 0; dy < superSample; dy++ {
|
||||
for dx := 0; dx < superSample; dx++ {
|
||||
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
||||
sr += c >> 16 & 0xFF
|
||||
sg += c >> 8 & 0xFF
|
||||
sb += c & 0xFF
|
||||
}
|
||||
}
|
||||
n := uint32(superSample * superSample)
|
||||
return sr / n, sg / n, sb / n
|
||||
}
|
||||
|
||||
// redraw paints the whole bar and hands it to Windows as a layered window
|
||||
// with a transparency value for every pixel.
|
||||
func redraw(hwnd uintptr) {
|
||||
if hwnd == 0 {
|
||||
return
|
||||
}
|
||||
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
||||
pw, ph := pillSize()
|
||||
var crc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
||||
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
||||
x, y := pillPos(pw, ph)
|
||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
||||
}
|
||||
w, h := clientSize(hwnd)
|
||||
if w <= 0 || h <= 0 {
|
||||
return
|
||||
}
|
||||
fw, fh := w, h
|
||||
if vertical {
|
||||
fw, fh = h, w
|
||||
}
|
||||
|
||||
screen, _, _ := pGetDC.Call(0)
|
||||
defer pReleaseDC.Call(0, screen)
|
||||
|
||||
// Layer 1: backgrounds, at real size.
|
||||
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
||||
|
||||
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
||||
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
||||
scale *= superSample
|
||||
fontTime, fontApp = fontTime2, fontApp2
|
||||
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
|
||||
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
|
||||
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
||||
|
||||
n := int(fw) * int(fh)
|
||||
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
|
||||
return
|
||||
}
|
||||
|
||||
// The finished bitmap that Windows will show.
|
||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||
defer pDeleteDC.Call(mem)
|
||||
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||
var bits unsafe.Pointer
|
||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||
if bmp == 0 || bits == nil {
|
||||
return
|
||||
}
|
||||
defer pDeleteObject.Call(bmp)
|
||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||
defer pSelectObject.Call(mem, old)
|
||||
pix := unsafe.Slice((*uint32)(bits), n)
|
||||
|
||||
a := uint32(bgAlpha)
|
||||
hoverA := max(a, 120)
|
||||
barC := barRGB()
|
||||
lightBar := barIsLight()
|
||||
length := float64(max(fw, fh))
|
||||
rad := float64(min(fw, fh)) / 2
|
||||
stride := int(fw) * superSample
|
||||
|
||||
for i := range pix {
|
||||
x, y := i%int(fw), i/int(fw)
|
||||
|
||||
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
||||
c := bgPix[i] & 0x00FFFFFF
|
||||
bgA := a
|
||||
if c != colBg {
|
||||
bgA = hoverA
|
||||
c = hoverTint(c, lightBar)
|
||||
} else {
|
||||
c = barC
|
||||
}
|
||||
bgR := (c >> 16 & 0xFF) * bgA / 255
|
||||
bgG := (c >> 8 & 0xFF) * bgA / 255
|
||||
bgB := (c & 0xFF) * bgA / 255
|
||||
|
||||
// Foreground: how solid is this pixel, and what color is it.
|
||||
br, bgn, bb := avg4(onBlack, stride, x, y)
|
||||
wr, wg, wb := avg4(onWhite, stride, x, y)
|
||||
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
|
||||
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
|
||||
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
||||
|
||||
// Foreground over background.
|
||||
inv := 255 - fa
|
||||
oa := fa + bgA*inv/255
|
||||
or := fr + bgR*inv/255
|
||||
og := fg + bgG*inv/255
|
||||
ob := fb + bgB*inv/255
|
||||
|
||||
// Rounded ends: how much of this pixel is inside the pill.
|
||||
along := float64(x) + 0.5
|
||||
across := float64(y) + 0.5
|
||||
if vertical {
|
||||
along, across = across, along
|
||||
}
|
||||
da := 0.0
|
||||
if along < rad {
|
||||
da = rad - along
|
||||
} else if along > length-rad {
|
||||
da = along - (length - rad)
|
||||
}
|
||||
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
|
||||
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
|
||||
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
|
||||
}
|
||||
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
dst := point{wr.Left, wr.Top}
|
||||
sz := size{fw, fh}
|
||||
src := point{0, 0}
|
||||
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
||||
pUpdateLayeredWindow.Call(hwnd, screen,
|
||||
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
|
||||
mem, uintptr(unsafe.Pointer(&src)), 0,
|
||||
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
||||
}
|
||||
|
||||
func sub0(a, b uint32) uint32 {
|
||||
if a > b {
|
||||
return a - b
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
+450
-373
@@ -1,373 +1,450 @@
|
||||
package main
|
||||
|
||||
// The settings window: everything the right-click menu can change, in one
|
||||
// place. It opens from "MirrorBar settings..." in the menu. Changes apply the
|
||||
// moment you make them, and the window stays in step if the menu is used too.
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pSendMessage = user32.NewProc("SendMessageW")
|
||||
pSetWindowText = user32.NewProc("SetWindowTextW")
|
||||
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
|
||||
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
||||
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
|
||||
pGetFocus = user32.NewProc("GetFocus")
|
||||
)
|
||||
|
||||
const (
|
||||
menuSettingsID = 45
|
||||
|
||||
wmCommand = 0x0111
|
||||
wmHScroll = 0x0114
|
||||
wmSetFont = 0x0030
|
||||
|
||||
wsChild = 0x40000000
|
||||
wsTabStop = 0x00010000
|
||||
wsVScroll = 0x00200000
|
||||
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
|
||||
wsBorder = 0x00800000
|
||||
bsPushButton = 0x0000
|
||||
bsDefPushButton = 0x0001
|
||||
bsAutoCheckBox = 0x0003
|
||||
cbsDropDownList = 0x0003
|
||||
tbsNoTicks = 0x0010
|
||||
esAutoHScroll = 0x0080
|
||||
esNumber = 0x2000
|
||||
|
||||
emSetLimitText = 0x00C5
|
||||
enChange = 0x0300
|
||||
|
||||
bmGetCheck = 0x00F0
|
||||
bmSetCheck = 0x00F1
|
||||
cbAddString = 0x0143
|
||||
cbGetCurSel = 0x0147
|
||||
cbSetCurSel = 0x014E
|
||||
tbmGetPos = 0x0400
|
||||
tbmSetPos = 0x0405
|
||||
tbmSetRange = 0x0406
|
||||
|
||||
cbnSelChange = 1
|
||||
tbEndTrack = 8
|
||||
colorBtnFace = 15
|
||||
|
||||
idAlpha = 200
|
||||
idAlphaValue = 201
|
||||
idLogo = 202
|
||||
idClock = 203
|
||||
idTrayIcons = 204
|
||||
idStyle = 205
|
||||
idVertical = 206
|
||||
idAutostart = 207
|
||||
idResetPos = 208
|
||||
idResetWidth = 209
|
||||
idClose = 210
|
||||
idZip = 211
|
||||
idZipStatus = 212
|
||||
idShowWeather = 213
|
||||
idShowNews = 214
|
||||
idShowSys = 215
|
||||
idPanelFade = 216
|
||||
idShowGM = 217
|
||||
)
|
||||
|
||||
var (
|
||||
hwndSettings uintptr
|
||||
settingsClass bool
|
||||
settingsFont uintptr
|
||||
|
||||
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
||||
ctlVertical, ctlAutostart uintptr
|
||||
ctlZip, ctlZipStatus uintptr
|
||||
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
|
||||
zipSyncing bool // true while the program itself is filling in the ZIP box
|
||||
)
|
||||
|
||||
func boolWP(b bool) uintptr {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// makeControl creates one child control; sizes are in 96 dpi units.
|
||||
func makeControl(parent, inst uintptr, class, text string, style uintptr, x, y, w, h int, id uintptr) uintptr {
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(u16(class))), uintptr(unsafe.Pointer(u16(text))),
|
||||
style|wsChild|wsVisible,
|
||||
uintptr(px(float64(x))), uintptr(px(float64(y))), uintptr(px(float64(w))), uintptr(px(float64(h))),
|
||||
parent, id, inst, 0)
|
||||
if hw != 0 && settingsFont != 0 {
|
||||
pSendMessage.Call(hw, wmSetFont, settingsFont, 1)
|
||||
}
|
||||
return hw
|
||||
}
|
||||
|
||||
func openSettings() {
|
||||
if hwndSettings != 0 {
|
||||
pShowWindow.Call(hwndSettings, swRestore)
|
||||
pSetForegroundWindow.Call(hwndSettings)
|
||||
settingsSync()
|
||||
return
|
||||
}
|
||||
inst, _, _ := pGetModuleHandle.Call(0)
|
||||
className := u16("MirrorBarSettings")
|
||||
if !settingsClass {
|
||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||
wc := wndClassEx{
|
||||
WndProc: syscall.NewCallback(settingsProc),
|
||||
Instance: inst,
|
||||
Cursor: cursor,
|
||||
Background: colorBtnFace + 1,
|
||||
ClassName: className,
|
||||
}
|
||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||
icc := struct{ Size, Classes uint32 }{8, 0x4} // ICC_BAR_CLASSES: the slider
|
||||
pInitCommonControls.Call(uintptr(unsafe.Pointer(&icc)))
|
||||
settingsClass = true
|
||||
}
|
||||
if settingsFont == 0 {
|
||||
settingsFont = makeFont(px(13), 400)
|
||||
}
|
||||
|
||||
r := rect{0, 0, px(400), px(516)}
|
||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||
sw, sh := screenSize()
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16("MirrorBar settings"))),
|
||||
wsWindowFrame,
|
||||
uintptr(max(0, (sw-ow)/2)), uintptr(max(0, (sh-oh)/2)), uintptr(ow), uintptr(oh),
|
||||
0, 0, inst, 0)
|
||||
if hw == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
label := func(text string, y int) {
|
||||
makeControl(hw, inst, "STATIC", text, 0, 16, y+4, 150, 20, 0)
|
||||
}
|
||||
combo := func(y int, id uintptr) uintptr {
|
||||
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 170, y, 214, 200, id)
|
||||
}
|
||||
|
||||
label("Background opacity", 16)
|
||||
ctlAlpha = makeControl(hw, inst, "msctls_trackbar32", "", tbsNoTicks|wsTabStop, 166, 14, 170, 28, idAlpha)
|
||||
ctlAlphaValue = makeControl(hw, inst, "STATIC", "", 0, 344, 20, 44, 20, idAlphaValue)
|
||||
pSendMessage.Call(ctlAlpha, tbmSetRange, 1, uintptr(3|255<<16))
|
||||
|
||||
label("Windows logo color", 60)
|
||||
ctlLogo = combo(60, idLogo)
|
||||
label("Clock color", 96)
|
||||
ctlClock = combo(96, idClock)
|
||||
label("Tray icon color", 132)
|
||||
ctlTrayIcons = combo(132, idTrayIcons)
|
||||
label("Icon style", 168)
|
||||
ctlStyle = combo(168, idStyle)
|
||||
for _, c := range []uintptr{ctlLogo, ctlClock, ctlTrayIcons} {
|
||||
for _, p := range palette {
|
||||
pSendMessage.Call(c, cbAddString, 0, uintptr(unsafe.Pointer(u16(p.name))))
|
||||
}
|
||||
}
|
||||
for _, n := range styleNames {
|
||||
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||
}
|
||||
|
||||
label("ZIP code", 204)
|
||||
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
|
||||
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
|
||||
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
|
||||
|
||||
ctlShowWeather = makeControl(hw, inst, "BUTTON", "Show weather on the bar", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idShowWeather)
|
||||
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, 470, 116, 28, idResetPos)
|
||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 470, 116, 28, idResetWidth)
|
||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 470, 92, 28, idClose)
|
||||
|
||||
hwndSettings = hw
|
||||
settingsSync()
|
||||
pShowWindow.Call(hw, 1)
|
||||
pSetForegroundWindow.Call(hw)
|
||||
}
|
||||
|
||||
// settingsSync makes every control show the current setting.
|
||||
func settingsSync() {
|
||||
if hwndSettings == 0 {
|
||||
return
|
||||
}
|
||||
pSendMessage.Call(ctlAlpha, tbmSetPos, 1, uintptr(bgAlpha))
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
pSendMessage.Call(ctlLogo, cbSetCurSel, uintptr(logoIdx), 0)
|
||||
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
||||
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 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(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
||||
|
||||
// Leave the ZIP box alone while the person is typing in it.
|
||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||
zipSyncing = true
|
||||
pSetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(u16(wxZip))))
|
||||
zipSyncing = false
|
||||
}
|
||||
settingsZipStatusUpdate()
|
||||
}
|
||||
|
||||
// zipText is what is typed in the ZIP box right now.
|
||||
func zipText() string {
|
||||
var buf [32]uint16
|
||||
n, _, _ := pGetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
|
||||
return syscall.UTF16ToString(buf[:n])
|
||||
}
|
||||
|
||||
// settingsZipStatusUpdate refreshes the line under the ZIP box ("Showing weather for ...").
|
||||
func settingsZipStatusUpdate() {
|
||||
if hwndSettings == 0 || ctlZipStatus == 0 {
|
||||
return
|
||||
}
|
||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(zipStatusText()))))
|
||||
}
|
||||
|
||||
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
||||
// for that ZIP code; an empty box turns it off.
|
||||
func zipEdited() {
|
||||
z := onlyDigits(zipText())
|
||||
switch {
|
||||
case len(z) == 5:
|
||||
weatherSetZip(z)
|
||||
case z == "":
|
||||
weatherSetZip("")
|
||||
default:
|
||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16("A ZIP code has 5 digits."))))
|
||||
return
|
||||
}
|
||||
settingsZipStatusUpdate()
|
||||
}
|
||||
|
||||
func comboChoice(c uintptr) int {
|
||||
r, _, _ := pSendMessage.Call(c, cbGetCurSel, 0, 0)
|
||||
return int(int32(r))
|
||||
}
|
||||
|
||||
func checked(c uintptr) bool {
|
||||
r, _, _ := pSendMessage.Call(c, bmGetCheck, 0, 0)
|
||||
return r == 1
|
||||
}
|
||||
|
||||
func settingsCommand(id, note uintptr) {
|
||||
switch id {
|
||||
case 1, 2: // Enter and Esc
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idClose:
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idLogo, idClock, idTrayIcons:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
case idLogo:
|
||||
if i := comboChoice(ctlLogo); i >= 0 {
|
||||
logoIdx = i
|
||||
}
|
||||
case idClock:
|
||||
if i := comboChoice(ctlClock); i >= 0 {
|
||||
clockIdx = i
|
||||
}
|
||||
case idTrayIcons:
|
||||
if i := comboChoice(ctlTrayIcons); i >= 0 {
|
||||
iconIdx = i
|
||||
}
|
||||
}
|
||||
saveColors()
|
||||
redraw(hwndMain)
|
||||
flyRefreshAll()
|
||||
case idStyle:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
if i := comboChoice(ctlStyle); i >= 0 && i < len(styleNames) {
|
||||
iconMode = i
|
||||
saveIconMode()
|
||||
styleCacheClear()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
case idZip:
|
||||
if note == enChange && !zipSyncing {
|
||||
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:
|
||||
vertical = checked(ctlVertical)
|
||||
saveOrient()
|
||||
resetPos(hwndMain)
|
||||
case idAutostart:
|
||||
setAutostart(checked(ctlAutostart))
|
||||
settingsSync()
|
||||
case idResetPos:
|
||||
resetPos(hwndMain)
|
||||
case idResetWidth:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
}
|
||||
|
||||
func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
switch uint32(m) {
|
||||
case wmCommand:
|
||||
settingsCommand(wparam&0xFFFF, wparam>>16&0xFFFF)
|
||||
return 0
|
||||
case wmHScroll:
|
||||
if lparam == ctlAlpha && ctlAlpha != 0 {
|
||||
pos, _, _ := pSendMessage.Call(ctlAlpha, tbmGetPos, 0, 0)
|
||||
n := int(pos)
|
||||
if n >= 3 && n <= 255 && n != bgAlpha {
|
||||
bgAlpha = n
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
redraw(hwndMain)
|
||||
flyRefreshAll()
|
||||
}
|
||||
if wparam&0xFFFF == tbEndTrack {
|
||||
saveAlpha()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
case wmClose:
|
||||
pDestroyWindow.Call(hwnd)
|
||||
return 0
|
||||
case wmDestroy:
|
||||
hwndSettings = 0
|
||||
return 0
|
||||
}
|
||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||
return r
|
||||
}
|
||||
package main
|
||||
|
||||
// The settings window: everything the right-click menu can change, in one
|
||||
// place. It opens from "MirrorBar settings..." in the menu. Changes apply the
|
||||
// moment you make them, and the window stays in step if the menu is used too.
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
pSendMessage = user32.NewProc("SendMessageW")
|
||||
pSetWindowText = user32.NewProc("SetWindowTextW")
|
||||
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
|
||||
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
||||
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
|
||||
pGetFocus = user32.NewProc("GetFocus")
|
||||
)
|
||||
|
||||
const (
|
||||
menuSettingsID = 45
|
||||
|
||||
wmCommand = 0x0111
|
||||
wmHScroll = 0x0114
|
||||
wmSetFont = 0x0030
|
||||
|
||||
wsChild = 0x40000000
|
||||
wsTabStop = 0x00010000
|
||||
wsVScroll = 0x00200000
|
||||
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
|
||||
wsBorder = 0x00800000
|
||||
bsPushButton = 0x0000
|
||||
bsDefPushButton = 0x0001
|
||||
bsAutoCheckBox = 0x0003
|
||||
cbsDropDownList = 0x0003
|
||||
tbsNoTicks = 0x0010
|
||||
esAutoHScroll = 0x0080
|
||||
esNumber = 0x2000
|
||||
|
||||
emSetLimitText = 0x00C5
|
||||
enChange = 0x0300
|
||||
|
||||
bmGetCheck = 0x00F0
|
||||
bmSetCheck = 0x00F1
|
||||
cbAddString = 0x0143
|
||||
cbGetCurSel = 0x0147
|
||||
cbSetCurSel = 0x014E
|
||||
tbmGetPos = 0x0400
|
||||
tbmSetPos = 0x0405
|
||||
tbmSetRange = 0x0406
|
||||
|
||||
cbnSelChange = 1
|
||||
tbEndTrack = 8
|
||||
colorBtnFace = 15
|
||||
|
||||
idAlpha = 200
|
||||
idAlphaValue = 201
|
||||
idLogo = 202
|
||||
idClock = 203
|
||||
idTrayIcons = 204
|
||||
idStyle = 205
|
||||
idVertical = 206
|
||||
idAutostart = 207
|
||||
idResetPos = 208
|
||||
idResetWidth = 209
|
||||
idClose = 210
|
||||
idZip = 211
|
||||
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
|
||||
)
|
||||
|
||||
var (
|
||||
hwndSettings uintptr
|
||||
settingsClass bool
|
||||
settingsFont uintptr
|
||||
|
||||
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
||||
ctlVertical, ctlAutostart uintptr
|
||||
ctlZip, ctlZipStatus uintptr
|
||||
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
|
||||
ctlGroup, ctlAutoHide uintptr
|
||||
ctlBarColor, ctlLogoStyle, ctlClockSize, ctlClockBold uintptr
|
||||
ctlShowBattery, ctlShowVolume, ctlShowWifi uintptr
|
||||
zipSyncing bool // true while the program itself is filling in the ZIP box
|
||||
)
|
||||
|
||||
func boolWP(b bool) uintptr {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// makeControl creates one child control; sizes are in 96 dpi units.
|
||||
func makeControl(parent, inst uintptr, class, text string, style uintptr, x, y, w, h int, id uintptr) uintptr {
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(u16(class))), uintptr(unsafe.Pointer(u16(text))),
|
||||
style|wsChild|wsVisible,
|
||||
uintptr(px(float64(x))), uintptr(px(float64(y))), uintptr(px(float64(w))), uintptr(px(float64(h))),
|
||||
parent, id, inst, 0)
|
||||
if hw != 0 && settingsFont != 0 {
|
||||
pSendMessage.Call(hw, wmSetFont, settingsFont, 1)
|
||||
}
|
||||
return hw
|
||||
}
|
||||
|
||||
func openSettings() {
|
||||
if hwndSettings != 0 {
|
||||
pShowWindow.Call(hwndSettings, swRestore)
|
||||
pSetForegroundWindow.Call(hwndSettings)
|
||||
settingsSync()
|
||||
return
|
||||
}
|
||||
inst, _, _ := pGetModuleHandle.Call(0)
|
||||
className := u16("MirrorBarSettings")
|
||||
if !settingsClass {
|
||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||
wc := wndClassEx{
|
||||
WndProc: syscall.NewCallback(settingsProc),
|
||||
Instance: inst,
|
||||
Cursor: cursor,
|
||||
Background: colorBtnFace + 1,
|
||||
ClassName: className,
|
||||
}
|
||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||
icc := struct{ Size, Classes uint32 }{8, 0x4} // ICC_BAR_CLASSES: the slider
|
||||
pInitCommonControls.Call(uintptr(unsafe.Pointer(&icc)))
|
||||
settingsClass = true
|
||||
}
|
||||
if settingsFont == 0 {
|
||||
settingsFont = makeFont(px(13), 400)
|
||||
}
|
||||
|
||||
r := rect{0, 0, px(800), px(572)}
|
||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||
sw, sh := screenSize()
|
||||
hw, _, _ := pCreateWindowEx.Call(0,
|
||||
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16("MirrorBar settings"))),
|
||||
wsWindowFrame,
|
||||
uintptr(max(0, (sw-ow)/2)), uintptr(max(0, (sh-oh)/2)), uintptr(ow), uintptr(oh),
|
||||
0, 0, inst, 0)
|
||||
if hw == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
label := func(text string, y int) {
|
||||
makeControl(hw, inst, "STATIC", text, 0, 16, y+4, 150, 20, 0)
|
||||
}
|
||||
combo := func(y int, id uintptr) uintptr {
|
||||
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 170, y, 214, 200, id)
|
||||
}
|
||||
|
||||
label("Background opacity", 16)
|
||||
ctlAlpha = makeControl(hw, inst, "msctls_trackbar32", "", tbsNoTicks|wsTabStop, 166, 14, 170, 28, idAlpha)
|
||||
ctlAlphaValue = makeControl(hw, inst, "STATIC", "", 0, 344, 20, 44, 20, idAlphaValue)
|
||||
pSendMessage.Call(ctlAlpha, tbmSetRange, 1, uintptr(3|255<<16))
|
||||
|
||||
label("Windows logo color", 60)
|
||||
ctlLogo = combo(60, idLogo)
|
||||
label("Clock color", 96)
|
||||
ctlClock = combo(96, idClock)
|
||||
label("Tray icon color", 132)
|
||||
ctlTrayIcons = combo(132, idTrayIcons)
|
||||
label("Icon style", 168)
|
||||
ctlStyle = combo(168, idStyle)
|
||||
for _, c := range []uintptr{ctlLogo, ctlClock, ctlTrayIcons} {
|
||||
for _, p := range palette {
|
||||
pSendMessage.Call(c, cbAddString, 0, uintptr(unsafe.Pointer(u16(p.name))))
|
||||
}
|
||||
}
|
||||
for _, n := range styleNames {
|
||||
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||
}
|
||||
|
||||
label("ZIP code", 204)
|
||||
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
|
||||
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
|
||||
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
|
||||
|
||||
ctlShowWeather = makeControl(hw, inst, "BUTTON", "Show weather on the bar", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idShowWeather)
|
||||
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)
|
||||
|
||||
ctlGroup = makeControl(hw, inst, "BUTTON", "Combine windows of the same program into one icon", bsAutoCheckBox|wsTabStop, 16, 458, 368, 22, idGroup)
|
||||
ctlAutoHide = makeControl(hw, inst, "BUTTON", "Hide the bar until the mouse touches the screen edge", bsAutoCheckBox|wsTabStop, 16, 486, 368, 22, idAutoHide)
|
||||
|
||||
// The right-hand column: how the bar looks, and what is on it.
|
||||
combo2 := func(y int, id uintptr) uintptr {
|
||||
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 560, y, 224, 200, id)
|
||||
}
|
||||
label2 := func(text string, y int) {
|
||||
makeControl(hw, inst, "STATIC", text, 0, 416, y+4, 140, 20, 0)
|
||||
}
|
||||
label2("Bar color", 16)
|
||||
ctlBarColor = combo2(16, idBarColor)
|
||||
label2("Windows logo shape", 52)
|
||||
ctlLogoStyle = combo2(52, idLogoStyle)
|
||||
label2("Clock text size", 88)
|
||||
ctlClockSize = combo2(88, idClockSize)
|
||||
ctlClockBold = makeControl(hw, inst, "BUTTON", "Bold clock text", bsAutoCheckBox|wsTabStop, 416, 124, 368, 22, idClockBold)
|
||||
makeControl(hw, inst, "STATIC", "Show on the bar:", 0, 416, 172, 368, 20, 0)
|
||||
ctlShowBattery = makeControl(hw, inst, "BUTTON", "Battery", bsAutoCheckBox|wsTabStop, 416, 198, 368, 22, idShowBattery)
|
||||
ctlShowVolume = makeControl(hw, inst, "BUTTON", "Volume", bsAutoCheckBox|wsTabStop, 416, 226, 368, 22, idShowVolume)
|
||||
ctlShowWifi = makeControl(hw, inst, "BUTTON", "Wifi", bsAutoCheckBox|wsTabStop, 416, 254, 368, 22, idShowWifi)
|
||||
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))))
|
||||
}
|
||||
|
||||
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
|
||||
settingsSync()
|
||||
pShowWindow.Call(hw, 1)
|
||||
pSetForegroundWindow.Call(hw)
|
||||
}
|
||||
|
||||
// settingsSync makes every control show the current setting.
|
||||
func settingsSync() {
|
||||
if hwndSettings == 0 {
|
||||
return
|
||||
}
|
||||
pSendMessage.Call(ctlAlpha, tbmSetPos, 1, uintptr(bgAlpha))
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
pSendMessage.Call(ctlLogo, cbSetCurSel, uintptr(logoIdx), 0)
|
||||
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
||||
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 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(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(ctlShowBattery, bmSetCheck, boolWP(showBattery), 0)
|
||||
pSendMessage.Call(ctlShowVolume, bmSetCheck, boolWP(showVolume), 0)
|
||||
pSendMessage.Call(ctlShowWifi, bmSetCheck, boolWP(showWifi), 0)
|
||||
|
||||
// Leave the ZIP box alone while the person is typing in it.
|
||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||
zipSyncing = true
|
||||
pSetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(u16(wxZip))))
|
||||
zipSyncing = false
|
||||
}
|
||||
settingsZipStatusUpdate()
|
||||
}
|
||||
|
||||
// zipText is what is typed in the ZIP box right now.
|
||||
func zipText() string {
|
||||
var buf [32]uint16
|
||||
n, _, _ := pGetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
|
||||
return syscall.UTF16ToString(buf[:n])
|
||||
}
|
||||
|
||||
// settingsZipStatusUpdate refreshes the line under the ZIP box ("Showing weather for ...").
|
||||
func settingsZipStatusUpdate() {
|
||||
if hwndSettings == 0 || ctlZipStatus == 0 {
|
||||
return
|
||||
}
|
||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(zipStatusText()))))
|
||||
}
|
||||
|
||||
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
||||
// for that ZIP code; an empty box turns it off.
|
||||
func zipEdited() {
|
||||
z := onlyDigits(zipText())
|
||||
switch {
|
||||
case len(z) == 5:
|
||||
weatherSetZip(z)
|
||||
case z == "":
|
||||
weatherSetZip("")
|
||||
default:
|
||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16("A ZIP code has 5 digits."))))
|
||||
return
|
||||
}
|
||||
settingsZipStatusUpdate()
|
||||
}
|
||||
|
||||
func comboChoice(c uintptr) int {
|
||||
r, _, _ := pSendMessage.Call(c, cbGetCurSel, 0, 0)
|
||||
return int(int32(r))
|
||||
}
|
||||
|
||||
func checked(c uintptr) bool {
|
||||
r, _, _ := pSendMessage.Call(c, bmGetCheck, 0, 0)
|
||||
return r == 1
|
||||
}
|
||||
|
||||
func settingsCommand(id, note uintptr) {
|
||||
switch id {
|
||||
case 1, 2: // Enter and Esc
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idClose:
|
||||
pDestroyWindow.Call(hwndSettings)
|
||||
case idLogo, idClock, idTrayIcons:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
case idLogo:
|
||||
if i := comboChoice(ctlLogo); i >= 0 {
|
||||
logoIdx = i
|
||||
}
|
||||
case idClock:
|
||||
if i := comboChoice(ctlClock); i >= 0 {
|
||||
clockIdx = i
|
||||
}
|
||||
case idTrayIcons:
|
||||
if i := comboChoice(ctlTrayIcons); i >= 0 {
|
||||
iconIdx = i
|
||||
}
|
||||
}
|
||||
saveColors()
|
||||
redraw(hwndMain)
|
||||
flyRefreshAll()
|
||||
case idStyle:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
if i := comboChoice(ctlStyle); i >= 0 && i < len(styleNames) {
|
||||
iconMode = i
|
||||
saveIconMode()
|
||||
styleCacheClear()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
case idZip:
|
||||
if note == enChange && !zipSyncing {
|
||||
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:
|
||||
vertical = checked(ctlVertical)
|
||||
saveOrient()
|
||||
resetPos(hwndMain)
|
||||
case idGroup:
|
||||
setGroupWins(checked(ctlGroup))
|
||||
case idAutoHide:
|
||||
setAutoHide(checked(ctlAutoHide))
|
||||
case idBarColor, idLogoStyle, idClockSize:
|
||||
if note != cbnSelChange {
|
||||
return
|
||||
}
|
||||
switch id {
|
||||
case idBarColor:
|
||||
setBarColor(comboChoice(ctlBarColor))
|
||||
case idLogoStyle:
|
||||
setLogoStyle(comboChoice(ctlLogoStyle))
|
||||
case idClockSize:
|
||||
setClockSize(comboChoice(ctlClockSize))
|
||||
}
|
||||
case idClockBold:
|
||||
setClockBold(checked(ctlClockBold))
|
||||
case idShowBattery:
|
||||
setShowBattery(checked(ctlShowBattery))
|
||||
case idShowVolume:
|
||||
setShowVolume(checked(ctlShowVolume))
|
||||
case idShowWifi:
|
||||
setShowWifi(checked(ctlShowWifi))
|
||||
case idAutostart:
|
||||
setAutostart(checked(ctlAutostart))
|
||||
settingsSync()
|
||||
case idResetPos:
|
||||
resetPos(hwndMain)
|
||||
case idResetWidth:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwndMain)
|
||||
}
|
||||
}
|
||||
|
||||
func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
result = 0
|
||||
}
|
||||
}()
|
||||
switch uint32(m) {
|
||||
case wmCommand:
|
||||
settingsCommand(wparam&0xFFFF, wparam>>16&0xFFFF)
|
||||
return 0
|
||||
case wmHScroll:
|
||||
if lparam == ctlAlpha && ctlAlpha != 0 {
|
||||
pos, _, _ := pSendMessage.Call(ctlAlpha, tbmGetPos, 0, 0)
|
||||
n := int(pos)
|
||||
if n >= 3 && n <= 255 && n != bgAlpha {
|
||||
bgAlpha = n
|
||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||
redraw(hwndMain)
|
||||
flyRefreshAll()
|
||||
}
|
||||
if wparam&0xFFFF == tbEndTrack {
|
||||
saveAlpha()
|
||||
}
|
||||
}
|
||||
return 0
|
||||
case wmClose:
|
||||
pDestroyWindow.Call(hwnd)
|
||||
return 0
|
||||
case wmDestroy:
|
||||
hwndSettings = 0
|
||||
return 0
|
||||
}
|
||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user