-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - fix cursor grab issue #7010
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,4 +1,3 @@ | ||||
use crate::converters::convert_cursor_grab_mode; | ||||
use bevy_math::{DVec2, IVec2}; | ||||
use bevy_utils::HashMap; | ||||
use bevy_window::{ | ||||
|
@@ -165,16 +164,6 @@ impl WinitWindows { | |||
} | ||||
} | ||||
|
||||
// Do not set the grab mode on window creation if it's none, this can fail on mobile | ||||
if window_descriptor.cursor_grab_mode != CursorGrabMode::None { | ||||
match winit_window | ||||
.set_cursor_grab(convert_cursor_grab_mode(window_descriptor.cursor_grab_mode)) | ||||
{ | ||||
Ok(_) | Err(winit::error::ExternalError::NotSupported(_)) => {} | ||||
Err(err) => Err(err).unwrap(), | ||||
} | ||||
} | ||||
|
||||
winit_window.set_cursor_visible(window_descriptor.cursor_visible); | ||||
|
||||
self.window_id_to_winit.insert(window_id, winit_window.id()); | ||||
|
@@ -207,15 +196,20 @@ impl WinitWindows { | |||
display_handle: winit_window.raw_display_handle(), | ||||
}; | ||||
self.windows.insert(winit_window.id(), winit_window); | ||||
Window::new( | ||||
let mut window = Window::new( | ||||
window_id, | ||||
window_descriptor, | ||||
inner_size.width, | ||||
inner_size.height, | ||||
scale_factor, | ||||
position, | ||||
Some(raw_handle), | ||||
) | ||||
); | ||||
// Do not set the grab mode on window creation if it's none, this can fail on mobile | ||||
if window_descriptor.cursor_grab_mode != CursorGrabMode::None { | ||||
window.set_cursor_grab_mode(window_descriptor.cursor_grab_mode); | ||||
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. I think I would prefer if this still logged an error here, so the user gets some feedback rather than silently failing 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. Sorry for the late reply. I'm experiencing covid-19 this week. Like the fallback will be done in bevy/crates/bevy_winit/src/lib.rs Line 150 in 1aeaafa
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. oh gotcha nvm, my brain was in windows as entities mode and I forgot we had window commands |
||||
} | ||||
window | ||||
} | ||||
|
||||
pub fn get_window(&self, id: WindowId) -> Option<&winit::window::Window> { | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ fn main() { | |
height: 300., | ||
present_mode: PresentMode::AutoVsync, | ||
always_on_top: true, | ||
cursor_grab_mode: CursorGrabMode::Confined, | ||
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. Does the example here need to be changed? Feels like this just adds noise to the example without an explanation why users should set this. If it should, we should document what this is actually doing so that people learning from the example can improve their understanding. 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. I just want to show users they could set cursor grab mode directly. But they will do this without guidance since this field is already in |
||
..default() | ||
}, | ||
..default() | ||
|
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.
This is non-blocking but I'm going to Chesterton-fence you here: What purpose did this serve? I notice it is marked
pub
so technically this is breaking change. Though such a conversion method defined as a free function is really weird.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.
This is only for bevy crates' internal usage. I introduced this function for
bevy_window
abstracts its ownCursorGrabMode
struct becausebevy_window
doesn't want to depend onwinit
, thenbevy_winit
should convertbevy_window
'sCursorGrabMode
towinit::window::CursorGrabMode
. I think this function shouldn't bepub
but I just followed these conversion functions' signature above. Anyway, we could remove it now and it shouldn't break much code since it's not intended for end users in the beginning. If this breaks the semantic version, please help us find a way to get of it... Sorry for this mistake.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.
Don't worry. This is perfectly fine.
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.
This isn't a public module so this isn't a breaking change.