Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40370fce29 | ||
|
|
4f05e6e411 | ||
|
|
968bc0ad22 |
@@ -1,58 +1,60 @@
|
|||||||
# MirrorBar+
|
# MirrorBar+
|
||||||
|
|
||||||
MirrorBar+ is a small Windows 11 taskbar replacement, one exe, no installer, no dependencies.
|
MirrorBar+ is a small Windows 11 taskbar replacement, one exe, no installer, no dependencies.
|
||||||
|
|
||||||
The real taskbar is hidden and a see-through pill takes its place. The pill is a mirror image around its center line. To the left of center is the Start button, with your open apps as small icon-only buttons stretching further left. To the right of center is the clock (time and date on one line), then a little 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.
|
The real taskbar is hidden and a see-through pill takes its place. The pill is a mirror image around its center line. To the left of center is the Start button, with your open apps as small icon-only buttons stretching further left. To the right of center is the clock (time and date on one line), then a little sun-and-cloud for the weather, a little newspaper for local news, a little monitor for system stats, battery, volume, wifi and the ^ hidden-icons arrow stretching further right.
|
||||||
|
|
||||||
## What it does
|
## What it does
|
||||||
|
|
||||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
- 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.
|
- 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.
|
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||||
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
- Right-click and choose "Switch to vertical" to stand it up and down against the right edge of the screen.
|
||||||
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
- Right-click an app icon for the normal window options (Restore, Move, Size, Minimize, Maximize, Close) plus Open new window and Open file location.
|
||||||
- Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
- Drag the app icons and the Windows logo along the left row to reorder them. MirrorBar remembers the order of your apps and the logo's spot.
|
||||||
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
- Drag the clock, battery, volume, wifi and hidden-icons arrow along the right row to reorder them. That order is remembered.
|
||||||
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
- Rest the mouse on an app icon for a moment and a live preview of that window pops up beside the bar (minimized windows show their icon instead). Click the preview to switch to that window.
|
||||||
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
- Right-click an app icon and choose "Pin to MirrorBar" to keep it on the bar. A pinned app that isn't running shows as a launcher: click it to start the program, and when its window opens it takes that spot. Pinning works for normal programs; Store apps can't be pinned.
|
||||||
- "Open notification center" is in the right-click menu.
|
- "Open notification center" is in the right-click menu.
|
||||||
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
- Drag files from Explorer onto an app icon and that program opens them, running or pinned.
|
||||||
- "MirrorBar settings..." in the right-click menu opens one window for background opacity, the three colors, icon style, the 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.
|
- "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.
|
- 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 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 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.
|
||||||
|
|
||||||
- "Show weather on the bar" and "Show local news on the bar" in the settings window turn either feature off. The icon leaves the bar and nothing is downloaded for it; tick the box again and it comes back.
|
- 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.
|
||||||
|
|
||||||
- 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.
|
- "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.
|
||||||
|
|
||||||
- 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.
|
- 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.
|
||||||
- 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.
|
- 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.
|
||||||
- Background see-through level: Clear, Light, Medium or Solid.
|
- 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).
|
||||||
- "Start MirrorBar when I sign in" in the right-click menu.
|
- "Icon style" in the right-click menu: colorized or grayscale. It applies to the app icons and to the logo, clock and tray icons.
|
||||||
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
- Background see-through level: Clear, Light, Medium or Solid.
|
||||||
|
- "Start MirrorBar when I sign in" in the right-click menu.
|
||||||
## Safety
|
- Scroll over the speaker to change the volume. Click the clock, battery, volume or wifi for the matching Windows panel.
|
||||||
|
|
||||||
- `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.
|
## Safety
|
||||||
- Ctrl+Alt+Q quits and restores the taskbar.
|
|
||||||
- Right-click, "Exit MirrorBar and restore taskbar".
|
- `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.
|
||||||
- Hold Shift while it launches and it exits at once without touching anything.
|
- Ctrl+Alt+Q quits and restores the taskbar.
|
||||||
- `restore_taskbar.exe` (the same program, renamed) or `--restore` puts the normal taskbar back.
|
- Right-click, "Exit MirrorBar and restore taskbar".
|
||||||
|
- Hold Shift while it launches and it exits at once without touching anything.
|
||||||
## Download
|
- `restore_taskbar.exe` (the same program, renamed) or `--restore` puts the normal taskbar back.
|
||||||
|
|
||||||
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.
|
## Download
|
||||||
|
|
||||||
## Build
|
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.
|
||||||
|
|
||||||
Go 1.24 or newer, standard library only:
|
## 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 .
|
|
||||||
```
|
```
|
||||||
|
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-H=windowsgui -s -w" -o mirrorbar.exe .
|
||||||
Settings are kept in `%LOCALAPPDATA%\MirrorBar`.
|
```
|
||||||
|
|
||||||
|
Settings are kept in `%LOCALAPPDATA%\MirrorBar`.
|
||||||
|
|
||||||
|
|||||||
+146
-128
@@ -1,128 +1,146 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// The two optional features, weather and local news. Each can be turned off in
|
// 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
|
// the settings window: its icon leaves the bar, its panel is closed, and nothing
|
||||||
// is downloaded for it. Both are on until switched off.
|
// is downloaded for it. Both are on until switched off.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
showWeather = true
|
showWeather = true
|
||||||
showNews = true
|
showNews = true
|
||||||
showSys = true
|
showSys = true
|
||||||
)
|
showGM = true // the Google Messages bubble
|
||||||
|
)
|
||||||
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
|
||||||
|
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
||||||
func loadFeatures() {
|
|
||||||
b, err := os.ReadFile(featuresFile())
|
func loadFeatures() {
|
||||||
if err != nil {
|
b, err := os.ReadFile(featuresFile())
|
||||||
return
|
if err != nil {
|
||||||
}
|
return
|
||||||
for _, ln := range strings.Split(string(b), "\n") {
|
}
|
||||||
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
for _, ln := range strings.Split(string(b), "\n") {
|
||||||
if !ok {
|
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||||
continue
|
if !ok {
|
||||||
}
|
continue
|
||||||
on := strings.TrimSpace(v) != "0"
|
}
|
||||||
switch strings.TrimSpace(k) {
|
on := strings.TrimSpace(v) != "0"
|
||||||
case "weather":
|
switch strings.TrimSpace(k) {
|
||||||
showWeather = on
|
case "weather":
|
||||||
case "news":
|
showWeather = on
|
||||||
showNews = on
|
case "news":
|
||||||
case "sys":
|
showNews = on
|
||||||
showSys = on
|
case "sys":
|
||||||
case "panelfade":
|
showSys = on
|
||||||
flyMatchBar = on
|
case "messages":
|
||||||
}
|
showGM = on
|
||||||
}
|
case "panelfade":
|
||||||
}
|
flyMatchBar = on
|
||||||
|
}
|
||||||
func saveFeatures() {
|
}
|
||||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\npanelfade=" + b01(flyMatchBar) + "\n"
|
}
|
||||||
_ = os.MkdirAll(dataDir(), 0o755)
|
|
||||||
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
func saveFeatures() {
|
||||||
}
|
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\n"
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
func b01(b bool) string {
|
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
||||||
if b {
|
}
|
||||||
return "1"
|
|
||||||
}
|
func b01(b bool) string {
|
||||||
return "0"
|
if b {
|
||||||
}
|
return "1"
|
||||||
|
}
|
||||||
// setShowWeather is called by the settings window.
|
return "0"
|
||||||
func setShowWeather(on bool) {
|
}
|
||||||
if showWeather == on {
|
|
||||||
return
|
// setShowWeather is called by the settings window.
|
||||||
}
|
func setShowWeather(on bool) {
|
||||||
showWeather = on
|
if showWeather == on {
|
||||||
saveFeatures()
|
return
|
||||||
if on {
|
}
|
||||||
weatherRefresh(false)
|
showWeather = on
|
||||||
} else {
|
saveFeatures()
|
||||||
weatherHide()
|
if on {
|
||||||
}
|
weatherRefresh(false)
|
||||||
featuresChanged()
|
} else {
|
||||||
}
|
weatherHide()
|
||||||
|
}
|
||||||
// setShowNews is called by the settings window.
|
featuresChanged()
|
||||||
func setShowNews(on bool) {
|
}
|
||||||
if showNews == on {
|
|
||||||
return
|
// setShowNews is called by the settings window.
|
||||||
}
|
func setShowNews(on bool) {
|
||||||
showNews = on
|
if showNews == on {
|
||||||
saveFeatures()
|
return
|
||||||
if on {
|
}
|
||||||
newsRefresh(false)
|
showNews = on
|
||||||
} else {
|
saveFeatures()
|
||||||
newsHide()
|
if on {
|
||||||
}
|
newsRefresh(false)
|
||||||
featuresChanged()
|
} else {
|
||||||
}
|
newsHide()
|
||||||
|
}
|
||||||
// setShowSys is called by the settings window.
|
featuresChanged()
|
||||||
func setShowSys(on bool) {
|
}
|
||||||
if showSys == on {
|
|
||||||
return
|
// setShowSys is called by the settings window.
|
||||||
}
|
func setShowSys(on bool) {
|
||||||
showSys = on
|
if showSys == on {
|
||||||
saveFeatures()
|
return
|
||||||
if !on {
|
}
|
||||||
sysHide()
|
showSys = on
|
||||||
}
|
saveFeatures()
|
||||||
featuresChanged()
|
if !on {
|
||||||
}
|
sysHide()
|
||||||
|
}
|
||||||
// setFlyMatchBar is called by the settings window: should the panels be as
|
featuresChanged()
|
||||||
// see-through as the bar?
|
}
|
||||||
func setFlyMatchBar(on bool) {
|
|
||||||
if flyMatchBar == on {
|
// setShowGM is called by the settings window.
|
||||||
return
|
func setShowGM(on bool) {
|
||||||
}
|
if showGM == on {
|
||||||
flyMatchBar = on
|
return
|
||||||
saveFeatures()
|
}
|
||||||
flyRefreshAll()
|
showGM = on
|
||||||
}
|
saveFeatures()
|
||||||
|
if on {
|
||||||
func featuresChanged() {
|
gmAutoTried = false // let the background check start Messages again
|
||||||
settingsZipStatusUpdate()
|
} else {
|
||||||
redraw(hwndMain)
|
gmClose()
|
||||||
}
|
}
|
||||||
|
featuresChanged()
|
||||||
// zipStatusText is the one line the settings window shows under the ZIP box.
|
}
|
||||||
func zipStatusText() string {
|
|
||||||
switch {
|
// setFlyMatchBar is called by the settings window: should the panels be as
|
||||||
case !showWeather && !showNews:
|
// see-through as the bar?
|
||||||
return "Weather and news are both turned off."
|
func setFlyMatchBar(on bool) {
|
||||||
case wxZip == "":
|
if flyMatchBar == on {
|
||||||
return "Type a 5 digit ZIP code to turn on weather and local news."
|
return
|
||||||
case showWeather:
|
}
|
||||||
return weatherStatusText()
|
flyMatchBar = on
|
||||||
}
|
saveFeatures()
|
||||||
return newsStatusText()
|
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()
|
||||||
|
}
|
||||||
|
|||||||
+553
@@ -0,0 +1,553 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// The Google Messages flyout: a speech bubble on the bar that opens Messages for
|
||||||
|
// web (messages.google.com) in a small window above the bar, so you can read and
|
||||||
|
// answer texts without opening a browser tab.
|
||||||
|
//
|
||||||
|
// How it works: MirrorBar starts Microsoft Edge in "app" mode (no tabs, no address
|
||||||
|
// bar) with its own private profile folder, so the sign-in from pairing your phone
|
||||||
|
// is remembered and never touches your normal Edge. Edge is already on every
|
||||||
|
// Windows 11 PC, so there is nothing to install. The window is kept just off the
|
||||||
|
// edge of the screen while the flyout is closed; clicking the bubble slides it
|
||||||
|
// above the bar, clicking anywhere else slides it away again. Because the page
|
||||||
|
// keeps running, the unread number in its window title can be shown on the bubble.
|
||||||
|
//
|
||||||
|
// Messages for web only works while the phone is on and connected; that is how
|
||||||
|
// Google built it, not something MirrorBar can change.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
gmURL = "https://messages.google.com/web/conversations"
|
||||||
|
|
||||||
|
gmW = 780.0 // flyout size, in 96 dpi units
|
||||||
|
gmH = 580.0
|
||||||
|
|
||||||
|
gmTimerID = 3 // on the main window: watches for clicks outside the flyout
|
||||||
|
gmParkX = -32000
|
||||||
|
gmParkY = -32000
|
||||||
|
gmAutoDelay = 20 * time.Second // wait this long after start before opening Messages in the background
|
||||||
|
gmLaunchMax = 45 * time.Second // give up looking for the window after this long
|
||||||
|
|
||||||
|
gmSwpNoSize = 0x0001
|
||||||
|
gmSwpNoMove = 0x0002
|
||||||
|
gmSwpNoZOrder = 0x0004
|
||||||
|
gmSwpFrameChanged = 0x0020
|
||||||
|
gmSwShowNoActive = 4
|
||||||
|
gmWsExAppWindow = 0x00040000
|
||||||
|
gmGaRootOwner = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pIsWindow = user32.NewProc("IsWindow")
|
||||||
|
pWindowFromPoint = user32.NewProc("WindowFromPoint")
|
||||||
|
pGetAncestor = user32.NewProc("GetAncestor")
|
||||||
|
pSetWindowLongPtr = user32.NewProc("SetWindowLongPtrW")
|
||||||
|
pSetWindowPlace = user32.NewProc("SetWindowPlacement")
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
gmHwnd uintptr
|
||||||
|
gmPid uint32
|
||||||
|
gmShown bool
|
||||||
|
gmPrevBtn bool
|
||||||
|
gmPrevFg uintptr
|
||||||
|
gmShownAt time.Time
|
||||||
|
gmLaunching bool
|
||||||
|
gmLaunchedAt time.Time
|
||||||
|
gmWantOpen bool // the bubble was clicked while the window was still starting
|
||||||
|
gmAutoTried bool
|
||||||
|
gmUnread int
|
||||||
|
gmEnumCb uintptr
|
||||||
|
gmFound uintptr
|
||||||
|
gmLogged = map[string]bool{}
|
||||||
|
gmLoggedN int
|
||||||
|
)
|
||||||
|
|
||||||
|
type gmPlacementT struct {
|
||||||
|
Length uint32
|
||||||
|
Flags uint32
|
||||||
|
ShowCmd uint32
|
||||||
|
MinPos point
|
||||||
|
MaxPos point
|
||||||
|
Normal rect
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
|
func drawGMIcon(hdc uintptr, r rect) {
|
||||||
|
if !layerFg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
col := iconColor()
|
||||||
|
cx, cy := center(r)
|
||||||
|
e := px(1)
|
||||||
|
l, t, rt, b := cx-px(6.5), cy-px(5.5), cx+px(6.5), cy+px(3)
|
||||||
|
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
||||||
|
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
||||||
|
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
||||||
|
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
||||||
|
// the little tail at the bottom left
|
||||||
|
polyline(hdc, []point{{cx - px(3.5), b}, {cx - px(3.5), cy + px(6)}, {cx - px(0.5), b}}, e, col)
|
||||||
|
// two lines of "text" in the bubble
|
||||||
|
fillRaw(hdc, rect{cx - px(4), cy - px(3), cx + px(4), cy - px(3) + e}, col)
|
||||||
|
fillRaw(hdc, rect{cx - px(4), cy - px(0.5), cx + px(1.5), cy - px(0.5) + e}, col)
|
||||||
|
|
||||||
|
if gmUnread > 0 {
|
||||||
|
br, bg, bb := styleColor(235, 70, 70)
|
||||||
|
bx, by, rad := cx+px(6.5), cy-px(5.5), px(5)
|
||||||
|
circleRaw(hdc, bx, by, rad, rgb(br, bg, bb))
|
||||||
|
txt := strconv.Itoa(gmUnread)
|
||||||
|
if gmUnread > 9 {
|
||||||
|
txt = "9+"
|
||||||
|
}
|
||||||
|
f := makeFont(px(8), 700)
|
||||||
|
old, _, _ := pSelectObject.Call(hdc, f)
|
||||||
|
pSetBkMode.Call(hdc, transparent)
|
||||||
|
pSetTextColor.Call(hdc, rgb(255, 255, 255))
|
||||||
|
drawText(hdc, txt, rect{bx - rad, by - rad, bx + rad + 1, by + rad + 1})
|
||||||
|
pSelectObject.Call(hdc, old)
|
||||||
|
pDeleteObject.Call(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- finding and starting the browser window ----------
|
||||||
|
|
||||||
|
func gmProfileDir() string { return filepath.Join(dataDir(), "messages") }
|
||||||
|
|
||||||
|
func gmProfileExists() bool {
|
||||||
|
_, err := os.Stat(filepath.Join(gmProfileDir(), "Local State"))
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmBrowserPath is Edge (always there on Windows 11), or Chrome if Edge is gone.
|
||||||
|
func gmBrowserPath() string {
|
||||||
|
type cand struct{ env, vendor, app, exe string }
|
||||||
|
for _, c := range []cand{
|
||||||
|
{"ProgramFiles(x86)", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"ProgramFiles", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"LOCALAPPDATA", "Microsoft", "Edge", "msedge.exe"},
|
||||||
|
{"ProgramFiles", "Google", "Chrome", "chrome.exe"},
|
||||||
|
{"ProgramFiles(x86)", "Google", "Chrome", "chrome.exe"},
|
||||||
|
{"LOCALAPPDATA", "Google", "Chrome", "chrome.exe"},
|
||||||
|
} {
|
||||||
|
base := os.Getenv(c.env)
|
||||||
|
if base == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
p := filepath.Join(base, c.vendor, c.app, "Application", c.exe)
|
||||||
|
if _, err := os.Stat(p); err == nil {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmLaunch starts the app window. Started in the background it opens minimized
|
||||||
|
// and is never given focus, so it does not interrupt whatever is being typed.
|
||||||
|
func gmLaunch(visible bool) bool {
|
||||||
|
exe := gmBrowserPath()
|
||||||
|
if exe == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
prof := gmProfileDir()
|
||||||
|
if err := os.MkdirAll(prof, 0o755); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
args := []string{
|
||||||
|
exe,
|
||||||
|
"--app=" + gmURL,
|
||||||
|
"--user-data-dir=" + prof,
|
||||||
|
"--no-first-run",
|
||||||
|
"--no-default-browser-check",
|
||||||
|
// keep the page awake while its window is parked off the screen
|
||||||
|
"--disable-features=CalculateNativeWinOcclusion",
|
||||||
|
"--disable-renderer-backgrounding",
|
||||||
|
"--disable-background-timer-throttling",
|
||||||
|
"--disable-backgrounding-occluded-windows",
|
||||||
|
}
|
||||||
|
parts := make([]string, len(args))
|
||||||
|
for i, a := range args {
|
||||||
|
parts[i] = syscall.EscapeArg(a)
|
||||||
|
}
|
||||||
|
si := syscall.StartupInfo{Flags: 1} // STARTF_USESHOWWINDOW
|
||||||
|
si.Cb = uint32(unsafe.Sizeof(si))
|
||||||
|
si.ShowWindow = 7 // SW_SHOWMINNOACTIVE
|
||||||
|
if visible {
|
||||||
|
si.ShowWindow = 1 // SW_SHOWNORMAL
|
||||||
|
}
|
||||||
|
var pi syscall.ProcessInformation
|
||||||
|
err := syscall.CreateProcess(u16(exe), u16(strings.Join(parts, " ")), nil, nil, false, 0, nil, nil, &si, &pi)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
gmPid = pi.ProcessId
|
||||||
|
syscall.CloseHandle(pi.Process)
|
||||||
|
syscall.CloseHandle(pi.Thread)
|
||||||
|
gmLaunching = true
|
||||||
|
gmLaunchedAt = time.Now()
|
||||||
|
gmWantOpen = visible
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmWindowTitle(hwnd uintptr) string {
|
||||||
|
var tb [512]uint16
|
||||||
|
n, _, _ := pGetWindowText.Call(hwnd, uintptr(unsafe.Pointer(&tb[0])), 512)
|
||||||
|
return syscall.UTF16ToString(tb[:n])
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmTitleMatch is true for the app window's title ("Messages for web", maybe
|
||||||
|
// with a count in front) and false for ordinary browser windows.
|
||||||
|
func gmTitleMatch(t string) bool {
|
||||||
|
l := strings.ToLower(t)
|
||||||
|
if strings.Contains(l, "microsoft edge") || strings.Contains(l, "google chrome") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.Contains(l, "messages")
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmEnumProc(hwnd, lparam uintptr) uintptr {
|
||||||
|
var cls [64]uint16
|
||||||
|
n, _, _ := pGetClassName.Call(hwnd, uintptr(unsafe.Pointer(&cls[0])), 64)
|
||||||
|
if syscall.UTF16ToString(cls[:n]) != "Chrome_WidgetWin_1" {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if !gmTitleMatch(gmWindowTitle(hwnd)) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
var pid uint32
|
||||||
|
pGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
||||||
|
if gmPid != 0 && pid == gmPid {
|
||||||
|
gmFound = hwnd
|
||||||
|
return 0 // exactly the window we started
|
||||||
|
}
|
||||||
|
if gmFound == 0 {
|
||||||
|
gmFound = hwnd
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmFindWindow() uintptr {
|
||||||
|
if gmEnumCb == 0 {
|
||||||
|
gmEnumCb = syscall.NewCallback(gmEnumProc)
|
||||||
|
}
|
||||||
|
gmFound = 0
|
||||||
|
pEnumWindows.Call(gmEnumCb, 0)
|
||||||
|
return gmFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmWindowOK() bool {
|
||||||
|
if gmHwnd == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
ok, _, _ := pIsWindow.Call(gmHwnd)
|
||||||
|
return ok != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmAdopt takes charge of the window once it exists: it stays out of the app
|
||||||
|
// list and Alt+Tab, and sits off screen until the bubble is clicked.
|
||||||
|
func gmAdopt(h uintptr) {
|
||||||
|
gmHwnd = h
|
||||||
|
var pid uint32
|
||||||
|
pGetWindowThreadProcessId.Call(h, uintptr(unsafe.Pointer(&pid)))
|
||||||
|
if pid != 0 {
|
||||||
|
gmPid = pid
|
||||||
|
}
|
||||||
|
ex, _, _ := pGetWindowLongPtr.Call(h, neg(-20))
|
||||||
|
want := (ex | wsExToolWindow) &^ gmWsExAppWindow
|
||||||
|
if want != ex {
|
||||||
|
pSetWindowLongPtr.Call(h, neg(-20), want)
|
||||||
|
pSetWindowPos.Call(h, 0, 0, 0, 0, 0, gmSwpNoMove|gmSwpNoSize|gmSwpNoZOrder|swpNoActivate|gmSwpFrameChanged)
|
||||||
|
}
|
||||||
|
gmLaunching = false
|
||||||
|
if gmWantOpen {
|
||||||
|
gmWantOpen = false
|
||||||
|
gmShow()
|
||||||
|
} else {
|
||||||
|
gmPark()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- moving the window ----------
|
||||||
|
|
||||||
|
func gmSize() (int32, int32) {
|
||||||
|
sw, sh := screenSize()
|
||||||
|
cw := min(px(gmW), sw-px(16))
|
||||||
|
ch := min(px(gmH), sh-px(24))
|
||||||
|
return cw, ch
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmMove puts the window at x, y, w, h. A minimized window is first brought back
|
||||||
|
// to that spot without taking focus.
|
||||||
|
func gmMove(x, y, w, h int32, topmost, activate bool) {
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if z, _, _ := pIsZoomed.Call(gmHwnd); z != 0 {
|
||||||
|
pShowWindow.Call(gmHwnd, swRestore)
|
||||||
|
}
|
||||||
|
if ic, _, _ := pIsIconic.Call(gmHwnd); ic != 0 {
|
||||||
|
cmd := uint32(gmSwShowNoActive)
|
||||||
|
if activate {
|
||||||
|
cmd = swRestore
|
||||||
|
}
|
||||||
|
wp := gmPlacementT{ShowCmd: cmd, Normal: rect{x, y, x + w, y + h}}
|
||||||
|
wp.Length = uint32(unsafe.Sizeof(wp))
|
||||||
|
pSetWindowPlace.Call(gmHwnd, uintptr(unsafe.Pointer(&wp)))
|
||||||
|
}
|
||||||
|
after := ^uintptr(1) // HWND_NOTOPMOST
|
||||||
|
if topmost {
|
||||||
|
after = hwndTopmost
|
||||||
|
}
|
||||||
|
var flags uintptr
|
||||||
|
if !activate {
|
||||||
|
flags = swpNoActivate
|
||||||
|
}
|
||||||
|
pSetWindowPos.Call(gmHwnd, after, uintptr(x), uintptr(y), uintptr(w), uintptr(h), flags|swpShowWindow)
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmPark() {
|
||||||
|
cw, ch := gmSize()
|
||||||
|
gmMove(gmParkX, gmParkY, cw, ch, false, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmPlace is where the flyout goes: above a horizontal bar, to the left of a
|
||||||
|
// vertical one, centered on the bubble and always on the screen.
|
||||||
|
func gmPlace() (x, y, w, h int32) {
|
||||||
|
cw, ch := gmSize()
|
||||||
|
ar := trayAnchor(trayGM)
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
sw, sh := screenSize()
|
||||||
|
space := px(8)
|
||||||
|
if vertical {
|
||||||
|
x = wr.Left - cw - space
|
||||||
|
if x < 0 {
|
||||||
|
x = wr.Right + space
|
||||||
|
}
|
||||||
|
y = (ar.Top+ar.Bottom)/2 - ch/2
|
||||||
|
} else {
|
||||||
|
x = (ar.Left+ar.Right)/2 - cw/2
|
||||||
|
y = wr.Top - ch - space
|
||||||
|
if y < 0 {
|
||||||
|
y = wr.Bottom + space
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clampI(x, 0, sw-cw), clampI(y, 0, sh-ch), cw, ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmFocus() {
|
||||||
|
// This program just received the click, so Windows lets it hand the focus on.
|
||||||
|
pSetForegroundWindow.Call(gmHwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- open, close, click ----------
|
||||||
|
|
||||||
|
func gmToggle() {
|
||||||
|
if !showGM {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if gmShown {
|
||||||
|
gmHide()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewHide()
|
||||||
|
weatherHide() // one panel at a time
|
||||||
|
newsHide()
|
||||||
|
sysHide()
|
||||||
|
if gmWindowOK() {
|
||||||
|
gmShow()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
if gmLaunching {
|
||||||
|
gmWantOpen = true // it is still starting; open it the moment it exists
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !gmLaunch(true) {
|
||||||
|
shellOpen(gmURL, "") // no Edge or Chrome found: use the default browser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmShow() {
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
if fg != gmHwnd {
|
||||||
|
gmPrevFg = fg
|
||||||
|
}
|
||||||
|
gmShown = true
|
||||||
|
gmPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||||
|
gmShownAt = time.Now()
|
||||||
|
x, y, w, h := gmPlace()
|
||||||
|
gmMove(x, y, w, h, true, true)
|
||||||
|
gmFocus()
|
||||||
|
pSetTimer.Call(hwndMain, gmTimerID, 80, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmHide() {
|
||||||
|
if !gmShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
if !gmWindowOK() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
|
gmPark()
|
||||||
|
if fg == gmHwnd && gmPrevFg != 0 && gmPrevFg != hwndMain && gmPrevFg != gmHwnd {
|
||||||
|
if ok, _, _ := pIsWindow.Call(gmPrevFg); ok != 0 {
|
||||||
|
pSetForegroundWindow.Call(gmPrevFg) // give the keyboard back to what you were doing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmClose shuts the Messages window down (right-click, "Close Messages").
|
||||||
|
func gmClose() {
|
||||||
|
gmHide()
|
||||||
|
if gmWindowOK() {
|
||||||
|
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
gmLaunching = false
|
||||||
|
gmWantOpen = false
|
||||||
|
gmAutoTried = true // do not bring it back by itself
|
||||||
|
gmUnread = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func gmShutdown() {
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
if gmWindowOK() {
|
||||||
|
pPostMessage.Call(gmHwnd, wmClose, 0, 0)
|
||||||
|
}
|
||||||
|
gmHwnd = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmPoll runs every 80 ms while the flyout is open and closes it when a mouse
|
||||||
|
// button goes down anywhere outside it (the bubble itself is left alone, so
|
||||||
|
// clicking it can close the flyout).
|
||||||
|
func gmPoll() {
|
||||||
|
if !gmShown {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !gmWindowOK() {
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
|
down := (l|r)&0x8000 != 0
|
||||||
|
if down && !gmPrevBtn && time.Since(gmShownAt) > 300*time.Millisecond {
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var fr rect
|
||||||
|
pGetWindowRect.Call(gmHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
|
inside := inRect(fr, cp)
|
||||||
|
if !inside {
|
||||||
|
// a dialog or menu that belongs to the Messages window counts as inside
|
||||||
|
h, _, _ := pWindowFromPoint.Call(uintptr(uint32(cp.X)) | uintptr(uint32(cp.Y))<<32)
|
||||||
|
if h != 0 {
|
||||||
|
root, _, _ := pGetAncestor.Call(h, gmGaRootOwner)
|
||||||
|
inside = root == gmHwnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !inside && !inRect(trayAnchor(trayGM), cp) {
|
||||||
|
gmHide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gmPrevBtn = down
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the background check ----------
|
||||||
|
|
||||||
|
var gmCountRe = regexp.MustCompile(`[\(\[](\d{1,3})\+?[\)\]]`)
|
||||||
|
|
||||||
|
func gmParseUnread(title string) int {
|
||||||
|
m := gmCountRe.FindStringSubmatch(title)
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
n, _ := strconv.Atoi(m[1])
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmLogTitle keeps the first few different window titles in titles.txt next to
|
||||||
|
// the Messages profile, so the unread badge can be tuned if Google words it
|
||||||
|
// differently than expected. It stops after 25 so it never grows.
|
||||||
|
func gmLogTitle(t string) {
|
||||||
|
if t == "" || gmLogged[t] || gmLoggedN >= 25 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gmLogged[t] = true
|
||||||
|
gmLoggedN++
|
||||||
|
f, err := os.OpenFile(filepath.Join(dataDir(), "messages-titles.txt"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if len(t) > 80 {
|
||||||
|
t = t[:80]
|
||||||
|
}
|
||||||
|
_, _ = f.WriteString(time.Now().Format("2006-01-02 15:04:05") + "\t" + t + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// gmTick runs from the bar's 250 ms timer. It starts Messages in the background
|
||||||
|
// once you have paired a phone, notices when the window goes away, and reads
|
||||||
|
// the unread count from the window title. Returns true when the bar needs a
|
||||||
|
// repaint.
|
||||||
|
func gmTick(tick int) (changed bool) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
changed = false // optional feature; never take the bar down with it
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if !showGM {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if gmHwnd != 0 && !gmWindowOK() {
|
||||||
|
gmHwnd = 0
|
||||||
|
gmShown = false
|
||||||
|
pKillTimer.Call(hwndMain, gmTimerID)
|
||||||
|
changed = gmUnread != 0
|
||||||
|
gmUnread = 0
|
||||||
|
}
|
||||||
|
if gmHwnd == 0 {
|
||||||
|
switch {
|
||||||
|
case gmLaunching:
|
||||||
|
if h := gmFindWindow(); h != 0 {
|
||||||
|
gmAdopt(h)
|
||||||
|
} else if time.Since(gmLaunchedAt) > gmLaunchMax {
|
||||||
|
gmLaunching = false
|
||||||
|
gmWantOpen = false
|
||||||
|
}
|
||||||
|
case !gmAutoTried && time.Since(startedAt) > gmAutoDelay:
|
||||||
|
gmAutoTried = true
|
||||||
|
if h := gmFindWindow(); h != 0 {
|
||||||
|
gmAdopt(h) // left over from an earlier run of MirrorBar
|
||||||
|
} else if gmProfileExists() {
|
||||||
|
gmLaunch(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gmHwnd != 0 && tick%8 == 0 {
|
||||||
|
t := gmWindowTitle(gmHwnd)
|
||||||
|
gmLogTitle(t)
|
||||||
|
if n := gmParseUnread(t); n != gmUnread {
|
||||||
|
gmUnread = n
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed
|
||||||
|
}
|
||||||
@@ -437,6 +437,17 @@ func setTaskbarState(owner uintptr, state uintptr) {
|
|||||||
appBar(abmSetState, &abd)
|
appBar(abmSetState, &abd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// keepOnTop puts the bar back in the topmost band if Windows or another program
|
||||||
|
// has knocked it out of it, which otherwise sinks it under every other window.
|
||||||
|
func keepOnTop(hwnd uintptr) {
|
||||||
|
ex, _, _ := pGetWindowLongPtr.Call(hwnd, neg(-20))
|
||||||
|
if ex&wsExTopmost != 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const swpNoSize, swpNoMove = 0x0001, 0x0002
|
||||||
|
pSetWindowPos.Call(hwnd, hwndTopmost, 0, 0, 0, 0, swpNoSize|swpNoMove|swpNoActivate)
|
||||||
|
}
|
||||||
|
|
||||||
func hideTaskbar() {
|
func hideTaskbar() {
|
||||||
tb := findTaskbar()
|
tb := findTaskbar()
|
||||||
if tb == 0 {
|
if tb == 0 {
|
||||||
@@ -462,7 +473,7 @@ func restoreAll() {
|
|||||||
// ---------- open windows ----------
|
// ---------- open windows ----------
|
||||||
|
|
||||||
func collectWindow(hwnd uintptr) {
|
func collectWindow(hwnd uintptr) {
|
||||||
if hwnd == hwndMain {
|
if hwnd == hwndMain || (gmHwnd != 0 && hwnd == gmHwnd) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vis, _, _ := pIsWindowVisible.Call(hwnd)
|
vis, _, _ := pIsWindowVisible.Call(hwnd)
|
||||||
@@ -974,13 +985,21 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
return 0
|
return 0
|
||||||
case wmTimer:
|
case wmTimer:
|
||||||
|
if wparam == gmTimerID {
|
||||||
|
gmPoll()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if wparam == previewTimerID {
|
if wparam == previewTimerID {
|
||||||
previewTick()
|
previewTick()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
hideTaskbar()
|
hideTaskbar()
|
||||||
|
keepOnTop(hwnd)
|
||||||
tick++
|
tick++
|
||||||
changed := refreshApps(tick%16 == 0)
|
changed := refreshApps(tick%16 == 0)
|
||||||
|
if gmTick(tick) {
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
|
if tick%4 == 0 && refreshStatus(tick%16 == 0) {
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
@@ -1190,6 +1209,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
weatherShutdown()
|
weatherShutdown()
|
||||||
newsShutdown()
|
newsShutdown()
|
||||||
sysShutdown()
|
sysShutdown()
|
||||||
|
gmShutdown()
|
||||||
abd := appBarData{Hwnd: hwnd}
|
abd := appBarData{Hwnd: hwnd}
|
||||||
appBar(abmRemove, &abd)
|
appBar(abmRemove, &abd)
|
||||||
pKillTimer.Call(hwnd, timerID)
|
pKillTimer.Call(hwnd, timerID)
|
||||||
|
|||||||
+360
-359
@@ -1,359 +1,360 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// The local news flyout: a little newspaper on the bar that opens a panel above
|
// The local news flyout: a little newspaper on the bar that opens a panel above
|
||||||
// it with a list of local headlines. Each headline is a link; clicking one opens
|
// it with a list of local headlines. Each headline is a link; clicking one opens
|
||||||
// it in the default browser. The panel is its own window that never takes focus,
|
// it in the default browser. The panel is its own window that never takes focus,
|
||||||
// it goes away when you click the newspaper again or click anywhere else, and it
|
// it goes away when you click the newspaper again or click anywhere else, and it
|
||||||
// is painted at double size and shrunk down, the same way the weather panel is.
|
// is painted at double size and shrunk down, the same way the weather panel is.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
newsW = 380.0 // panel width, in 96 dpi units
|
newsW = 380.0 // panel width, in 96 dpi units
|
||||||
newsHead = 44.0 // header height
|
newsHead = 44.0 // header height
|
||||||
newsRow = 58.0 // height of one headline
|
newsRow = 58.0 // height of one headline
|
||||||
newsFoot = 8.0
|
newsFoot = 8.0
|
||||||
newsMaxRows = 10
|
newsMaxRows = 10
|
||||||
|
|
||||||
idcHandCursor = 32649
|
idcHandCursor = 32649
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
newsHwnd uintptr
|
newsHwnd uintptr
|
||||||
newsShown bool
|
newsShown bool
|
||||||
newsPrevBtn bool
|
newsPrevBtn bool
|
||||||
newsHover = -1 // the headline under the mouse, -1 for none
|
newsHover = -1 // the headline under the mouse, -1 for none
|
||||||
newsVisible int // how many headlines the panel is showing
|
newsVisible int // how many headlines the panel is showing
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------- the button on the bar ----------
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
// drawNewsIcon draws the little newspaper on the bar.
|
// drawNewsIcon draws the little newspaper on the bar.
|
||||||
func drawNewsIcon(hdc uintptr, r rect) {
|
func drawNewsIcon(hdc uintptr, r rect) {
|
||||||
if !layerFg {
|
if !layerFg {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
col := iconColor()
|
col := iconColor()
|
||||||
cx, cy := center(r)
|
cx, cy := center(r)
|
||||||
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(5.5)
|
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(5.5)
|
||||||
e := px(1)
|
e := px(1)
|
||||||
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
||||||
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
||||||
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
||||||
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
||||||
fillRaw(hdc, rect{l + px(2.5), t + px(2.5), l + px(6), t + px(5.5)}, col) // the main headline
|
fillRaw(hdc, rect{l + px(2.5), t + px(2.5), l + px(6), t + px(5.5)}, col) // the main headline
|
||||||
fillRaw(hdc, rect{l + px(7.5), t + px(2.5), rt - px(2.5), t + px(3.5)}, col)
|
fillRaw(hdc, rect{l + px(7.5), t + px(2.5), rt - px(2.5), t + px(3.5)}, col)
|
||||||
fillRaw(hdc, rect{l + px(7.5), t + px(4.5), rt - px(2.5), t + px(5.5)}, col)
|
fillRaw(hdc, rect{l + px(7.5), t + px(4.5), rt - px(2.5), t + px(5.5)}, col)
|
||||||
fillRaw(hdc, rect{l + px(2.5), t + px(7), rt - px(2.5), t + px(8)}, col) // lines of text
|
fillRaw(hdc, rect{l + px(2.5), t + px(7), rt - px(2.5), t + px(8)}, col) // lines of text
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- the panel window ----------
|
// ---------- the panel window ----------
|
||||||
|
|
||||||
func newsInit(inst uintptr) {
|
func newsInit(inst uintptr) {
|
||||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
className := u16("MirrorBarNews")
|
className := u16("MirrorBarNews")
|
||||||
wc := wndClassEx{
|
wc := wndClassEx{
|
||||||
WndProc: syscall.NewCallback(newsProc),
|
WndProc: syscall.NewCallback(newsProc),
|
||||||
Instance: inst,
|
Instance: inst,
|
||||||
Cursor: cursor,
|
Cursor: cursor,
|
||||||
ClassName: className,
|
ClassName: className,
|
||||||
}
|
}
|
||||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
newsHwnd, _, _ = pCreateWindowEx.Call(
|
newsHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
||||||
uintptr(unsafe.Pointer(className)),
|
uintptr(unsafe.Pointer(className)),
|
||||||
uintptr(unsafe.Pointer(u16(""))),
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
wsPopup,
|
wsPopup,
|
||||||
0, 0, 10, 10,
|
0, 0, 10, 10,
|
||||||
0, 0, inst, 0)
|
0, 0, inst, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
func newsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
result = 0 // the flyout is optional; never take the bar down with it
|
result = 0 // the flyout is optional; never take the bar down with it
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
switch uint32(m) {
|
switch uint32(m) {
|
||||||
case wmEraseBkgnd:
|
case wmEraseBkgnd:
|
||||||
return 1
|
return 1
|
||||||
case wmMouseActivate:
|
case wmMouseActivate:
|
||||||
return maNoActivate
|
return maNoActivate
|
||||||
case wmPaint:
|
case wmPaint:
|
||||||
flyPaint(hwnd, newsDraw)
|
flyPaint(hwnd, newsDraw)
|
||||||
return 0
|
return 0
|
||||||
case wmTimer:
|
case wmTimer:
|
||||||
newsPoll()
|
newsPoll()
|
||||||
return 0
|
return 0
|
||||||
case wmSetCursor:
|
case wmSetCursor:
|
||||||
if newsHover >= 0 {
|
if newsHover >= 0 {
|
||||||
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
||||||
pSetCursor.Call(h)
|
pSetCursor.Call(h)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
case wmLButtonUp:
|
case wmLButtonUp:
|
||||||
newsClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
newsClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// newsToggle is what clicking the newspaper does.
|
// newsToggle is what clicking the newspaper does.
|
||||||
func newsToggle() {
|
func newsToggle() {
|
||||||
if !showNews {
|
if !showNews {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if newsShown {
|
if newsShown {
|
||||||
newsHide()
|
newsHide()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if newsHwnd == 0 {
|
if newsHwnd == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
previewHide()
|
previewHide()
|
||||||
weatherHide() // one panel at a time
|
weatherHide() // one panel at a time
|
||||||
sysHide()
|
sysHide()
|
||||||
newsRefresh(false)
|
gmHide()
|
||||||
newsShown = true
|
newsRefresh(false)
|
||||||
newsPrevBtn = true // ignore a button that is still held from the click that opened this
|
newsShown = true
|
||||||
newsHover = -1
|
newsPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||||
newsPlace()
|
newsHover = -1
|
||||||
pSetTimer.Call(newsHwnd, wxPollTimerID, 80, 0)
|
newsPlace()
|
||||||
}
|
pSetTimer.Call(newsHwnd, wxPollTimerID, 80, 0)
|
||||||
|
}
|
||||||
func newsHide() {
|
|
||||||
if !newsShown {
|
func newsHide() {
|
||||||
return
|
if !newsShown {
|
||||||
}
|
return
|
||||||
newsShown = false
|
}
|
||||||
newsHover = -1
|
newsShown = false
|
||||||
pKillTimer.Call(newsHwnd, wxPollTimerID)
|
newsHover = -1
|
||||||
pShowWindow.Call(newsHwnd, swHide)
|
pKillTimer.Call(newsHwnd, wxPollTimerID)
|
||||||
}
|
pShowWindow.Call(newsHwnd, swHide)
|
||||||
|
}
|
||||||
func newsShutdown() {
|
|
||||||
newsHide()
|
func newsShutdown() {
|
||||||
if newsHwnd != 0 {
|
newsHide()
|
||||||
pDestroyWindow.Call(newsHwnd)
|
if newsHwnd != 0 {
|
||||||
newsHwnd = 0
|
pDestroyWindow.Call(newsHwnd)
|
||||||
}
|
newsHwnd = 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// newsVisibleRows is how many headlines fit on the screen, up to ten.
|
|
||||||
func newsVisibleRows(n int) int {
|
// newsVisibleRows is how many headlines fit on the screen, up to ten.
|
||||||
_, sh := screenSize()
|
func newsVisibleRows(n int) int {
|
||||||
avail := sh - px(90) - px(newsHead+newsFoot)
|
_, sh := screenSize()
|
||||||
m := int(avail / px(newsRow))
|
avail := sh - px(90) - px(newsHead+newsFoot)
|
||||||
m = max(3, min(m, newsMaxRows))
|
m := int(avail / px(newsRow))
|
||||||
return min(n, m)
|
m = max(3, min(m, newsMaxRows))
|
||||||
}
|
return min(n, m)
|
||||||
|
}
|
||||||
// newsPlace sizes the panel for what it has to show and puts it next to the
|
|
||||||
// newspaper: above a horizontal bar, to the left of a vertical one.
|
// newsPlace sizes the panel for what it has to show and puts it next to the
|
||||||
func newsPlace() {
|
// newspaper: above a horizontal bar, to the left of a vertical one.
|
||||||
if newsHwnd == 0 {
|
func newsPlace() {
|
||||||
return
|
if newsHwnd == 0 {
|
||||||
}
|
return
|
||||||
s := newsSnapshot()
|
}
|
||||||
lh := wxShortH
|
s := newsSnapshot()
|
||||||
newsVisible = 0
|
lh := wxShortH
|
||||||
if wxZip != "" && len(s.items) > 0 {
|
newsVisible = 0
|
||||||
newsVisible = newsVisibleRows(len(s.items))
|
if wxZip != "" && len(s.items) > 0 {
|
||||||
lh = newsHead + float64(newsVisible)*newsRow + newsFoot
|
newsVisible = newsVisibleRows(len(s.items))
|
||||||
}
|
lh = newsHead + float64(newsVisible)*newsRow + newsFoot
|
||||||
flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh))
|
}
|
||||||
flyRefresh(newsHwnd)
|
flyPlace(newsHwnd, trayAnchor(trayNews), px(newsW), px(lh))
|
||||||
}
|
flyRefresh(newsHwnd)
|
||||||
|
}
|
||||||
// newsDone runs when a download finishes.
|
|
||||||
func newsDone() {
|
// newsDone runs when a download finishes.
|
||||||
if newsShown {
|
func newsDone() {
|
||||||
newsPlace()
|
if newsShown {
|
||||||
}
|
newsPlace()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// newsPoll closes the panel when a mouse button goes down anywhere outside it
|
|
||||||
// (the newspaper itself is left alone, so clicking it can close the panel) and
|
// newsPoll closes the panel when a mouse button goes down anywhere outside it
|
||||||
// keeps track of which headline the mouse is over.
|
// (the newspaper itself is left alone, so clicking it can close the panel) and
|
||||||
func newsPoll() {
|
// keeps track of which headline the mouse is over.
|
||||||
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
func newsPoll() {
|
||||||
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
down := (l|r)&0x8000 != 0
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
var cp point
|
down := (l|r)&0x8000 != 0
|
||||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
var cp point
|
||||||
var fr rect
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
pGetWindowRect.Call(newsHwnd, uintptr(unsafe.Pointer(&fr)))
|
var fr rect
|
||||||
if down && !newsPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(trayNews), cp) {
|
pGetWindowRect.Call(newsHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
newsHide()
|
if down && !newsPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(trayNews), cp) {
|
||||||
newsPrevBtn = down
|
newsHide()
|
||||||
return
|
newsPrevBtn = down
|
||||||
}
|
return
|
||||||
newsPrevBtn = down
|
}
|
||||||
|
newsPrevBtn = down
|
||||||
h := -1
|
|
||||||
if inRect(fr, cp) {
|
h := -1
|
||||||
h = newsRowAt(cp.X-fr.Left, cp.Y-fr.Top)
|
if inRect(fr, cp) {
|
||||||
}
|
h = newsRowAt(cp.X-fr.Left, cp.Y-fr.Top)
|
||||||
if h != newsHover {
|
}
|
||||||
newsHover = h
|
if h != newsHover {
|
||||||
flyRefresh(newsHwnd)
|
newsHover = h
|
||||||
}
|
flyRefresh(newsHwnd)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// newsRowAt is the headline under a spot in the panel (real pixels), or -1.
|
|
||||||
func newsRowAt(x, y int32) int {
|
// newsRowAt is the headline under a spot in the panel (real pixels), or -1.
|
||||||
ry := y - px(newsHead)
|
func newsRowAt(x, y int32) int {
|
||||||
if ry < 0 || x < 0 {
|
ry := y - px(newsHead)
|
||||||
return -1
|
if ry < 0 || x < 0 {
|
||||||
}
|
return -1
|
||||||
i := int(ry / px(newsRow))
|
}
|
||||||
if i >= newsVisible {
|
i := int(ry / px(newsRow))
|
||||||
return -1
|
if i >= newsVisible {
|
||||||
}
|
return -1
|
||||||
return i
|
}
|
||||||
}
|
return i
|
||||||
|
}
|
||||||
// newsClick runs when the panel is clicked: a headline opens in the browser, the
|
|
||||||
// header refreshes, and the messages in an empty panel are buttons.
|
// newsClick runs when the panel is clicked: a headline opens in the browser, the
|
||||||
func newsClick(x, y int32) {
|
// header refreshes, and the messages in an empty panel are buttons.
|
||||||
s := newsSnapshot()
|
func newsClick(x, y int32) {
|
||||||
switch {
|
s := newsSnapshot()
|
||||||
case wxZip == "":
|
switch {
|
||||||
newsHide()
|
case wxZip == "":
|
||||||
openSettings()
|
newsHide()
|
||||||
return
|
openSettings()
|
||||||
case len(s.items) == 0:
|
return
|
||||||
if !s.loading {
|
case len(s.items) == 0:
|
||||||
newsRefresh(true)
|
if !s.loading {
|
||||||
}
|
newsRefresh(true)
|
||||||
return
|
}
|
||||||
case y < px(newsHead):
|
return
|
||||||
newsRefresh(true)
|
case y < px(newsHead):
|
||||||
return
|
newsRefresh(true)
|
||||||
}
|
return
|
||||||
if i := newsRowAt(x, y); i >= 0 && i < len(s.items) {
|
}
|
||||||
link := s.items[i].link
|
if i := newsRowAt(x, y); i >= 0 && i < len(s.items) {
|
||||||
newsHide()
|
link := s.items[i].link
|
||||||
shellOpen(link, "") // only web links were kept when the feed was read
|
newsHide()
|
||||||
}
|
shellOpen(link, "") // only web links were kept when the feed was read
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ---------- painting ----------
|
|
||||||
|
// ---------- painting ----------
|
||||||
func newsDraw(hdc uintptr, W, H int32) {
|
|
||||||
u := px
|
func newsDraw(hdc uintptr, W, H int32) {
|
||||||
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
u := px
|
||||||
|
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
||||||
pad := u(14)
|
|
||||||
s := newsSnapshot()
|
pad := u(14)
|
||||||
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
s := newsSnapshot()
|
||||||
|
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
||||||
title := "Local news"
|
|
||||||
if s.place != "" && wxZip != "" {
|
title := "Local news"
|
||||||
title = s.place + " news"
|
if s.place != "" && wxZip != "" {
|
||||||
}
|
title = s.place + " news"
|
||||||
wxText(hdc, title, rect{pad, u(10), W - pad - u(108), u(34)}, fMed, colText, line)
|
}
|
||||||
status := ""
|
wxText(hdc, title, rect{pad, u(10), W - pad - u(108), u(34)}, fMed, colText, line)
|
||||||
switch {
|
status := ""
|
||||||
case s.loading:
|
switch {
|
||||||
status = "Updating..."
|
case s.loading:
|
||||||
case s.ok && s.err != "":
|
status = "Updating..."
|
||||||
status = "Couldn't update"
|
case s.ok && s.err != "":
|
||||||
case s.ok:
|
status = "Couldn't update"
|
||||||
status = "Updated " + s.fetched.Format("3:04 PM")
|
case s.ok:
|
||||||
}
|
status = "Updated " + s.fetched.Format("3:04 PM")
|
||||||
wxText(hdc, status, rect{W - pad - u(108), u(12), W - pad, u(32)}, fSmall, colDim, dtRight|dtVCenter|dtSingleLine)
|
}
|
||||||
|
wxText(hdc, status, rect{W - pad - u(108), u(12), W - pad, u(32)}, fSmall, colDim, dtRight|dtVCenter|dtSingleLine)
|
||||||
// Nothing to show yet: say why. These messages are clickable.
|
|
||||||
if wxZip == "" || len(s.items) == 0 {
|
// Nothing to show yet: say why. These messages are clickable.
|
||||||
var head, sub string
|
if wxZip == "" || len(s.items) == 0 {
|
||||||
switch {
|
var head, sub string
|
||||||
case wxZip == "":
|
switch {
|
||||||
head, sub = "No ZIP code yet", "Click here to open the settings and type your ZIP code."
|
case wxZip == "":
|
||||||
case s.loading:
|
head, sub = "No ZIP code yet", "Click here to open the settings and type your ZIP code."
|
||||||
head, sub = "Getting the headlines...", ""
|
case s.loading:
|
||||||
default:
|
head, sub = "Getting the headlines...", ""
|
||||||
head, sub = "No news right now", s.err+" Click here to try again."
|
default:
|
||||||
}
|
head, sub = "No news right now", s.err+" Click here to try again."
|
||||||
wxText(hdc, head, rect{pad, u(48), W - pad, u(74)}, fMed, colText, dtCenter|dtVCenter|dtSingleLine)
|
}
|
||||||
if sub != "" {
|
wxText(hdc, head, rect{pad, u(48), W - pad, u(74)}, fMed, colText, dtCenter|dtVCenter|dtSingleLine)
|
||||||
wxText(hdc, sub, rect{pad, u(78), W - pad, H - pad}, fText, colDim, dtCenter|dtWordBreak)
|
if sub != "" {
|
||||||
}
|
wxText(hdc, sub, rect{pad, u(78), W - pad, H - pad}, fText, colDim, dtCenter|dtWordBreak)
|
||||||
return
|
}
|
||||||
}
|
return
|
||||||
|
}
|
||||||
fillRaw(hdc, rect{pad, u(newsHead) - u(2), W - pad, u(newsHead) - u(1)}, colRule)
|
|
||||||
now := time.Now()
|
fillRaw(hdc, rect{pad, u(newsHead) - u(2), W - pad, u(newsHead) - u(1)}, colRule)
|
||||||
for i := 0; i < newsVisible && i < len(s.items); i++ {
|
now := time.Now()
|
||||||
it := s.items[i]
|
for i := 0; i < newsVisible && i < len(s.items); i++ {
|
||||||
y := u(newsHead) + int32(i)*u(newsRow)
|
it := s.items[i]
|
||||||
head := colText
|
y := u(newsHead) + int32(i)*u(newsRow)
|
||||||
if i == newsHover {
|
head := colText
|
||||||
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(newsRow)}, rgb(40, 40, 48))
|
if i == newsHover {
|
||||||
head = colAccent
|
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(newsRow)}, rgb(40, 40, 48))
|
||||||
}
|
head = colAccent
|
||||||
wxText(hdc, it.title, rect{pad, y + u(6), W - pad, y + u(42)}, fBold, head, dtLeft|dtWordBreak|dtEndEllipsis)
|
}
|
||||||
meta := it.source
|
wxText(hdc, it.title, rect{pad, y + u(6), W - pad, y + u(42)}, fBold, head, dtLeft|dtWordBreak|dtEndEllipsis)
|
||||||
if age := newsAge(it.when, now); age != "" {
|
meta := it.source
|
||||||
if meta != "" {
|
if age := newsAge(it.when, now); age != "" {
|
||||||
meta += " · "
|
if meta != "" {
|
||||||
}
|
meta += " · "
|
||||||
meta += age
|
}
|
||||||
}
|
meta += age
|
||||||
wxText(hdc, meta, rect{pad, y + u(42), W - pad, y + u(56)}, fSmall, colDim, line)
|
}
|
||||||
if i < newsVisible-1 && i != newsHover && i+1 != newsHover {
|
wxText(hdc, meta, rect{pad, y + u(42), W - pad, y + u(56)}, fSmall, colDim, line)
|
||||||
fillRaw(hdc, rect{pad, y + u(newsRow) - u(1), W - pad, y + u(newsRow)}, colRule)
|
if i < newsVisible-1 && i != newsHover && i+1 != newsHover {
|
||||||
}
|
fillRaw(hdc, rect{pad, y + u(newsRow) - u(1), W - pad, y + u(newsRow)}, colRule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ---------- shared by both panels ----------
|
|
||||||
|
// ---------- shared by both panels ----------
|
||||||
// trayAnchor is where an icon on the bar sits on the screen.
|
|
||||||
func trayAnchor(kind int) rect {
|
// trayAnchor is where an icon on the bar sits on the screen.
|
||||||
var wr rect
|
func trayAnchor(kind int) rect {
|
||||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
var wr rect
|
||||||
w, h := clientSize(hwndMain)
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
for _, it := range trayItems(w, h) {
|
w, h := clientSize(hwndMain)
|
||||||
if it.kind == kind {
|
for _, it := range trayItems(w, h) {
|
||||||
r := it.r
|
if it.kind == kind {
|
||||||
if vertical {
|
r := it.r
|
||||||
r = mapRect(r, h)
|
if vertical {
|
||||||
}
|
r = mapRect(r, h)
|
||||||
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
}
|
||||||
}
|
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
||||||
}
|
}
|
||||||
return wr
|
}
|
||||||
}
|
return wr
|
||||||
|
}
|
||||||
// flyPlace puts a panel of size cw by ch next to an icon: above a horizontal
|
|
||||||
// bar, to the left of a vertical one, and always on the screen.
|
// flyPlace puts a panel of size cw by ch next to an icon: above a horizontal
|
||||||
func flyPlace(hwnd uintptr, ar rect, cw, ch int32) {
|
// bar, to the left of a vertical one, and always on the screen.
|
||||||
var wr rect
|
func flyPlace(hwnd uintptr, ar rect, cw, ch int32) {
|
||||||
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
var wr rect
|
||||||
sw, sh := screenSize()
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
space := px(8)
|
sw, sh := screenSize()
|
||||||
var x, y int32
|
space := px(8)
|
||||||
if vertical {
|
var x, y int32
|
||||||
x = wr.Left - cw - space
|
if vertical {
|
||||||
if x < 0 {
|
x = wr.Left - cw - space
|
||||||
x = wr.Right + space
|
if x < 0 {
|
||||||
}
|
x = wr.Right + space
|
||||||
y = (ar.Top+ar.Bottom)/2 - ch/2
|
}
|
||||||
} else {
|
y = (ar.Top+ar.Bottom)/2 - ch/2
|
||||||
x = (ar.Left+ar.Right)/2 - cw/2
|
} else {
|
||||||
y = wr.Top - ch - space
|
x = (ar.Left+ar.Right)/2 - cw/2
|
||||||
if y < 0 {
|
y = wr.Top - ch - space
|
||||||
y = wr.Bottom + space
|
if y < 0 {
|
||||||
}
|
y = wr.Bottom + space
|
||||||
}
|
}
|
||||||
x = clampI(x, 0, sw-cw)
|
}
|
||||||
y = clampI(y, 0, sh-ch)
|
x = clampI(x, 0, sw-cw)
|
||||||
pSetWindowPos.Call(hwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
y = clampI(y, 0, sh-ch)
|
||||||
}
|
pSetWindowPos.Call(hwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,390 +1,392 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// Painting the bar smoothly on a see-through background.
|
// Painting the bar smoothly on a see-through background.
|
||||||
//
|
//
|
||||||
// Drawing icons and text straight onto a dark bitmap leaves a dark fringe
|
// 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
|
// 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
|
// 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
|
// 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
|
// the two copies shows exactly how see-through every edge pixel is, and
|
||||||
// shrinking back down gives smooth edges with no dark outline.
|
// shrinking back down gives smooth edges with no dark outline.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
superSample = 2
|
superSample = 2
|
||||||
mfPopup = 0x0010
|
mfPopup = 0x0010
|
||||||
|
|
||||||
menuLogoColorBase = 100
|
menuLogoColorBase = 100
|
||||||
menuClockColorBase = 120
|
menuClockColorBase = 120
|
||||||
menuIconColorBase = 140
|
menuIconColorBase = 140
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fontTime2 uintptr
|
fontTime2 uintptr
|
||||||
fontApp2 uintptr
|
fontApp2 uintptr
|
||||||
)
|
)
|
||||||
|
|
||||||
// initSuperFonts makes the double size fonts used for the smooth pass.
|
// initSuperFonts makes the double size fonts used for the smooth pass.
|
||||||
func initSuperFonts() {
|
func initSuperFonts() {
|
||||||
scale *= superSample
|
scale *= superSample
|
||||||
fontTime2 = makeFont(px(13), 400)
|
fontTime2 = makeFont(px(13), 400)
|
||||||
fontApp2 = makeFont(px(12), 600)
|
fontApp2 = makeFont(px(12), 600)
|
||||||
scale /= superSample
|
scale /= superSample
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- colors ----------
|
// ---------- colors ----------
|
||||||
|
|
||||||
type namedColor struct {
|
type namedColor struct {
|
||||||
name string
|
name string
|
||||||
r, g, b int
|
r, g, b int
|
||||||
}
|
}
|
||||||
|
|
||||||
var palette = []namedColor{
|
var palette = []namedColor{
|
||||||
{"White", 245, 245, 245},
|
{"White", 245, 245, 245},
|
||||||
{"Blue", 0, 120, 212},
|
{"Blue", 0, 120, 212},
|
||||||
{"Sky blue", 90, 190, 255},
|
{"Sky blue", 90, 190, 255},
|
||||||
{"Green", 70, 200, 110},
|
{"Green", 70, 200, 110},
|
||||||
{"Yellow", 255, 205, 60},
|
{"Yellow", 255, 205, 60},
|
||||||
{"Orange", 255, 140, 40},
|
{"Orange", 255, 140, 40},
|
||||||
{"Red", 235, 70, 70},
|
{"Red", 235, 70, 70},
|
||||||
{"Pink", 255, 125, 195},
|
{"Pink", 255, 125, 195},
|
||||||
{"Purple", 175, 115, 240},
|
{"Purple", 175, 115, 240},
|
||||||
{"Black", 0, 0, 0},
|
{"Black", 0, 0, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logoIdx = 1 // Blue, like the real Windows logo
|
logoIdx = 1 // Blue, like the real Windows logo
|
||||||
clockIdx = 0 // White
|
clockIdx = 0 // White
|
||||||
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
||||||
)
|
)
|
||||||
|
|
||||||
func colorOf(i int) uintptr {
|
func colorOf(i int) uintptr {
|
||||||
if i < 0 || i >= len(palette) {
|
if i < 0 || i >= len(palette) {
|
||||||
i = 0
|
i = 0
|
||||||
}
|
}
|
||||||
c := palette[i]
|
c := palette[i]
|
||||||
r, g, b := styleColor(c.r, c.g, c.b)
|
r, g, b := styleColor(c.r, c.g, c.b)
|
||||||
return rgb(r, g, b)
|
return rgb(r, g, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func logoColor() uintptr { return colorOf(logoIdx) }
|
func logoColor() uintptr { return colorOf(logoIdx) }
|
||||||
func clockColor() uintptr { return colorOf(clockIdx) }
|
func clockColor() uintptr { return colorOf(clockIdx) }
|
||||||
func iconColor() uintptr { return colorOf(iconIdx) }
|
func iconColor() uintptr { return colorOf(iconIdx) }
|
||||||
|
|
||||||
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
||||||
func iconDim() uintptr {
|
func iconDim() uintptr {
|
||||||
c := palette[iconIdx]
|
c := palette[iconIdx]
|
||||||
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
||||||
return rgb(140, 140, 150)
|
return rgb(140, 140, 150)
|
||||||
}
|
}
|
||||||
return rgb(110, 110, 120)
|
return rgb(110, 110, 120)
|
||||||
}
|
}
|
||||||
|
|
||||||
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
||||||
|
|
||||||
func loadColors() {
|
func loadColors() {
|
||||||
b, err := os.ReadFile(colorsFile())
|
b, err := os.ReadFile(colorsFile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
||||||
if len(parts) < 2 || len(parts) > 3 {
|
if len(parts) < 2 || len(parts) > 3 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vals := []int{0, 0, 0}
|
vals := []int{0, 0, 0}
|
||||||
for i, p := range parts {
|
for i, p := range parts {
|
||||||
n, err := strconv.Atoi(p)
|
n, err := strconv.Atoi(p)
|
||||||
if err != nil || n < 0 || n >= len(palette) {
|
if err != nil || n < 0 || n >= len(palette) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vals[i] = n
|
vals[i] = n
|
||||||
}
|
}
|
||||||
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveColors() {
|
func saveColors() {
|
||||||
_ = os.MkdirAll(dataDir(), 0o755)
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// addColorMenus adds the two color pickers as sub menus.
|
// addColorMenus adds the two color pickers as sub menus.
|
||||||
func addColorMenus(menu uintptr) {
|
func addColorMenus(menu uintptr) {
|
||||||
build := func(base uintptr, cur int, title string) {
|
build := func(base uintptr, cur int, title string) {
|
||||||
sub, _, _ := pCreatePopupMenu.Call()
|
sub, _, _ := pCreatePopupMenu.Call()
|
||||||
for i, c := range palette {
|
for i, c := range palette {
|
||||||
var flags uintptr
|
var flags uintptr
|
||||||
if i == cur {
|
if i == cur {
|
||||||
flags = mfChecked
|
flags = mfChecked
|
||||||
}
|
}
|
||||||
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
||||||
}
|
}
|
||||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
||||||
}
|
}
|
||||||
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
||||||
build(menuClockColorBase, clockIdx, "Clock color")
|
build(menuClockColorBase, clockIdx, "Clock color")
|
||||||
build(menuIconColorBase, iconIdx, "Tray icon color")
|
build(menuIconColorBase, iconIdx, "Tray icon color")
|
||||||
addStyleMenu(menu)
|
addStyleMenu(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleColorCommand(cmd uintptr) bool {
|
func handleColorCommand(cmd uintptr) bool {
|
||||||
n := uintptr(len(palette))
|
n := uintptr(len(palette))
|
||||||
switch {
|
switch {
|
||||||
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
||||||
logoIdx = int(cmd - menuLogoColorBase)
|
logoIdx = int(cmd - menuLogoColorBase)
|
||||||
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
||||||
clockIdx = int(cmd - menuClockColorBase)
|
clockIdx = int(cmd - menuClockColorBase)
|
||||||
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
||||||
iconIdx = int(cmd - menuIconColorBase)
|
iconIdx = int(cmd - menuIconColorBase)
|
||||||
case handleStyleCommand(cmd):
|
case handleStyleCommand(cmd):
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
saveColors()
|
saveColors()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- painting ----------
|
// ---------- painting ----------
|
||||||
|
|
||||||
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
|
// 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
|
// and returns its pixels at the real orientation. fills and fg choose which
|
||||||
// parts are painted; base is the color everything is painted onto.
|
// parts are painted; base is the color everything is painted onto.
|
||||||
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
||||||
layerFills, layerFg = fills, fg
|
layerFills, layerFg = fills, fg
|
||||||
defer func() { layerFills, layerFg = true, true }()
|
defer func() { layerFills, layerFg = true, true }()
|
||||||
|
|
||||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
defer pDeleteDC.Call(mem)
|
defer pDeleteDC.Call(mem)
|
||||||
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
||||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
var bits unsafe.Pointer
|
var bits unsafe.Pointer
|
||||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||||
if bmp == 0 || bits == nil {
|
if bmp == 0 || bits == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer pDeleteObject.Call(bmp)
|
defer pDeleteObject.Call(bmp)
|
||||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||||
defer pSelectObject.Call(mem, old)
|
defer pSelectObject.Call(mem, old)
|
||||||
|
|
||||||
fillRaw(mem, rect{0, 0, w, h}, base)
|
fillRaw(mem, rect{0, 0, w, h}, base)
|
||||||
sr := startRect(w, h)
|
sr := startRect(w, h)
|
||||||
if hoverStart {
|
if hoverStart {
|
||||||
fill(mem, sr, rgb(58, 58, 68))
|
fill(mem, sr, rgb(58, 58, 68))
|
||||||
}
|
}
|
||||||
drawLogo(mem, sr)
|
drawLogo(mem, sr)
|
||||||
drawApps(mem, w, h)
|
drawApps(mem, w, h)
|
||||||
drawTray(mem, w, h)
|
drawTray(mem, w, h)
|
||||||
pGdiFlush.Call()
|
pGdiFlush.Call()
|
||||||
|
|
||||||
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
||||||
if !vertical {
|
if !vertical {
|
||||||
out := make([]uint32, len(src))
|
out := make([]uint32, len(src))
|
||||||
copy(out, src)
|
copy(out, src)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// Turn a quarter turn, then put the icons and symbols back on upright.
|
// Turn a quarter turn, then put the icons and symbols back on upright.
|
||||||
fw, fh := h, w
|
fw, fh := h, w
|
||||||
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||||
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
||||||
var bitsV unsafe.Pointer
|
var bitsV unsafe.Pointer
|
||||||
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
||||||
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
||||||
if bmpV == 0 || bitsV == nil {
|
if bmpV == 0 || bitsV == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
defer pDeleteObject.Call(bmpV)
|
defer pDeleteObject.Call(bmpV)
|
||||||
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
defer pDeleteDC.Call(memV)
|
defer pDeleteDC.Call(memV)
|
||||||
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
||||||
defer pSelectObject.Call(memV, oldV)
|
defer pSelectObject.Call(memV, oldV)
|
||||||
|
|
||||||
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
||||||
for y := int32(0); y < h; y++ {
|
for y := int32(0); y < h; y++ {
|
||||||
for x := int32(0); x < w; x++ {
|
for x := int32(0); x < w; x++ {
|
||||||
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fg {
|
if fg {
|
||||||
for i, r := range appRects(w, h) {
|
for i, r := range appRects(w, h) {
|
||||||
if i < len(apps) {
|
if i < len(apps) {
|
||||||
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, it := range trayItems(w, h) {
|
for _, it := range trayItems(w, h) {
|
||||||
r := mapRect(it.r, h)
|
r := mapRect(it.r, h)
|
||||||
switch it.kind {
|
switch it.kind {
|
||||||
case trayBattery:
|
case trayBattery:
|
||||||
drawBattery(memV, r)
|
drawBattery(memV, r)
|
||||||
case trayVolume:
|
case trayVolume:
|
||||||
drawVolume(memV, r)
|
drawVolume(memV, r)
|
||||||
case trayWifi:
|
case trayWifi:
|
||||||
drawNetwork(memV, r)
|
drawNetwork(memV, r)
|
||||||
case trayChevron:
|
case trayChevron:
|
||||||
drawChevron(memV, r)
|
drawChevron(memV, r)
|
||||||
case trayWeather:
|
case trayWeather:
|
||||||
drawWeatherIcon(memV, r)
|
drawWeatherIcon(memV, r)
|
||||||
case trayNews:
|
case trayNews:
|
||||||
drawNewsIcon(memV, r)
|
drawNewsIcon(memV, r)
|
||||||
case traySys:
|
case traySys:
|
||||||
drawSysIcon(memV, r)
|
drawSysIcon(memV, r)
|
||||||
}
|
case trayGM:
|
||||||
}
|
drawGMIcon(memV, r)
|
||||||
pGdiFlush.Call()
|
}
|
||||||
}
|
}
|
||||||
out := make([]uint32, len(dst))
|
pGdiFlush.Call()
|
||||||
copy(out, dst)
|
}
|
||||||
return out
|
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) {
|
// avg4 averages the superSample x superSample block of pixels that makes up
|
||||||
var sr, sg, sb uint32
|
// one real pixel, one color channel at a time.
|
||||||
for dy := 0; dy < superSample; dy++ {
|
func avg4(p []uint32, stride, x, y int) (r, g, b uint32) {
|
||||||
for dx := 0; dx < superSample; dx++ {
|
var sr, sg, sb uint32
|
||||||
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
for dy := 0; dy < superSample; dy++ {
|
||||||
sr += c >> 16 & 0xFF
|
for dx := 0; dx < superSample; dx++ {
|
||||||
sg += c >> 8 & 0xFF
|
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
||||||
sb += c & 0xFF
|
sr += c >> 16 & 0xFF
|
||||||
}
|
sg += c >> 8 & 0xFF
|
||||||
}
|
sb += c & 0xFF
|
||||||
n := uint32(superSample * superSample)
|
}
|
||||||
return sr / n, sg / n, sb / n
|
}
|
||||||
}
|
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) {
|
// redraw paints the whole bar and hands it to Windows as a layered window
|
||||||
if hwnd == 0 {
|
// with a transparency value for every pixel.
|
||||||
return
|
func redraw(hwnd uintptr) {
|
||||||
}
|
if hwnd == 0 {
|
||||||
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
return
|
||||||
pw, ph := pillSize()
|
}
|
||||||
var crc rect
|
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
||||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
pw, ph := pillSize()
|
||||||
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
var crc rect
|
||||||
x, y := pillPos(pw, ph)
|
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
||||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
||||||
}
|
x, y := pillPos(pw, ph)
|
||||||
w, h := clientSize(hwnd)
|
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
||||||
if w <= 0 || h <= 0 {
|
}
|
||||||
return
|
w, h := clientSize(hwnd)
|
||||||
}
|
if w <= 0 || h <= 0 {
|
||||||
fw, fh := w, h
|
return
|
||||||
if vertical {
|
}
|
||||||
fw, fh = h, w
|
fw, fh := w, h
|
||||||
}
|
if vertical {
|
||||||
|
fw, fh = h, w
|
||||||
screen, _, _ := pGetDC.Call(0)
|
}
|
||||||
defer pReleaseDC.Call(0, screen)
|
|
||||||
|
screen, _, _ := pGetDC.Call(0)
|
||||||
// Layer 1: backgrounds, at real size.
|
defer pReleaseDC.Call(0, screen)
|
||||||
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
|
||||||
|
// Layer 1: backgrounds, at real size.
|
||||||
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
||||||
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
|
||||||
scale *= superSample
|
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
||||||
fontTime, fontApp = fontTime2, fontApp2
|
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
||||||
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
|
scale *= superSample
|
||||||
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
|
fontTime, fontApp = fontTime2, fontApp2
|
||||||
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
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))
|
||||||
n := int(fw) * int(fh)
|
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
||||||
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
|
|
||||||
return
|
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)
|
// The finished bitmap that Windows will show.
|
||||||
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
defer pDeleteDC.Call(mem)
|
||||||
var bits unsafe.Pointer
|
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
var bits unsafe.Pointer
|
||||||
if bmp == 0 || bits == nil {
|
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||||
return
|
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||||
}
|
if bmp == 0 || bits == nil {
|
||||||
defer pDeleteObject.Call(bmp)
|
return
|
||||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
}
|
||||||
defer pSelectObject.Call(mem, old)
|
defer pDeleteObject.Call(bmp)
|
||||||
pix := unsafe.Slice((*uint32)(bits), n)
|
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||||
|
defer pSelectObject.Call(mem, old)
|
||||||
a := uint32(bgAlpha)
|
pix := unsafe.Slice((*uint32)(bits), n)
|
||||||
hoverA := max(a, 120)
|
|
||||||
length := float64(max(fw, fh))
|
a := uint32(bgAlpha)
|
||||||
rad := float64(min(fw, fh)) / 2
|
hoverA := max(a, 120)
|
||||||
stride := int(fw) * superSample
|
length := float64(max(fw, fh))
|
||||||
|
rad := float64(min(fw, fh)) / 2
|
||||||
for i := range pix {
|
stride := int(fw) * superSample
|
||||||
x, y := i%int(fw), i/int(fw)
|
|
||||||
|
for i := range pix {
|
||||||
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
x, y := i%int(fw), i/int(fw)
|
||||||
c := bgPix[i] & 0x00FFFFFF
|
|
||||||
bgA := a
|
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
||||||
if c != colBg {
|
c := bgPix[i] & 0x00FFFFFF
|
||||||
bgA = hoverA
|
bgA := a
|
||||||
}
|
if c != colBg {
|
||||||
bgR := (c >> 16 & 0xFF) * bgA / 255
|
bgA = hoverA
|
||||||
bgG := (c >> 8 & 0xFF) * bgA / 255
|
}
|
||||||
bgB := (c & 0xFF) * bgA / 255
|
bgR := (c >> 16 & 0xFF) * bgA / 255
|
||||||
|
bgG := (c >> 8 & 0xFF) * bgA / 255
|
||||||
// Foreground: how solid is this pixel, and what color is it.
|
bgB := (c & 0xFF) * bgA / 255
|
||||||
br, bgn, bb := avg4(onBlack, stride, x, y)
|
|
||||||
wr, wg, wb := avg4(onWhite, stride, x, y)
|
// Foreground: how solid is this pixel, and what color is it.
|
||||||
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
|
br, bgn, bb := avg4(onBlack, stride, x, y)
|
||||||
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
|
wr, wg, wb := avg4(onWhite, stride, x, y)
|
||||||
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
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
|
||||||
// Foreground over background.
|
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
||||||
inv := 255 - fa
|
|
||||||
oa := fa + bgA*inv/255
|
// Foreground over background.
|
||||||
or := fr + bgR*inv/255
|
inv := 255 - fa
|
||||||
og := fg + bgG*inv/255
|
oa := fa + bgA*inv/255
|
||||||
ob := fb + bgB*inv/255
|
or := fr + bgR*inv/255
|
||||||
|
og := fg + bgG*inv/255
|
||||||
// Rounded ends: how much of this pixel is inside the pill.
|
ob := fb + bgB*inv/255
|
||||||
along := float64(x) + 0.5
|
|
||||||
across := float64(y) + 0.5
|
// Rounded ends: how much of this pixel is inside the pill.
|
||||||
if vertical {
|
along := float64(x) + 0.5
|
||||||
along, across = across, along
|
across := float64(y) + 0.5
|
||||||
}
|
if vertical {
|
||||||
da := 0.0
|
along, across = across, along
|
||||||
if along < rad {
|
}
|
||||||
da = rad - along
|
da := 0.0
|
||||||
} else if along > length-rad {
|
if along < rad {
|
||||||
da = along - (length - rad)
|
da = rad - along
|
||||||
}
|
} else if along > length-rad {
|
||||||
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
|
da = along - (length - rad)
|
||||||
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
|
}
|
||||||
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
|
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}
|
var wr rect
|
||||||
sz := size{fw, fh}
|
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||||
src := point{0, 0}
|
dst := point{wr.Left, wr.Top}
|
||||||
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
sz := size{fw, fh}
|
||||||
pUpdateLayeredWindow.Call(hwnd, screen,
|
src := point{0, 0}
|
||||||
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
|
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
||||||
mem, uintptr(unsafe.Pointer(&src)), 0,
|
pUpdateLayeredWindow.Call(hwnd, screen,
|
||||||
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
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
|
func sub0(a, b uint32) uint32 {
|
||||||
}
|
if a > b {
|
||||||
return 0
|
return a - b
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|||||||
+373
-368
@@ -1,368 +1,373 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// The settings window: everything the right-click menu can change, in one
|
// The settings window: everything the right-click menu can change, in one
|
||||||
// place. It opens from "MirrorBar settings..." in the menu. Changes apply the
|
// 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.
|
// moment you make them, and the window stays in step if the menu is used too.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pSendMessage = user32.NewProc("SendMessageW")
|
pSendMessage = user32.NewProc("SendMessageW")
|
||||||
pSetWindowText = user32.NewProc("SetWindowTextW")
|
pSetWindowText = user32.NewProc("SetWindowTextW")
|
||||||
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
|
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
|
||||||
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
|
||||||
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
|
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
|
||||||
pGetFocus = user32.NewProc("GetFocus")
|
pGetFocus = user32.NewProc("GetFocus")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
menuSettingsID = 45
|
menuSettingsID = 45
|
||||||
|
|
||||||
wmCommand = 0x0111
|
wmCommand = 0x0111
|
||||||
wmHScroll = 0x0114
|
wmHScroll = 0x0114
|
||||||
wmSetFont = 0x0030
|
wmSetFont = 0x0030
|
||||||
|
|
||||||
wsChild = 0x40000000
|
wsChild = 0x40000000
|
||||||
wsTabStop = 0x00010000
|
wsTabStop = 0x00010000
|
||||||
wsVScroll = 0x00200000
|
wsVScroll = 0x00200000
|
||||||
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
|
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
|
||||||
wsBorder = 0x00800000
|
wsBorder = 0x00800000
|
||||||
bsPushButton = 0x0000
|
bsPushButton = 0x0000
|
||||||
bsDefPushButton = 0x0001
|
bsDefPushButton = 0x0001
|
||||||
bsAutoCheckBox = 0x0003
|
bsAutoCheckBox = 0x0003
|
||||||
cbsDropDownList = 0x0003
|
cbsDropDownList = 0x0003
|
||||||
tbsNoTicks = 0x0010
|
tbsNoTicks = 0x0010
|
||||||
esAutoHScroll = 0x0080
|
esAutoHScroll = 0x0080
|
||||||
esNumber = 0x2000
|
esNumber = 0x2000
|
||||||
|
|
||||||
emSetLimitText = 0x00C5
|
emSetLimitText = 0x00C5
|
||||||
enChange = 0x0300
|
enChange = 0x0300
|
||||||
|
|
||||||
bmGetCheck = 0x00F0
|
bmGetCheck = 0x00F0
|
||||||
bmSetCheck = 0x00F1
|
bmSetCheck = 0x00F1
|
||||||
cbAddString = 0x0143
|
cbAddString = 0x0143
|
||||||
cbGetCurSel = 0x0147
|
cbGetCurSel = 0x0147
|
||||||
cbSetCurSel = 0x014E
|
cbSetCurSel = 0x014E
|
||||||
tbmGetPos = 0x0400
|
tbmGetPos = 0x0400
|
||||||
tbmSetPos = 0x0405
|
tbmSetPos = 0x0405
|
||||||
tbmSetRange = 0x0406
|
tbmSetRange = 0x0406
|
||||||
|
|
||||||
cbnSelChange = 1
|
cbnSelChange = 1
|
||||||
tbEndTrack = 8
|
tbEndTrack = 8
|
||||||
colorBtnFace = 15
|
colorBtnFace = 15
|
||||||
|
|
||||||
idAlpha = 200
|
idAlpha = 200
|
||||||
idAlphaValue = 201
|
idAlphaValue = 201
|
||||||
idLogo = 202
|
idLogo = 202
|
||||||
idClock = 203
|
idClock = 203
|
||||||
idTrayIcons = 204
|
idTrayIcons = 204
|
||||||
idStyle = 205
|
idStyle = 205
|
||||||
idVertical = 206
|
idVertical = 206
|
||||||
idAutostart = 207
|
idAutostart = 207
|
||||||
idResetPos = 208
|
idResetPos = 208
|
||||||
idResetWidth = 209
|
idResetWidth = 209
|
||||||
idClose = 210
|
idClose = 210
|
||||||
idZip = 211
|
idZip = 211
|
||||||
idZipStatus = 212
|
idZipStatus = 212
|
||||||
idShowWeather = 213
|
idShowWeather = 213
|
||||||
idShowNews = 214
|
idShowNews = 214
|
||||||
idShowSys = 215
|
idShowSys = 215
|
||||||
idPanelFade = 216
|
idPanelFade = 216
|
||||||
)
|
idShowGM = 217
|
||||||
|
)
|
||||||
var (
|
|
||||||
hwndSettings uintptr
|
var (
|
||||||
settingsClass bool
|
hwndSettings uintptr
|
||||||
settingsFont uintptr
|
settingsClass bool
|
||||||
|
settingsFont uintptr
|
||||||
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
|
||||||
ctlVertical, ctlAutostart uintptr
|
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
|
||||||
ctlZip, ctlZipStatus uintptr
|
ctlVertical, ctlAutostart uintptr
|
||||||
ctlShowWeather, ctlShowNews, ctlShowSys, ctlPanelFade uintptr
|
ctlZip, ctlZipStatus uintptr
|
||||||
zipSyncing bool // true while the program itself is filling in the ZIP box
|
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 {
|
func boolWP(b bool) uintptr {
|
||||||
return 1
|
if b {
|
||||||
}
|
return 1
|
||||||
return 0
|
}
|
||||||
}
|
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 {
|
// makeControl creates one child control; sizes are in 96 dpi units.
|
||||||
hw, _, _ := pCreateWindowEx.Call(0,
|
func makeControl(parent, inst uintptr, class, text string, style uintptr, x, y, w, h int, id uintptr) uintptr {
|
||||||
uintptr(unsafe.Pointer(u16(class))), uintptr(unsafe.Pointer(u16(text))),
|
hw, _, _ := pCreateWindowEx.Call(0,
|
||||||
style|wsChild|wsVisible,
|
uintptr(unsafe.Pointer(u16(class))), uintptr(unsafe.Pointer(u16(text))),
|
||||||
uintptr(px(float64(x))), uintptr(px(float64(y))), uintptr(px(float64(w))), uintptr(px(float64(h))),
|
style|wsChild|wsVisible,
|
||||||
parent, id, inst, 0)
|
uintptr(px(float64(x))), uintptr(px(float64(y))), uintptr(px(float64(w))), uintptr(px(float64(h))),
|
||||||
if hw != 0 && settingsFont != 0 {
|
parent, id, inst, 0)
|
||||||
pSendMessage.Call(hw, wmSetFont, settingsFont, 1)
|
if hw != 0 && settingsFont != 0 {
|
||||||
}
|
pSendMessage.Call(hw, wmSetFont, settingsFont, 1)
|
||||||
return hw
|
}
|
||||||
}
|
return hw
|
||||||
|
}
|
||||||
func openSettings() {
|
|
||||||
if hwndSettings != 0 {
|
func openSettings() {
|
||||||
pShowWindow.Call(hwndSettings, swRestore)
|
if hwndSettings != 0 {
|
||||||
pSetForegroundWindow.Call(hwndSettings)
|
pShowWindow.Call(hwndSettings, swRestore)
|
||||||
settingsSync()
|
pSetForegroundWindow.Call(hwndSettings)
|
||||||
return
|
settingsSync()
|
||||||
}
|
return
|
||||||
inst, _, _ := pGetModuleHandle.Call(0)
|
}
|
||||||
className := u16("MirrorBarSettings")
|
inst, _, _ := pGetModuleHandle.Call(0)
|
||||||
if !settingsClass {
|
className := u16("MirrorBarSettings")
|
||||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
if !settingsClass {
|
||||||
wc := wndClassEx{
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
WndProc: syscall.NewCallback(settingsProc),
|
wc := wndClassEx{
|
||||||
Instance: inst,
|
WndProc: syscall.NewCallback(settingsProc),
|
||||||
Cursor: cursor,
|
Instance: inst,
|
||||||
Background: colorBtnFace + 1,
|
Cursor: cursor,
|
||||||
ClassName: className,
|
Background: colorBtnFace + 1,
|
||||||
}
|
ClassName: className,
|
||||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
}
|
||||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
icc := struct{ Size, Classes uint32 }{8, 0x4} // ICC_BAR_CLASSES: the slider
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
pInitCommonControls.Call(uintptr(unsafe.Pointer(&icc)))
|
icc := struct{ Size, Classes uint32 }{8, 0x4} // ICC_BAR_CLASSES: the slider
|
||||||
settingsClass = true
|
pInitCommonControls.Call(uintptr(unsafe.Pointer(&icc)))
|
||||||
}
|
settingsClass = true
|
||||||
if settingsFont == 0 {
|
}
|
||||||
settingsFont = makeFont(px(13), 400)
|
if settingsFont == 0 {
|
||||||
}
|
settingsFont = makeFont(px(13), 400)
|
||||||
|
}
|
||||||
r := rect{0, 0, px(400), px(488)}
|
|
||||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
r := rect{0, 0, px(400), px(516)}
|
||||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||||
sw, sh := screenSize()
|
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||||
hw, _, _ := pCreateWindowEx.Call(0,
|
sw, sh := screenSize()
|
||||||
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16("MirrorBar settings"))),
|
hw, _, _ := pCreateWindowEx.Call(0,
|
||||||
wsWindowFrame,
|
uintptr(unsafe.Pointer(className)), uintptr(unsafe.Pointer(u16("MirrorBar settings"))),
|
||||||
uintptr(max(0, (sw-ow)/2)), uintptr(max(0, (sh-oh)/2)), uintptr(ow), uintptr(oh),
|
wsWindowFrame,
|
||||||
0, 0, inst, 0)
|
uintptr(max(0, (sw-ow)/2)), uintptr(max(0, (sh-oh)/2)), uintptr(ow), uintptr(oh),
|
||||||
if hw == 0 {
|
0, 0, inst, 0)
|
||||||
return
|
if hw == 0 {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
label := func(text string, y int) {
|
|
||||||
makeControl(hw, inst, "STATIC", text, 0, 16, y+4, 150, 20, 0)
|
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)
|
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)
|
label("Background opacity", 16)
|
||||||
ctlAlphaValue = makeControl(hw, inst, "STATIC", "", 0, 344, 20, 44, 20, idAlphaValue)
|
ctlAlpha = makeControl(hw, inst, "msctls_trackbar32", "", tbsNoTicks|wsTabStop, 166, 14, 170, 28, idAlpha)
|
||||||
pSendMessage.Call(ctlAlpha, tbmSetRange, 1, uintptr(3|255<<16))
|
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("Windows logo color", 60)
|
||||||
label("Clock color", 96)
|
ctlLogo = combo(60, idLogo)
|
||||||
ctlClock = combo(96, idClock)
|
label("Clock color", 96)
|
||||||
label("Tray icon color", 132)
|
ctlClock = combo(96, idClock)
|
||||||
ctlTrayIcons = combo(132, idTrayIcons)
|
label("Tray icon color", 132)
|
||||||
label("Icon style", 168)
|
ctlTrayIcons = combo(132, idTrayIcons)
|
||||||
ctlStyle = combo(168, idStyle)
|
label("Icon style", 168)
|
||||||
for _, c := range []uintptr{ctlLogo, ctlClock, ctlTrayIcons} {
|
ctlStyle = combo(168, idStyle)
|
||||||
for _, p := range palette {
|
for _, c := range []uintptr{ctlLogo, ctlClock, ctlTrayIcons} {
|
||||||
pSendMessage.Call(c, cbAddString, 0, uintptr(unsafe.Pointer(u16(p.name))))
|
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))))
|
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)
|
label("ZIP code", 204)
|
||||||
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
|
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
|
||||||
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
|
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)
|
ctlShowWeather = makeControl(hw, inst, "BUTTON", "Show weather on the bar", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idShowWeather)
|
||||||
ctlShowSys = makeControl(hw, inst, "BUTTON", "Show system stats on the bar", bsAutoCheckBox|wsTabStop, 16, 318, 368, 22, idShowSys)
|
ctlShowNews = makeControl(hw, inst, "BUTTON", "Show local news on the bar", bsAutoCheckBox|wsTabStop, 16, 290, 368, 22, idShowNews)
|
||||||
ctlPanelFade = makeControl(hw, inst, "BUTTON", "Panels match the bar's transparency", bsAutoCheckBox|wsTabStop, 16, 346, 368, 22, idPanelFade)
|
ctlShowSys = makeControl(hw, inst, "BUTTON", "Show system stats on the bar", bsAutoCheckBox|wsTabStop, 16, 318, 368, 22, idShowSys)
|
||||||
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 374, 368, 22, idVertical)
|
ctlShowGM = makeControl(hw, inst, "BUTTON", "Show Google Messages on the bar", bsAutoCheckBox|wsTabStop, 16, 346, 368, 22, idShowGM)
|
||||||
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 402, 368, 22, idAutostart)
|
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)
|
||||||
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 442, 116, 28, idResetPos)
|
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 430, 368, 22, idAutostart)
|
||||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 442, 116, 28, idResetWidth)
|
|
||||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 442, 92, 28, idClose)
|
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)
|
||||||
hwndSettings = hw
|
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 470, 92, 28, idClose)
|
||||||
settingsSync()
|
|
||||||
pShowWindow.Call(hw, 1)
|
hwndSettings = hw
|
||||||
pSetForegroundWindow.Call(hw)
|
settingsSync()
|
||||||
}
|
pShowWindow.Call(hw, 1)
|
||||||
|
pSetForegroundWindow.Call(hw)
|
||||||
// settingsSync makes every control show the current setting.
|
}
|
||||||
func settingsSync() {
|
|
||||||
if hwndSettings == 0 {
|
// settingsSync makes every control show the current setting.
|
||||||
return
|
func settingsSync() {
|
||||||
}
|
if hwndSettings == 0 {
|
||||||
pSendMessage.Call(ctlAlpha, tbmSetPos, 1, uintptr(bgAlpha))
|
return
|
||||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
}
|
||||||
pSendMessage.Call(ctlLogo, cbSetCurSel, uintptr(logoIdx), 0)
|
pSendMessage.Call(ctlAlpha, tbmSetPos, 1, uintptr(bgAlpha))
|
||||||
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||||
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 0)
|
pSendMessage.Call(ctlLogo, cbSetCurSel, uintptr(logoIdx), 0)
|
||||||
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
|
pSendMessage.Call(ctlClock, cbSetCurSel, uintptr(clockIdx), 0)
|
||||||
pSendMessage.Call(ctlShowWeather, bmSetCheck, boolWP(showWeather), 0)
|
pSendMessage.Call(ctlTrayIcons, cbSetCurSel, uintptr(iconIdx), 0)
|
||||||
pSendMessage.Call(ctlShowNews, bmSetCheck, boolWP(showNews), 0)
|
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
|
||||||
pSendMessage.Call(ctlShowSys, bmSetCheck, boolWP(showSys), 0)
|
pSendMessage.Call(ctlShowWeather, bmSetCheck, boolWP(showWeather), 0)
|
||||||
pSendMessage.Call(ctlPanelFade, bmSetCheck, boolWP(flyMatchBar), 0)
|
pSendMessage.Call(ctlShowNews, bmSetCheck, boolWP(showNews), 0)
|
||||||
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
|
pSendMessage.Call(ctlShowSys, bmSetCheck, boolWP(showSys), 0)
|
||||||
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
pSendMessage.Call(ctlShowGM, bmSetCheck, boolWP(showGM), 0)
|
||||||
|
pSendMessage.Call(ctlPanelFade, bmSetCheck, boolWP(flyMatchBar), 0)
|
||||||
// Leave the ZIP box alone while the person is typing in it.
|
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
|
||||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
||||||
zipSyncing = true
|
|
||||||
pSetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(u16(wxZip))))
|
// Leave the ZIP box alone while the person is typing in it.
|
||||||
zipSyncing = false
|
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||||
}
|
zipSyncing = true
|
||||||
settingsZipStatusUpdate()
|
pSetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(u16(wxZip))))
|
||||||
}
|
zipSyncing = false
|
||||||
|
}
|
||||||
// zipText is what is typed in the ZIP box right now.
|
settingsZipStatusUpdate()
|
||||||
func zipText() string {
|
}
|
||||||
var buf [32]uint16
|
|
||||||
n, _, _ := pGetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
|
// zipText is what is typed in the ZIP box right now.
|
||||||
return syscall.UTF16ToString(buf[:n])
|
func zipText() string {
|
||||||
}
|
var buf [32]uint16
|
||||||
|
n, _, _ := pGetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
|
||||||
// settingsZipStatusUpdate refreshes the line under the ZIP box ("Showing weather for ...").
|
return syscall.UTF16ToString(buf[:n])
|
||||||
func settingsZipStatusUpdate() {
|
}
|
||||||
if hwndSettings == 0 || ctlZipStatus == 0 {
|
|
||||||
return
|
// settingsZipStatusUpdate refreshes the line under the ZIP box ("Showing weather for ...").
|
||||||
}
|
func settingsZipStatusUpdate() {
|
||||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(zipStatusText()))))
|
if hwndSettings == 0 || ctlZipStatus == 0 {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(zipStatusText()))))
|
||||||
// for that ZIP code; an empty box turns it off.
|
}
|
||||||
func zipEdited() {
|
|
||||||
z := onlyDigits(zipText())
|
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
|
||||||
switch {
|
// for that ZIP code; an empty box turns it off.
|
||||||
case len(z) == 5:
|
func zipEdited() {
|
||||||
weatherSetZip(z)
|
z := onlyDigits(zipText())
|
||||||
case z == "":
|
switch {
|
||||||
weatherSetZip("")
|
case len(z) == 5:
|
||||||
default:
|
weatherSetZip(z)
|
||||||
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16("A ZIP code has 5 digits."))))
|
case z == "":
|
||||||
return
|
weatherSetZip("")
|
||||||
}
|
default:
|
||||||
settingsZipStatusUpdate()
|
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16("A ZIP code has 5 digits."))))
|
||||||
}
|
return
|
||||||
|
}
|
||||||
func comboChoice(c uintptr) int {
|
settingsZipStatusUpdate()
|
||||||
r, _, _ := pSendMessage.Call(c, cbGetCurSel, 0, 0)
|
}
|
||||||
return int(int32(r))
|
|
||||||
}
|
func comboChoice(c uintptr) int {
|
||||||
|
r, _, _ := pSendMessage.Call(c, cbGetCurSel, 0, 0)
|
||||||
func checked(c uintptr) bool {
|
return int(int32(r))
|
||||||
r, _, _ := pSendMessage.Call(c, bmGetCheck, 0, 0)
|
}
|
||||||
return r == 1
|
|
||||||
}
|
func checked(c uintptr) bool {
|
||||||
|
r, _, _ := pSendMessage.Call(c, bmGetCheck, 0, 0)
|
||||||
func settingsCommand(id, note uintptr) {
|
return r == 1
|
||||||
switch id {
|
}
|
||||||
case 1, 2: // Enter and Esc
|
|
||||||
pDestroyWindow.Call(hwndSettings)
|
func settingsCommand(id, note uintptr) {
|
||||||
case idClose:
|
switch id {
|
||||||
pDestroyWindow.Call(hwndSettings)
|
case 1, 2: // Enter and Esc
|
||||||
case idLogo, idClock, idTrayIcons:
|
pDestroyWindow.Call(hwndSettings)
|
||||||
if note != cbnSelChange {
|
case idClose:
|
||||||
return
|
pDestroyWindow.Call(hwndSettings)
|
||||||
}
|
case idLogo, idClock, idTrayIcons:
|
||||||
switch id {
|
if note != cbnSelChange {
|
||||||
case idLogo:
|
return
|
||||||
if i := comboChoice(ctlLogo); i >= 0 {
|
}
|
||||||
logoIdx = i
|
switch id {
|
||||||
}
|
case idLogo:
|
||||||
case idClock:
|
if i := comboChoice(ctlLogo); i >= 0 {
|
||||||
if i := comboChoice(ctlClock); i >= 0 {
|
logoIdx = i
|
||||||
clockIdx = i
|
}
|
||||||
}
|
case idClock:
|
||||||
case idTrayIcons:
|
if i := comboChoice(ctlClock); i >= 0 {
|
||||||
if i := comboChoice(ctlTrayIcons); i >= 0 {
|
clockIdx = i
|
||||||
iconIdx = i
|
}
|
||||||
}
|
case idTrayIcons:
|
||||||
}
|
if i := comboChoice(ctlTrayIcons); i >= 0 {
|
||||||
saveColors()
|
iconIdx = i
|
||||||
redraw(hwndMain)
|
}
|
||||||
flyRefreshAll()
|
}
|
||||||
case idStyle:
|
saveColors()
|
||||||
if note != cbnSelChange {
|
redraw(hwndMain)
|
||||||
return
|
flyRefreshAll()
|
||||||
}
|
case idStyle:
|
||||||
if i := comboChoice(ctlStyle); i >= 0 && i < len(styleNames) {
|
if note != cbnSelChange {
|
||||||
iconMode = i
|
return
|
||||||
saveIconMode()
|
}
|
||||||
styleCacheClear()
|
if i := comboChoice(ctlStyle); i >= 0 && i < len(styleNames) {
|
||||||
redraw(hwndMain)
|
iconMode = i
|
||||||
}
|
saveIconMode()
|
||||||
case idZip:
|
styleCacheClear()
|
||||||
if note == enChange && !zipSyncing {
|
redraw(hwndMain)
|
||||||
zipEdited()
|
}
|
||||||
}
|
case idZip:
|
||||||
case idShowWeather:
|
if note == enChange && !zipSyncing {
|
||||||
setShowWeather(checked(ctlShowWeather))
|
zipEdited()
|
||||||
case idShowNews:
|
}
|
||||||
setShowNews(checked(ctlShowNews))
|
case idShowWeather:
|
||||||
case idShowSys:
|
setShowWeather(checked(ctlShowWeather))
|
||||||
setShowSys(checked(ctlShowSys))
|
case idShowNews:
|
||||||
case idPanelFade:
|
setShowNews(checked(ctlShowNews))
|
||||||
setFlyMatchBar(checked(ctlPanelFade))
|
case idShowSys:
|
||||||
case idVertical:
|
setShowSys(checked(ctlShowSys))
|
||||||
vertical = checked(ctlVertical)
|
case idShowGM:
|
||||||
saveOrient()
|
setShowGM(checked(ctlShowGM))
|
||||||
resetPos(hwndMain)
|
case idPanelFade:
|
||||||
case idAutostart:
|
setFlyMatchBar(checked(ctlPanelFade))
|
||||||
setAutostart(checked(ctlAutostart))
|
case idVertical:
|
||||||
settingsSync()
|
vertical = checked(ctlVertical)
|
||||||
case idResetPos:
|
saveOrient()
|
||||||
resetPos(hwndMain)
|
resetPos(hwndMain)
|
||||||
case idResetWidth:
|
case idAutostart:
|
||||||
leftPref = 0
|
setAutostart(checked(ctlAutostart))
|
||||||
saveLeftPref()
|
settingsSync()
|
||||||
redraw(hwndMain)
|
case idResetPos:
|
||||||
}
|
resetPos(hwndMain)
|
||||||
}
|
case idResetWidth:
|
||||||
|
leftPref = 0
|
||||||
func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
saveLeftPref()
|
||||||
defer func() {
|
redraw(hwndMain)
|
||||||
if r := recover(); r != nil {
|
}
|
||||||
result = 0
|
}
|
||||||
}
|
|
||||||
}()
|
func settingsProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
switch uint32(m) {
|
defer func() {
|
||||||
case wmCommand:
|
if r := recover(); r != nil {
|
||||||
settingsCommand(wparam&0xFFFF, wparam>>16&0xFFFF)
|
result = 0
|
||||||
return 0
|
}
|
||||||
case wmHScroll:
|
}()
|
||||||
if lparam == ctlAlpha && ctlAlpha != 0 {
|
switch uint32(m) {
|
||||||
pos, _, _ := pSendMessage.Call(ctlAlpha, tbmGetPos, 0, 0)
|
case wmCommand:
|
||||||
n := int(pos)
|
settingsCommand(wparam&0xFFFF, wparam>>16&0xFFFF)
|
||||||
if n >= 3 && n <= 255 && n != bgAlpha {
|
return 0
|
||||||
bgAlpha = n
|
case wmHScroll:
|
||||||
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
if lparam == ctlAlpha && ctlAlpha != 0 {
|
||||||
redraw(hwndMain)
|
pos, _, _ := pSendMessage.Call(ctlAlpha, tbmGetPos, 0, 0)
|
||||||
flyRefreshAll()
|
n := int(pos)
|
||||||
}
|
if n >= 3 && n <= 255 && n != bgAlpha {
|
||||||
if wparam&0xFFFF == tbEndTrack {
|
bgAlpha = n
|
||||||
saveAlpha()
|
pSetWindowText.Call(ctlAlphaValue, uintptr(unsafe.Pointer(u16(strconv.Itoa(bgAlpha*100/255)+"%"))))
|
||||||
}
|
redraw(hwndMain)
|
||||||
}
|
flyRefreshAll()
|
||||||
return 0
|
}
|
||||||
case wmClose:
|
if wparam&0xFFFF == tbEndTrack {
|
||||||
pDestroyWindow.Call(hwnd)
|
saveAlpha()
|
||||||
return 0
|
}
|
||||||
case wmDestroy:
|
}
|
||||||
hwndSettings = 0
|
return 0
|
||||||
return 0
|
case wmClose:
|
||||||
}
|
pDestroyWindow.Call(hwnd)
|
||||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
return 0
|
||||||
return r
|
case wmDestroy:
|
||||||
}
|
hwndSettings = 0
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
+271
-270
@@ -1,270 +1,271 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
// The system stats flyout: a little monitor on the bar that opens a panel with
|
// The system stats flyout: a little monitor on the bar that opens a panel with
|
||||||
// the sort of thing neofetch prints (OS, CPU, memory, disks, uptime...). Click a
|
// the sort of thing neofetch prints (OS, CPU, memory, disks, uptime...). Click a
|
||||||
// line to copy it, or click the header to copy everything as plain text that can
|
// line to copy it, or click the header to copy everything as plain text that can
|
||||||
// be pasted into any other program.
|
// be pasted into any other program.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sysW = 420.0
|
sysW = 420.0
|
||||||
sysHead = 44.0
|
sysHead = 44.0
|
||||||
sysRow_ = 24.0
|
sysRow_ = 24.0
|
||||||
sysFoot = 26.0
|
sysFoot = 26.0
|
||||||
|
|
||||||
sysRefreshTimerID = 2
|
sysRefreshTimerID = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sysHwnd uintptr
|
sysHwnd uintptr
|
||||||
sysShown bool
|
sysShown bool
|
||||||
sysPrevBtn bool
|
sysPrevBtn bool
|
||||||
sysHover = -1
|
sysHover = -1
|
||||||
sysRows []sysRow
|
sysRows []sysRow
|
||||||
sysCopied string // what the header says after a copy: "Copied" or "Copy failed"
|
sysCopied string // what the header says after a copy: "Copied" or "Copy failed"
|
||||||
sysCopiedAt time.Time
|
sysCopiedAt time.Time
|
||||||
sysTick int
|
sysTick int
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------- the button on the bar ----------
|
// ---------- the button on the bar ----------
|
||||||
|
|
||||||
func drawSysIcon(hdc uintptr, r rect) {
|
func drawSysIcon(hdc uintptr, r rect) {
|
||||||
if !layerFg {
|
if !layerFg {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
col := iconColor()
|
col := iconColor()
|
||||||
cx, cy := center(r)
|
cx, cy := center(r)
|
||||||
e := px(1)
|
e := px(1)
|
||||||
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(2.5)
|
l, t, rt, b := cx-px(6), cy-px(5.5), cx+px(6), cy+px(2.5)
|
||||||
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
fillRaw(hdc, rect{l, t, rt, t + e}, col)
|
||||||
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
fillRaw(hdc, rect{l, b - e, rt, b}, col)
|
||||||
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
fillRaw(hdc, rect{l, t, l + e, b}, col)
|
||||||
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
fillRaw(hdc, rect{rt - e, t, rt, b}, col)
|
||||||
fillRaw(hdc, rect{cx - px(1), b, cx + px(1), cy + px(4.5)}, col) // stand
|
fillRaw(hdc, rect{cx - px(1), b, cx + px(1), cy + px(4.5)}, col) // stand
|
||||||
fillRaw(hdc, rect{cx - px(3), cy + px(4.5), cx + px(3), cy + px(5.5)}, col)
|
fillRaw(hdc, rect{cx - px(3), cy + px(4.5), cx + px(3), cy + px(5.5)}, col)
|
||||||
fillRaw(hdc, rect{cx - px(3.5), cy - px(0.5), cx - px(2), cy + px(1.5)}, col) // little bars on the screen
|
fillRaw(hdc, rect{cx - px(3.5), cy - px(0.5), cx - px(2), cy + px(1.5)}, col) // little bars on the screen
|
||||||
fillRaw(hdc, rect{cx - px(1), cy - px(2.5), cx + px(0.5), cy + px(1.5)}, col)
|
fillRaw(hdc, rect{cx - px(1), cy - px(2.5), cx + px(0.5), cy + px(1.5)}, col)
|
||||||
fillRaw(hdc, rect{cx + px(2), cy - px(1.5), cx + px(3.5), cy + px(1.5)}, col)
|
fillRaw(hdc, rect{cx + px(2), cy - px(1.5), cx + px(3.5), cy + px(1.5)}, col)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- the panel window ----------
|
// ---------- the panel window ----------
|
||||||
|
|
||||||
func sysInit(inst uintptr) {
|
func sysInit(inst uintptr) {
|
||||||
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
className := u16("MirrorBarSys")
|
className := u16("MirrorBarSys")
|
||||||
wc := wndClassEx{
|
wc := wndClassEx{
|
||||||
WndProc: syscall.NewCallback(sysProc),
|
WndProc: syscall.NewCallback(sysProc),
|
||||||
Instance: inst,
|
Instance: inst,
|
||||||
Cursor: cursor,
|
Cursor: cursor,
|
||||||
ClassName: className,
|
ClassName: className,
|
||||||
}
|
}
|
||||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
sysHwnd, _, _ = pCreateWindowEx.Call(
|
sysHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
wsExToolWindow|wsExTopmost|wsExNoActivate|wsExLayered,
|
||||||
uintptr(unsafe.Pointer(className)),
|
uintptr(unsafe.Pointer(className)),
|
||||||
uintptr(unsafe.Pointer(u16(""))),
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
wsPopup,
|
wsPopup,
|
||||||
0, 0, 10, 10,
|
0, 0, 10, 10,
|
||||||
0, 0, inst, 0)
|
0, 0, inst, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
func sysProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
result = 0 // the flyout is optional; never take the bar down with it
|
result = 0 // the flyout is optional; never take the bar down with it
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
switch uint32(m) {
|
switch uint32(m) {
|
||||||
case wmEraseBkgnd:
|
case wmEraseBkgnd:
|
||||||
return 1
|
return 1
|
||||||
case wmMouseActivate:
|
case wmMouseActivate:
|
||||||
return maNoActivate
|
return maNoActivate
|
||||||
case wmPaint:
|
case wmPaint:
|
||||||
flyPaint(hwnd, sysDraw)
|
flyPaint(hwnd, sysDraw)
|
||||||
return 0
|
return 0
|
||||||
case wmTimer:
|
case wmTimer:
|
||||||
if wparam == sysRefreshTimerID {
|
if wparam == sysRefreshTimerID {
|
||||||
sysRows = sysGather() // uptime and memory move
|
sysRows = sysGather() // uptime and memory move
|
||||||
flyRefresh(sysHwnd)
|
flyRefresh(sysHwnd)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
sysPoll()
|
sysPoll()
|
||||||
return 0
|
return 0
|
||||||
case wmSetCursor:
|
case wmSetCursor:
|
||||||
if sysOverButton() {
|
if sysOverButton() {
|
||||||
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
h, _, _ := pLoadCursor.Call(0, idcHandCursor)
|
||||||
pSetCursor.Call(h)
|
pSetCursor.Call(h)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
case wmLButtonUp:
|
case wmLButtonUp:
|
||||||
sysClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
sysClick(int32(int16(lparam&0xFFFF)), int32(int16(lparam>>16&0xFFFF)))
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// sysOverButton is true when the mouse is on something clickable: a line or the header.
|
// sysOverButton is true when the mouse is on something clickable: a line or the header.
|
||||||
func sysOverButton() bool {
|
func sysOverButton() bool {
|
||||||
var cp point
|
var cp point
|
||||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
var fr rect
|
var fr rect
|
||||||
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
if !inRect(fr, cp) {
|
if !inRect(fr, cp) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
y := cp.Y - fr.Top
|
y := cp.Y - fr.Top
|
||||||
return y < px(sysHead) || sysRowAt(y) >= 0
|
return y < px(sysHead) || sysRowAt(y) >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func sysToggle() {
|
func sysToggle() {
|
||||||
if !showSys {
|
if !showSys {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if sysShown {
|
if sysShown {
|
||||||
sysHide()
|
sysHide()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if sysHwnd == 0 {
|
if sysHwnd == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
previewHide()
|
previewHide()
|
||||||
weatherHide() // one panel at a time
|
weatherHide() // one panel at a time
|
||||||
newsHide()
|
newsHide()
|
||||||
sysRows = sysGather()
|
gmHide()
|
||||||
sysShown = true
|
sysRows = sysGather()
|
||||||
sysPrevBtn = true // ignore a button that is still held from the click that opened this
|
sysShown = true
|
||||||
sysHover = -1
|
sysPrevBtn = true // ignore a button that is still held from the click that opened this
|
||||||
sysCopied = ""
|
sysHover = -1
|
||||||
sysPlace()
|
sysCopied = ""
|
||||||
pSetTimer.Call(sysHwnd, wxPollTimerID, 80, 0)
|
sysPlace()
|
||||||
pSetTimer.Call(sysHwnd, sysRefreshTimerID, 1500, 0)
|
pSetTimer.Call(sysHwnd, wxPollTimerID, 80, 0)
|
||||||
}
|
pSetTimer.Call(sysHwnd, sysRefreshTimerID, 1500, 0)
|
||||||
|
}
|
||||||
func sysHide() {
|
|
||||||
if !sysShown {
|
func sysHide() {
|
||||||
return
|
if !sysShown {
|
||||||
}
|
return
|
||||||
sysShown = false
|
}
|
||||||
sysHover = -1
|
sysShown = false
|
||||||
pKillTimer.Call(sysHwnd, wxPollTimerID)
|
sysHover = -1
|
||||||
pKillTimer.Call(sysHwnd, sysRefreshTimerID)
|
pKillTimer.Call(sysHwnd, wxPollTimerID)
|
||||||
pShowWindow.Call(sysHwnd, swHide)
|
pKillTimer.Call(sysHwnd, sysRefreshTimerID)
|
||||||
}
|
pShowWindow.Call(sysHwnd, swHide)
|
||||||
|
}
|
||||||
func sysShutdown() {
|
|
||||||
sysHide()
|
func sysShutdown() {
|
||||||
if sysHwnd != 0 {
|
sysHide()
|
||||||
pDestroyWindow.Call(sysHwnd)
|
if sysHwnd != 0 {
|
||||||
sysHwnd = 0
|
pDestroyWindow.Call(sysHwnd)
|
||||||
}
|
sysHwnd = 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
func sysPlace() {
|
|
||||||
if sysHwnd == 0 {
|
func sysPlace() {
|
||||||
return
|
if sysHwnd == 0 {
|
||||||
}
|
return
|
||||||
lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot
|
}
|
||||||
flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh))
|
lh := sysHead + float64(len(sysRows))*sysRow_ + sysFoot
|
||||||
flyRefresh(sysHwnd)
|
flyPlace(sysHwnd, trayAnchor(traySys), px(sysW), px(lh))
|
||||||
}
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
// sysRowAt is the line under a height in the panel (real pixels), or -1.
|
|
||||||
func sysRowAt(y int32) int {
|
// sysRowAt is the line under a height in the panel (real pixels), or -1.
|
||||||
ry := y - px(sysHead)
|
func sysRowAt(y int32) int {
|
||||||
if ry < 0 {
|
ry := y - px(sysHead)
|
||||||
return -1
|
if ry < 0 {
|
||||||
}
|
return -1
|
||||||
i := int(ry / px(sysRow_))
|
}
|
||||||
if i >= len(sysRows) {
|
i := int(ry / px(sysRow_))
|
||||||
return -1
|
if i >= len(sysRows) {
|
||||||
}
|
return -1
|
||||||
return i
|
}
|
||||||
}
|
return i
|
||||||
|
}
|
||||||
func sysPoll() {
|
|
||||||
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
func sysPoll() {
|
||||||
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
l, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
down := (l|r)&0x8000 != 0
|
r, _, _ := pGetAsyncKeyState.Call(vkRButton)
|
||||||
var cp point
|
down := (l|r)&0x8000 != 0
|
||||||
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
var cp point
|
||||||
var fr rect
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
var fr rect
|
||||||
if down && !sysPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(traySys), cp) {
|
pGetWindowRect.Call(sysHwnd, uintptr(unsafe.Pointer(&fr)))
|
||||||
sysHide()
|
if down && !sysPrevBtn && !inRect(fr, cp) && !inRect(trayAnchor(traySys), cp) {
|
||||||
sysPrevBtn = down
|
sysHide()
|
||||||
return
|
sysPrevBtn = down
|
||||||
}
|
return
|
||||||
sysPrevBtn = down
|
}
|
||||||
|
sysPrevBtn = down
|
||||||
h := -1
|
|
||||||
if inRect(fr, cp) {
|
h := -1
|
||||||
h = sysRowAt(cp.Y - fr.Top)
|
if inRect(fr, cp) {
|
||||||
}
|
h = sysRowAt(cp.Y - fr.Top)
|
||||||
changed := h != sysHover
|
}
|
||||||
sysHover = h
|
changed := h != sysHover
|
||||||
if sysCopied != "" && time.Since(sysCopiedAt) > 1500*time.Millisecond {
|
sysHover = h
|
||||||
sysCopied = ""
|
if sysCopied != "" && time.Since(sysCopiedAt) > 1500*time.Millisecond {
|
||||||
changed = true
|
sysCopied = ""
|
||||||
}
|
changed = true
|
||||||
if changed {
|
}
|
||||||
flyRefresh(sysHwnd)
|
if changed {
|
||||||
}
|
flyRefresh(sysHwnd)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
func sysCopy(text, what string) {
|
|
||||||
if clipboardSet(text) {
|
func sysCopy(text, what string) {
|
||||||
sysCopied = what
|
if clipboardSet(text) {
|
||||||
} else {
|
sysCopied = what
|
||||||
sysCopied = "Copy failed"
|
} else {
|
||||||
}
|
sysCopied = "Copy failed"
|
||||||
sysCopiedAt = time.Now()
|
}
|
||||||
flyRefresh(sysHwnd)
|
sysCopiedAt = time.Now()
|
||||||
}
|
flyRefresh(sysHwnd)
|
||||||
|
}
|
||||||
func sysClick(x, y int32) {
|
|
||||||
if y < px(sysHead) {
|
func sysClick(x, y int32) {
|
||||||
sysCopy(sysText(sysRows), "Copied everything")
|
if y < px(sysHead) {
|
||||||
return
|
sysCopy(sysText(sysRows), "Copied everything")
|
||||||
}
|
return
|
||||||
if i := sysRowAt(y); i >= 0 {
|
}
|
||||||
sysCopy(sysRows[i].label+": "+sysRows[i].value, "Copied "+sysRows[i].label)
|
if i := sysRowAt(y); i >= 0 {
|
||||||
}
|
sysCopy(sysRows[i].label+": "+sysRows[i].value, "Copied "+sysRows[i].label)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ---------- painting ----------
|
|
||||||
|
// ---------- painting ----------
|
||||||
func sysDraw(hdc uintptr, W, H int32) {
|
|
||||||
u := px
|
func sysDraw(hdc uintptr, W, H int32) {
|
||||||
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
u := px
|
||||||
|
flyFrame(hdc, W, H) // outline in the tray icon color; the background is added when painting
|
||||||
pad := u(14)
|
|
||||||
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
pad := u(14)
|
||||||
wxText(hdc, sysUserHost(), rect{pad, u(10), W - pad - u(150), u(34)}, fMed, colText, line)
|
line := uintptr(dtLeft | dtVCenter | dtSingleLine | dtEndEllipsis)
|
||||||
btn, col := "Copy all", colAccent
|
wxText(hdc, sysUserHost(), rect{pad, u(10), W - pad - u(150), u(34)}, fMed, colText, line)
|
||||||
if sysCopied != "" {
|
btn, col := "Copy all", colAccent
|
||||||
btn, col = sysCopied, colDim
|
if sysCopied != "" {
|
||||||
}
|
btn, col = sysCopied, colDim
|
||||||
wxText(hdc, btn, rect{W - pad - u(150), u(12), W - pad, u(32)}, fBold, col, dtRight|dtVCenter|dtSingleLine|dtEndEllipsis)
|
}
|
||||||
fillRaw(hdc, rect{pad, u(sysHead) - u(2), W - pad, u(sysHead) - u(1)}, colRule)
|
wxText(hdc, btn, rect{W - pad - u(150), u(12), W - pad, u(32)}, fBold, col, dtRight|dtVCenter|dtSingleLine|dtEndEllipsis)
|
||||||
|
fillRaw(hdc, rect{pad, u(sysHead) - u(2), W - pad, u(sysHead) - u(1)}, colRule)
|
||||||
labelW := u(96)
|
|
||||||
for i, r := range sysRows {
|
labelW := u(96)
|
||||||
y := u(sysHead) + int32(i)*u(sysRow_)
|
for i, r := range sysRows {
|
||||||
val := colText
|
y := u(sysHead) + int32(i)*u(sysRow_)
|
||||||
if i == sysHover {
|
val := colText
|
||||||
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(sysRow_)}, rgb(40, 40, 48))
|
if i == sysHover {
|
||||||
val = colAccent
|
fillRaw(hdc, rect{u(6), y, W - u(6), y + u(sysRow_)}, rgb(40, 40, 48))
|
||||||
}
|
val = colAccent
|
||||||
wxText(hdc, r.label, rect{pad, y, pad + labelW, y + u(sysRow_)}, fBold, colAccent, line)
|
}
|
||||||
wxText(hdc, r.value, rect{pad + labelW, y, W - pad, y + u(sysRow_)}, fText, val, line)
|
wxText(hdc, r.label, rect{pad, y, pad + labelW, y + u(sysRow_)}, fBold, colAccent, line)
|
||||||
}
|
wxText(hdc, r.value, rect{pad + labelW, y, W - pad, y + u(sysRow_)}, fText, val, line)
|
||||||
y := u(sysHead) + int32(len(sysRows))*u(sysRow_)
|
}
|
||||||
wxText(hdc, "Click a line to copy it, or the top to copy everything.", rect{pad, y + u(4), W - pad, H - u(2)}, fTiny, colDim, line)
|
y := u(sysHead) + int32(len(sysRows))*u(sysRow_)
|
||||||
}
|
wxText(hdc, "Click a line to copy it, or the top to copy everything.", rect{pad, y + u(4), W - pad, H - u(2)}, fTiny, colDim, line)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user