Drag to reorder the app icons and the Windows logo
This commit is contained in:
@@ -634,29 +634,17 @@ func positionBar(hwnd uintptr) {
|
||||
// too many to fit, the buttons shrink to a minimum width and the oldest run
|
||||
// off the left edge.
|
||||
func appRects(clientW, clientH int32) []rect {
|
||||
n := int32(len(apps))
|
||||
if n == 0 {
|
||||
if len(apps) == 0 {
|
||||
return nil
|
||||
}
|
||||
right := clientW/2 - startWidth()
|
||||
avail := right - px(8)
|
||||
bw := px(36)
|
||||
if avail/n < bw {
|
||||
bw = avail / n
|
||||
}
|
||||
if bw < px(24) {
|
||||
bw = px(24)
|
||||
}
|
||||
rects := make([]rect, n)
|
||||
for i := int32(0); i < n; i++ {
|
||||
r := right - i*bw
|
||||
rects[i] = rect{r - bw, 0, r, clientH}
|
||||
row := rowLayout(clientW, clientH)
|
||||
rects := make([]rect, len(apps))
|
||||
for i := range rects {
|
||||
rects[i] = row[seqOfApp(i)]
|
||||
}
|
||||
return rects
|
||||
}
|
||||
|
||||
// clientSize is the size of the bar in the horizontal layout (length, thickness),
|
||||
// whichever way the real window is turned.
|
||||
func clientSize(hwnd uintptr) (int32, int32) {
|
||||
var rc rect
|
||||
pGetClientRect.Call(hwnd, uintptr(unsafe.Pointer(&rc)))
|
||||
@@ -793,9 +781,9 @@ func premul(c uint32, a uint32) uint32 {
|
||||
}
|
||||
|
||||
func inStart(hwnd uintptr, x int32) bool {
|
||||
w, _ := clientSize(hwnd)
|
||||
cx := w / 2
|
||||
return x >= cx-startWidth() && x < cx
|
||||
w, h := clientSize(hwnd)
|
||||
r := startRect(w, h)
|
||||
return x >= r.Left && x < r.Right
|
||||
}
|
||||
|
||||
func tapWinKey() {
|
||||
@@ -1004,8 +992,39 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
pDestroyWindow.Call(hwnd)
|
||||
}
|
||||
return 0
|
||||
case wmLButtonDown:
|
||||
x := alongClient(lparam)
|
||||
if inStart(hwnd, x) {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = slot(), true, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||
dragSeq, dragIsStart, dragStart, dragActive = seqOfApp(idx), false, x, false
|
||||
pSetCapture.Call(hwnd)
|
||||
}
|
||||
return 0
|
||||
case wmCaptureChanged:
|
||||
endIconDrag()
|
||||
return 0
|
||||
case wmMouseMove:
|
||||
x := alongClient(lparam)
|
||||
if dragSeq >= 0 && dragSeq <= len(apps) {
|
||||
if !dragActive && abs32(x-dragStart) > px(5) {
|
||||
dragActive = true
|
||||
}
|
||||
if dragActive {
|
||||
if t := seqAt(hwnd, x); t >= 0 && t != dragSeq {
|
||||
moveSeq(dragSeq, t)
|
||||
dragSeq = t
|
||||
}
|
||||
hoverStart = dragIsStart
|
||||
hoverApp = -1
|
||||
if !dragIsStart {
|
||||
hoverApp = appOfSeq(dragSeq)
|
||||
}
|
||||
redraw(hwnd)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
overStart := inStart(hwnd, x)
|
||||
overApp := appIndexAt(hwnd, x)
|
||||
overTray := trayAt(hwnd, x)
|
||||
@@ -1032,11 +1051,21 @@ func wndProc(hwnd, m, wparam, lparam uintptr) (result uintptr) {
|
||||
return 0
|
||||
case wmLButtonUp:
|
||||
x := alongClient(lparam)
|
||||
if inStart(hwnd, x) {
|
||||
tapWinKey()
|
||||
} else if idx := appIndexAt(hwnd, x); idx >= 0 {
|
||||
activateApp(idx)
|
||||
if dragSeq >= 0 {
|
||||
// A press on the Start button or an app icon: a click if it never moved, otherwise the drag ends here.
|
||||
seq, wasStart, wasDrag := dragSeq, dragIsStart, dragActive
|
||||
endIconDrag()
|
||||
pReleaseCapture.Call()
|
||||
if wasDrag {
|
||||
saveStartSlot()
|
||||
} else if wasStart {
|
||||
tapWinKey()
|
||||
} else if idx := appOfSeq(seq); idx >= 0 && idx < len(apps) {
|
||||
activateApp(idx)
|
||||
}
|
||||
redraw(hwnd)
|
||||
} else if inStart(hwnd, x) {
|
||||
tapWinKey()
|
||||
} else if k := trayAt(hwnd, x); k != 0 {
|
||||
trayClick(k)
|
||||
}
|
||||
@@ -1146,6 +1175,7 @@ func main() {
|
||||
|
||||
loadAlpha()
|
||||
loadPos()
|
||||
loadStartSlot()
|
||||
loadOrient()
|
||||
|
||||
hdc, _, _ := pGetDC.Call(0)
|
||||
|
||||
Reference in New Issue
Block a user