Add window::Action::CursorGrab
and mouse::Event::MouseMotion
#2614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Together they allow you to confine or lock the cursor, and still recive mouse events.
Corresponds to
winit::window::CursorGrabMode
andwinit::event::DeviceEvent::MouseMotion
respectively.Some use cases they allow are panning in viewports and inputs that can be dragged like sliders without a range, these can be implemented using the cursor position but lead to bad UX from the cursor exiting the window or hitting the edge of the monitor, making you have to stop the interaction and reposition the cursor. Blender is a good example of both of these behaviors.
Unfortunately, there are currently some pretty big limitations, stemming from winit (and potentially platform limitations):
winit::event::DeviceEvent::MouseMotion
uses raw (unaccelerated) mouse input. This really hurts usability and the reason this is a draft PR. I'm looking into solving this in winit, probably by adding awinit::event::WindowEvent::MouseMotion
counterpart that is accelerated (and will also be specific to a window instead of being sent to all windows), this is very straight forward on wayland (the event is on a toplevel (window), and gives both accelerated and unaccelerated), but I'm not sure about other platforms.CursorGrab
, it works out that there's exactly one mode that is guaranteed to work for each platform (on linuxCursorGrab::Confined
works for both wayland and x11).CursorGrab::Confined
, which happens to be particularly useful for GUIs.