-
Notifications
You must be signed in to change notification settings - Fork 937
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
Add cursor_position
getter API
#2648
Open
amrbashir
wants to merge
22
commits into
rust-windowing:master
Choose a base branch
from
amrbashir:feat/cursor-position
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7f55366
Add `cursor_position` getter API
amrbashir 04aec3c
Restore examples/window.rs
amrbashir 7495b2f
update docs
amrbashir d2bd7af
fix build
amrbashir 5b34692
Update window.rs
amrbashir 5555119
remove `Window::cursor_position`
amrbashir 71985a8
Merge branch 'feat/cursor-position' of https://github.com/amrbashir/w…
amrbashir e08d28d
Merge branch 'master' into feat/cursor-position
amrbashir 64f7e38
Merge branch 'master' into feat/cursor-position
amrbashir 4d6d78d
fix a few missed imports after merge
amrbashir 86506db
Discard changes to dpi/LICENSE
amrbashir a6a7636
Discard changes to dpi/LICENSE
amrbashir f976f2f
revert license file change
amrbashir 5f811f8
Update unreleased.md
amrbashir e48ec28
try fix build
amrbashir 37dbcc7
Update src/changelog/unreleased.md
amrbashir 9ee1fd6
duplicate import
amrbashir 261a709
fix x11 impl
amrbashir 76ba0b6
unsafe
amrbashir 61db908
Merge branch 'master' into feat/cursor-position
amrbashir 1f9a3df
reference `Window::outer_position`
amrbashir cd6b857
macOS: Fix cursor position calculation
madsmtm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ use instant::{Duration, Instant}; | |
use once_cell::sync::OnceCell; | ||
use raw_window_handle::{HasRawDisplayHandle, RawDisplayHandle}; | ||
|
||
use crate::dpi::PhysicalPosition; | ||
use crate::error::ExternalError; | ||
use crate::{event::Event, monitor::MonitorHandle, platform_impl}; | ||
|
||
/// Provides a way to retrieve events from the system and from the windows that were registered to | ||
|
@@ -359,6 +361,16 @@ impl<T> EventLoopWindowTarget<T> { | |
#[cfg(any(x11_platform, wayland_platform, windows))] | ||
self.p.set_device_event_filter(_filter); | ||
} | ||
|
||
/// Returns the current cursor position in screen coordinates. | ||
/// | ||
amrbashir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// ## Platform-specific | ||
/// | ||
/// - **iOS / Android / Wayland / Orbital / Web**: Unsupported. | ||
#[inline] | ||
pub fn cursor_position(&self) -> Result<PhysicalPosition<f64>, ExternalError> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It confused me that the return type of this is not |
||
self.p.cursor_position() | ||
} | ||
} | ||
|
||
unsafe impl<T> HasRawDisplayHandle for EventLoopWindowTarget<T> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referencing #2648 (review).
I think we thought this was on
Window
, and hence expected things to be in window coordinates, just like the coordinates forset_cursor_position
(such thatwindow.set_cursor_position(window.cursor_position()?)?
is (roughly) a no-op). But we decided againstWindow::cursor_position
in https://github.com/rust-windowing/winit/pull/2648/files#r1090072945, this API isActiveEventLoop::cursor_position
.In that case, I'd expect the coordinates to be the same as those from
Window::outer_position
, is that correct? If so, could you refer to that for discussion about the coordinate space, just likeWindow::set_outer_position
does?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(If you think that this interpretation is correct, I'll test the macOS implementation myself to ensure that it matches
Window::outer_position
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
like this amrbashir@1f9a3df ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup.
And I've tested it now, and pushed a fix to return positions with the correct scaling and such (it's still a little broken, but that's a more general issue, see #3615).