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
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:
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;
|
||||||
@@ -31,6 +31,7 @@ import RouterLoading from "@/components/routerLoading";
|
|||||||
import Search from "@/components/search";
|
import Search from "@/components/search";
|
||||||
import Updater from "@/components/updater";
|
import Updater from "@/components/updater";
|
||||||
import WindowChrome from "@/components/windowControls/windowChrome";
|
import WindowChrome from "@/components/windowControls/windowChrome";
|
||||||
|
import WindowDrag from "@/components/windowControls/windowDrag";
|
||||||
import WindowResizeHandles from "@/components/windowControls/resizeHandles";
|
import WindowResizeHandles from "@/components/windowControls/resizeHandles";
|
||||||
|
|
||||||
type ApiContext = {
|
type ApiContext = {
|
||||||
@@ -59,6 +60,7 @@ export const Route = createRootRouteWithContext<ApiContext>()({
|
|||||||
<RemoteControlDialog />
|
<RemoteControlDialog />
|
||||||
<AppBar />
|
<AppBar />
|
||||||
<WindowChrome />
|
<WindowChrome />
|
||||||
|
<WindowDrag />
|
||||||
<WindowResizeHandles />
|
<WindowResizeHandles />
|
||||||
<AudioPlayer />
|
<AudioPlayer />
|
||||||
<PlaybackSync />
|
<PlaybackSync />
|
||||||
|
|||||||
Reference in new issue
Block a user