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

Feature request: Let me opt out of web_sys preventDefaults on a per-event basis #3797

Closed
mcclure opened this issue Jul 18, 2024 · 1 comment
Labels
S - enhancement Wouldn't this be the coolest?

Comments

@mcclure
Copy link

mcclure commented Jul 18, 2024

Description

I have a web app: https://data.runhello.com/j/wgpu/special/winit-swallow/
That URL is https://github.com/mcclure/webgpu-tutorial-rs/ commit a8fa378.
It is built with Rust + Trunk + winit + webgpu (so it will only work on Chrome or possibly Firefox Nightly).

It has a problem, which is that it swallows right clicks. So if I or a user want to look at the Chrome Inspector, they can't just right click the way they're used to.
I find the documentation explains that winit by default calls preventDefault() on every event; and if I add window.set_prevent_default(false); to line 979, right after initializing the window, then as documented winit will not do this, pass on the events, and right click works.

But, I do not want all events preventDefaulted! For example I don't want the scrollwheel to trigger, and I plan to add special behaviors for click-and-drag. There doesn't currently seem to be a way to request preventDefault for some events but not all.

So, here is my feature request: add to either Event<T> or ActiveEventLoop a function named like prevent_default_current(p: bool) which, if calls, overrides the set_prevent_default for the current event. That way I could default to preventing default, but prevent_default_current(false) on right-clicks specifically, and that way get the behavior I want in all cases with little hassle.

Relevant platforms

Web

@mcclure mcclure added the S - enhancement Wouldn't this be the coolest? label Jul 18, 2024
@daxpedda
Copy link
Member

daxpedda commented Jul 18, 2024

This is a duplicate of #2831.
While we concluded there that it might not be needed to do fine-grained filtering because the only relevant use case is the clipboard, allowing the developer console specifically is a use case that might change this outlook.

Note that you can use WindowAttributes::with_prevent_default() to do this before creating the window.

@daxpedda daxpedda closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S - enhancement Wouldn't this be the coolest?
Development

No branches or pull requests

2 participants