tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] [macOS] Configure `acceptsFirstMouse` for specific elements

Open probablykasper opened this issue 2 years ago • 16 comments

Describe the bug

Elements with data-tauri-drag-region can't be dragged while the window isn't in focus, which is not how native windows (or Electron's implementation) works

Note: acceptsFirstMouse doesn't entirely solve this because that would also make everything in the window clickable

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment
  › OS: Mac OS 10.15.7 X64
  › Node.js: 16.15.0
  › npm: 8.12.1
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.24.3
  › rustc: 1.61.0
  › cargo: 1.61.0
  › Rust toolchain: stable-x86_64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.12 (outdated, latest: 1.0.0-rc.13)
  › @tauri-apps/api [NPM]: 1.0.0-rc.6
  › tauri [RUST]: git+https://github.com/tauri-apps/tauri?branch=mac-app-hide#ade64c9b1695043c40ffccb3a38b11d1a7f1b6bb (1.0.0-rc.12),
  › tauri-build [RUST]: 1.0.0-rc.10,
  › tao [RUST]: 0.9.1,
  › wry [RUST]: 0.17.0,

App
  › build-type: bundle
  › CSP: default-src 'self'; img-src *
  › distDir: ../build
  › devPath: http://localhost:9000/
  › framework: Svelte

App directory structure
  ├─ node_modules
  ├─ public
  ├─ .github
  ├─ src-tauri
  ├─ build
  ├─ .git
  ├─ assets
  └─ src

Stack trace

No response

Additional context

No response

probablykasper avatar Jun 10 '22 22:06 probablykasper

I have this problem too,And Gaussian blur doesn't work when you lose focus

lhf6623 avatar Jun 15 '22 00:06 lhf6623

I ran into this too. I thought it might have something to do with the acceptsFirstMouse method.

It looks like at least tao is overriding that to be true here so it's probably taken care of at the window level, but I'm wondering if maybe it needs to be overridden for the WKWebView too. It looks like Electron overrides this:

This allows Electron to override acceptsFirstMouse on Mac so that windows can respond to the first mouse click in their window, which is desirable for some kinds of utility windows.

It looks like wry already has a WryWebView that subclasses WKWebView and that might be a good place to put this override. It would be overzealous though, and then filtering of mouse clicks would need to happen somewhere or we'd end up in the reverse situation where the window shouldn't respond to the first mouse click in a lot of situations. I guess ideally it would be up to the application whether it accepts those clicks, but I'm not sure where that would go.

dceddia avatar Jun 26 '22 02:06 dceddia

Enabling acceptsFirstMouse would technically fix it, but then you get unconventional behavior (although some Electron apps do this)

If we're able to detect the first mouse click position, we would be able to forward it to the frontend to decide if the window should be dragged

probablykasper avatar Jun 26 '22 03:06 probablykasper

If it were special-cased for only data-tauri-drag-region I think it'd break strategies like this one that make most of the window draggable, which would be a bummer. Maybe it could be made into an option, and do something like...

  • enable acceptsFirstMouse so that all clicks get passed through
  • add an acceptsFirstMouse tauri.conf config option to let the developer opt in to receiving those events, but default it to false so behavior is conventional by default
  • update the existing mousedown handler to check for a combo of window focus, the configurable firstMouse config, and whether the click was on a data-tauri-drag-region to decide whether to pass the event through

I think a system like that would still let the developer do their custom startDragging code, and also allow breaking convention for apps where that's desirable. From Apple's acceptsFirstMouse docs it sounds like the convention is to pass firstMouse through for certain types of elements, too. Just as a random example I notice that Chrome passes firstMouse through if you click on a browser tab, but not to elements on the page. It'd be neat to have that level of control in Tauri too.

dceddia avatar Jun 26 '22 03:06 dceddia

If it were special-cased for only data-tauri-drag-region I think it'd break strategies like this one that make most of the window draggable, which would be a bummer. Maybe it could be made into an option, and do something like...

I think the solution there is to have data-tauri-drag-region="self" that applies only to the element itself, not children

probablykasper avatar Jun 26 '22 04:06 probablykasper

/upstream tauri-apps/tao

amrbashir avatar Sep 30 '22 14:09 amrbashir

Upstream issue at https://github.com/tauri-apps/tao/issues/575 has been closed.

tauri-apps[bot] avatar Oct 03 '22 20:10 tauri-apps[bot]

/upstream tauri-apps/wry

amrbashir avatar Oct 03 '22 20:10 amrbashir

Upstream issue at https://github.com/tauri-apps/wry/issues/714 has been closed.

tauri-apps[bot] avatar Oct 04 '22 15:10 tauri-apps[bot]

Opened #5347 for exposing acceptsFirstMouse

probablykasper avatar Oct 04 '22 19:10 probablykasper

/upstream tauri-apps/wry

amrbashir avatar Oct 04 '22 19:10 amrbashir