Add hover previews, pinned apps, saved icon order and notification center menu item
This commit is contained in:
@@ -302,9 +302,10 @@ type trackMouseEvent struct {
|
||||
|
||||
// appWin is one open window shown as an icon button on the left side of the bar.
|
||||
type appWin struct {
|
||||
hwnd uintptr
|
||||
hwnd uintptr // 0 for a pinned program that has no window open right now
|
||||
title string
|
||||
icon uintptr
|
||||
exe string // full path of the program, "" when unknown
|
||||
}
|
||||
|
||||
type alphaLevel struct {
|
||||
@@ -514,58 +515,18 @@ func fetchIcon(hwnd uintptr) uintptr {
|
||||
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) {
|
||||
if idx < 0 || idx >= len(apps) {
|
||||
return
|
||||
}
|
||||
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()
|
||||
iconic, _, _ := pIsIconic.Call(h)
|
||||
switch {
|
||||
@@ -851,37 +812,62 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
add(mfGrayed, 0, strings.ReplaceAll(text, "&", "&&"))
|
||||
sep()
|
||||
|
||||
exe = windowExePath(target)
|
||||
if exe != "" {
|
||||
exe = apps[appIdx].exe
|
||||
if target != 0 && exe == "" {
|
||||
exe = windowExePath(target)
|
||||
}
|
||||
if target == 0 {
|
||||
// A pinned program that isn't running: only launcher options apply.
|
||||
add(0, menuLaunchID, "Open")
|
||||
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, 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()
|
||||
}
|
||||
|
||||
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
||||
iconic, _, _ := pIsIconic.Call(target)
|
||||
zoomed, _, _ := pIsZoomed.Call(target)
|
||||
normal := iconic == 0 && zoomed == 0
|
||||
enabled := func(ok bool) uintptr {
|
||||
if ok {
|
||||
return 0
|
||||
if target != 0 {
|
||||
style, _, _ := pGetWindowLongPtr.Call(target, neg(-16)) // GWL_STYLE
|
||||
iconic, _, _ := pIsIconic.Call(target)
|
||||
zoomed, _, _ := pIsZoomed.Call(target)
|
||||
normal := iconic == 0 && zoomed == 0
|
||||
enabled := func(ok bool) uintptr {
|
||||
if ok {
|
||||
return 0
|
||||
}
|
||||
return mfGrayed
|
||||
}
|
||||
return mfGrayed
|
||||
add(enabled(!normal), menuRestoreID, "Restore")
|
||||
add(enabled(normal), menuMoveID, "Move")
|
||||
add(enabled(normal && style&wsThickFrame != 0), menuSizeID, "Size")
|
||||
add(enabled(iconic == 0 && style&wsMinimizeBox != 0), menuMinimizeID, "Minimize")
|
||||
add(enabled(zoomed == 0 && style&wsMaximizeBox != 0), menuMaximizeID, "Maximize")
|
||||
sep()
|
||||
add(0, menuCloseID, "Close window")
|
||||
sep()
|
||||
}
|
||||
add(enabled(!normal), menuRestoreID, "Restore")
|
||||
add(enabled(normal), menuMoveID, "Move")
|
||||
add(enabled(normal && style&wsThickFrame != 0), menuSizeID, "Size")
|
||||
add(enabled(iconic == 0 && style&wsMinimizeBox != 0), menuMinimizeID, "Minimize")
|
||||
add(enabled(zoomed == 0 && style&wsMaximizeBox != 0), menuMaximizeID, "Maximize")
|
||||
sep()
|
||||
add(0, menuCloseID, "Close window")
|
||||
sep()
|
||||
}
|
||||
|
||||
if appIdx < 0 {
|
||||
addTrayMenu(add, sep, trayKind)
|
||||
}
|
||||
|
||||
add(0, menuNotifyID, "Open notification center")
|
||||
sep()
|
||||
for i, l := range alphaLevels {
|
||||
var flags uintptr
|
||||
if bgAlpha == l.alpha {
|
||||
@@ -940,6 +926,18 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pPostMessage.Call(target, wmClose, 0, 0)
|
||||
case cmd == menuNewWindowID && 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 != "":
|
||||
shellOpen("explorer.exe", `/select,"`+exe+`"`)
|
||||
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)))
|
||||
return 0
|
||||
case wmTimer:
|
||||
if wparam == previewTimerID {
|
||||
previewTick()
|
||||
return 0
|
||||
}
|
||||
hideTaskbar()
|
||||
tick++
|
||||
changed := refreshApps(tick%16 == 0)
|
||||
@@ -993,6 +995,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmLButtonDown:
|
||||
previewSuppress()
|
||||
x := alongClient(lparam)
|
||||
if inStart(hwnd, x) {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||
@@ -1051,6 +1054,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
hoverTray = overTray
|
||||
redraw(hwnd)
|
||||
}
|
||||
if overApp >= 0 {
|
||||
previewKick()
|
||||
}
|
||||
if !trackingMouse {
|
||||
tme := trackMouseEvent{Size: uint32(unsafe.Sizeof(trackMouseEvent{})), Flags: tmeLeave, HwndTrack: hwnd}
|
||||
pTrackMouseEvent.Call(uintptr(unsafe.Pointer(&tme)))
|
||||
@@ -1075,6 +1081,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
pReleaseCapture.Call()
|
||||
if wasDrag {
|
||||
saveStartSlot()
|
||||
saveOrder()
|
||||
} else if wasStart {
|
||||
tapWinKey()
|
||||
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
||||
@@ -1098,7 +1105,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
return 0
|
||||
case wmRButtonUp:
|
||||
x := alongClient(lparam)
|
||||
previewBlock(true)
|
||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||
previewBlock(false)
|
||||
return 0
|
||||
case wmMouseWheel:
|
||||
// Scrolling over the volume icon changes the volume. The wheel
|
||||
@@ -1126,7 +1135,9 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
var wr rect
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||
x := alongScreen(lparam, wr)
|
||||
previewBlock(true)
|
||||
showMenu(hwnd, appIndexAt(hwnd, x), trayAt(hwnd, x))
|
||||
previewBlock(false)
|
||||
return 0
|
||||
case wmEnterSizeMove:
|
||||
dragging = true
|
||||
@@ -1148,6 +1159,7 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmDestroy:
|
||||
previewShutdown()
|
||||
abd := appBarData{Hwnd: hwnd}
|
||||
appBar(abmRemove, &abd)
|
||||
pKillTimer.Call(hwnd, timerID)
|
||||
@@ -1204,6 +1216,8 @@ func main() {
|
||||
loadStartSlot()
|
||||
loadTrayOrder()
|
||||
loadOrient()
|
||||
loadPinned()
|
||||
loadOrderKeys()
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
dpi, _, _ := pGetDeviceCaps.Call(hdc, logPixelsX)
|
||||
@@ -1256,6 +1270,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
hwndMain = hwnd
|
||||
previewInit(inst)
|
||||
refreshAutostartPath()
|
||||
|
||||
// Hotkey: Ctrl+Alt+Q exits and restores.
|
||||
|
||||
Reference in New Issue
Block a user