feat(window): drag the frameless window from any page
Continuous Integration / build_web (push) Failing after 0s
Continuous Integration / build (macos-latest) (push) Skipped
Continuous Integration / build (ubuntu-22.04) (push) Skipped
Continuous Integration / build (windows-11-arm) (push) Skipped
Continuous Integration / build (windows-latest) (push) Skipped
Continuous Integration / nightly_release (push) Skipped

Adds a global titlebar drag zone for pages without a header drag region, while leaving buttons, inputs, menus, sliders, resize handles and native drag regions untouched.
This commit is contained in:
1xDed committed 2026-11-28 16:37:16 +03:00
1 parent 610a7e4dbf
commit b1d9b40def
2 files changed
+73

No files matched your search

@@ -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;