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