fix(window): restore first-click titlebar dragging
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
- update wry 0.57.0 -> 0.57.4, which drops the WM_ENTERSIZEMOVE focus call that swallowed the first drag on Windows - let the global drag handler take clicks on non-interactive children of data-tauri-drag-region elements (title text, logo), with double-click maximize
This commit is contained in:
1 parent
daa1c3f007
commit
785f64a72e
2 files changed
+257
-61
No files matched your search
@@ -1,8 +1,11 @@
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { useEffect } from "react";
|
||||
|
||||
/** Height of the draggable titlebar hit area. */
|
||||
const DRAG_ZONE = 36;
|
||||
/**
|
||||
* Height of the draggable titlebar hit area. Headers on every page fit inside
|
||||
* it; interactive controls are filtered out below.
|
||||
*/
|
||||
const DRAG_ZONE = 64;
|
||||
|
||||
/**
|
||||
* Interactive elements inside the titlebar must keep receiving clicks
|
||||
@@ -25,7 +28,6 @@ const INTERACTIVE_SELECTOR = [
|
||||
"[role='checkbox']",
|
||||
"[role='slider']",
|
||||
"[role='combobox']",
|
||||
"[data-tauri-drag-region]",
|
||||
".MuiMenu-root",
|
||||
".MuiPopover-root",
|
||||
".MuiDialog-root",
|
||||
@@ -37,13 +39,16 @@ const INTERACTIVE_SELECTOR = [
|
||||
|
||||
/**
|
||||
* 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.).
|
||||
*
|
||||
* Tauri's `data-tauri-drag-region` is not inherited by child elements, so a
|
||||
* click on the text inside a header (the Blink wordmark, a title, an icon)
|
||||
* would otherwise do nothing. Native regions are still left to Tauri; this
|
||||
* handler only takes over clicks on their non-interactive children.
|
||||
*/
|
||||
const WindowDrag = () => {
|
||||
useEffect(() => {
|
||||
const onPointerDown = (event: PointerEvent) => {
|
||||
if (event.button !== 0 || event.pointerType !== "mouse") return;
|
||||
const onMouseDown = (event: MouseEvent) => {
|
||||
if (event.button !== 0 || event.buttons !== 1) return;
|
||||
if (event.clientY > DRAG_ZONE) return;
|
||||
if (document.fullscreenElement) return;
|
||||
if (window.location.pathname.startsWith("/player")) return;
|
||||
@@ -51,17 +56,29 @@ const WindowDrag = () => {
|
||||
const target = event.target as Element | null;
|
||||
if (!target || target.closest(INTERACTIVE_SELECTOR)) return;
|
||||
|
||||
// Let Tauri's native drag-region handler deal with the elements
|
||||
// that explicitly carry the attribute. It does not bubble to
|
||||
// children, and those are exactly the clicks handled below.
|
||||
if (target.hasAttribute("data-tauri-drag-region")) return;
|
||||
|
||||
event.preventDefault();
|
||||
getCurrentWindow()
|
||||
.startDragging()
|
||||
.catch((error) => {
|
||||
console.warn("Could not start dragging the window", error);
|
||||
const appWindow = getCurrentWindow();
|
||||
|
||||
if (event.detail === 2) {
|
||||
appWindow.toggleMaximize().catch((error) => {
|
||||
console.warn("Could not toggle the window size", error);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
appWindow.startDragging().catch((error) => {
|
||||
console.warn("Could not start dragging the window", error);
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener("pointerdown", onPointerDown, true);
|
||||
document.addEventListener("mousedown", onMouseDown, true);
|
||||
return () => {
|
||||
document.removeEventListener("pointerdown", onPointerDown, true);
|
||||
document.removeEventListener("mousedown", onMouseDown, true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in new issue
Block a user