Drag to reorder the app icons and the Windows logo

This commit is contained in:
2026-11-06 11:43:42 +00:00
parent d72cf82604
commit 171afe6605
3 changed files with 198 additions and 26 deletions
+143
View File
@@ -180,3 +180,146 @@ func resetPos(hwnd uintptr) {
}
positionBar(hwnd)
}
// ---------- the left row: Start button and app icons, all draggable ----------
var (
pSetCapture = user32.NewProc("SetCapture")
pReleaseCapture = user32.NewProc("ReleaseCapture")
)
const (
wmLButtonDown = 0x0201
wmCaptureChanged = 0x0215
)
var (
startSlot int // where the Start button sits in the left row (0 is against the center line)
dragSeq = -1 // row position of the item the mouse went down on, -1 for none
dragIsStart bool // the item being pressed is the Start button
dragStart int32 // where along the bar the mouse went down
dragActive bool // true once the mouse has moved far enough to count as a drag
)
func startSlotFile() string { return filepath.Join(dataDir(), "startslot.txt") }
func loadStartSlot() {
b, err := os.ReadFile(startSlotFile())
if err != nil {
return
}
if n, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil && n >= 0 {
startSlot = n
}
}
func saveStartSlot() {
_ = os.MkdirAll(dataDir(), 0o755)
_ = os.WriteFile(startSlotFile(), []byte(strconv.Itoa(startSlot)), 0o644)
}
func endIconDrag() {
dragSeq = -1
dragIsStart = false
dragActive = false
}
// slot is the Start button's position, kept within the row.
func slot() int {
return max(0, min(startSlot, len(apps)))
}
// The row is the Start button plus every app, from the center line leftward.
// A "row position" counts those items; app i sits at seqOfApp(i).
func seqOfApp(i int) int {
if i < slot() {
return i
}
return i + 1
}
func appOfSeq(t int) int {
if t < slot() {
return t
}
return t - 1
}
// rowLayout gives the rectangle of every row position (Start included).
func rowLayout(clientW, clientH int32) []rect {
n := int32(len(apps))
sl := int32(slot())
cx := clientW / 2
bw := px(36)
if n > 0 {
avail := cx - startWidth() - px(8)
if avail/n < bw {
bw = avail / n
}
if bw < px(24) {
bw = px(24)
}
}
rects := make([]rect, n+1)
x := cx
for k := int32(0); k <= n; k++ {
wd := bw
if k == sl {
wd = startWidth()
}
rects[k] = rect{x - wd, 0, x, clientH}
x -= wd
}
return rects
}
func startRect(clientW, clientH int32) rect {
return rowLayout(clientW, clientH)[slot()]
}
// seqAt is the row position under a spot along the bar, clamped to the ends.
func seqAt(hwnd uintptr, x int32) int {
w, h := clientSize(hwnd)
rects := rowLayout(w, h)
if x >= rects[0].Right {
return 0
}
if x < rects[len(rects)-1].Left {
return len(rects) - 1
}
for k, r := range rects {
if x >= r.Left && x < r.Right {
return k
}
}
return -1
}
// moveSeq moves one item of the row to another position, shifting the rest.
func moveSeq(from, to int) {
n := len(apps)
if from == to || from < 0 || to < 0 || from > n || to > n {
return
}
sl := slot()
seq := make([]int, 0, n+1) // -1 stands for the Start button, otherwise an app index
for k := 0; k <= n; k++ {
if k == sl {
seq = append(seq, -1)
} else {
seq = append(seq, appOfSeq(k))
}
}
v := seq[from]
rest := append(append([]int{}, seq[:from]...), seq[from+1:]...)
seq = append(append(append([]int{}, rest[:to]...), v), rest[to:]...)
next := make([]appWin, 0, n)
for k, a := range seq {
if a == -1 {
startSlot = k
} else {
next = append(next, apps[a])
}
}
apps = next
}