-
Notifications
You must be signed in to change notification settings - Fork 920
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
web: prevent_default depending on keys #2831
Comments
I suggest changing the current exposed |
Sounds reasonable to me. PR's welcome. |
I think one thing we could do for sure is to detect copy/paste/cut shortcuts and not block those by default. I believe that's the main use-case currently for something like this anyway. |
I'm looking at implementing this, but wanted to check in first. My current thinking is to take a closure instead of adding an enum (i.e. change A couple drawbacks:
How does this sound as a way forward? |
As pointed out in #2831 (comment):
I'm not sure what other use-cases are out there, my first impression is that this would satisfy the majority. |
Not calling preventDefault on copy/cut/paste shortcuts is an important part of my use-case as well, but I'd also like to allow some other common browser shortcuts that would otherwise be interrupted (e.g. ctrl-L to focus the address bar, ctrl-R to refresh, etc). The ability to decide which shortcuts the app intercepts vs which is passes to the browser in a fine grained way is pretty important to me from a design perspective. The other plug I'd make for the general approach is that it would be easy to add convenience methods for the more specific use cases (like supporting copy/cut/paste), but it would still allow folks to customize the specific behavior when they need to for their particular application. |
Would you mind expanding on that? At that point why aren't you just using
The thing is that users can still just use Particularly, I don't believe we can really expose something useful here. E.g. you proposed exposing Alternatively with #3432 we might let users just return a Let me know what you think! |
A couple examples: I want to act on things like instead of it tabbing through the browser UI, and I want ctrl-p to open a command palette instead of printing.
Ahh, I think you're right -- adding an event listener to the |
This would definitely be handy! |
Absolutely, adding a little guide to
|
I entered a feature request #3797, it got closed as a dupe of this one, but with the note that this bug saw little movement in part due to the perceived limited range of use cases. I have another possible use case to add. Here's a winit+webgpu app I made (because webgpu is an emerging tech, this might only work on Chrome): https://data.runhello.com/j/wgpu/special/winit-swallow and an alternate version, where I call https://data.runhello.com/j/wgpu/special/winit-swallow-2 What I want to call attention to is that in the default implementation right-clicking on the entire window is suppressed, whereas in the second implementation it works. Not having access to right-click in the first one means it's a good bit harder to get into the Chrome inspector (where for example I might look at my app's error messages), it also completely excludes use of the "copy image"/"save image as…" verbs Chrome offers for canvases. (In currently shipping Chrome these menu items are grayed out for WebGPU canvases, but will still work for WebGL and Canvas2D.) In Firefox you can shift-right-click and this is always handled by the browser and not your app, but Chrome doesn't seem to have this feature. I can get the right-clicks back with I've taken a look at @ddfisher's docs and I'm sorry but I'm not sure if I understand them or not :( It looks like I'd have to add a lot of boilerplate to my app, enough so that (for a simple graphics effect like my current app) a significant percentage of my total code would be just doing event handling to express the single idea of "when running on Web, swallow events that aren't a right click". My preferred API would be if we could keep |
I think #3451 clearly shows that this actually doesn't take a lot of effort. Its currently something around 60 lines and I'm pretty sure we can whittle it down to half that. Opening developer tools I believe is a weak use case because this can be easily circumvented if you know how. I test Winit on Chrome regularly by de-focusing the canvas by clicking on the address bar and then press F11. That said, I have to clarify that in my perspective we have already long cleared the threshold of usefulness here. The problem is just how to design an API around the current limitations of Winit.
I would be happy to review a PR implementing this, otherwise I will get to it myself at some point, but its probably on the bottom of my priority list for Winit right now. |
I'm contributing on bevy_egui, comparing its functionalities with eframe.
eframe has a fine control over which keys it wants to prevent its defaults or not, I think this could be a good addition to winit:
https://github.com/emilk/egui/blob/307565efa55158cfa6b82d2e8fdc4c4914b954ed/crates/eframe/src/web/events.rs#L101
This fine control allows eframe to support copy/paste/etc... while disallowing tabbing outside, going to previous page, and others.
The text was updated successfully, but these errors were encountered: