From bf427a628e490e0b1a1c15b42dafcb311fde4123 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Sat, 17 Oct 2026 22:35:22 +0200 Subject: [PATCH] Fixed drag and drop position accuracy --- frontend/src/lib/fileDrop.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/fileDrop.ts b/frontend/src/lib/fileDrop.ts index 6711885..3013c6f 100644 --- a/frontend/src/lib/fileDrop.ts +++ b/frontend/src/lib/fileDrop.ts @@ -1,6 +1,8 @@ import { useEffect, useRef } from 'react' import { nativeDragEnd, nativeDragMove, nativeDragStart } from './drag' +const IS_WINDOWS = /Windows/.test(navigator.userAgent) + /** * Files dragged in from Finder / Explorer, fed into the window's ONE drag * store (`lib/drag.tsx`) as a `files` payload, so the targets that take track @@ -48,8 +50,12 @@ export function useNativeFileDrop(enabled: boolean, onBrowserDrop: () => void) { void (async () => { const { getCurrentWebview } = await import('@tauri-apps/api/webview') const off = await getCurrentWebview().onDragDropEvent(({ payload }) => { - // Tauri reports PHYSICAL pixels; the page works in CSS pixels. - const scale = window.devicePixelRatio || 1 + // Tauri calls the position PHYSICAL, but only Windows (WebView2: + // ScreenToClient) really reports device pixels. macOS (WKWebView) and + // Linux (WebKitGTK) report the view's own points — CSS pixels already — + // so dividing there put the ghost at half the cursor's position on a + // Retina screen (wry 0.55). + const scale = IS_WINDOWS ? window.devicePixelRatio || 1 : 1 const at = 'position' in payload ? { x: payload.position.x / scale, y: payload.position.y / scale } : null switch (payload.type) { case 'enter':