Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c43c4b4bd | ||
|
|
f8f579252d | ||
|
|
ddfd5a375b | ||
|
|
ed8a7cf275 |
@@ -10,7 +10,11 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
|||||||
- 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.
|
||||||
- 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. The logo remembers its spot; the app order lasts until MirrorBar restarts.
|
- 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.
|
||||||
|
- 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.
|
||||||
|
- "Open notification center" is in the right-click menu.
|
||||||
- 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.
|
||||||
- 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).
|
- 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).
|
||||||
- Background see-through level: Clear, Light, Medium or Solid.
|
- Background see-through level: Clear, Light, Medium or Solid.
|
||||||
|
|||||||
@@ -302,9 +302,10 @@ type trackMouseEvent struct {
|
|||||||
|
|
||||||
// appWin is one open window shown as an icon button on the left side of the bar.
|
// appWin is one open window shown as an icon button on the left side of the bar.
|
||||||
type appWin struct {
|
type appWin struct {
|
||||||
hwnd uintptr
|
hwnd uintptr // 0 for a pinned program that has no window open right now
|
||||||
title string
|
title string
|
||||||
icon uintptr
|
icon uintptr
|
||||||
|
exe string // full path of the program, "" when unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
type alphaLevel struct {
|
type alphaLevel struct {
|
||||||
@@ -514,58 +515,18 @@ func fetchIcon(hwnd uintptr) uintptr {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// refreshApps re-reads the open windows, keeping existing buttons in their
|
|
||||||
// places and adding new windows at the far end. Returns true if anything changed.
|
|
||||||
func refreshApps(refreshIcons bool) bool {
|
|
||||||
enumFound = enumFound[:0]
|
|
||||||
pEnumWindows.Call(enumCb, 0)
|
|
||||||
|
|
||||||
present := make(map[uintptr]appWin, len(enumFound))
|
|
||||||
for _, f := range enumFound {
|
|
||||||
present[f.hwnd] = f
|
|
||||||
}
|
|
||||||
var next []appWin
|
|
||||||
for _, a := range apps {
|
|
||||||
if f, ok := present[a.hwnd]; ok {
|
|
||||||
a.title = f.title
|
|
||||||
next = append(next, a)
|
|
||||||
delete(present, a.hwnd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, f := range enumFound {
|
|
||||||
if _, ok := present[f.hwnd]; ok {
|
|
||||||
next = append(next, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := range next {
|
|
||||||
if next[i].icon == 0 || refreshIcons {
|
|
||||||
if ic := fetchIcon(next[i].hwnd); ic != 0 {
|
|
||||||
next[i].icon = ic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Titles change constantly (browser tabs, documents) but nothing on the
|
|
||||||
// bar shows them, so only a change in which windows exist, or their icons,
|
|
||||||
// counts as a change.
|
|
||||||
changed := len(next) != len(apps)
|
|
||||||
if !changed {
|
|
||||||
for i := range next {
|
|
||||||
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
|
||||||
changed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apps = next
|
|
||||||
return changed
|
|
||||||
}
|
|
||||||
|
|
||||||
func activateApp(idx int) {
|
func activateApp(idx int) {
|
||||||
if idx < 0 || idx >= len(apps) {
|
if idx < 0 || idx >= len(apps) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h := apps[idx].hwnd
|
h := apps[idx].hwnd
|
||||||
|
if h == 0 {
|
||||||
|
// A pinned program with no window: start it.
|
||||||
|
if apps[idx].exe != "" {
|
||||||
|
shellOpen(apps[idx].exe, "")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
fg, _, _ := pGetForegroundWindow.Call()
|
fg, _, _ := pGetForegroundWindow.Call()
|
||||||
iconic, _, _ := pIsIconic.Call(h)
|
iconic, _, _ := pIsIconic.Call(h)
|
||||||
switch {
|
switch {
|
||||||
@@ -851,13 +812,35 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
add(mfGrayed, 0, strings.ReplaceAll(text, "&", "&&"))
|
add(mfGrayed, 0, strings.ReplaceAll(text, "&", "&&"))
|
||||||
sep()
|
sep()
|
||||||
|
|
||||||
|
exe = apps[appIdx].exe
|
||||||
|
if target != 0 && exe == "" {
|
||||||
exe = windowExePath(target)
|
exe = windowExePath(target)
|
||||||
|
}
|
||||||
|
if target == 0 {
|
||||||
|
// A pinned program that isn't running: only launcher options apply.
|
||||||
|
add(0, menuLaunchID, "Open")
|
||||||
if exe != "" {
|
if exe != "" {
|
||||||
|
add(0, menuFileLocID, "Open file location")
|
||||||
|
}
|
||||||
|
sep()
|
||||||
|
add(0, menuUnpinID, "Unpin from MirrorBar")
|
||||||
|
sep()
|
||||||
|
}
|
||||||
|
if exe != "" && target != 0 {
|
||||||
add(0, menuNewWindowID, "Open new window")
|
add(0, menuNewWindowID, "Open new window")
|
||||||
add(0, menuFileLocID, "Open file location")
|
add(0, menuFileLocID, "Open file location")
|
||||||
|
switch {
|
||||||
|
case isPinned(exe):
|
||||||
|
add(0, menuUnpinID, "Unpin from MirrorBar")
|
||||||
|
case canPin(exe):
|
||||||
|
add(0, menuPinID, "Pin to MirrorBar")
|
||||||
|
default:
|
||||||
|
add(mfGrayed, 0, "Pin to MirrorBar (Store apps can't be pinned)")
|
||||||
|
}
|
||||||
sep()
|
sep()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if target != 0 {
|
||||||
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
||||||
iconic, _, _ := pIsIconic.Call(target)
|
iconic, _, _ := pIsIconic.Call(target)
|
||||||
zoomed, _, _ := pIsZoomed.Call(target)
|
zoomed, _, _ := pIsZoomed.Call(target)
|
||||||
@@ -877,11 +860,14 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
add(0, menuCloseID, "Close window")
|
add(0, menuCloseID, "Close window")
|
||||||
sep()
|
sep()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if appIdx < 0 {
|
if appIdx < 0 {
|
||||||
addTrayMenu(add, sep, trayKind)
|
addTrayMenu(add, sep, trayKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add(0, menuNotifyID, "Open notification center")
|
||||||
|
sep()
|
||||||
for i, l := range alphaLevels {
|
for i, l := range alphaLevels {
|
||||||
var flags uintptr
|
var flags uintptr
|
||||||
if bgAlpha == l.alpha {
|
if bgAlpha == l.alpha {
|
||||||
@@ -940,6 +926,18 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
pPostMessage.Call(target, wmClose, 0, 0)
|
pPostMessage.Call(target, wmClose, 0, 0)
|
||||||
case cmd == menuNewWindowID && exe != "":
|
case cmd == menuNewWindowID && exe != "":
|
||||||
shellOpen(exe, "")
|
shellOpen(exe, "")
|
||||||
|
case cmd == menuLaunchID && exe != "":
|
||||||
|
shellOpen(exe, "")
|
||||||
|
case cmd == menuPinID && exe != "":
|
||||||
|
pinApp(exe)
|
||||||
|
refreshApps(false)
|
||||||
|
redraw(hwnd)
|
||||||
|
case cmd == menuUnpinID && exe != "":
|
||||||
|
unpinApp(exe)
|
||||||
|
refreshApps(false)
|
||||||
|
redraw(hwnd)
|
||||||
|
case cmd == menuNotifyID:
|
||||||
|
openNotifications()
|
||||||
case cmd == menuFileLocID && exe != "":
|
case cmd == menuFileLocID && exe != "":
|
||||||
shellOpen("explorer.exe", `/select,"`+exe+`"`)
|
shellOpen("explorer.exe", `/select,"`+exe+`"`)
|
||||||
case target != 0 && sysCommands[cmd] != 0:
|
case target != 0 && sysCommands[cmd] != 0:
|
||||||
@@ -974,6 +972,10 @@ 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 == previewTimerID {
|
||||||
|
previewTick()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
hideTaskbar()
|
hideTaskbar()
|
||||||
tick++
|
tick++
|
||||||
changed := refreshApps(tick%16 == 0)
|
changed := refreshApps(tick%16 == 0)
|
||||||
@@ -993,6 +995,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmLButtonDown:
|
case wmLButtonDown:
|
||||||
|
previewSuppress()
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
if inStart(hwnd, x) {
|
if inStart(hwnd, x) {
|
||||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||||
@@ -1000,10 +1003,14 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||||
dragSeq, dragIsStart, dragStart, dragActive = seqOfApp(idx), false, x, false
|
dragSeq, dragIsStart, dragStart, dragActive = seqOfApp(idx), false, x, false
|
||||||
pSetCapture.Call(hwnd)
|
pSetCapture.Call(hwnd)
|
||||||
|
} else if k := trayAt(hwnd, x); k != 0 {
|
||||||
|
dragTray, dragTrayStart, dragTrayActive = k, x, false
|
||||||
|
pSetCapture.Call(hwnd)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmCaptureChanged:
|
case wmCaptureChanged:
|
||||||
endIconDrag()
|
endIconDrag()
|
||||||
|
dragTray, dragTrayActive = 0, false
|
||||||
return 0
|
return 0
|
||||||
case wmMouseMove:
|
case wmMouseMove:
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
@@ -1025,6 +1032,19 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if dragTray != 0 {
|
||||||
|
if !dragTrayActive && abs32(x-dragTrayStart) > px(5) {
|
||||||
|
dragTrayActive = true
|
||||||
|
}
|
||||||
|
if dragTrayActive {
|
||||||
|
if t := trayKindAt(hwnd, x); t != 0 && t != dragTray {
|
||||||
|
moveTray(dragTray, t)
|
||||||
|
}
|
||||||
|
hoverStart, hoverApp, hoverTray = false, -1, dragTray
|
||||||
|
redraw(hwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
overStart := inStart(hwnd, x)
|
overStart := inStart(hwnd, x)
|
||||||
overApp := appIndexAt(hwnd, x)
|
overApp := appIndexAt(hwnd, x)
|
||||||
overTray := trayAt(hwnd, x)
|
overTray := trayAt(hwnd, x)
|
||||||
@@ -1034,6 +1054,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
hoverTray = overTray
|
hoverTray = overTray
|
||||||
redraw(hwnd)
|
redraw(hwnd)
|
||||||
}
|
}
|
||||||
|
if overApp >= 0 {
|
||||||
|
previewKick()
|
||||||
|
}
|
||||||
if !trackingMouse {
|
if !trackingMouse {
|
||||||
tme := trackMouseEvent{Size: uint32(unsafe.Sizeof(trackMouseEvent{})), Flags: tmeLeave, HwndTrack: hwnd}
|
tme := trackMouseEvent{Size: uint32(unsafe.Sizeof(trackMouseEvent{})), Flags: tmeLeave, HwndTrack: hwnd}
|
||||||
pTrackMouseEvent.Call(uintptr(unsafe.Pointer(&tme)))
|
pTrackMouseEvent.Call(uintptr(unsafe.Pointer(&tme)))
|
||||||
@@ -1058,21 +1081,33 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
pReleaseCapture.Call()
|
pReleaseCapture.Call()
|
||||||
if wasDrag {
|
if wasDrag {
|
||||||
saveStartSlot()
|
saveStartSlot()
|
||||||
|
saveOrder()
|
||||||
} else if wasStart {
|
} else if wasStart {
|
||||||
tapWinKey()
|
tapWinKey()
|
||||||
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
||||||
activateApp(idx)
|
activateApp(idx)
|
||||||
}
|
}
|
||||||
redraw(hwnd)
|
redraw(hwnd)
|
||||||
|
} else if dragTray != 0 {
|
||||||
|
// A press on a tray item: a click if it never moved, otherwise the drag ends here.
|
||||||
|
k, wasDrag := dragTray, dragTrayActive
|
||||||
|
dragTray, dragTrayActive = 0, false
|
||||||
|
pReleaseCapture.Call()
|
||||||
|
if wasDrag {
|
||||||
|
saveTrayOrder()
|
||||||
|
} else {
|
||||||
|
trayClick(k)
|
||||||
|
}
|
||||||
|
redraw(hwnd)
|
||||||
} else if inStart(hwnd, x) {
|
} else if inStart(hwnd, x) {
|
||||||
tapWinKey()
|
tapWinKey()
|
||||||
} else if k := trayAt(hwnd, x); k != 0 {
|
|
||||||
trayClick(k)
|
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmRButtonUp:
|
case wmRButtonUp:
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
|
previewBlock(true)
|
||||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||||
|
previewBlock(false)
|
||||||
return 0
|
return 0
|
||||||
case wmMouseWheel:
|
case wmMouseWheel:
|
||||||
// Scrolling over the volume icon changes the volume. The wheel
|
// Scrolling over the volume icon changes the volume. The wheel
|
||||||
@@ -1100,7 +1135,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
var wr rect
|
var wr rect
|
||||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||||
x := alongScreen(lparam, wr)
|
x := alongScreen(lparam, wr)
|
||||||
|
previewBlock(true)
|
||||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||||
|
previewBlock(false)
|
||||||
return 0
|
return 0
|
||||||
case wmEnterSizeMove:
|
case wmEnterSizeMove:
|
||||||
dragging = true
|
dragging = true
|
||||||
@@ -1122,6 +1159,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmDestroy:
|
case wmDestroy:
|
||||||
|
previewShutdown()
|
||||||
abd := appBarData{Hwnd: hwnd}
|
abd := appBarData{Hwnd: hwnd}
|
||||||
appBar(abmRemove, &abd)
|
appBar(abmRemove, &abd)
|
||||||
pKillTimer.Call(hwnd, timerID)
|
pKillTimer.Call(hwnd, timerID)
|
||||||
@@ -1176,7 +1214,10 @@ func main() {
|
|||||||
loadAlpha()
|
loadAlpha()
|
||||||
loadPos()
|
loadPos()
|
||||||
loadStartSlot()
|
loadStartSlot()
|
||||||
|
loadTrayOrder()
|
||||||
loadOrient()
|
loadOrient()
|
||||||
|
loadPinned()
|
||||||
|
loadOrderKeys()
|
||||||
|
|
||||||
hdc, _, _ := pGetDC.Call(0)
|
hdc, _, _ := pGetDC.Call(0)
|
||||||
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
||||||
@@ -1229,6 +1270,7 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
hwndMain = hwnd
|
hwndMain = hwnd
|
||||||
|
previewInit(inst)
|
||||||
refreshAutostartPath()
|
refreshAutostartPath()
|
||||||
|
|
||||||
// Hotkey: Ctrl+Alt+Q exits and restores.
|
// Hotkey: Ctrl+Alt+Q exits and restores.
|
||||||
|
|||||||
@@ -0,0 +1,348 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Pinned apps and the saved icon order.
|
||||||
|
//
|
||||||
|
// A pinned app that has no open window still gets a button (a "launcher",
|
||||||
|
// which is an appWin with hwnd 0). Clicking it starts the program. When the
|
||||||
|
// program opens a window, the window takes over that very spot, and when its
|
||||||
|
// last window closes the launcher comes back in the same place.
|
||||||
|
//
|
||||||
|
// The order of the icons is remembered by program, so it comes back after a
|
||||||
|
// restart no matter which windows happen to be open.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pSHGetFileInfo = shell32.NewProc("SHGetFileInfoW")
|
||||||
|
|
||||||
|
pinned []string // full paths of pinned programs
|
||||||
|
orderKeys []string // programs in icon order, nearest the center first (lower case)
|
||||||
|
winExe = map[uintptr]string{}
|
||||||
|
exeIcons = map[string]uintptr{}
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
menuPinID = 40
|
||||||
|
menuUnpinID = 41
|
||||||
|
menuNotifyID = 42
|
||||||
|
menuLaunchID = 43
|
||||||
|
|
||||||
|
shgfiIcon = 0x100
|
||||||
|
shgfiSmallIcon = 0x1
|
||||||
|
vkN = 0x4E
|
||||||
|
)
|
||||||
|
|
||||||
|
type shFileInfo struct {
|
||||||
|
Icon uintptr
|
||||||
|
IIcon int32
|
||||||
|
Attrs uint32
|
||||||
|
Display [260]uint16
|
||||||
|
Type [80]uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
func pinnedFile() string { return filepath.Join(dataDir(), "pinned.txt") }
|
||||||
|
func orderFile() string { return filepath.Join(dataDir(), "order.txt") }
|
||||||
|
|
||||||
|
func readLines(path string) []string {
|
||||||
|
b, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var out []string
|
||||||
|
for _, l := range strings.Split(string(b), "\n") {
|
||||||
|
if l = strings.TrimSpace(l); l != "" {
|
||||||
|
out = append(out, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeLines(path string, lines []string) {
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
|
_ = os.WriteFile(path, []byte(strings.Join(lines, "\n")+"\n"), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadPinned() { pinned = readLines(pinnedFile()) }
|
||||||
|
func savePinned() { writeLines(pinnedFile(), pinned) }
|
||||||
|
func loadOrderKeys() { orderKeys = readLines(orderFile()) }
|
||||||
|
|
||||||
|
func isPinned(exe string) bool {
|
||||||
|
if exe == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, p := range pinned {
|
||||||
|
if strings.EqualFold(p, exe) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func pinApp(exe string) {
|
||||||
|
if exe == "" || isPinned(exe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pinned = append(pinned, exe)
|
||||||
|
savePinned()
|
||||||
|
saveOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
func unpinApp(exe string) {
|
||||||
|
var keep []string
|
||||||
|
for _, p := range pinned {
|
||||||
|
if !strings.EqualFold(p, exe) {
|
||||||
|
keep = append(keep, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pinned = keep
|
||||||
|
savePinned()
|
||||||
|
saveOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
// canPin is false for Store and other packaged apps: their programs can't be
|
||||||
|
// started again from a plain path.
|
||||||
|
func canPin(exe string) bool {
|
||||||
|
return exe != "" && !strings.Contains(strings.ToLower(exe), `\windowsapps\`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- order ----------
|
||||||
|
|
||||||
|
func orderRank(exe string) int {
|
||||||
|
if exe == "" {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
for i, k := range orderKeys {
|
||||||
|
if k == strings.ToLower(exe) {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
// saveOrder remembers the current icon order. Programs that aren't open right
|
||||||
|
// now keep their place relative to their old neighbors.
|
||||||
|
func saveOrder() {
|
||||||
|
var cur []string
|
||||||
|
have := map[string]bool{}
|
||||||
|
for _, a := range apps {
|
||||||
|
k := strings.ToLower(a.exe)
|
||||||
|
if k == "" || have[k] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
have[k] = true
|
||||||
|
cur = append(cur, k)
|
||||||
|
}
|
||||||
|
res := cur
|
||||||
|
for i, k := range orderKeys {
|
||||||
|
if have[k] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pos := 0
|
||||||
|
for j := i - 1; j >= 0; j-- {
|
||||||
|
if p := indexOf(res, orderKeys[j]); p >= 0 {
|
||||||
|
pos = p + 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = append(res[:pos], append([]string{k}, res[pos:]...)...)
|
||||||
|
have[k] = true
|
||||||
|
}
|
||||||
|
if len(res) > 200 {
|
||||||
|
res = res[:200]
|
||||||
|
}
|
||||||
|
orderKeys = res
|
||||||
|
writeLines(orderFile(), orderKeys)
|
||||||
|
}
|
||||||
|
|
||||||
|
func indexOf(list []string, s string) int {
|
||||||
|
for i, v := range list {
|
||||||
|
if v == s {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertAt(list []appWin, i int, a appWin) []appWin {
|
||||||
|
list = append(list, appWin{})
|
||||||
|
copy(list[i+1:], list[i:])
|
||||||
|
list[i] = a
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// addApp puts a new button into the list: into the spot of a waiting launcher
|
||||||
|
// for the same program, else beside the program's other windows, else where
|
||||||
|
// the saved order says, else at the far end.
|
||||||
|
func addApp(list []appWin, f appWin) []appWin {
|
||||||
|
if f.exe != "" {
|
||||||
|
if f.hwnd != 0 {
|
||||||
|
for i, a := range list {
|
||||||
|
if a.hwnd == 0 && strings.EqualFold(a.exe, f.exe) {
|
||||||
|
list[i] = f
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
last := -1
|
||||||
|
for i, a := range list {
|
||||||
|
if a.hwnd != 0 && strings.EqualFold(a.exe, f.exe) {
|
||||||
|
last = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if last >= 0 {
|
||||||
|
return insertAt(list, last+1, f)
|
||||||
|
}
|
||||||
|
if r := orderRank(f.exe); r >= 0 {
|
||||||
|
for i, a := range list {
|
||||||
|
if ra := orderRank(a.exe); ra < 0 || ra > r {
|
||||||
|
return insertAt(list, i, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return append(list, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- launchers and icons ----------
|
||||||
|
|
||||||
|
func launcher(exe string) appWin {
|
||||||
|
name := filepath.Base(exe)
|
||||||
|
name = strings.TrimSuffix(name, filepath.Ext(name))
|
||||||
|
return appWin{title: name, exe: exe, icon: exeIcon(exe)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// exeIcon is the small icon of a program file, fetched once.
|
||||||
|
func exeIcon(path string) uintptr {
|
||||||
|
key := strings.ToLower(path)
|
||||||
|
if ic, ok := exeIcons[key]; ok {
|
||||||
|
return ic
|
||||||
|
}
|
||||||
|
var fi shFileInfo
|
||||||
|
r, _, _ := pSHGetFileInfo.Call(uintptr(unsafe.Pointer(u16(path))), 0,
|
||||||
|
uintptr(unsafe.Pointer(&fi)), unsafe.Sizeof(fi), shgfiIcon|shgfiSmallIcon)
|
||||||
|
var ic uintptr
|
||||||
|
if r != 0 {
|
||||||
|
ic = fi.Icon
|
||||||
|
}
|
||||||
|
exeIcons[key] = ic
|
||||||
|
return ic
|
||||||
|
}
|
||||||
|
|
||||||
|
// refreshApps re-reads the open windows and merges them with the pinned
|
||||||
|
// programs, keeping every button where it was. Returns true if anything changed.
|
||||||
|
func refreshApps(refreshIcons bool) bool {
|
||||||
|
enumFound = enumFound[:0]
|
||||||
|
pEnumWindows.Call(enumCb, 0)
|
||||||
|
|
||||||
|
present := make(map[uintptr]appWin, len(enumFound))
|
||||||
|
live := map[string]int{} // open windows per program
|
||||||
|
for _, f := range enumFound {
|
||||||
|
if _, ok := winExe[f.hwnd]; !ok {
|
||||||
|
winExe[f.hwnd] = windowExePath(f.hwnd)
|
||||||
|
}
|
||||||
|
f.exe = winExe[f.hwnd]
|
||||||
|
present[f.hwnd] = f
|
||||||
|
if f.exe != "" {
|
||||||
|
live[strings.ToLower(f.exe)]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for h := range winExe {
|
||||||
|
if _, ok := present[h]; !ok {
|
||||||
|
delete(winExe, h)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var next []appWin
|
||||||
|
for _, a := range apps {
|
||||||
|
if a.hwnd == 0 {
|
||||||
|
next = append(next, a) // a waiting launcher; sorted out below
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if f, ok := present[a.hwnd]; ok {
|
||||||
|
a.title, a.exe = f.title, f.exe
|
||||||
|
next = append(next, a)
|
||||||
|
delete(present, a.hwnd)
|
||||||
|
} else if isPinned(a.exe) && live[strings.ToLower(a.exe)] == 0 {
|
||||||
|
// The last window of a pinned program closed: leave a launcher in its place.
|
||||||
|
next = append(next, launcher(a.exe))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range enumFound {
|
||||||
|
if _, ok := present[f.hwnd]; ok {
|
||||||
|
next = addApp(next, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launchers for pinned programs that have neither a window nor a launcher yet.
|
||||||
|
have := map[string]bool{}
|
||||||
|
for _, a := range next {
|
||||||
|
if a.exe != "" {
|
||||||
|
have[strings.ToLower(a.exe)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, p := range pinned {
|
||||||
|
if !have[strings.ToLower(p)] {
|
||||||
|
next = addApp(next, launcher(p))
|
||||||
|
have[strings.ToLower(p)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drop launchers that are no longer needed.
|
||||||
|
var tidy []appWin
|
||||||
|
seen := map[string]bool{}
|
||||||
|
for _, a := range next {
|
||||||
|
if a.hwnd == 0 {
|
||||||
|
k := strings.ToLower(a.exe)
|
||||||
|
if !isPinned(a.exe) || live[k] > 0 || seen[k] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[k] = true
|
||||||
|
}
|
||||||
|
tidy = append(tidy, a)
|
||||||
|
}
|
||||||
|
next = tidy
|
||||||
|
|
||||||
|
for i := range next {
|
||||||
|
if next[i].hwnd == 0 {
|
||||||
|
if next[i].icon == 0 {
|
||||||
|
next[i].icon = exeIcon(next[i].exe)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if next[i].icon == 0 || refreshIcons {
|
||||||
|
if ic := fetchIcon(next[i].hwnd); ic != 0 {
|
||||||
|
next[i].icon = ic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
if !changed {
|
||||||
|
for i := range next {
|
||||||
|
if next[i].hwnd != apps[i].hwnd || next[i].icon != apps[i].icon {
|
||||||
|
changed = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
apps = next
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- notification center ----------
|
||||||
|
|
||||||
|
// openNotifications presses Win+N, which opens the notification center and calendar.
|
||||||
|
func openNotifications() {
|
||||||
|
pKeybdEvent.Call(vkLWin, 0, 0, 0)
|
||||||
|
pKeybdEvent.Call(vkN, 0, 0, 0)
|
||||||
|
pKeybdEvent.Call(vkN, 0, keyUp, 0)
|
||||||
|
pKeybdEvent.Call(vkLWin, 0, keyUp, 0)
|
||||||
|
}
|
||||||
+385
@@ -0,0 +1,385 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Hover preview: rest the mouse on an app icon and a small window with a live
|
||||||
|
// picture of that app appears next to the bar. Windows draws the picture
|
||||||
|
// itself (a DWM thumbnail), so it stays live and costs almost nothing. A
|
||||||
|
// minimized window has nothing live to show, so it gets its icon instead.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pDwmRegisterThumbnail = dwmapi.NewProc("DwmRegisterThumbnail")
|
||||||
|
pDwmUnregisterThumbnail = dwmapi.NewProc("DwmUnregisterThumbnail")
|
||||||
|
pDwmUpdateThumbnailProperties = dwmapi.NewProc("DwmUpdateThumbnailProperties")
|
||||||
|
pDwmQueryThumbnailSourceSize = dwmapi.NewProc("DwmQueryThumbnailSourceSize")
|
||||||
|
pSetWindowPos = user32.NewProc("SetWindowPos")
|
||||||
|
pInvalidateRect = user32.NewProc("InvalidateRect")
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
previewTimerID = 2
|
||||||
|
previewDelay = 350 * time.Millisecond
|
||||||
|
|
||||||
|
hwndTopmost = ^uintptr(0) // HWND_TOPMOST is (HWND)-1
|
||||||
|
swpNoActivate = 0x0010
|
||||||
|
swpShowWindow = 0x0040
|
||||||
|
wmMouseActivate = 0x0021
|
||||||
|
maNoActivate = 3
|
||||||
|
dtEndEllipsis = 0x8000
|
||||||
|
vkLButton = 0x01
|
||||||
|
|
||||||
|
dwmTnpDest = 0x1
|
||||||
|
dwmTnpOpacity = 0x4
|
||||||
|
dwmTnpVisible = 0x8
|
||||||
|
)
|
||||||
|
|
||||||
|
type dwmThumbProps struct {
|
||||||
|
Flags uint32
|
||||||
|
Dest rect
|
||||||
|
Src rect
|
||||||
|
Opacity byte
|
||||||
|
_ [3]byte
|
||||||
|
Visible int32
|
||||||
|
ClientOnly int32
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
pvHwnd uintptr // the preview window itself
|
||||||
|
pvThumb uintptr // the live picture registered on it, if any
|
||||||
|
pvSrc uintptr // the window being previewed; 0 means nothing is showing
|
||||||
|
pvTitle string //
|
||||||
|
pvIcon uintptr //
|
||||||
|
pvIconic bool // true: no live picture, draw the icon instead
|
||||||
|
pvThumbR rect // picture area, in the preview's own coordinates
|
||||||
|
pvTitleR rect // title row
|
||||||
|
pvCand uintptr // the icon the mouse has been resting on
|
||||||
|
pvSince time.Time // since when
|
||||||
|
pvSupp uintptr // an icon that was just clicked: no preview until the mouse leaves it
|
||||||
|
pvTimer bool
|
||||||
|
pvBlock bool // a menu is open
|
||||||
|
)
|
||||||
|
|
||||||
|
func previewInit(inst uintptr) {
|
||||||
|
cursor, _, _ := pLoadCursor.Call(0, idcArrow)
|
||||||
|
className := u16("MirrorBarPreview")
|
||||||
|
wc := wndClassEx{
|
||||||
|
WndProc: syscall.NewCallback(previewProc),
|
||||||
|
Instance: inst,
|
||||||
|
Cursor: cursor,
|
||||||
|
ClassName: className,
|
||||||
|
}
|
||||||
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
|
pRegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
|
||||||
|
pvHwnd, _, _ = pCreateWindowEx.Call(
|
||||||
|
wsExToolWindow|wsExTopmost|wsExNoActivate,
|
||||||
|
uintptr(unsafe.Pointer(className)),
|
||||||
|
uintptr(unsafe.Pointer(u16(""))),
|
||||||
|
wsPopup,
|
||||||
|
0, 0, 10, 10,
|
||||||
|
0, 0, inst, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
result = 0 // the preview is optional; never take the bar down with it
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
switch uint32(m) {
|
||||||
|
case wmEraseBkgnd:
|
||||||
|
return 1
|
||||||
|
case wmMouseActivate:
|
||||||
|
return maNoActivate
|
||||||
|
case wmPaint:
|
||||||
|
previewPaint(hwnd)
|
||||||
|
return 0
|
||||||
|
case wmLButtonUp:
|
||||||
|
previewActivate()
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
r, _, _ := pDefWindowProc.Call(hwnd, m, wparam, lparam)
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewPaint(hwnd uintptr) {
|
||||||
|
var ps paintStruct
|
||||||
|
hdc, _, _ := pBeginPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
|
var rc rect
|
||||||
|
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||||
|
|
||||||
|
edge, _, _ := pCreateSolidBrush.Call(rgb(78, 78, 92))
|
||||||
|
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&rc)), edge)
|
||||||
|
pDeleteObject.Call(edge)
|
||||||
|
inner := rect{rc.Left + 1, rc.Top + 1, rc.Right - 1, rc.Bottom - 1}
|
||||||
|
body, _, _ := pCreateSolidBrush.Call(rgb(28, 28, 34))
|
||||||
|
pFillRect.Call(hdc, uintptr(unsafe.Pointer(&inner)), body)
|
||||||
|
pDeleteObject.Call(body)
|
||||||
|
|
||||||
|
isz := px(16)
|
||||||
|
if pvIcon != 0 {
|
||||||
|
y := pvTitleR.Top + (pvTitleR.Bottom-pvTitleR.Top-isz)/2
|
||||||
|
pDrawIconEx.Call(hdc, uintptr(pvTitleR.Left), uintptr(y), pvIcon, uintptr(isz), uintptr(isz), 0, 0, diNormal)
|
||||||
|
}
|
||||||
|
pSetBkMode.Call(hdc, transparent)
|
||||||
|
pSetTextColor.Call(hdc, rgb(240, 240, 245))
|
||||||
|
old, _, _ := pSelectObject.Call(hdc, fontApp)
|
||||||
|
tr := rect{pvTitleR.Left + isz + px(6), pvTitleR.Top, pvTitleR.Right, pvTitleR.Bottom}
|
||||||
|
pDrawText.Call(hdc, uintptr(unsafe.Pointer(u16(pvTitle))), ^uintptr(0), uintptr(unsafe.Pointer(&tr)),
|
||||||
|
dtLeft|dtVCenter|dtSingleLine|dtNoPrefix|dtEndEllipsis)
|
||||||
|
pSelectObject.Call(hdc, old)
|
||||||
|
|
||||||
|
if pvIconic && pvIcon != 0 {
|
||||||
|
big := px(48)
|
||||||
|
cx := (pvThumbR.Left + pvThumbR.Right) / 2
|
||||||
|
cy := (pvThumbR.Top + pvThumbR.Bottom) / 2
|
||||||
|
pDrawIconEx.Call(hdc, uintptr(cx-big/2), uintptr(cy-big/2), pvIcon, uintptr(big), uintptr(big), 0, 0, diNormal)
|
||||||
|
}
|
||||||
|
pEndPaint.Call(hwnd, uintptr(unsafe.Pointer(&ps)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewDropThumb() {
|
||||||
|
if pvThumb != 0 {
|
||||||
|
pDwmUnregisterThumbnail.Call(pvThumb)
|
||||||
|
pvThumb = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewHide() {
|
||||||
|
previewDropThumb()
|
||||||
|
if pvSrc != 0 && pvHwnd != 0 {
|
||||||
|
pShowWindow.Call(pvHwnd, swHide)
|
||||||
|
}
|
||||||
|
pvSrc = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewIconRect is where an app icon sits on the screen.
|
||||||
|
func previewIconRect(idx int, wr rect) rect {
|
||||||
|
w, h := clientSize(hwndMain)
|
||||||
|
rs := appRects(w, h)
|
||||||
|
if idx < 0 || idx >= len(rs) {
|
||||||
|
return wr
|
||||||
|
}
|
||||||
|
r := rs[idx]
|
||||||
|
if vertical {
|
||||||
|
r = mapRect(r, barHeight)
|
||||||
|
}
|
||||||
|
return rect{wr.Left + r.Left, wr.Top + r.Top, wr.Left + r.Right, wr.Top + r.Bottom}
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewShow(idx int) {
|
||||||
|
if pvHwnd == 0 || idx < 0 || idx >= len(apps) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a := apps[idx]
|
||||||
|
previewDropThumb()
|
||||||
|
|
||||||
|
iconic, _, _ := pIsIconic.Call(a.hwnd)
|
||||||
|
pvIconic = iconic != 0
|
||||||
|
var tw, th int32
|
||||||
|
if !pvIconic {
|
||||||
|
var t uintptr
|
||||||
|
hr, _, _ := pDwmRegisterThumbnail.Call(pvHwnd, a.hwnd, uintptr(unsafe.Pointer(&t)))
|
||||||
|
if hr == 0 && t != 0 {
|
||||||
|
pvThumb = t
|
||||||
|
var sz size
|
||||||
|
hr2, _, _ := pDwmQueryThumbnailSourceSize.Call(t, uintptr(unsafe.Pointer(&sz)))
|
||||||
|
if hr2 == 0 && sz.CX > 0 && sz.CY > 0 {
|
||||||
|
f := min(float64(px(260))/float64(sz.CX), float64(px(160))/float64(sz.CY), 1.0)
|
||||||
|
tw = max(int32(float64(sz.CX)*f), 1)
|
||||||
|
th = max(int32(float64(sz.CY)*f), 1)
|
||||||
|
} else {
|
||||||
|
previewDropThumb()
|
||||||
|
pvIconic = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pvIconic = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pvIconic {
|
||||||
|
tw, th = px(200), px(110)
|
||||||
|
}
|
||||||
|
|
||||||
|
pad, titleH, gap := px(8), px(22), px(4)
|
||||||
|
cw := max(px(180), tw+2*pad)
|
||||||
|
ch := pad + titleH + gap + th + pad
|
||||||
|
pvTitleR = rect{pad, pad, cw - pad, pad + titleH}
|
||||||
|
tx, ty := (cw-tw)/2, pad+titleH+gap
|
||||||
|
pvThumbR = rect{tx, ty, tx + tw, ty + th}
|
||||||
|
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
ir := previewIconRect(idx, wr)
|
||||||
|
sw, sh := screenSize()
|
||||||
|
space := px(8)
|
||||||
|
var x, y int32
|
||||||
|
if vertical {
|
||||||
|
x = wr.Left - cw - space
|
||||||
|
if x < 0 {
|
||||||
|
x = wr.Right + space
|
||||||
|
}
|
||||||
|
y = (ir.Top+ir.Bottom)/2 - ch/2
|
||||||
|
} else {
|
||||||
|
x = (ir.Left+ir.Right)/2 - cw/2
|
||||||
|
y = wr.Top - ch - space
|
||||||
|
if y < 0 {
|
||||||
|
y = wr.Bottom + space
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x = clampI(x, 0, sw-cw)
|
||||||
|
y = clampI(y, 0, sh-ch)
|
||||||
|
|
||||||
|
pvSrc, pvTitle, pvIcon = a.hwnd, a.title, a.icon
|
||||||
|
pSetWindowPos.Call(pvHwnd, hwndTopmost, uintptr(x), uintptr(y), uintptr(cw), uintptr(ch), swpNoActivate|swpShowWindow)
|
||||||
|
if pvThumb != 0 {
|
||||||
|
props := dwmThumbProps{Flags: dwmTnpDest | dwmTnpOpacity | dwmTnpVisible, Dest: pvThumbR, Opacity: 255, Visible: 1}
|
||||||
|
pDwmUpdateThumbnailProperties.Call(pvThumb, uintptr(unsafe.Pointer(&props)))
|
||||||
|
}
|
||||||
|
pInvalidateRect.Call(pvHwnd, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inRect(r rect, p point) bool {
|
||||||
|
return p.X >= r.Left && p.X < r.Right && p.Y >= r.Top && p.Y < r.Bottom
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewKick starts the short timer that watches where the mouse is.
|
||||||
|
func previewKick() {
|
||||||
|
if pvHwnd == 0 || pvTimer {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pSetTimer.Call(hwndMain, previewTimerID, 60, 0)
|
||||||
|
pvTimer = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewStopTimer() {
|
||||||
|
if pvTimer {
|
||||||
|
pKillTimer.Call(hwndMain, previewTimerID)
|
||||||
|
pvTimer = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewTick decides what the preview should be doing right now, from where
|
||||||
|
// the mouse is. It runs only while the mouse is near the bar.
|
||||||
|
func previewTick() {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
previewHide()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if pvHwnd == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var cp point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&cp)))
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwndMain, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
overBar := inRect(wr, cp)
|
||||||
|
|
||||||
|
btn, _, _ := pGetAsyncKeyState.Call(vkLButton)
|
||||||
|
if btn&0x8000 != 0 || pvBlock || dragging {
|
||||||
|
previewHide()
|
||||||
|
pvCand = 0
|
||||||
|
if !overBar {
|
||||||
|
previewStopTimer()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
idx := -1
|
||||||
|
var raw uintptr
|
||||||
|
if overBar {
|
||||||
|
x := cp.X - wr.Left
|
||||||
|
if vertical {
|
||||||
|
x = cp.Y - wr.Top
|
||||||
|
}
|
||||||
|
idx = appIndexAt(hwndMain, x)
|
||||||
|
if idx >= 0 && idx < len(apps) {
|
||||||
|
raw = apps[idx].hwnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
target := raw
|
||||||
|
if raw != 0 && raw == pvSupp {
|
||||||
|
target = 0 // just clicked: stay quiet until the mouse moves off this icon
|
||||||
|
} else {
|
||||||
|
pvSupp = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if target != 0 {
|
||||||
|
if pvSrc == target {
|
||||||
|
if apps[idx].title != pvTitle {
|
||||||
|
pvTitle = apps[idx].title
|
||||||
|
pInvalidateRect.Call(pvHwnd, 0, 1)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pvCand != target {
|
||||||
|
pvCand = target
|
||||||
|
pvSince = time.Now()
|
||||||
|
}
|
||||||
|
if pvSrc != 0 || time.Since(pvSince) >= previewDelay {
|
||||||
|
previewShow(idx)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
pvCand = 0
|
||||||
|
if pvSrc != 0 {
|
||||||
|
var pr rect
|
||||||
|
pGetWindowRect.Call(pvHwnd, uintptr(unsafe.Pointer(&pr)))
|
||||||
|
g := px(10) // covers the small gap between the icon and the preview
|
||||||
|
pr = rect{pr.Left - g, pr.Top - g, pr.Right + g, pr.Bottom + g}
|
||||||
|
if inRect(pr, cp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
previewHide()
|
||||||
|
}
|
||||||
|
if !overBar {
|
||||||
|
previewStopTimer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewSuppress hides the preview because the icon was clicked, and keeps it
|
||||||
|
// away until the mouse leaves that icon.
|
||||||
|
func previewSuppress() {
|
||||||
|
if pvSrc != 0 {
|
||||||
|
pvSupp = pvSrc
|
||||||
|
} else {
|
||||||
|
pvSupp = pvCand
|
||||||
|
}
|
||||||
|
pvCand = 0
|
||||||
|
previewHide()
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewBlock keeps the preview down while a menu is open.
|
||||||
|
func previewBlock(on bool) {
|
||||||
|
pvBlock = on
|
||||||
|
if on {
|
||||||
|
previewSuppress()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// previewActivate runs when the preview itself is clicked: bring that window forward.
|
||||||
|
func previewActivate() {
|
||||||
|
h := pvSrc
|
||||||
|
previewHide()
|
||||||
|
if h == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
iconic, _, _ := pIsIconic.Call(h)
|
||||||
|
if iconic != 0 {
|
||||||
|
pShowWindow.Call(h, swRestore)
|
||||||
|
}
|
||||||
|
pSetForegroundWindow.Call(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewShutdown() {
|
||||||
|
previewStopTimer()
|
||||||
|
previewHide()
|
||||||
|
if pvHwnd != 0 {
|
||||||
|
pDestroyWindow.Call(pvHwnd)
|
||||||
|
pvHwnd = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -85,17 +87,24 @@ type trayItem struct {
|
|||||||
func trayItems(clientW, clientH int32) []trayItem {
|
func trayItems(clientW, clientH int32) []trayItem {
|
||||||
x := clientW / 2
|
x := clientW / 2
|
||||||
var out []trayItem
|
var out []trayItem
|
||||||
add := func(kind int, w int32) {
|
for _, kind := range trayOrder {
|
||||||
|
var w int32
|
||||||
|
switch kind {
|
||||||
|
case trayClock:
|
||||||
|
w = clockWidth()
|
||||||
|
case trayBattery:
|
||||||
|
if battPct < 0 {
|
||||||
|
continue // this PC has no battery
|
||||||
|
}
|
||||||
|
w = px(36)
|
||||||
|
case trayVolume, trayWifi:
|
||||||
|
w = px(36)
|
||||||
|
case trayChevron:
|
||||||
|
w = px(28)
|
||||||
|
}
|
||||||
out = append(out, trayItem{kind, rect{x, 0, x + w, clientH}})
|
out = append(out, trayItem{kind, rect{x, 0, x + w, clientH}})
|
||||||
x += w
|
x += w
|
||||||
}
|
}
|
||||||
add(trayClock, clockWidth())
|
|
||||||
if battPct >= 0 {
|
|
||||||
add(trayBattery, px(36))
|
|
||||||
}
|
|
||||||
add(trayVolume, px(36))
|
|
||||||
add(trayWifi, px(36))
|
|
||||||
add(trayChevron, px(28))
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,3 +671,85 @@ func handleTrayCommand(cmd uintptr) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- the right row can be rearranged too ----------
|
||||||
|
|
||||||
|
// trayOrder is the left to right order of the items to the right of center.
|
||||||
|
var trayOrder = []int{trayClock, trayBattery, trayVolume, trayWifi, trayChevron}
|
||||||
|
|
||||||
|
var (
|
||||||
|
dragTray int // the tray item the mouse went down on, 0 for none
|
||||||
|
dragTrayStart int32 // where along the bar the mouse went down
|
||||||
|
dragTrayActive bool // true once the mouse has moved far enough to count as a drag
|
||||||
|
)
|
||||||
|
|
||||||
|
func trayOrderFile() string { return filepath.Join(dataDir(), "trayorder.txt") }
|
||||||
|
|
||||||
|
func loadTrayOrder() {
|
||||||
|
b, err := os.ReadFile(trayOrderFile())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var order []int
|
||||||
|
seen := map[int]bool{}
|
||||||
|
for _, p := range strings.Split(strings.TrimSpace(string(b)), ",") {
|
||||||
|
n, err := strconv.Atoi(strings.TrimSpace(p))
|
||||||
|
if err != nil || n < trayClock || n > trayChevron || seen[n] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
seen[n] = true
|
||||||
|
order = append(order, n)
|
||||||
|
}
|
||||||
|
if len(order) == len(trayOrder) {
|
||||||
|
trayOrder = order
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveTrayOrder() {
|
||||||
|
parts := make([]string, len(trayOrder))
|
||||||
|
for i, k := range trayOrder {
|
||||||
|
parts[i] = strconv.Itoa(k)
|
||||||
|
}
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
|
_ = os.WriteFile(trayOrderFile(), []byte(strings.Join(parts, ",")), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
// trayKindAt is the tray item under a spot along the bar, clamped to the ends
|
||||||
|
// of the right row.
|
||||||
|
func trayKindAt(hwnd uintptr, x int32) int {
|
||||||
|
w, h := clientSize(hwnd)
|
||||||
|
items := trayItems(w, h)
|
||||||
|
if len(items) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if x < items[0].r.Left {
|
||||||
|
return items[0].kind
|
||||||
|
}
|
||||||
|
if x >= items[len(items)-1].r.Right {
|
||||||
|
return items[len(items)-1].kind
|
||||||
|
}
|
||||||
|
for _, it := range items {
|
||||||
|
if x >= it.r.Left && x < it.r.Right {
|
||||||
|
return it.kind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// moveTray puts one item where another one is, shifting the rest.
|
||||||
|
func moveTray(kind, target int) {
|
||||||
|
from, to := -1, -1
|
||||||
|
for i, k := range trayOrder {
|
||||||
|
if k == kind {
|
||||||
|
from = i
|
||||||
|
}
|
||||||
|
if k == target {
|
||||||
|
to = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if from < 0 || to < 0 || from == to {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rest := append(append([]int{}, trayOrder[:from]...), trayOrder[from+1:]...)
|
||||||
|
trayOrder = append(append(append([]int{}, rest[:to]...), kind), rest[to:]...)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user