Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] [macOS] Configure acceptsFirstMouse for specific elements #4316

Open
probablykasper opened this issue Jun 10, 2022 · 11 comments
Open

Comments

@probablykasper
Copy link
Member

probablykasper commented Jun 10, 2022

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

@lhf6623
Copy link

lhf6623 commented Jun 15, 2022

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

@dceddia
Copy link
Contributor

dceddia commented Jun 26, 2022

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.

@probablykasper
Copy link
Member Author

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

@dceddia
Copy link
Contributor

dceddia commented Jun 26, 2022

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.

@probablykasper
Copy link
Member Author

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

@amrbashir amrbashir changed the title [bug] data-tauri-drag-region requires focus on macOS [feat] [macOS] Add an option to configure acceptsFirstMouse Sep 30, 2022
@amrbashir
Copy link
Member

/upstream tauri-apps/tao

@tauri-apps
Copy link

tauri-apps bot commented Oct 3, 2022

Upstream issue at tauri-apps/tao#575 has been closed.

@tauri-apps tauri-apps bot added status: backlog Issue is ready and we can work on it and removed status: upstream labels Oct 3, 2022
@amrbashir amrbashir removed status: backlog Issue is ready and we can work on it good first issue Good for newcomers labels Oct 3, 2022
@amrbashir
Copy link
Member

/upstream tauri-apps/wry

@tauri-apps
Copy link

tauri-apps bot commented Oct 4, 2022

Upstream issue at tauri-apps/wry#714 has been closed.

@tauri-apps tauri-apps bot added status: backlog Issue is ready and we can work on it and removed status: upstream labels Oct 4, 2022
@probablykasper probablykasper changed the title [feat] [macOS] Add an option to configure acceptsFirstMouse [feat] [macOS] Handle data-tauri-drag-region when unfocused Oct 4, 2022
@probablykasper probablykasper changed the title [feat] [macOS] Handle data-tauri-drag-region when unfocused [feat] [macOS] Configure acceptsFirstMouse for specific elements Oct 4, 2022
@probablykasper
Copy link
Member Author

Opened #5347 for exposing acceptsFirstMouse

@amrbashir
Copy link
Member

/upstream tauri-apps/wry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📬Proposal
Development

No branches or pull requests

4 participants