v27: weather flyout with sun and cloud icon, ZIP code in settings

This commit is contained in:
2026-11-08 02:15:20 +00:00
parent c94e74451f
commit e796560d0e
5 changed files with 1247 additions and 9 deletions
+65 -6
View File
@@ -16,6 +16,7 @@ var (
pIsDialogMessage = user32.NewProc("IsDialogMessageW")
pAdjustWindowRectEx = user32.NewProc("AdjustWindowRectEx")
pInitCommonControls = syscall.NewLazyDLL("comctl32.dll").NewProc("InitCommonControlsEx")
pGetFocus = user32.NewProc("GetFocus")
)
const (
@@ -29,11 +30,17 @@ const (
wsTabStop = 0x00010000
wsVScroll = 0x00200000
wsWindowFrame = 0x00C80000 // caption, system menu, border: a plain window that can't be resized
wsBorder = 0x00800000
bsPushButton = 0x0000
bsDefPushButton = 0x0001
bsAutoCheckBox = 0x0003
cbsDropDownList = 0x0003
tbsNoTicks = 0x0010
esAutoHScroll = 0x0080
esNumber = 0x2000
emSetLimitText = 0x00C5
enChange = 0x0300
bmGetCheck = 0x00F0
bmSetCheck = 0x00F1
@@ -59,6 +66,8 @@ const (
idResetPos = 208
idResetWidth = 209
idClose = 210
idZip = 211
idZipStatus = 212
)
var (
@@ -68,6 +77,8 @@ var (
ctlAlpha, ctlAlphaValue, ctlLogo, ctlClock, ctlTrayIcons, ctlStyle uintptr
ctlVertical, ctlAutostart uintptr
ctlZip, ctlZipStatus uintptr
zipSyncing bool // true while the program itself is filling in the ZIP box
)
func boolWP(b bool) uintptr {
@@ -118,7 +129,7 @@ func openSettings() {
settingsFont = makeFont(px(13), 400)
}
r := rect{0, 0, px(400), px(330)}
r := rect{0, 0, px(400), px(376)}
pAdjustWindowRectEx.Call(uintptr(unsafe.Pointer(&r)), wsWindowFrame, 0, 0)
ow, oh := r.Right-r.Left, r.Bottom-r.Top
sw, sh := screenSize()
@@ -160,12 +171,17 @@ func openSettings() {
pSendMessage.Call(ctlStyle, cbAddString, 0, uintptr(unsafe.Pointer(u16(n))))
}
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 214, 368, 22, idVertical)
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 242, 368, 22, idAutostart)
label("Weather ZIP code", 204)
ctlZip = makeControl(hw, inst, "EDIT", "", esNumber|esAutoHScroll|wsBorder|wsTabStop, 170, 204, 90, 24, idZip)
pSendMessage.Call(ctlZip, emSetLimitText, 5, 0)
ctlZipStatus = makeControl(hw, inst, "STATIC", "", 0, 16, 236, 368, 20, idZipStatus)
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 284, 116, 28, idResetPos)
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 284, 116, 28, idResetWidth)
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 284, 92, 28, idClose)
ctlVertical = makeControl(hw, inst, "BUTTON", "Stand the bar up at the right edge (vertical)", bsAutoCheckBox|wsTabStop, 16, 262, 368, 22, idVertical)
ctlAutostart = makeControl(hw, inst, "BUTTON", "Start MirrorBar when I sign in", bsAutoCheckBox|wsTabStop, 16, 290, 368, 22, idAutostart)
makeControl(hw, inst, "BUTTON", "Reset position", bsPushButton|wsTabStop, 16, 330, 116, 28, idResetPos)
makeControl(hw, inst, "BUTTON", "Reset bar width", bsPushButton|wsTabStop, 140, 330, 116, 28, idResetWidth)
makeControl(hw, inst, "BUTTON", "Close", bsDefPushButton|wsTabStop, 292, 330, 92, 28, idClose)
hwndSettings = hw
settingsSync()
@@ -186,6 +202,45 @@ func settingsSync() {
pSendMessage.Call(ctlStyle, cbSetCurSel, uintptr(iconMode), 0)
pSendMessage.Call(ctlVertical, bmSetCheck, boolWP(vertical), 0)
pSendMessage.Call(ctlAutostart, bmSetCheck, boolWP(autostartEnabled()), 0)
// Leave the ZIP box alone while the person is typing in it.
if f, _, _ := pGetFocus.Call(); f != ctlZip && zipText() != wxZip {
zipSyncing = true
pSetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(u16(wxZip))))
zipSyncing = false
}
settingsZipStatusUpdate()
}
// zipText is what is typed in the ZIP box right now.
func zipText() string {
var buf [32]uint16
n, _, _ := pGetWindowText.Call(ctlZip, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
return syscall.UTF16ToString(buf[:n])
}
// settingsZipStatusUpdate refreshes the line under the ZIP box ("Showing weather for ...").
func settingsZipStatusUpdate() {
if hwndSettings == 0 || ctlZipStatus == 0 {
return
}
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16(weatherStatusText()))))
}
// zipEdited runs each time the ZIP box changes. Five digits turn the weather on
// for that ZIP code; an empty box turns it off.
func zipEdited() {
z := onlyDigits(zipText())
switch {
case len(z) == 5:
weatherSetZip(z)
case z == "":
weatherSetZip("")
default:
pSetWindowText.Call(ctlZipStatus, uintptr(unsafe.Pointer(u16("A ZIP code has 5 digits."))))
return
}
settingsZipStatusUpdate()
}
func comboChoice(c uintptr) int {
@@ -234,6 +289,10 @@ func settingsCommand(id, note uintptr) {
styleCacheClear()
redraw(hwndMain)
}
case idZip:
if note == enChange && !zipSyncing {
zipEdited()
}
case idVertical:
vertical = checked(ctlVertical)
saveOrient()