Add screen absolute mouse position for resizing window. #211
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.
Add screen-absolute mouse position and cursor setting support
Motivation
I understand this might not be accepted due to breaking changes but as it worked so well locally I thought I'd pass it upstream just incase 😄
When implementing custom window resize handles (or any drag operations that modify window geometry), window-relative mouse coordinates become unreliable. As the window resizes, the cursor position relative to the window constantly changes even when the mouse hasn't moved, making smooth drag calculations difficult or impossible.
Changes
Mouse Events - Screen Position Support:
Added
screen_position: Pointfield to:MouseEvent::CursorMovedMouseEvent::DragEnteredMouseEvent::DragMovedMouseEvent::DragDroppedmacOS Cursor Support:
set_mouse_cursor()for macOS (was previouslytodo!())macos/cursor.rsmodule with cursor conversionsMouseCursorvariants including resize cursors using privateNSCursorAPIsImplementation Details
macOS:
NSEvent::mouseLocation()for screen coordinatesNSView::convertPoint(window-relative) and global mouse locationWindows:
GetCursorPos()for screen-absolute coordinatesWM_MOUSEMOVEand drag eventsX11:
root_x/root_yfrom X11 events (already in screen space)Breaking Changes
This is a breaking API change. The following enum variants now have an additional
screen_positionfield:MouseEvent::CursorMoved { position, screen_position, modifiers }MouseEvent::DragEntered { position, screen_position, modifiers, data }MouseEvent::DragMoved { position, screen_position, modifiers, data }MouseEvent::DragDropped { position, screen_position, modifiers, data }Users will need to update pattern matches, either by:
MouseEvent::CursorMoved { position, screen_position, modifiers }MouseEvent::CursorMoved { position, modifiers, .. }