Python
fix(gui): prevent topbar controls from starting native window drags
pj9912078626fed37dfc
diff --git a/surfaces/gui/e2e/window-drag.spec.ts b/surfaces/gui/e2e/window-drag.spec.tsnew file mode 100644index 00000000..b4509fee--- /dev/null+++ b/surfaces/gui/e2e/window-drag.spec.ts@@ -0,0 +1,64 @@+import { expect, sendSessionEvent, test } from "./fixtures";++// Exercise the real App handlers with a recorded Tauri bridge. This checks drag+// requests, not the native Windows move loop (which still needs a manual check).+test("topbar controls do not request a native window drag", async ({ page }) => {+ await page.addInitScript(() => {+ (window as any).__OCW_PLATFORM__ = "windows";+ (window as any).__windowDragRequests = 0;+ (window as any).__TAURI__ = {+ core: {+ invoke: async (command: string) => {+ if (command === "start_window_drag") (window as any).__windowDragRequests++;+ return null;+ },+ },+ };+ });+ await page.goto("/");+ await page.getByText("Draft the launch note").first().click();+ await sendSessionEvent(page, {+ type: "ready",+ data: { sandbox: { state: "sandboxed", provider: "openshell", network: "allowlist", sites: [] } },+ });++ const dragRequests = () => page.evaluate(() => (window as any).__windowDragRequests);+ const chip = page.getByTestId("sandbox-chip");+ await expect(chip).toBeVisible();+ await chip.locator("svg").click();+ await expect(page.getByTestId("sandbox-chip-panel")).toBeVisible();+ expect(await dragRequests()).toBe(0);+ await chip.click();+ await expect(page.getByTestId("sandbox-chip-panel")).toHaveCount(0);++ await page.getByRole("button", { name: "Hide side panel", exact: true }).click();+ await expect(page.locator(".right-rail")).toHaveCount(0);+ expect(await dragRequests()).toBe(0);+ await page.locator(".topbar-artifacts-btn").click();+ await expect(page.locator(".right-rail")).toBeVisible();+ expect(await dragRequests()).toBe(0);++ await chip.click();+ await page.getByTestId("sandbox-chip-settings").click();+ await expect(page.getByTestId("sandbox-chip-panel")).toHaveCount(0);+ expect(await dragRequests()).toBe(0);+});++test("empty title-bar space still requests a drag only for the primary button", async ({ page }) => {+ await page.addInitScript(() => {+ (window as any).__windowDragRequests = 0;+ (window as any).__TAURI__ = {+ core: { invoke: async (command: string) => {+ if (command === "start_window_drag") (window as any).__windowDragRequests++;+ return null;+ } },+ };+ });+ await page.goto("/");+ const title = page.locator(".main-title");+ await expect(title).toBeVisible();+ await title.dispatchEvent("pointerdown", { button: 2, bubbles: true });+ expect(await page.evaluate(() => (window as any).__windowDragRequests)).toBe(0);+ await title.dispatchEvent("pointerdown", { button: 0, bubbles: true });+ expect(await page.evaluate(() => (window as any).__windowDragRequests)).toBe(1);+});diff --git a/surfaces/gui/src/App.tsx b/surfaces/gui/src/App.tsxindex 4aa72a36..004f0559 100644--- a/surfaces/gui/src/App.tsx+++ b/surfaces/gui/src/App.tsx@@ -119,6 +119,7 @@ import { TeamRequestCard } from "./components/TeamRequestCard";import { WorkItemsCard } from "./components/WorkItemsCard";import { TeamChatView } from "./components/TeamChatView";import { WorkspaceTrustPrompt } from "./components/WorkspaceTrustPrompt";+import { shouldStartWindowDrag } from "./windowDrag";const newId = () =>(crypto as any).randomUUID ? crypto.randomUUID().slice(0, 12) : Math.random().toString(36).slice(2, 14);@@ -1884,7 +1885,7 @@ export function App() {overlay && (macosMajor() >= 26 || new URLSearchParams(window.location.search).get("overlay") === "26");const overlayClass = overlay ? " tauri-overlay" + (lightsHigh ? " macos-26" : "") : "";const beginWindowDrag = (event: PointerEvent) => {- if (!desktop || event.button !== 0) return;+ if (!desktop || !shouldStartWindowDrag(event)) return;startWindowDrag();};diff --git a/surfaces/gui/src/windowDrag.test.ts b/surfaces/gui/src/windowDrag.test.tsnew file mode 100644index 00000000..67d3a322--- /dev/null+++ b/surfaces/gui/src/windowDrag.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vitest";+import { shouldStartWindowDrag } from "./windowDrag";++const press = (target: EventTarget | null, button = 0) => ({ button, target });++describe("shouldStartWindowDrag", () => {+ it("drags from empty title-bar space", () => {+ expect(shouldStartWindowDrag(press(document.createElement("div")))).toBe(true);+ });++ it.each([+ '<button><svg><path /></svg></button>',+ '<a href="#"><span>link</span></a>',+ '<span role="button"><span>button</span></span>',+ '<span role="menuitem">item</span>',+ '<span role="link">link</span>',+ '<input />',+ '<textarea></textarea>',+ '<select><option>option</option></select>',+ '<label><span>label</span></label>',+ '<div contenteditable="true"><span>edit</span></div>',+ ])("does not start a native drag from an interactive control: %s", (html) => {+ const bar = document.createElement("div");+ bar.innerHTML = html;+ for (const target of bar.querySelectorAll("*")) {+ expect(shouldStartWindowDrag(press(target))).toBe(false);+ }+ });++ it.each([1, 2])("ignores mouse button %s", (button) => {+ expect(shouldStartWindowDrag(press(document.createElement("div"), button))).toBe(false);+ });++ it("tolerates targets without closest", () => {+ expect(shouldStartWindowDrag(press(null))).toBe(true);+ expect(shouldStartWindowDrag(press(document.createTextNode("title")))).toBe(true);+ });+});diff --git a/surfaces/gui/src/windowDrag.ts b/surfaces/gui/src/windowDrag.tsnew file mode 100644index 00000000..7c7c8451--- /dev/null+++ b/surfaces/gui/src/windowDrag.ts@@ -0,0 +1,10 @@+// Native window drags can swallow the mouse-up that an interactive control needs+// for its click. Filter pointerdown at the title bar, including nested icons.+const INTERACTIVE =+ "button, a, input, textarea, select, label, [role='button'], [role='menuitem'], [role='link'], [contenteditable='true']";++export function shouldStartWindowDrag(event: { button: number; target: EventTarget | null }): boolean {+ if (event.button !== 0) return false;+ const el = event.target as Element | null;+ return !(el && typeof el.closest === "function" && el.closest(INTERACTIVE));+}