From 55e18a45f02550ab6983516b74da140659684473 Mon Sep 17 00:00:00 2001 From: Brandon Oxendine Date: Mon, 7 Sep 2026 15:53:43 +0200 Subject: [PATCH] Keep the window draggable while a modal is open MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Rūdolfs Ošiņš --- src/App.svelte | 29 +-------- src/components/FullscreenModalPortal.svelte | 21 +++++++ src/lib/window.ts | 68 +++++++++++++++++++++ 3 files changed, 91 insertions(+), 27 deletions(-) create mode 100644 src/lib/window.ts diff --git a/src/App.svelte b/src/App.svelte index 4bc07f02d..5a9118fce 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4,7 +4,6 @@ import type { RepoInfo } from "@bindings/repo/RepoInfo"; import { listen } from "@tauri-apps/api/event"; - import { getCurrentWindow } from "@tauri-apps/api/window"; import { onDestroy, onMount } from "svelte"; import { get } from "svelte/store"; @@ -27,6 +26,7 @@ unlistenNodeEvents, } from "@app/lib/startup.svelte"; import { isMac, unreachable } from "@app/lib/utils"; + import { dragWindow } from "@app/lib/window"; import AppSidebar from "@app/components/AppSidebar.svelte"; import { codeFont } from "@app/components/CodeFontSwitch.svelte"; @@ -60,27 +60,6 @@ return isLoadedRepoRoute(route) ? route.params.repo : undefined; }); - const DRAG_REGION_HEIGHT = 32; - const INTERACTIVE_TAGS = new Set([ - "a", - "button", - "input", - "select", - "textarea", - ]); - - function isDraggableArea(e: MouseEvent): boolean { - if (e.clientY > DRAG_REGION_HEIGHT) return false; - let el = e.target as HTMLElement | null; - while (el && el !== document.body) { - if (INTERACTIVE_TAGS.has(el.tagName.toLowerCase())) return false; - if (el.getAttribute("role") === "button") return false; - if (el.classList.contains("txt-selectable")) return false; - el = el.parentElement; - } - return true; - } - window .matchMedia("(prefers-color-scheme: dark)") .addEventListener("change", ({ matches }) => { @@ -165,11 +144,7 @@ { - if (window.__TAURI_INTERNALS__ && isDraggableArea(e)) { - void getCurrentWindow().startDragging(); - } - }} + onmousedown={dragWindow} onkeydown={e => { const auxiliarKey = isMac() ? e.metaKey : e.ctrlKey; // Handles the position of the plus key on different keyboard layouts. diff --git a/src/components/FullscreenModalPortal.svelte b/src/components/FullscreenModalPortal.svelte index c45b0291a..c3b85958f 100644 --- a/src/components/FullscreenModalPortal.svelte +++ b/src/components/FullscreenModalPortal.svelte @@ -1,5 +1,10 @@