Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
807befdd53 | ||
|
|
7e5cf13afe |
@@ -8,6 +8,7 @@ The real taskbar is hidden and a see-through pill takes its place. The pill is a
|
|||||||
|
|
||||||
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
- Transparent pill that is only as wide as what is in it, centered on the screen with a few pixels of space under it.
|
||||||
- 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.
|
||||||
|
- Pull the far left end of the pill (the cursor turns into a double arrow) to shrink the empty space on the left. The center line stays put, and the left side stretches back out as you open more apps. Right-click and choose "Reset bar width" to go back to the mirrored look.
|
||||||
- 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. MirrorBar remembers the order of your apps and the logo's spot.
|
- 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.
|
||||||
|
|||||||
+159
@@ -0,0 +1,159 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
// Resizing the left half: the center line (where the Start button and the
|
||||||
|
// clock meet) stays put, but the two halves no longer have to be the same
|
||||||
|
// length. Pull the far left end of the pill (the top end when it stands up) and
|
||||||
|
// the empty space shrinks, down to where the buttons touch. Open more apps and
|
||||||
|
// the left half stretches back out to fit them.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
menuResetWidthID = 44
|
||||||
|
|
||||||
|
wmSetCursor = 0x0020
|
||||||
|
idcSizeWE = 32644
|
||||||
|
idcSizeNS = 32645
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pSetCursor = user32.NewProc("SetCursor")
|
||||||
|
|
||||||
|
leftPref int32 // 0: mirror the right half (the original look), -1: hug the buttons, else the chosen length
|
||||||
|
resizing bool
|
||||||
|
resizeFrom int32 // where the cursor was along the bar when the drag began
|
||||||
|
resizeLen int32 // the length of the left half when the drag began
|
||||||
|
)
|
||||||
|
|
||||||
|
func widthFile() string { return filepath.Join(dataDir(), "leftwidth.txt") }
|
||||||
|
|
||||||
|
func loadLeftPref() {
|
||||||
|
b, err := os.ReadFile(widthFile())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch s := strings.TrimSpace(string(b)); s {
|
||||||
|
case "tight":
|
||||||
|
leftPref = -1
|
||||||
|
case "", "mirror":
|
||||||
|
leftPref = 0
|
||||||
|
default:
|
||||||
|
if n, err := strconv.Atoi(s); err == nil && n > 0 {
|
||||||
|
leftPref = int32(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveLeftPref() {
|
||||||
|
_ = os.MkdirAll(dataDir(), 0o755)
|
||||||
|
s := "mirror"
|
||||||
|
switch {
|
||||||
|
case leftPref < 0:
|
||||||
|
s = "tight"
|
||||||
|
case leftPref > 0:
|
||||||
|
s = strconv.Itoa(int(leftPref))
|
||||||
|
}
|
||||||
|
_ = os.WriteFile(widthFile(), []byte(s), 0o644)
|
||||||
|
}
|
||||||
|
|
||||||
|
// halfLimit is the longest either half may be.
|
||||||
|
func halfLimit() int32 {
|
||||||
|
sw, _ := screenSize()
|
||||||
|
return sw/2 - px(4)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rightHalf is the length of the right half: the tray items plus a little padding.
|
||||||
|
func rightHalf() int32 {
|
||||||
|
items := trayItemsAt(0, 1)
|
||||||
|
return min(items[len(items)-1].r.Right+px(16), halfLimit())
|
||||||
|
}
|
||||||
|
|
||||||
|
// leftContent is the least the left half needs: Start, every app, and padding.
|
||||||
|
func leftContent() int32 {
|
||||||
|
return startWidth() + int32(len(apps))*px(36) + px(16)
|
||||||
|
}
|
||||||
|
|
||||||
|
// leftHalf is the length of the left half.
|
||||||
|
func leftHalf() int32 {
|
||||||
|
lc := leftContent()
|
||||||
|
var h int32
|
||||||
|
switch {
|
||||||
|
case leftPref < 0:
|
||||||
|
h = lc
|
||||||
|
case leftPref > 0:
|
||||||
|
h = max(lc, leftPref)
|
||||||
|
default:
|
||||||
|
h = max(lc, rightHalf())
|
||||||
|
}
|
||||||
|
return min(h, halfLimit())
|
||||||
|
}
|
||||||
|
|
||||||
|
// axisX is where the center line is, along the bar, measured from its start.
|
||||||
|
func axisX(clientW int32) int32 { return leftHalf() }
|
||||||
|
|
||||||
|
// ---------- the drag handle ----------
|
||||||
|
|
||||||
|
func edgeZone(along int32) bool { return along >= 0 && along < px(10) }
|
||||||
|
|
||||||
|
func cursorAlong() int32 {
|
||||||
|
var p point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||||
|
if vertical {
|
||||||
|
return p.Y
|
||||||
|
}
|
||||||
|
return p.X
|
||||||
|
}
|
||||||
|
|
||||||
|
// overEdge reports whether the cursor is on the draggable far end of the pill.
|
||||||
|
func overEdge(hwnd uintptr) bool {
|
||||||
|
var p point
|
||||||
|
pGetCursorPos.Call(uintptr(unsafe.Pointer(&p)))
|
||||||
|
var wr rect
|
||||||
|
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&wr)))
|
||||||
|
if p.X < wr.Left || p.X >= wr.Right || p.Y < wr.Top || p.Y >= wr.Bottom {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if vertical {
|
||||||
|
return edgeZone(p.Y - wr.Top)
|
||||||
|
}
|
||||||
|
return edgeZone(p.X - wr.Left)
|
||||||
|
}
|
||||||
|
|
||||||
|
func beginResize(hwnd uintptr) {
|
||||||
|
resizing = true
|
||||||
|
resizeFrom = cursorAlong()
|
||||||
|
resizeLen = leftHalf()
|
||||||
|
pSetCapture.Call(hwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveResize(hwnd uintptr) {
|
||||||
|
newLen := resizeLen - (cursorAlong() - resizeFrom)
|
||||||
|
if newLen <= leftContent()+px(10) {
|
||||||
|
leftPref = -1 // pulled all the way in: hug the buttons
|
||||||
|
} else {
|
||||||
|
leftPref = min(newLen, halfLimit())
|
||||||
|
}
|
||||||
|
redraw(hwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func endResize(hwnd uintptr) {
|
||||||
|
resizing = false
|
||||||
|
pReleaseCapture.Call()
|
||||||
|
saveLeftPref()
|
||||||
|
redraw(hwnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sizeCursor() uintptr {
|
||||||
|
id := uintptr(idcSizeWE)
|
||||||
|
if vertical {
|
||||||
|
id = idcSizeNS
|
||||||
|
}
|
||||||
|
c, _, _ := pLoadCursor.Call(0, id)
|
||||||
|
return c
|
||||||
|
}
|
||||||
@@ -551,18 +551,11 @@ func screenSize() (int32, int32) {
|
|||||||
return int32(w), int32(h)
|
return int32(w), int32(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pillWidth is the width the bar needs: the wider of the two halves, doubled so
|
// pillWidth is the width the bar needs: the left half plus the right half. By
|
||||||
// the bar stays a mirror image around the center, plus a little padding.
|
// default the left half is as long as the right one (a mirror image); pulling
|
||||||
|
// the far left end changes that (see barwidth.go).
|
||||||
func pillWidth() int32 {
|
func pillWidth() int32 {
|
||||||
sw, _ := screenSize()
|
return leftHalf() + rightHalf()
|
||||||
left := startWidth() + int32(len(apps))*px(36)
|
|
||||||
items := trayItems(0, 1)
|
|
||||||
right := items[len(items)-1].r.Right
|
|
||||||
half := max(left, right) + px(16)
|
|
||||||
if limit := sw/2 - px(4); half > limit {
|
|
||||||
half = limit
|
|
||||||
}
|
|
||||||
return half * 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// barGap is the space left under the pill so it stands off the screen edge.
|
// barGap is the space left under the pill so it stands off the screen edge.
|
||||||
@@ -888,6 +881,7 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
posFlags = mfGrayed
|
posFlags = mfGrayed
|
||||||
}
|
}
|
||||||
add(posFlags, menuResetPosID, "Reset position to bottom center")
|
add(posFlags, menuResetPosID, "Reset position to bottom center")
|
||||||
|
add(0, menuResetWidthID, "Reset bar width")
|
||||||
var autoFlags uintptr
|
var autoFlags uintptr
|
||||||
if autostartEnabled() {
|
if autostartEnabled() {
|
||||||
autoFlags = mfChecked
|
autoFlags = mfChecked
|
||||||
@@ -916,6 +910,10 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
|||||||
pDestroyWindow.Call(hwnd)
|
pDestroyWindow.Call(hwnd)
|
||||||
case cmd == menuResetPosID:
|
case cmd == menuResetPosID:
|
||||||
resetPos(hwnd)
|
resetPos(hwnd)
|
||||||
|
case cmd == menuResetWidthID:
|
||||||
|
leftPref = 0
|
||||||
|
saveLeftPref()
|
||||||
|
redraw(hwnd)
|
||||||
case handleColorCommand(cmd):
|
case handleColorCommand(cmd):
|
||||||
redraw(hwnd)
|
redraw(hwnd)
|
||||||
case cmd == menuOrientID:
|
case cmd == menuOrientID:
|
||||||
@@ -997,6 +995,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
case wmLButtonDown:
|
case wmLButtonDown:
|
||||||
previewSuppress()
|
previewSuppress()
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
|
if edgeZone(x) {
|
||||||
|
beginResize(hwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
if inStart(hwnd, x) {
|
if inStart(hwnd, x) {
|
||||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||||
pSetCapture.Call(hwnd)
|
pSetCapture.Call(hwnd)
|
||||||
@@ -1009,10 +1011,15 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmCaptureChanged:
|
case wmCaptureChanged:
|
||||||
|
resizing = false
|
||||||
endIconDrag()
|
endIconDrag()
|
||||||
dragTray, dragTrayActive = 0, false
|
dragTray, dragTrayActive = 0, false
|
||||||
return 0
|
return 0
|
||||||
case wmMouseMove:
|
case wmMouseMove:
|
||||||
|
if resizing {
|
||||||
|
moveResize(hwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
if dragSeq >= 0 && dragSeq <= len(apps) {
|
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||||
if !dragActive && abs32(x-dragStart) > px(5) {
|
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||||
@@ -1073,6 +1080,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
|||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
case wmLButtonUp:
|
case wmLButtonUp:
|
||||||
|
if resizing {
|
||||||
|
endResize(hwnd)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
x := alongClient(lparam)
|
x := alongClient(lparam)
|
||||||
if dragSeq >= 0 {
|
if dragSeq >= 0 {
|
||||||
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
||||||
@@ -1125,10 +1136,16 @@ 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)
|
||||||
if inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
if edgeZone(x) || inStart(hwnd, x) || appIndexAt(hwnd, x) >= 0 || trayAt(hwnd, x) != 0 {
|
||||||
return htClient
|
return htClient
|
||||||
}
|
}
|
||||||
return htCaption
|
return htCaption
|
||||||
|
case wmSetCursor:
|
||||||
|
// The far end of the pill shows the resize arrow.
|
||||||
|
if resizing || (uint16(lparam&0xFFFF) == htClient && overEdge(hwnd)) {
|
||||||
|
pSetCursor.Call(sizeCursor())
|
||||||
|
return 1
|
||||||
|
}
|
||||||
case wmNcLButtonDblClk:
|
case wmNcLButtonDblClk:
|
||||||
return 0 // a double click on the drag area must not maximize the pill
|
return 0 // a double click on the drag area must not maximize the pill
|
||||||
case wmNcRButtonUp:
|
case wmNcRButtonUp:
|
||||||
@@ -1216,6 +1233,7 @@ func main() {
|
|||||||
loadStartSlot()
|
loadStartSlot()
|
||||||
loadTrayOrder()
|
loadTrayOrder()
|
||||||
loadOrient()
|
loadOrient()
|
||||||
|
loadLeftPref()
|
||||||
loadPinned()
|
loadPinned()
|
||||||
loadOrderKeys()
|
loadOrderKeys()
|
||||||
loadIconMode()
|
loadIconMode()
|
||||||
|
|||||||
@@ -128,17 +128,20 @@ func pillPos(pw, ph int32) (int32, int32) {
|
|||||||
return defaultPos(pw, ph)
|
return defaultPos(pw, ph)
|
||||||
}
|
}
|
||||||
sw, sh := screenSize()
|
sw, sh := screenSize()
|
||||||
x := clampI(customCX-pw/2, 0, sw-pw)
|
l := leftHalf() // the center line stays at the remembered spot
|
||||||
y := clampI(customY-ph/2, 0, sh-ph)
|
if vertical {
|
||||||
return x, y
|
return clampI(customCX-pw/2, 0, sw-pw), clampI(customY-l, 0, sh-ph)
|
||||||
|
}
|
||||||
|
return clampI(customCX-l, 0, sw-pw), clampI(customY-ph/2, 0, sh-ph)
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultPos(pw, ph int32) (int32, int32) {
|
func defaultPos(pw, ph int32) (int32, int32) {
|
||||||
sw, sh := screenSize()
|
sw, sh := screenSize()
|
||||||
|
l := leftHalf() // the center line sits at the middle of the screen
|
||||||
if vertical {
|
if vertical {
|
||||||
return sw - pw - barGap(), (sh - ph) / 2
|
return sw - pw - barGap(), sh/2 - l
|
||||||
}
|
}
|
||||||
return (sw - pw) / 2, sh - ph - barGap()
|
return sw/2 - l, sh - ph - barGap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// finishDrag runs when a drag ends: remember the new spot, or snap back to the
|
// finishDrag runs when a drag ends: remember the new spot, or snap back to the
|
||||||
@@ -152,7 +155,12 @@ func finishDrag(hwnd uintptr) {
|
|||||||
resetPos(hwnd)
|
resetPos(hwnd)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, (wr.Top+wr.Bottom)/2
|
l := leftHalf()
|
||||||
|
if vertical {
|
||||||
|
customPos, customCX, customY = true, (wr.Left+wr.Right)/2, wr.Top+l
|
||||||
|
} else {
|
||||||
|
customPos, customCX, customY = true, wr.Left+l, (wr.Top+wr.Bottom)/2
|
||||||
|
}
|
||||||
savePos()
|
savePos()
|
||||||
if appbarOn {
|
if appbarOn {
|
||||||
// A floating bar no longer reserves screen space.
|
// A floating bar no longer reserves screen space.
|
||||||
@@ -249,7 +257,7 @@ func appOfSeq(t int) int {
|
|||||||
func rowLayout(clientW, clientH int32) []rect {
|
func rowLayout(clientW, clientH int32) []rect {
|
||||||
n := int32(len(apps))
|
n := int32(len(apps))
|
||||||
sl := int32(slot())
|
sl := int32(slot())
|
||||||
cx := clientW / 2
|
cx := axisX(clientW)
|
||||||
bw := px(36)
|
bw := px(36)
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
avail := cx - startWidth() - px(8)
|
avail := cx - startWidth() - px(8)
|
||||||
|
|||||||
@@ -85,7 +85,11 @@ type trayItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func trayItems(clientW, clientH int32) []trayItem {
|
func trayItems(clientW, clientH int32) []trayItem {
|
||||||
x := clientW / 2
|
return trayItemsAt(axisX(clientW), clientH)
|
||||||
|
}
|
||||||
|
|
||||||
|
// trayItemsAt lays the right-hand items out rightward from x.
|
||||||
|
func trayItemsAt(x, clientH int32) []trayItem {
|
||||||
var out []trayItem
|
var out []trayItem
|
||||||
for _, kind := range trayOrder {
|
for _, kind := range trayOrder {
|
||||||
var w int32
|
var w int32
|
||||||
|
|||||||
Reference in New Issue
Block a user