diff --git a/src/components/windowControls/windowDrag.tsx b/src/components/windowControls/windowDrag.tsx new file mode 100644 index 0000000..f47ad3b --- /dev/null +++ b/src/components/windowControls/windowDrag.tsx @@ -0,0 +1,71 @@ +import { getCurrentWindow } from "@tauri-apps/api/window"; +import { useEffect } from "react"; + +/** Height of the draggable titlebar hit area. */ +const DRAG_ZONE = 36; + +/** + * Interactive elements inside the titlebar must keep receiving clicks + * (window buttons, nav buttons, search fields, menus, sliders…). + */ +const INTERACTIVE_SELECTOR = [ + "button", + "a", + "input", + "textarea", + "select", + "option", + "label", + "[contenteditable='true']", + "[role='button']", + "[role='link']", + "[role='menuitem']", + "[role='tab']", + "[role='switch']", + "[role='checkbox']", + "[role='slider']", + "[role='combobox']", + "[data-tauri-drag-region]", + ".MuiMenu-root", + ".MuiPopover-root", + ".MuiDialog-root", + ".MuiDrawer-root", + ".MuiSlider-root", + ".MuiTooltip-popper", + ".window-resize-handle", +].join(","); + +/** + * Lets the user drag the frameless window from the top area of any page. + * Existing headers still use their native Tauri drag regions; this covers + * pages without one (settings, login, empty states, etc.). + */ +const WindowDrag = () => { + useEffect(() => { + const onPointerDown = (event: PointerEvent) => { + if (event.button !== 0 || event.pointerType !== "mouse") return; + if (event.clientY > DRAG_ZONE) return; + if (document.fullscreenElement) return; + if (window.location.pathname.startsWith("/player")) return; + + const target = event.target as Element | null; + if (!target || target.closest(INTERACTIVE_SELECTOR)) return; + + event.preventDefault(); + getCurrentWindow() + .startDragging() + .catch((error) => { + console.warn("Could not start dragging the window", error); + }); + }; + + document.addEventListener("pointerdown", onPointerDown, true); + return () => { + document.removeEventListener("pointerdown", onPointerDown, true); + }; + }, []); + + return null; +}; + +export default WindowDrag; diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 689e598..94b3698 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -31,6 +31,7 @@ import RouterLoading from "@/components/routerLoading"; import Search from "@/components/search"; import Updater from "@/components/updater"; import WindowChrome from "@/components/windowControls/windowChrome"; +import WindowDrag from "@/components/windowControls/windowDrag"; import WindowResizeHandles from "@/components/windowControls/resizeHandles"; type ApiContext = { @@ -59,6 +60,7 @@ export const Route = createRootRouteWithContext()({ +