Draggable left edge resize, part 1
This commit is contained in:
@@ -551,18 +551,11 @@ func screenSize() (int32, int32) {
|
||||
return int32(w), int32(h)
|
||||
}
|
||||
|
||||
// pillWidth is the width the bar needs: the wider of the two halves, doubled so
|
||||
// the bar stays a mirror image around the center, plus a little padding.
|
||||
// pillWidth is the width the bar needs: the left half plus the right half. By
|
||||
// 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 {
|
||||
sw, _ := screenSize()
|
||||
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
|
||||
return leftHalf() + rightHalf()
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
add(posFlags, menuResetPosID, "Reset position to bottom center")
|
||||
add(0, menuResetWidthID, "Reset bar width")
|
||||
var autoFlags uintptr
|
||||
if autostartEnabled() {
|
||||
autoFlags = mfChecked
|
||||
@@ -916,6 +910,10 @@ func showMenu(hwnd uintptr, appIdx int, trayKind int) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
case cmd == menuResetPosID:
|
||||
resetPos(hwnd)
|
||||
case cmd == menuResetWidthID:
|
||||
leftPref = 0
|
||||
saveLeftPref()
|
||||
redraw(hwnd)
|
||||
case handleColorCommand(cmd):
|
||||
redraw(hwnd)
|
||||
case cmd == menuOrientID:
|
||||
@@ -997,6 +995,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
case wmLButtonDown:
|
||||
previewSuppress()
|
||||
x := alongClient(lparam)
|
||||
if edgeZone(x) {
|
||||
beginResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
if inStart(hwnd, x) {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
@@ -1009,10 +1011,15 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmCaptureChanged:
|
||||
resizing = false
|
||||
endIconDrag()
|
||||
dragTray, dragTrayActive = 0, false
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
if resizing {
|
||||
moveResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||
@@ -1073,6 +1080,10 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
}
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
if resizing {
|
||||
endResize(hwnd)
|
||||
return 0
|
||||
}
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 {
|
||||
// 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
|
||||
pGetWindowRect.Call(hwnd, uintptr(unsafe.Pointer(&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 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:
|
||||
return 0 // a double click on the drag area must not maximize the pill
|
||||
case wmNcRButtonUp:
|
||||
@@ -1216,6 +1233,7 @@ func main() {
|
||||
loadStartSlot()
|
||||
loadTrayOrder()
|
||||
loadOrient()
|
||||
loadLeftPref()
|
||||
loadPinned()
|
||||
loadOrderKeys()
|
||||
loadIconMode()
|
||||
|
||||
@@ -128,17 +128,20 @@ func pillPos(pw, ph int32) (int32, int32) {
|
||||
return defaultPos(pw, ph)
|
||||
}
|
||||
sw, sh := screenSize()
|
||||
x := clampI(customCX-pw/2, 0, sw-pw)
|
||||
y := clampI(customY-ph/2, 0, sh-ph)
|
||||
return x, y
|
||||
l := leftHalf() // the center line stays at the remembered spot
|
||||
if vertical {
|
||||
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) {
|
||||
sw, sh := screenSize()
|
||||
l := leftHalf() // the center line sits at the middle of the screen
|
||||
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
|
||||
@@ -152,7 +155,12 @@ func finishDrag(hwnd uintptr) {
|
||||
resetPos(hwnd)
|
||||
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()
|
||||
if appbarOn {
|
||||
// A floating bar no longer reserves screen space.
|
||||
@@ -249,7 +257,7 @@ func appOfSeq(t int) int {
|
||||
func rowLayout(clientW, clientH int32) []rect {
|
||||
n := int32(len(apps))
|
||||
sl := int32(slot())
|
||||
cx := clientW / 2
|
||||
cx := axisX(clientW)
|
||||
bw := px(36)
|
||||
if n > 0 {
|
||||
avail := cx - startWidth() - px(8)
|
||||
|
||||
@@ -85,7 +85,11 @@ type trayItem struct {
|
||||
}
|
||||
|
||||
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
|
||||
for _, kind := range trayOrder {
|
||||
var w int32
|
||||
|
||||
Reference in New Issue
Block a user