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 }