Combine windows of one program into a counted icon, auto-hide, links open in default browser

This commit is contained in:
2026-11-08 19:45:20 +00:00
parent 40370fce29
commit 75a88a4a91
5 changed files with 212 additions and 157 deletions
+163 -146
View File
@@ -1,146 +1,163 @@
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 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() { func loadFeatures() {
b, err := os.ReadFile(featuresFile()) b, err := os.ReadFile(featuresFile())
if err != nil { if err != nil {
return return
} }
for _, ln := range strings.Split(string(b), "\n") { for _, ln := range strings.Split(string(b), "\n") {
k, v, ok := strings.Cut(strings.TrimSpace(ln), "=") k, v, ok := strings.Cut(strings.TrimSpace(ln), "=")
if !ok { if !ok {
continue continue
} }
on := strings.TrimSpace(v) != "0" on := strings.TrimSpace(v) != "0"
switch strings.TrimSpace(k) { switch strings.TrimSpace(k) {
case "weather": case "weather":
showWeather = on showWeather = on
case "news": case "news":
showNews = on showNews = on
case "sys": case "sys":
showSys = on showSys = on
case "messages": case "messages":
showGM = on showGM = on
case "panelfade": case "panelfade":
flyMatchBar = on flyMatchBar = on
} case "group":
} groupWins = on
} case "autohide":
autoHide = on
func saveFeatures() { }
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\n" }
_ = os.MkdirAll(dataDir(), 0o755) }
_ = os.WriteFile(featuresFile(), []byte(s), 0o644)
} func saveFeatures() {
s := "weather=" + b01(showWeather) + "\nnews=" + b01(showNews) + "\nsys=" + b01(showSys) + "\nmessages=" + b01(showGM) + "\npanelfade=" + b01(flyMatchBar) + "\ngroup=" + b01(groupWins) + "\nautohide=" + b01(autoHide) + "\n"
func b01(b bool) string { _ = os.MkdirAll(dataDir(), 0o755)
if b { _ = os.WriteFile(featuresFile(), []byte(s), 0o644)
return "1" }
}
return "0" func b01(b bool) string {
} if b {
return "1"
// setShowWeather is called by the settings window. }
func setShowWeather(on bool) { return "0"
if showWeather == on { }
return
} // setShowWeather is called by the settings window.
showWeather = on func setShowWeather(on bool) {
saveFeatures() if showWeather == on {
if on { return
weatherRefresh(false) }
} else { showWeather = on
weatherHide() saveFeatures()
} if on {
featuresChanged() weatherRefresh(false)
} } else {
weatherHide()
// setShowNews is called by the settings window. }
func setShowNews(on bool) { featuresChanged()
if showNews == on { }
return
} // setShowNews is called by the settings window.
showNews = on func setShowNews(on bool) {
saveFeatures() if showNews == on {
if on { return
newsRefresh(false) }
} else { showNews = on
newsHide() saveFeatures()
} if on {
featuresChanged() newsRefresh(false)
} } else {
newsHide()
// setShowSys is called by the settings window. }
func setShowSys(on bool) { featuresChanged()
if showSys == on { }
return
} // setShowSys is called by the settings window.
showSys = on func setShowSys(on bool) {
saveFeatures() if showSys == on {
if !on { return
sysHide() }
} showSys = on
featuresChanged() saveFeatures()
} if !on {
sysHide()
// setShowGM is called by the settings window. }
func setShowGM(on bool) { featuresChanged()
if showGM == on { }
return
} // setShowGM is called by the settings window.
showGM = on func setShowGM(on bool) {
saveFeatures() if showGM == on {
if on { return
gmAutoTried = false // let the background check start Messages again }
} else { showGM = on
gmClose() saveFeatures()
} if on {
featuresChanged() gmAutoTried = false // let the background check start Messages again
} } else {
gmClose()
// setFlyMatchBar is called by the settings window: should the panels be as }
// see-through as the bar? featuresChanged()
func setFlyMatchBar(on bool) { }
if flyMatchBar == on {
return // setFlyMatchBar is called by the settings window: should the panels be as
} // see-through as the bar?
flyMatchBar = on func setFlyMatchBar(on bool) {
saveFeatures() if flyMatchBar == on {
flyRefreshAll() return
} }
flyMatchBar = on
func featuresChanged() { saveFeatures()
settingsZipStatusUpdate() flyRefreshAll()
redraw(hwndMain) }
}
func featuresChanged() {
// zipStatusText is the one line the settings window shows under the ZIP box. settingsZipStatusUpdate()
func zipStatusText() string { redraw(hwndMain)
switch { }
case !showWeather && !showNews:
return "Weather and news are both turned off." // zipStatusText is the one line the settings window shows under the ZIP box.
case wxZip == "": func zipStatusText() string {
return "Type a 5 digit ZIP code to turn on weather and local news." switch {
case showWeather: case !showWeather && !showNews:
return weatherStatusText() return "Weather and news are both turned off."
} case wxZip == "":
return newsStatusText() return "Type a 5 digit ZIP code to turn on weather and local news."
} case showWeather:
return weatherStatusText()
}
return newsStatusText()
}
// setGroupWins is called by the settings window: one icon per program, with a
// count, or one icon per window.
func setGroupWins(on bool) {
if groupWins == on {
return
}
groupWins = on
saveFeatures()
styleCacheClear()
apps = groupApps(allApps)
positionBar(hwndMain)
}
+31 -3
View File
@@ -306,6 +306,9 @@ type appWin struct {
title string title string
icon uintptr icon uintptr
exe string // full path of the program, "" when unknown exe string // full path of the program, "" when unknown
count int // windows combined into this icon (1 when alone)
members []uintptr // every window behind this icon
} }
type alphaLevel struct { type alphaLevel struct {
@@ -538,6 +541,10 @@ func activateApp(idx int) {
} }
return return
} }
if apps[idx].count > 1 {
activateGroup(apps[idx])
return
}
fg, _, _ := pGetForegroundWindow.Call() fg, _, _ := pGetForegroundWindow.Call()
iconic, _, _ := pIsIconic.Call(h) iconic, _, _ := pIsIconic.Call(h)
switch { switch {
@@ -574,7 +581,7 @@ func barGap() int32 { return px(6) }
func positionBar(hwnd uintptr) { func positionBar(hwnd uintptr) {
pw, ph := pillSize() pw, ph := pillSize()
if !customPos { if !customPos && !autoHide {
sw, sh := screenSize() sw, sh := screenSize()
edge := uintptr(abeBottom) edge := uintptr(abeBottom)
if vertical { if vertical {
@@ -590,6 +597,14 @@ func positionBar(hwnd uintptr) {
appBar(abmSetPos, &abd) appBar(abmSetPos, &abd)
} }
x, y := pillPos(pw, ph) x, y := pillPos(pw, ph)
if autoHide && ahHidden {
sw, sh := screenSize()
if vertical {
x = sw // just past the right edge
} else {
y = sh // just below the bottom edge
}
}
pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 1) pMoveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(pw), uintptr(ph), 1)
redraw(hwnd) redraw(hwnd)
} }
@@ -729,6 +744,9 @@ func drawAppGlyph(hdc uintptr, r rect, a appWin) {
if a.icon != 0 { if a.icon != 0 {
cx, cy := center(r) cx, cy := center(r)
pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal) pDrawIconEx.Call(hdc, uintptr(cx-isz/2), uintptr(cy-isz/2), styledIcon(a.icon), uintptr(isz), uintptr(isz), 0, 0, diNormal)
if a.count > 1 {
drawCountBadge(hdc, cx, cy, isz, a.count)
}
} else if rs := []rune(a.title); len(rs) > 0 { } else if rs := []rune(a.title); len(rs) > 0 {
pSetBkMode.Call(hdc, transparent) pSetBkMode.Call(hdc, transparent)
pSetTextColor.Call(hdc, rgb(245, 245, 245)) pSetTextColor.Call(hdc, rgb(245, 245, 245))
@@ -806,7 +824,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
var target uintptr var target uintptr
var exe string var exe string
if appIdx >= 0 && appIdx < len(apps) { if appIdx >= 0 && appIdx < len(apps) {
target = apps[appIdx].hwnd target = memberHwnd(apps[appIdx])
title := []rune(apps[appIdx].title) title := []rune(apps[appIdx].title)
text := string(title) text := string(title)
@@ -905,8 +923,11 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
var pt point var pt point
pGetCursorPos.Call(uintptr(unsafe.Pointer(&pt))) pGetCursorPos.Call(uintptr(unsafe.Pointer(&pt)))
pSetForegroundWindow.Call(hwnd) pSetForegroundWindow.Call(hwnd)
menuOpen = true
cmd, _, _ := pTrackPopupMenu.Call(menu, tpmRightButton|tpmBottomAlign|tpmReturnCmd, cmd, _, _ := pTrackPopupMenu.Call(menu, tpmRightButton|tpmBottomAlign|tpmReturnCmd,
uintptr(pt.X), uintptr(pt.Y), 0, hwnd, 0) uintptr(pt.X), uintptr(pt.Y), 0, hwnd, 0)
menuOpen = false
ahLeftAt = time.Now()
pDestroyMenu.Call(menu) pDestroyMenu.Call(menu)
sysCommands := map[uintptr]uintptr{ sysCommands := map[uintptr]uintptr{
@@ -989,6 +1010,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
gmPoll() gmPoll()
return 0 return 0
} }
if wparam == ahTimerID {
ahTick(hwnd)
return 0
}
if wparam == previewTimerID { if wparam == previewTimerID {
previewTick() previewTick()
return 0 return 0
@@ -1344,7 +1369,7 @@ func main() {
} }
// Register as an app bar so maximized windows stop above us. // Register as an app bar so maximized windows stop above us.
if customPos { if customPos || autoHide {
appbarOn = false appbarOn = false
} else { } else {
abd := appBarData{Hwnd: hwnd, CallbackMsg: callbackMsg} abd := appBarData{Hwnd: hwnd, CallbackMsg: callbackMsg}
@@ -1356,6 +1381,9 @@ func main() {
refreshApps(true) refreshApps(true)
positionBar(hwnd) positionBar(hwnd)
pSetTimer.Call(hwnd, timerID, 250, 0) pSetTimer.Call(hwnd, timerID, 250, 0)
if autoHide {
ahStart()
}
weatherRefresh(false) // have the forecast ready before the cloud is first clicked weatherRefresh(false) // have the forecast ready before the cloud is first clicked
newsRefresh(false) newsRefresh(false)
+15 -7
View File
@@ -257,8 +257,12 @@ func refreshApps(refreshIcons bool) bool {
} }
} }
present0 := make(map[uintptr]appWin, len(present))
for h, w := range present {
present0[h] = w
}
var next []appWin var next []appWin
for _, a := range apps { for _, a := range allApps {
if a.hwnd == 0 { if a.hwnd == 0 {
next = append(next, a) // a waiting launcher; sorted out below next = append(next, a) // a waiting launcher; sorted out below
continue continue
@@ -321,13 +325,17 @@ func refreshApps(refreshIcons bool) bool {
} }
} }
noteForeground(present0)
allApps = next
grouped := groupApps(next)
// Titles change constantly (browser tabs, documents) but nothing on the // Titles change constantly (browser tabs, documents) but nothing on the
// bar shows them, so only a change in which buttons exist, or their icons, // bar shows them, so only a change in which buttons exist, their icons, or
// counts as a change. // how many windows an icon stands for counts as a change.
changed := len(next) != len(apps) changed := len(grouped) != len(apps)
if !changed { if !changed {
for i := range next { for i := range grouped {
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon { if grouped[i].hwnd != apps[i].hwnd || grouped[i].icon != apps[i].icon || grouped[i].count != apps[i].count {
changed = true changed = true
break break
} }
@@ -336,7 +344,7 @@ func refreshApps(refreshIcons bool) bool {
if changed { if changed {
styleCacheClear() // icon handles can be reused by other icons styleCacheClear() // icon handles can be reused by other icons
} }
apps = next apps = grouped
return changed return changed
} }
+1
View File
@@ -330,4 +330,5 @@ func moveSeq(from, to int) {
} }
} }
apps = next apps = next
syncAllFromGrouped()
} }
+2 -1
View File
@@ -175,6 +175,7 @@ func previewShow(idx int) {
return return
} }
a := apps[idx] a := apps[idx]
a.hwnd = memberHwnd(a)
previewDropThumb() previewDropThumb()
iconic, _, _ := pIsIconic.Call(a.hwnd) iconic, _, _ := pIsIconic.Call(a.hwnd)
@@ -297,7 +298,7 @@ func previewTick() {
} }
idx = appIndexAt(hwndMain, x) idx = appIndexAt(hwndMain, x)
if idx >= 0 && idx < len(apps) { if idx >= 0 && idx < len(apps) {
raw = apps[idx].hwnd raw = memberHwnd(apps[idx])
} }
} }
target := raw target := raw