Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93f6b94d98 | ||
|
|
6ac9164755 | ||
|
|
9ea41cab49 | ||
|
|
2a76d1d9c9 | ||
|
|
fc1d82d790 | ||
|
|
c80267f81f | ||
|
|
e82ed224e8 | ||
|
|
8ab3cda02d | ||
|
|
b26879abdb |
@@ -22,7 +22,9 @@ Drag the app icons and the Windows logo along the left row to reorder them. Mirr
|
|||||||
- "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.
|
- In "MirrorBar settings..." you can also change how the bar looks. "Bar color" turns the pill dark (the default), black, white, red, dark green, navy, purple or gray. "Windows logo shape" swaps the four squares for rounded squares, four dots, squares tilted right or left, diamonds or a waving flag. "Clock text size" makes the time and date Normal, Large, Larger or Largest, and "Bold clock text" makes them heavier; the bar grows to fit. Under "Show on the bar" you can take the battery, volume and wifi icons off the bar and bring them back. The logo, clock and tray icon colors now have sixteen choices, including dark green, teal, navy, maroon, gray and lime. A light bar needs a dark clock and icon color to be readable.
|
||||||
|
|
||||||
|
Smooth, outline-free icons and text, even when the pill is see-through.
|
||||||
- Click the storm cloud and a weather panel opens above the bar: the temperature in Fahrenheit, what it feels like, the high and low, humidity, wind, chance of rain, sunrise, sunset, UV index, the moon phase, a looping radar picture of the last hour or so centered on your ZIP code, and the next five days. Click the cloud again, or click anywhere else, and it closes. It needs a ZIP code: type it in "MirrorBar settings..." (a 5 digit US ZIP code) and the weather turns on at once. The forecast comes from Open-Meteo (open-meteo.com, free, no account), the radar map comes from RainViewer and Esri and is only downloaded when you open the panel, and MirrorBar only goes to the internet when a ZIP code is set. The cloud can be dragged along the right row like the other icons.
|
- Click the 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.
|
||||||
|
|||||||
+14
-3
@@ -65,7 +65,18 @@ func saveLeftPref() {
|
|||||||
// halfLimit is the longest either half may be.
|
// halfLimit is the longest either half may be.
|
||||||
func halfLimit() int32 {
|
func halfLimit() int32 {
|
||||||
sw, _ := screenSize()
|
sw, _ := screenSize()
|
||||||
return sw/2 - px(4)
|
return sw*layerMul()/2 - px(4)
|
||||||
|
}
|
||||||
|
|
||||||
|
// layerMul is how much bigger the layer being drawn is than the real bar (2
|
||||||
|
// while the icons are drawn at double size, otherwise 1). Lengths kept in real
|
||||||
|
// pixels, like the chosen bar width and the screen size, are scaled by it so
|
||||||
|
// the icons land on the same spots the mouse tests.
|
||||||
|
func layerMul() int32 {
|
||||||
|
if realScale <= 0 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return int32(scale/realScale + 0.5)
|
||||||
}
|
}
|
||||||
|
|
||||||
// rightHalf is the length of the right half: the tray items plus a little padding.
|
// rightHalf is the length of the right half: the tray items plus a little padding.
|
||||||
@@ -87,7 +98,7 @@ func leftHalf() int32 {
|
|||||||
case leftPref < 0:
|
case leftPref < 0:
|
||||||
h = lc
|
h = lc
|
||||||
case leftPref > 0:
|
case leftPref > 0:
|
||||||
h = max(lc, leftPref)
|
h = max(lc, leftPref*layerMul())
|
||||||
default:
|
default:
|
||||||
h = max(lc, rightHalf())
|
h = max(lc, rightHalf())
|
||||||
}
|
}
|
||||||
@@ -128,7 +139,7 @@ func overEdge(hwnd uintptr) bool {
|
|||||||
func beginResize(hwnd uintptr) {
|
func beginResize(hwnd uintptr) {
|
||||||
resizing = true
|
resizing = true
|
||||||
resizeFrom = cursorAlong()
|
resizeFrom = cursorAlong()
|
||||||
resizeLen = leftHalf()
|
resizeLen = leftHalf() // always measured at real size here
|
||||||
pSetCapture.Call(hwnd)
|
pSetCapture.Call(hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -15,6 +15,10 @@ var (
|
|||||||
showNews = true
|
showNews = true
|
||||||
showSys = true
|
showSys = true
|
||||||
showGM = true // the Google Messages bubble
|
showGM = true // the Google Messages bubble
|
||||||
|
|
||||||
|
showBattery = true
|
||||||
|
showVolume = true
|
||||||
|
showWifi = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
func featuresFile() string { return filepath.Join(dataDir(), "features.txt") }
|
||||||
@@ -45,12 +49,18 @@ func loadFeatures() {
|
|||||||
groupWins = on
|
groupWins = on
|
||||||
case "autohide":
|
case "autohide":
|
||||||
autoHide = on
|
autoHide = on
|
||||||
|
case "battery":
|
||||||
|
showBattery = on
|
||||||
|
case "volume":
|
||||||
|
showVolume = on
|
||||||
|
case "wifi":
|
||||||
|
showWifi = on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveFeatures() {
|
func saveFeatures() {
|
||||||
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\ngroup=" + b01(groupWins) + "\nautohide=" + b01(autoHide) + "\n"
|
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\ngroup=" + b01(groupWins) + "\nautohide=" + b01(autoHide) + "\nbattery=" + b01(showBattery) + "\nvolume=" + b01(showVolume) + "\nwifi=" + b01(showWifi) + "\n"
|
||||||
_ = os.MkdirAll(dataDir(), 0o755)
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,325 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// How the bar looks: the color of the bar itself, the shape of the Windows
|
||||||
|
// logo, the size and weight of the clock text, and which of the battery, volume
|
||||||
|
// and wifi icons are on the bar. All of it is changed in the settings window.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pRoundRect = gdi32.NewProc("RoundRect")
|
||||||
|
|
||||||
|
// ---------- the color of the bar ----------
|
||||||
|
|
||||||
|
type barColor struct {
|
||||||
|
name string
|
||||||
|
r, g, b int
|
||||||
|
}
|
||||||
|
|
||||||
|
// New colors go on the end so a saved choice keeps meaning the same color.
|
||||||
|
var barPalette = []barColor{
|
||||||
|
{"Dark (default)", 22, 22, 26},
|
||||||
|
{"Black", 0, 0, 0},
|
||||||
|
{"White", 245, 245, 245},
|
||||||
|
{"Red", 190, 35, 35},
|
||||||
|
{"Dark green", 20, 72, 42},
|
||||||
|
{"Navy", 16, 36, 92},
|
||||||
|
{"Purple", 72, 38, 112},
|
||||||
|
{"Gray", 92, 92, 100},
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
barIdx = 0
|
||||||
|
logoStyle = 0
|
||||||
|
clockSizeIx = 0
|
||||||
|
clockBold = false
|
||||||
|
)
|
||||||
|
|
||||||
|
var logoStyleNames = []string{
|
||||||
|
"Classic squares",
|
||||||
|
"Rounded squares",
|
||||||
|
"Four dots",
|
||||||
|
"Tilted right",
|
||||||
|
"Tilted left",
|
||||||
|
"Diamonds",
|
||||||
|
"Waving flag",
|
||||||
|
}
|
||||||
|
|
||||||
|
type clockSizeChoice struct {
|
||||||
|
name string
|
||||||
|
px int
|
||||||
|
}
|
||||||
|
|
||||||
|
var clockSizes = []clockSizeChoice{
|
||||||
|
{"Normal", 13},
|
||||||
|
{"Large", 15},
|
||||||
|
{"Larger", 17},
|
||||||
|
{"Largest", 19},
|
||||||
|
}
|
||||||
|
|
||||||
|
// barRGB is the bar color as it sits in a bitmap (0xRRGGBB).
|
||||||
|
func barRGB() uint32 {
|
||||||
|
i := barIdx
|
||||||
|
if i < 0 || i >= len(barPalette) {
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
c := barPalette[i]
|
||||||
|
return uint32(c.r)<<16 | uint32(c.g)<<8 | uint32(c.b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// barIsLight is true for a bar bright enough that the dark hover fills would look wrong on it.
|
||||||
|
func barIsLight() bool {
|
||||||
|
i := barIdx
|
||||||
|
if i < 0 || i >= len(barPalette) {
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
c := barPalette[i]
|
||||||
|
return (c.r*299+c.g*587+c.b*114)/1000 > 140
|
||||||
|
}
|
||||||
|
|
||||||
|
// hoverTint is the fill used for a hovered button, matched to the bar color.
|
||||||
|
func hoverTint(c uint32, light bool) uint32 {
|
||||||
|
if light {
|
||||||
|
return 200<<16 | 200<<8 | 208
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the clock text ----------
|
||||||
|
|
||||||
|
func clockPx() int {
|
||||||
|
i := clockSizeIx
|
||||||
|
if i < 0 || i >= len(clockSizes) {
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
return clockSizes[i].px
|
||||||
|
}
|
||||||
|
|
||||||
|
// clockWidth is the room the time and date need, which grows with the text.
|
||||||
|
func clockWidth() int32 {
|
||||||
|
w := 140.0 * float64(clockPx()) / 13.0
|
||||||
|
if clockBold {
|
||||||
|
w *= 1.08
|
||||||
|
}
|
||||||
|
return px(w)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rebuildClockFonts makes the clock fonts again (the normal one and the double
|
||||||
|
// size one used for the smooth pass) after the size or weight changed.
|
||||||
|
func rebuildClockFonts() {
|
||||||
|
weight := 400
|
||||||
|
if clockBold {
|
||||||
|
weight = 700
|
||||||
|
}
|
||||||
|
oldA, oldB := fontTime, fontTime2
|
||||||
|
fontTime = makeFont(px(float64(clockPx())), weight)
|
||||||
|
scale *= superSample
|
||||||
|
fontTime2 = makeFont(px(float64(clockPx())), weight)
|
||||||
|
scale /= superSample
|
||||||
|
if oldA != 0 {
|
||||||
|
pDeleteObject.Call(oldA)
|
||||||
|
}
|
||||||
|
if oldB != 0 {
|
||||||
|
pDeleteObject.Call(oldB)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- remembering the choices ----------
|
||||||
|
|
||||||
|
func lookFile() string { return filepath.Join(dataDir(), "look.txt") }
|
||||||
|
|
||||||
|
func loadLook() {
|
||||||
|
b, err := os.ReadFile(lookFile())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, ln := range strings.Split(string(b), "\n") {
|
||||||
|
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
n, err := strconv.Atoi(strings.TrimSpace(v))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch strings.TrimSpace(k) {
|
||||||
|
case "barcolor":
|
||||||
|
if n >= 0 && n < len(barPalette) {
|
||||||
|
barIdx = n
|
||||||
|
}
|
||||||
|
case "logostyle":
|
||||||
|
if n >= 0 && n < len(logoStyleNames) {
|
||||||
|
logoStyle = n
|
||||||
|
}
|
||||||
|
case "clocksize":
|
||||||
|
if n >= 0 && n < len(clockSizes) {
|
||||||
|
clockSizeIx = n
|
||||||
|
}
|
||||||
|
case "clockbold":
|
||||||
|
clockBold = n != 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveLook() {
|
||||||
|
s := "barcolor=" + strconv.Itoa(barIdx) +
|
||||||
|
"\nlogostyle=" + strconv.Itoa(logoStyle) +
|
||||||
|
"\nclocksize=" + strconv.Itoa(clockSizeIx) +
|
||||||
|
"\nclockbold=" + b01(clockBold) + "\n"
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
|
_ = os.WriteFile(lookFile(), []byte(s), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the settings window calls these ----------
|
||||||
|
|
||||||
|
func setBarColor(i int) {
|
||||||
|
if i < 0 || i >= len(barPalette) || i == barIdx {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
barIdx = i
|
||||||
|
saveLook()
|
||||||
|
redraw(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setLogoStyle(i int) {
|
||||||
|
if i < 0 || i >= len(logoStyleNames) || i == logoStyle {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logoStyle = i
|
||||||
|
saveLook()
|
||||||
|
redraw(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setClockSize(i int) {
|
||||||
|
if i < 0 || i >= len(clockSizes) || i == clockSizeIx {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clockSizeIx = i
|
||||||
|
rebuildClockFonts()
|
||||||
|
saveLook()
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setClockBold(on bool) {
|
||||||
|
if clockBold == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clockBold = on
|
||||||
|
rebuildClockFonts()
|
||||||
|
saveLook()
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setShowBattery(on bool) {
|
||||||
|
if showBattery == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showBattery = on
|
||||||
|
saveFeatures()
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setShowVolume(on bool) {
|
||||||
|
if showVolume == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showVolume = on
|
||||||
|
saveFeatures()
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setShowWifi(on bool) {
|
||||||
|
if showWifi == on {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
showWifi = on
|
||||||
|
saveFeatures()
|
||||||
|
positionBar(hwndMain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- the Windows logo ----------
|
||||||
|
|
||||||
|
// roundRectRaw paints a filled rounded square with no outline.
|
||||||
|
func roundRectRaw(hdc uintptr, l, t, r, b, rad int32, color uintptr) {
|
||||||
|
brush, _, _ := pCreateSolidBrush.Call(color)
|
||||||
|
nullPen, _, _ := pGetStockObject.Call(8) // NULL_PEN
|
||||||
|
oldBrush, _, _ := pSelectObject.Call(hdc, brush)
|
||||||
|
oldPen, _, _ := pSelectObject.Call(hdc, nullPen)
|
||||||
|
pRoundRect.Call(hdc, uintptr(l), uintptr(t), uintptr(r), uintptr(b), uintptr(rad*2), uintptr(rad*2))
|
||||||
|
pSelectObject.Call(hdc, oldPen)
|
||||||
|
pSelectObject.Call(hdc, oldBrush)
|
||||||
|
pDeleteObject.Call(brush)
|
||||||
|
}
|
||||||
|
|
||||||
|
// drawLogoStyle draws the Windows logo in one of the shapes other than the
|
||||||
|
// classic four squares. The four panes are laid out around the center of r.
|
||||||
|
func drawLogoStyle(hdc uintptr, r rect) {
|
||||||
|
if !layerFg {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cx, cy := center(r)
|
||||||
|
c := logoColor()
|
||||||
|
|
||||||
|
sq := float64(px(8)) // one pane
|
||||||
|
gap := float64(px(2)) // the space between panes
|
||||||
|
if logoStyle == 5 {
|
||||||
|
sq, gap = float64(px(6)), float64(px(2)) // a diamond is wider than it looks, so shrink it
|
||||||
|
}
|
||||||
|
o := (sq + gap) / 2 // how far each pane's middle is from the logo's middle
|
||||||
|
h := sq / 2
|
||||||
|
offs := [4][2]float64{{-o, -o}, {o, -o}, {-o, o}, {o, o}}
|
||||||
|
|
||||||
|
// pane builds one pane's corners, moved by the transform for this style.
|
||||||
|
pane := func(ox, oy float64, tf func(x, y float64) (float64, float64)) []point {
|
||||||
|
corners := [4][2]float64{{ox - h, oy - h}, {ox + h, oy - h}, {ox + h, oy + h}, {ox - h, oy + h}}
|
||||||
|
pts := make([]point, 4)
|
||||||
|
for i, p := range corners {
|
||||||
|
x, y := tf(p[0], p[1])
|
||||||
|
pts[i] = point{cx + int32(math.Round(x)), cy + int32(math.Round(y))}
|
||||||
|
}
|
||||||
|
return pts
|
||||||
|
}
|
||||||
|
turn := func(deg float64) func(x, y float64) (float64, float64) {
|
||||||
|
a := deg * math.Pi / 180
|
||||||
|
s, co := math.Sin(a), math.Cos(a)
|
||||||
|
return func(x, y float64) (float64, float64) { return x*co - y*s, x*s + y*co }
|
||||||
|
}
|
||||||
|
|
||||||
|
switch logoStyle {
|
||||||
|
case 1: // rounded squares
|
||||||
|
rad := px(2)
|
||||||
|
for _, f := range offs {
|
||||||
|
l, t := cx+int32(math.Round(f[0]-h)), cy+int32(math.Round(f[1]-h))
|
||||||
|
roundRectRaw(hdc, l, t, l+int32(sq), t+int32(sq), rad, c)
|
||||||
|
}
|
||||||
|
case 2: // four dots
|
||||||
|
rad := int32(math.Round(sq * 0.46))
|
||||||
|
for _, f := range offs {
|
||||||
|
circleRaw(hdc, cx+int32(math.Round(f[0])), cy+int32(math.Round(f[1])), rad, c)
|
||||||
|
}
|
||||||
|
case 3: // tilted right
|
||||||
|
for _, f := range offs {
|
||||||
|
polygon(hdc, pane(f[0], f[1], turn(15)), c)
|
||||||
|
}
|
||||||
|
case 4: // tilted left
|
||||||
|
for _, f := range offs {
|
||||||
|
polygon(hdc, pane(f[0], f[1], turn(-15)), c)
|
||||||
|
}
|
||||||
|
case 5: // diamonds
|
||||||
|
for _, f := range offs {
|
||||||
|
polygon(hdc, pane(f[0], f[1], turn(45)), c)
|
||||||
|
}
|
||||||
|
case 6: // waving flag: every pane leans, and the left side sits lower than the right
|
||||||
|
wave := func(x, y float64) (float64, float64) {
|
||||||
|
return x, y - 0.22*x + 0.9*math.Sin(x*0.55)
|
||||||
|
}
|
||||||
|
for _, f := range offs {
|
||||||
|
polygon(hdc, pane(f[0], f[1], wave), c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -331,6 +331,7 @@ var (
|
|||||||
hoverApp = -1
|
hoverApp = -1
|
||||||
trackingMouse bool
|
trackingMouse bool
|
||||||
scale float64 = 1
|
scale float64 = 1
|
||||||
|
realScale float64 = 1 // scale as the screen really is; scale itself is doubled while the icon layers are drawn
|
||||||
barHeight int32
|
barHeight int32
|
||||||
fontTime uintptr
|
fontTime uintptr
|
||||||
fontDate uintptr
|
fontDate uintptr
|
||||||
@@ -561,7 +562,6 @@ func activateApp(idx int) {
|
|||||||
// ---------- our bar ----------
|
// ---------- our bar ----------
|
||||||
|
|
||||||
func startWidth() int32 { return px(52) }
|
func startWidth() int32 { return px(52) }
|
||||||
func clockWidth() int32 { return px(140) }
|
|
||||||
|
|
||||||
func screenSize() (int32, int32) {
|
func screenSize() (int32, int32) {
|
||||||
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
w, _, _ := pGetSystemMetrics.Call(smCxScreen)
|
||||||
@@ -689,6 +689,12 @@ func makeFont(height int32, weight int) uintptr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func drawLogo(hdc uintptr, r rect) {
|
func drawLogo(hdc uintptr, r rect) {
|
||||||
|
if logoStyle != 0 {
|
||||||
|
if !vertical { // a vertical bar draws it upright after turning (see renderLayer)
|
||||||
|
drawLogoStyle(hdc, r)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
sq := px(8)
|
sq := px(8)
|
||||||
gap := px(2)
|
gap := px(2)
|
||||||
total := sq*2 + gap
|
total := sq*2 + gap
|
||||||
@@ -1304,12 +1310,15 @@ func main() {
|
|||||||
if dpi > 0 {
|
if dpi > 0 {
|
||||||
scale = float64(dpi) / 96.0
|
scale = float64(dpi) / 96.0
|
||||||
}
|
}
|
||||||
|
realScale = scale
|
||||||
barHeight = px(36)
|
barHeight = px(36)
|
||||||
fontTime = makeFont(px(13), 400)
|
fontTime = makeFont(px(13), 400)
|
||||||
fontDate = makeFont(px(11), 400)
|
fontDate = makeFont(px(11), 400)
|
||||||
fontApp = makeFont(px(12), 600)
|
fontApp = makeFont(px(12), 600)
|
||||||
initSuperFonts()
|
initSuperFonts()
|
||||||
loadColors()
|
loadColors()
|
||||||
|
loadLook()
|
||||||
|
rebuildClockFonts()
|
||||||
|
|
||||||
autoQuit = autoQuitDef
|
autoQuit = autoQuitDef
|
||||||
if hasArg("--forever") || strings.Contains(name, "forever") {
|
if hasArg("--forever") || strings.Contains(name, "forever") {
|
||||||
|
|||||||
@@ -1,392 +1,406 @@
|
|||||||
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},
|
||||||
}
|
{"Dark green", 20, 120, 55},
|
||||||
|
{"Teal", 0, 160, 160},
|
||||||
var (
|
{"Navy", 30, 60, 160},
|
||||||
logoIdx = 1 // Blue, like the real Windows logo
|
{"Maroon", 140, 30, 50},
|
||||||
clockIdx = 0 // White
|
{"Gray", 140, 140, 150},
|
||||||
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
{"Lime", 150, 220, 40},
|
||||||
)
|
}
|
||||||
|
|
||||||
func colorOf(i int) uintptr {
|
var (
|
||||||
if i < 0 || i >= len(palette) {
|
logoIdx = 1 // Blue, like the real Windows logo
|
||||||
i = 0
|
clockIdx = 0 // White
|
||||||
}
|
iconIdx = 0 // White: battery, volume, wifi and the hidden-icons arrow
|
||||||
c := palette[i]
|
)
|
||||||
r, g, b := styleColor(c.r, c.g, c.b)
|
|
||||||
return rgb(r, g, b)
|
func colorOf(i int) uintptr {
|
||||||
}
|
if i < 0 || i >= len(palette) {
|
||||||
|
i = 0
|
||||||
func logoColor() uintptr { return colorOf(logoIdx) }
|
}
|
||||||
func clockColor() uintptr { return colorOf(clockIdx) }
|
c := palette[i]
|
||||||
func iconColor() uintptr { return colorOf(iconIdx) }
|
r, g, b := styleColor(c.r, c.g, c.b)
|
||||||
|
return rgb(r, g, b)
|
||||||
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
}
|
||||||
func iconDim() uintptr {
|
|
||||||
c := palette[iconIdx]
|
func logoColor() uintptr { return colorOf(logoIdx) }
|
||||||
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
func clockColor() uintptr { return colorOf(clockIdx) }
|
||||||
return rgb(140, 140, 150)
|
func iconColor() uintptr { return colorOf(iconIdx) }
|
||||||
}
|
|
||||||
return rgb(110, 110, 120)
|
// iconDim is the color of the "off" bars on the volume and wifi icons.
|
||||||
}
|
func iconDim() uintptr {
|
||||||
|
c := palette[iconIdx]
|
||||||
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
if c.r+c.g+c.b < 300 { // a dark icon color: the off bars are lighter
|
||||||
|
return rgb(140, 140, 150)
|
||||||
func loadColors() {
|
}
|
||||||
b, err := os.ReadFile(colorsFile())
|
return rgb(110, 110, 120)
|
||||||
if err != nil {
|
}
|
||||||
return
|
|
||||||
}
|
func colorsFile() string { return filepath.Join(dataDir(), "colors.txt") }
|
||||||
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
|
||||||
if len(parts) < 2 || len(parts) > 3 {
|
func loadColors() {
|
||||||
return
|
b, err := os.ReadFile(colorsFile())
|
||||||
}
|
if err != nil {
|
||||||
vals := []int{0, 0, 0}
|
return
|
||||||
for i, p := range parts {
|
}
|
||||||
n, err := strconv.Atoi(p)
|
parts := strings.Split(strings.TrimSpace(string(b)), ",")
|
||||||
if err != nil || n < 0 || n >= len(palette) {
|
if len(parts) < 2 || len(parts) > 3 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
vals[i] = n
|
vals := []int{0, 0, 0}
|
||||||
}
|
for i, p := range parts {
|
||||||
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
n, err := strconv.Atoi(p)
|
||||||
}
|
if err != nil || n < 0 || n >= len(palette) {
|
||||||
|
return
|
||||||
func saveColors() {
|
}
|
||||||
_ = os.MkdirAll(dataDir(), 0o755)
|
vals[i] = n
|
||||||
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
}
|
||||||
}
|
logoIdx, clockIdx, iconIdx = vals[0], vals[1], vals[2]
|
||||||
|
}
|
||||||
// addColorMenus adds the two color pickers as sub menus.
|
|
||||||
func addColorMenus(menu uintptr) {
|
func saveColors() {
|
||||||
build := func(base uintptr, cur int, title string) {
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
sub, _, _ := pCreatePopupMenu.Call()
|
_ = os.WriteFile(colorsFile(), []byte(strconv.Itoa(logoIdx)+","+strconv.Itoa(clockIdx)+","+strconv.Itoa(iconIdx)), 0o644)
|
||||||
for i, c := range palette {
|
}
|
||||||
var flags uintptr
|
|
||||||
if i == cur {
|
// addColorMenus adds the two color pickers as sub menus.
|
||||||
flags = mfChecked
|
func addColorMenus(menu uintptr) {
|
||||||
}
|
build := func(base uintptr, cur int, title string) {
|
||||||
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
sub, _, _ := pCreatePopupMenu.Call()
|
||||||
}
|
for i, c := range palette {
|
||||||
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
var flags uintptr
|
||||||
}
|
if i == cur {
|
||||||
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
flags = mfChecked
|
||||||
build(menuClockColorBase, clockIdx, "Clock color")
|
}
|
||||||
build(menuIconColorBase, iconIdx, "Tray icon color")
|
pAppendMenu.Call(sub, flags, base+uintptr(i), uintptr(unsafe.Pointer(u16(c.name))))
|
||||||
addStyleMenu(menu)
|
}
|
||||||
}
|
pAppendMenu.Call(menu, mfPopup, sub, uintptr(unsafe.Pointer(u16(title))))
|
||||||
|
}
|
||||||
func handleColorCommand(cmd uintptr) bool {
|
build(menuLogoColorBase, logoIdx, "Windows logo color")
|
||||||
n := uintptr(len(palette))
|
build(menuClockColorBase, clockIdx, "Clock color")
|
||||||
switch {
|
build(menuIconColorBase, iconIdx, "Tray icon color")
|
||||||
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
addStyleMenu(menu)
|
||||||
logoIdx = int(cmd - menuLogoColorBase)
|
}
|
||||||
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
|
||||||
clockIdx = int(cmd - menuClockColorBase)
|
func handleColorCommand(cmd uintptr) bool {
|
||||||
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
n := uintptr(len(palette))
|
||||||
iconIdx = int(cmd - menuIconColorBase)
|
switch {
|
||||||
case handleStyleCommand(cmd):
|
case cmd >= menuLogoColorBase && cmd < menuLogoColorBase+n:
|
||||||
return true
|
logoIdx = int(cmd - menuLogoColorBase)
|
||||||
default:
|
case cmd >= menuClockColorBase && cmd < menuClockColorBase+n:
|
||||||
return false
|
clockIdx = int(cmd - menuClockColorBase)
|
||||||
}
|
case cmd >= menuIconColorBase && cmd < menuIconColorBase+n:
|
||||||
saveColors()
|
iconIdx = int(cmd - menuIconColorBase)
|
||||||
return true
|
case handleStyleCommand(cmd):
|
||||||
}
|
return true
|
||||||
|
default:
|
||||||
// ---------- painting ----------
|
return false
|
||||||
|
}
|
||||||
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
|
saveColors()
|
||||||
// and returns its pixels at the real orientation. fills and fg choose which
|
return true
|
||||||
// parts are painted; base is the color everything is painted onto.
|
}
|
||||||
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
|
||||||
layerFills, layerFg = fills, fg
|
// ---------- painting ----------
|
||||||
defer func() { layerFills, layerFg = true, true }()
|
|
||||||
|
// renderLayer paints one layer of the bar (w by h in the horizontal layout)
|
||||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
// and returns its pixels at the real orientation. fills and fg choose which
|
||||||
defer pDeleteDC.Call(mem)
|
// parts are painted; base is the color everything is painted onto.
|
||||||
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
func renderLayer(screen uintptr, w, h int32, fills, fg bool, base uintptr) []uint32 {
|
||||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
layerFills, layerFg = fills, fg
|
||||||
var bits unsafe.Pointer
|
defer func() { layerFills, layerFg = true, true }()
|
||||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
|
||||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
if bmp == 0 || bits == nil {
|
defer pDeleteDC.Call(mem)
|
||||||
return nil
|
bmi := bitmapInfoHeader{Width: w, Height: -h, Planes: 1, BitCount: 32}
|
||||||
}
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
defer pDeleteObject.Call(bmp)
|
var bits unsafe.Pointer
|
||||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||||
defer pSelectObject.Call(mem, old)
|
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||||
|
if bmp == 0 || bits == nil {
|
||||||
fillRaw(mem, rect{0, 0, w, h}, base)
|
return nil
|
||||||
sr := startRect(w, h)
|
}
|
||||||
if hoverStart {
|
defer pDeleteObject.Call(bmp)
|
||||||
fill(mem, sr, rgb(58, 58, 68))
|
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||||
}
|
defer pSelectObject.Call(mem, old)
|
||||||
drawLogo(mem, sr)
|
|
||||||
drawApps(mem, w, h)
|
fillRaw(mem, rect{0, 0, w, h}, base)
|
||||||
drawTray(mem, w, h)
|
sr := startRect(w, h)
|
||||||
pGdiFlush.Call()
|
if hoverStart {
|
||||||
|
fill(mem, sr, rgb(58, 58, 68))
|
||||||
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
}
|
||||||
if !vertical {
|
drawLogo(mem, sr)
|
||||||
out := make([]uint32, len(src))
|
drawApps(mem, w, h)
|
||||||
copy(out, src)
|
drawTray(mem, w, h)
|
||||||
return out
|
pGdiFlush.Call()
|
||||||
}
|
|
||||||
|
src := unsafe.Slice((*uint32)(bits), int(w)*int(h))
|
||||||
// Turn a quarter turn, then put the icons and symbols back on upright.
|
if !vertical {
|
||||||
fw, fh := h, w
|
out := make([]uint32, len(src))
|
||||||
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
copy(out, src)
|
||||||
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
return out
|
||||||
var bitsV unsafe.Pointer
|
}
|
||||||
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
|
||||||
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
// Turn a quarter turn, then put the icons and symbols back on upright.
|
||||||
if bmpV == 0 || bitsV == nil {
|
fw, fh := h, w
|
||||||
return nil
|
bmiV := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||||
}
|
bmiV.Size = uint32(unsafe.Sizeof(bmiV))
|
||||||
defer pDeleteObject.Call(bmpV)
|
var bitsV unsafe.Pointer
|
||||||
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
bmpV, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmiV)), 0,
|
||||||
defer pDeleteDC.Call(memV)
|
uintptr(unsafe.Pointer(&bitsV)), 0, 0)
|
||||||
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
if bmpV == 0 || bitsV == nil {
|
||||||
defer pSelectObject.Call(memV, oldV)
|
return nil
|
||||||
|
}
|
||||||
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
defer pDeleteObject.Call(bmpV)
|
||||||
for y := int32(0); y < h; y++ {
|
memV, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
for x := int32(0); x < w; x++ {
|
defer pDeleteDC.Call(memV)
|
||||||
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
oldV, _, _ := pSelectObject.Call(memV, bmpV)
|
||||||
}
|
defer pSelectObject.Call(memV, oldV)
|
||||||
}
|
|
||||||
if fg {
|
dst := unsafe.Slice((*uint32)(bitsV), int(w)*int(h))
|
||||||
for i, r := range appRects(w, h) {
|
for y := int32(0); y < h; y++ {
|
||||||
if i < len(apps) {
|
for x := int32(0); x < w; x++ {
|
||||||
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
dst[int(x)*int(fw)+int(h-1-y)] = src[int(y)*int(w)+int(x)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, it := range trayItems(w, h) {
|
if fg {
|
||||||
r := mapRect(it.r, h)
|
if logoStyle != 0 {
|
||||||
switch it.kind {
|
drawLogoStyle(memV, mapRect(sr, h))
|
||||||
case trayBattery:
|
}
|
||||||
drawBattery(memV, r)
|
for i, r := range appRects(w, h) {
|
||||||
case trayVolume:
|
if i < len(apps) {
|
||||||
drawVolume(memV, r)
|
drawAppGlyph(memV, mapRect(rect{r.Left + px(2), r.Top + px(3), r.Right - px(2), r.Bottom - px(3)}, h), apps[i])
|
||||||
case trayWifi:
|
}
|
||||||
drawNetwork(memV, r)
|
}
|
||||||
case trayChevron:
|
for _, it := range trayItems(w, h) {
|
||||||
drawChevron(memV, r)
|
r := mapRect(it.r, h)
|
||||||
case trayWeather:
|
switch it.kind {
|
||||||
drawWeatherIcon(memV, r)
|
case trayBattery:
|
||||||
case trayNews:
|
drawBattery(memV, r)
|
||||||
drawNewsIcon(memV, r)
|
case trayVolume:
|
||||||
case traySys:
|
drawVolume(memV, r)
|
||||||
drawSysIcon(memV, r)
|
case trayWifi:
|
||||||
case trayGM:
|
drawNetwork(memV, r)
|
||||||
drawGMIcon(memV, r)
|
case trayChevron:
|
||||||
}
|
drawChevron(memV, r)
|
||||||
}
|
case trayWeather:
|
||||||
pGdiFlush.Call()
|
drawWeatherIcon(memV, r)
|
||||||
}
|
case trayNews:
|
||||||
out := make([]uint32, len(dst))
|
drawNewsIcon(memV, r)
|
||||||
copy(out, dst)
|
case traySys:
|
||||||
return out
|
drawSysIcon(memV, r)
|
||||||
}
|
case trayGM:
|
||||||
|
drawGMIcon(memV, r)
|
||||||
// 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) {
|
pGdiFlush.Call()
|
||||||
var sr, sg, sb uint32
|
}
|
||||||
for dy := 0; dy < superSample; dy++ {
|
out := make([]uint32, len(dst))
|
||||||
for dx := 0; dx < superSample; dx++ {
|
copy(out, dst)
|
||||||
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
return out
|
||||||
sr += c >> 16 & 0xFF
|
}
|
||||||
sg += c >> 8 & 0xFF
|
|
||||||
sb += c & 0xFF
|
// 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) {
|
||||||
n := uint32(superSample * superSample)
|
var sr, sg, sb uint32
|
||||||
return sr / n, sg / n, sb / n
|
for dy := 0; dy < superSample; dy++ {
|
||||||
}
|
for dx := 0; dx < superSample; dx++ {
|
||||||
|
c := p[(y*superSample+dy)*stride+x*superSample+dx]
|
||||||
// redraw paints the whole bar and hands it to Windows as a layered window
|
sr += c >> 16 & 0xFF
|
||||||
// with a transparency value for every pixel.
|
sg += c >> 8 & 0xFF
|
||||||
func redraw(hwnd uintptr) {
|
sb += c & 0xFF
|
||||||
if hwnd == 0 {
|
}
|
||||||
return
|
}
|
||||||
}
|
n := uint32(superSample * superSample)
|
||||||
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
return sr / n, sg / n, sb / n
|
||||||
pw, ph := pillSize()
|
}
|
||||||
var crc rect
|
|
||||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
// redraw paints the whole bar and hands it to Windows as a layered window
|
||||||
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
// with a transparency value for every pixel.
|
||||||
x, y := pillPos(pw, ph)
|
func redraw(hwnd uintptr) {
|
||||||
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
if hwnd == 0 {
|
||||||
}
|
return
|
||||||
w, h := clientSize(hwnd)
|
}
|
||||||
if w <= 0 || h <= 0 {
|
// Shrink or grow the pill to fit what is in it, staying centered where it is.
|
||||||
return
|
pw, ph := pillSize()
|
||||||
}
|
var crc rect
|
||||||
fw, fh := w, h
|
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&crc)))
|
||||||
if vertical {
|
if (crc.Right != pw || crc.Bottom != ph) && !dragging {
|
||||||
fw, fh = h, w
|
x, y := pillPos(pw, ph)
|
||||||
}
|
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 0)
|
||||||
|
}
|
||||||
screen, _, _ := pGetDC.Call(0)
|
w, h := clientSize(hwnd)
|
||||||
defer pReleaseDC.Call(0, screen)
|
if w <= 0 || h <= 0 {
|
||||||
|
return
|
||||||
// Layer 1: backgrounds, at real size.
|
}
|
||||||
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
fw, fh := w, h
|
||||||
|
if vertical {
|
||||||
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
fw, fh = h, w
|
||||||
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
}
|
||||||
scale *= superSample
|
|
||||||
fontTime, fontApp = fontTime2, fontApp2
|
screen, _, _ := pGetDC.Call(0)
|
||||||
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
|
defer pReleaseDC.Call(0, screen)
|
||||||
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
|
|
||||||
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
// Layer 1: backgrounds, at real size.
|
||||||
|
bgPix := renderLayer(screen, w, h, true, false, rgb(22, 22, 26))
|
||||||
n := int(fw) * int(fh)
|
|
||||||
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
|
// Layers 2 and 3: icons, text and symbols on black and on white, at double size.
|
||||||
return
|
savedScale, savedTime, savedApp := scale, fontTime, fontApp
|
||||||
}
|
scale *= superSample
|
||||||
|
fontTime, fontApp = fontTime2, fontApp2
|
||||||
// The finished bitmap that Windows will show.
|
onBlack := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(0, 0, 0))
|
||||||
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
onWhite := renderLayer(screen, w*superSample, h*superSample, false, true, rgb(255, 255, 255))
|
||||||
defer pDeleteDC.Call(mem)
|
scale, fontTime, fontApp = savedScale, savedTime, savedApp
|
||||||
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
|
||||||
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
n := int(fw) * int(fh)
|
||||||
var bits unsafe.Pointer
|
if len(bgPix) != n || len(onBlack) != n*superSample*superSample || len(onWhite) != len(onBlack) {
|
||||||
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
return
|
||||||
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
}
|
||||||
if bmp == 0 || bits == nil {
|
|
||||||
return
|
// The finished bitmap that Windows will show.
|
||||||
}
|
mem, _, _ := pCreateCompatibleDC.Call(screen)
|
||||||
defer pDeleteObject.Call(bmp)
|
defer pDeleteDC.Call(mem)
|
||||||
old, _, _ := pSelectObject.Call(mem, bmp)
|
bmi := bitmapInfoHeader{Width: fw, Height: -fh, Planes: 1, BitCount: 32}
|
||||||
defer pSelectObject.Call(mem, old)
|
bmi.Size = uint32(unsafe.Sizeof(bmi))
|
||||||
pix := unsafe.Slice((*uint32)(bits), n)
|
var bits unsafe.Pointer
|
||||||
|
bmp, _, _ := pCreateDIBSection.Call(screen, uintptr(unsafe.Pointer(&bmi)), 0,
|
||||||
a := uint32(bgAlpha)
|
uintptr(unsafe.Pointer(&bits)), 0, 0)
|
||||||
hoverA := max(a, 120)
|
if bmp == 0 || bits == nil {
|
||||||
length := float64(max(fw, fh))
|
return
|
||||||
rad := float64(min(fw, fh)) / 2
|
}
|
||||||
stride := int(fw) * superSample
|
defer pDeleteObject.Call(bmp)
|
||||||
|
old, _, _ := pSelectObject.Call(mem, bmp)
|
||||||
for i := range pix {
|
defer pSelectObject.Call(mem, old)
|
||||||
x, y := i%int(fw), i/int(fw)
|
pix := unsafe.Slice((*uint32)(bits), n)
|
||||||
|
|
||||||
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
a := uint32(bgAlpha)
|
||||||
c := bgPix[i] & 0x00FFFFFF
|
hoverA := max(a, 120)
|
||||||
bgA := a
|
barC := barRGB()
|
||||||
if c != colBg {
|
lightBar := barIsLight()
|
||||||
bgA = hoverA
|
length := float64(max(fw, fh))
|
||||||
}
|
rad := float64(min(fw, fh)) / 2
|
||||||
bgR := (c >> 16 & 0xFF) * bgA / 255
|
stride := int(fw) * superSample
|
||||||
bgG := (c >> 8 & 0xFF) * bgA / 255
|
|
||||||
bgB := (c & 0xFF) * bgA / 255
|
for i := range pix {
|
||||||
|
x, y := i%int(fw), i/int(fw)
|
||||||
// Foreground: how solid is this pixel, and what color is it.
|
|
||||||
br, bgn, bb := avg4(onBlack, stride, x, y)
|
// Background layer: the pill color or a hover highlight, at its own see-through level.
|
||||||
wr, wg, wb := avg4(onWhite, stride, x, y)
|
c := bgPix[i] & 0x00FFFFFF
|
||||||
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
|
bgA := a
|
||||||
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
|
if c != colBg {
|
||||||
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
bgA = hoverA
|
||||||
|
c = hoverTint(c, lightBar)
|
||||||
// Foreground over background.
|
} else {
|
||||||
inv := 255 - fa
|
c = barC
|
||||||
oa := fa + bgA*inv/255
|
}
|
||||||
or := fr + bgR*inv/255
|
bgR := (c >> 16 & 0xFF) * bgA / 255
|
||||||
og := fg + bgG*inv/255
|
bgG := (c >> 8 & 0xFF) * bgA / 255
|
||||||
ob := fb + bgB*inv/255
|
bgB := (c & 0xFF) * bgA / 255
|
||||||
|
|
||||||
// Rounded ends: how much of this pixel is inside the pill.
|
// Foreground: how solid is this pixel, and what color is it.
|
||||||
along := float64(x) + 0.5
|
br, bgn, bb := avg4(onBlack, stride, x, y)
|
||||||
across := float64(y) + 0.5
|
wr, wg, wb := avg4(onWhite, stride, x, y)
|
||||||
if vertical {
|
d := (sub0(wr, br) + sub0(wg, bgn) + sub0(wb, bb)) / 3
|
||||||
along, across = across, along
|
fa := 255 - min(d, 255) // 255 where the two copies match (solid), 0 where they differ fully
|
||||||
}
|
fr, fg, fb := min(br, fa), min(bgn, fa), min(bb, fa)
|
||||||
da := 0.0
|
|
||||||
if along < rad {
|
// Foreground over background.
|
||||||
da = rad - along
|
inv := 255 - fa
|
||||||
} else if along > length-rad {
|
oa := fa + bgA*inv/255
|
||||||
da = along - (length - rad)
|
or := fr + bgR*inv/255
|
||||||
}
|
og := fg + bgG*inv/255
|
||||||
cov := math.Max(0, math.Min(1, rad-math.Hypot(da, across-rad)+0.5))
|
ob := fb + bgB*inv/255
|
||||||
sc := func(v uint32) uint32 { return uint32(float64(v) * cov) }
|
|
||||||
pix[i] = sc(oa)<<24 | sc(or)<<16 | sc(og)<<8 | sc(ob)
|
// Rounded ends: how much of this pixel is inside the pill.
|
||||||
}
|
along := float64(x) + 0.5
|
||||||
|
across := float64(y) + 0.5
|
||||||
var wr rect
|
if vertical {
|
||||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
along, across = across, along
|
||||||
dst := point{wr.Left, wr.Top}
|
}
|
||||||
sz := size{fw, fh}
|
da := 0.0
|
||||||
src := point{0, 0}
|
if along < rad {
|
||||||
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
da = rad - along
|
||||||
pUpdateLayeredWindow.Call(hwnd, screen,
|
} else if along > length-rad {
|
||||||
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
|
da = along - (length - rad)
|
||||||
mem, uintptr(unsafe.Pointer(&src)), 0,
|
}
|
||||||
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
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)
|
||||||
func sub0(a, b uint32) uint32 {
|
}
|
||||||
if a > b {
|
|
||||||
return a - b
|
var wr rect
|
||||||
}
|
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||||
return 0
|
dst := point{wr.Left, wr.Top}
|
||||||
}
|
sz := size{fw, fh}
|
||||||
|
src := point{0, 0}
|
||||||
|
blend := blendFunction{Op: 0, Flags: 0, Alpha: 255, Format: 1} // AC_SRC_OVER, AC_SRC_ALPHA
|
||||||
|
pUpdateLayeredWindow.Call(hwnd, screen,
|
||||||
|
uintptr(unsafe.Pointer(&dst)), uintptr(unsafe.Pointer(&sz)),
|
||||||
|
mem, uintptr(unsafe.Pointer(&src)), 0,
|
||||||
|
uintptr(unsafe.Pointer(&blend)), ulwAlpha)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sub0(a, b uint32) uint32 {
|
||||||
|
if a > b {
|
||||||
|
return a - b
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|||||||
+66
-1
@@ -75,6 +75,14 @@ const (
|
|||||||
idShowGM = 217
|
idShowGM = 217
|
||||||
idGroup = 218
|
idGroup = 218
|
||||||
idAutoHide = 219
|
idAutoHide = 219
|
||||||
|
|
||||||
|
idBarColor = 220
|
||||||
|
idLogoStyle = 221
|
||||||
|
idClockSize = 222
|
||||||
|
idClockBold = 223
|
||||||
|
idShowBattery = 224
|
||||||
|
idShowVolume = 225
|
||||||
|
idShowWifi = 226
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -87,6 +95,8 @@ var (
|
|||||||
ctlZip, ctlZipStatus uintptr
|
ctlZip, ctlZipStatus uintptr
|
||||||
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
|
ctlShowWeather, ctlShowNews, ctlShowSys, ctlShowGM, ctlPanelFade uintptr
|
||||||
ctlGroup, ctlAutoHide uintptr
|
ctlGroup, ctlAutoHide uintptr
|
||||||
|
ctlBarColor, ctlLogoStyle, ctlClockSize, ctlClockBold uintptr
|
||||||
|
ctlShowBattery, ctlShowVolume, ctlShowWifi uintptr
|
||||||
zipSyncing bool // true while the program itself is filling in the ZIP box
|
zipSyncing bool // true while the program itself is filling in the ZIP box
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -138,7 +148,7 @@ func openSettings() {
|
|||||||
settingsFont = makeFont(px(13), 400)
|
settingsFont = makeFont(px(13), 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := rect{0, 0, px(400), px(572)}
|
r := rect{0, 0, px(800), px(572)}
|
||||||
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
|
||||||
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
ow, oh := r.Right-r.Left, r.Bottom-r.Top
|
||||||
sw, sh := screenSize()
|
sw, sh := screenSize()
|
||||||
@@ -196,6 +206,34 @@ func openSettings() {
|
|||||||
ctlGroup = makeControl(hw, inst, "BUTTON", "Combine windows of the same program into one icon", bsAutoCheckBox|wsTabStop, 16, 458, 368, 22, idGroup)
|
ctlGroup = makeControl(hw, inst, "BUTTON", "Combine windows of the same program into one icon", bsAutoCheckBox|wsTabStop, 16, 458, 368, 22, idGroup)
|
||||||
ctlAutoHide = makeControl(hw, inst, "BUTTON", "Hide the bar until the mouse touches the screen edge", bsAutoCheckBox|wsTabStop, 16, 486, 368, 22, idAutoHide)
|
ctlAutoHide = makeControl(hw, inst, "BUTTON", "Hide the bar until the mouse touches the screen edge", bsAutoCheckBox|wsTabStop, 16, 486, 368, 22, idAutoHide)
|
||||||
|
|
||||||
|
// The right-hand column: how the bar looks, and what is on it.
|
||||||
|
combo2 := func(y int, id uintptr) uintptr {
|
||||||
|
return makeControl(hw, inst, "COMBOBOX", "", cbsDropDownList|wsVScroll|wsTabStop, 560, y, 224, 200, id)
|
||||||
|
}
|
||||||
|
label2 := func(text string, y int) {
|
||||||
|
makeControl(hw, inst, "STATIC", text, 0, 416, y+4, 140, 20, 0)
|
||||||
|
}
|
||||||
|
label2("Bar color", 16)
|
||||||
|
ctlBarColor = combo2(16, idBarColor)
|
||||||
|
label2("Windows logo shape", 52)
|
||||||
|
ctlLogoStyle = combo2(52, idLogoStyle)
|
||||||
|
label2("Clock text size", 88)
|
||||||
|
ctlClockSize = combo2(88, idClockSize)
|
||||||
|
ctlClockBold = makeControl(hw, inst, "BUTTON", "Bold clock text", bsAutoCheckBox|wsTabStop, 416, 124, 368, 22, idClockBold)
|
||||||
|
makeControl(hw, inst, "STATIC", "Show on the bar:", 0, 416, 172, 368, 20, 0)
|
||||||
|
ctlShowBattery = makeControl(hw, inst, "BUTTON", "Battery", bsAutoCheckBox|wsTabStop, 416, 198, 368, 22, idShowBattery)
|
||||||
|
ctlShowVolume = makeControl(hw, inst, "BUTTON", "Volume", bsAutoCheckBox|wsTabStop, 416, 226, 368, 22, idShowVolume)
|
||||||
|
ctlShowWifi = makeControl(hw, inst, "BUTTON", "Wifi", bsAutoCheckBox|wsTabStop, 416, 254, 368, 22, idShowWifi)
|
||||||
|
for _, b := range barPalette {
|
||||||
|
pSendMessage.Call(ctlBarColor, cbAddString, 0, uintptr(unsafe.Pointer(u16(b.name))))
|
||||||
|
}
|
||||||
|
for _, n := range logoStyleNames {
|
||||||
|
pSendMessage.Call(ctlLogoStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
|
||||||
|
}
|
||||||
|
for _, c := range clockSizes {
|
||||||
|
pSendMessage.Call(ctlClockSize, cbAddString, 0, uintptr(unsafe.Pointer(u16(c.name))))
|
||||||
|
}
|
||||||
|
|
||||||
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 526, 116, 28, idResetPos)
|
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 526, 116, 28, idResetPos)
|
||||||
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 526, 116, 28, idResetWidth)
|
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 526, 116, 28, idResetWidth)
|
||||||
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 526, 92, 28, idClose)
|
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 526, 92, 28, idClose)
|
||||||
@@ -226,6 +264,13 @@ func settingsSync() {
|
|||||||
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
|
||||||
pSendMessage.Call(ctlGroup, bmSetCheck, boolWP(groupWins), 0)
|
pSendMessage.Call(ctlGroup, bmSetCheck, boolWP(groupWins), 0)
|
||||||
pSendMessage.Call(ctlAutoHide, bmSetCheck, boolWP(autoHide), 0)
|
pSendMessage.Call(ctlAutoHide, bmSetCheck, boolWP(autoHide), 0)
|
||||||
|
pSendMessage.Call(ctlBarColor, cbSetCurSel, uintptr(barIdx), 0)
|
||||||
|
pSendMessage.Call(ctlLogoStyle, cbSetCurSel, uintptr(logoStyle), 0)
|
||||||
|
pSendMessage.Call(ctlClockSize, cbSetCurSel, uintptr(clockSizeIx), 0)
|
||||||
|
pSendMessage.Call(ctlClockBold, bmSetCheck, boolWP(clockBold), 0)
|
||||||
|
pSendMessage.Call(ctlShowBattery, bmSetCheck, boolWP(showBattery), 0)
|
||||||
|
pSendMessage.Call(ctlShowVolume, bmSetCheck, boolWP(showVolume), 0)
|
||||||
|
pSendMessage.Call(ctlShowWifi, bmSetCheck, boolWP(showWifi), 0)
|
||||||
|
|
||||||
// Leave the ZIP box alone while the person is typing in it.
|
// Leave the ZIP box alone while the person is typing in it.
|
||||||
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
|
||||||
@@ -336,6 +381,26 @@ func settingsCommand(id, note uintptr) {
|
|||||||
setGroupWins(checked(ctlGroup))
|
setGroupWins(checked(ctlGroup))
|
||||||
case idAutoHide:
|
case idAutoHide:
|
||||||
setAutoHide(checked(ctlAutoHide))
|
setAutoHide(checked(ctlAutoHide))
|
||||||
|
case idBarColor, idLogoStyle, idClockSize:
|
||||||
|
if note != cbnSelChange {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch id {
|
||||||
|
case idBarColor:
|
||||||
|
setBarColor(comboChoice(ctlBarColor))
|
||||||
|
case idLogoStyle:
|
||||||
|
setLogoStyle(comboChoice(ctlLogoStyle))
|
||||||
|
case idClockSize:
|
||||||
|
setClockSize(comboChoice(ctlClockSize))
|
||||||
|
}
|
||||||
|
case idClockBold:
|
||||||
|
setClockBold(checked(ctlClockBold))
|
||||||
|
case idShowBattery:
|
||||||
|
setShowBattery(checked(ctlShowBattery))
|
||||||
|
case idShowVolume:
|
||||||
|
setShowVolume(checked(ctlShowVolume))
|
||||||
|
case idShowWifi:
|
||||||
|
setShowWifi(checked(ctlShowWifi))
|
||||||
case idAutostart:
|
case idAutostart:
|
||||||
setAutostart(checked(ctlAutostart))
|
setAutostart(checked(ctlAutostart))
|
||||||
settingsSync()
|
settingsSync()
|
||||||
|
|||||||
Reference in New Issue
Block a user