mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub13fn4ahfnvaa2qwylvegdgeajqs0mph6v4qsw4jcqnw4mjh3hzh2quuucm5 <8a675edd33677aa0389f6650d467b2041fb0df4ca820eacb009babb95e3715d4@sprout-oss.stage.blox.sqprod.co>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import * as React from "react";
|
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
|
|
|
import { isWindowDragHandleEvent } from "@/app/AppShell.helpers";
|
|
import { performTitleBarDoubleClickAction } from "@/shared/lib/titleBarActions";
|
|
|
|
export function useTauriWindowDrag() {
|
|
React.useEffect(() => {
|
|
function handlePointerDown(event: PointerEvent) {
|
|
if (
|
|
event.button !== 0 ||
|
|
event.detail > 1 ||
|
|
!isWindowDragHandleEvent(event)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
void getCurrentWindow().startDragging();
|
|
}
|
|
|
|
function stopTauriDragRegionHandler(event: MouseEvent) {
|
|
if (event.button !== 0 || !isWindowDragHandleEvent(event)) {
|
|
return;
|
|
}
|
|
|
|
// Tauri's injected data-tauri-drag-region listener hardcodes maximize on
|
|
// double-click. Buzz handles drag and double-click itself so macOS title
|
|
// bar preferences can be respected.
|
|
event.stopImmediatePropagation();
|
|
}
|
|
|
|
function handleDoubleClick(event: MouseEvent) {
|
|
if (event.button !== 0 || !isWindowDragHandleEvent(event)) {
|
|
return;
|
|
}
|
|
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
void performTitleBarDoubleClickAction();
|
|
}
|
|
|
|
window.addEventListener("pointerdown", handlePointerDown, true);
|
|
window.addEventListener("mousedown", stopTauriDragRegionHandler, true);
|
|
window.addEventListener("mouseup", stopTauriDragRegionHandler, true);
|
|
window.addEventListener("dblclick", handleDoubleClick, true);
|
|
return () => {
|
|
window.removeEventListener("pointerdown", handlePointerDown, true);
|
|
window.removeEventListener("mousedown", stopTauriDragRegionHandler, true);
|
|
window.removeEventListener("mouseup", stopTauriDragRegionHandler, true);
|
|
window.removeEventListener("dblclick", handleDoubleClick, true);
|
|
};
|
|
}, []);
|
|
}
|