1.1 KiB
1.1 KiB
Make App Windows Draggable
Problem
Windows currently use fixed defaultPosition via framer-motion animate, so they can't be repositioned by the user.
Approach
Use framer-motion's built-in drag prop on the window container, constrained by a dragConstraints ref (the desktop). The title bar acts as the drag handle via dragListener={false} on the main div + dragControls triggered from the title bar.
Changes
src/components/os/AppWindow.tsx
- Add
useStateforposition(initialized fromdefaultPosition) - Use
useDragControlsfrom framer-motion - Add
dragprop tomotion.divwithdragControls,dragMomentum={false},dragListener={false} - Add
dragConstraintsprop (parent bounds or screen-based object) - Title bar gets
onPointerDownto start drag viadragControls.start() - When maximized, disable drag
- Track position via
onDragEndto persist position across re-renders - Remove the
x/y/top/leftfrom theanimateprop (usestylefor initial positioning instead, so drag offset works correctly) - Set
cursor-grab/cursor-grabbingon title bar