Draggable left edge resize, part 1

This commit is contained in:
2026-11-06 23:32:26 +00:00
parent 9e6b24268f
commit 7e5cf13afe
3 changed files with 50 additions and 20 deletions
+30 -12
View File
@@ -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()
+15 -7
View File
@@ -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)
+5 -1
View File
@@ -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