-
-
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
Conversation
Oh no this doesn't solve the problem... The crash only happens on x11 platform for me, and it's always OK on wayland platform. This change doesn't make a difference. |
b11cc85
to
dec2611
Compare
This should work now. |
Sorry, I missed your PR, I just saw the original issue title and went "oh right, we only fixed that at update time, not at creation time" I can't test on Linux, I'll trust you if you say it's just an issue of it needed to being delayed. Fallback should still be added for Windows and macOS support. |
The fallback logic should be already in our codebase: bevy/crates/bevy_winit/src/lib.rs Line 143 in 1aeaafa
bevy::window::Window::create_window invokes bevy::window::Window::set_cursor_grab which is actually a wrapper ofbevy_winit::change_window in the above.
This also eliminates code duplicate 😃. |
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.
Can confirm it fixes #7007 .
@@ -266,12 +266,3 @@ pub fn convert_cursor_icon(cursor_icon: CursorIcon) -> winit::window::CursorIcon | |||
CursorIcon::RowResize => winit::window::CursorIcon::RowResize, | |||
} | |||
} | |||
|
|||
/// Map [`bevy_window::CursorGrabMode`] to [`winit::window::CursorGrabMode`]. | |||
pub fn convert_cursor_grab_mode(mode: CursorGrabMode) -> winit::window::CursorGrabMode { |
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 own CursorGrabMode
struct because bevy_window
doesn't want to depend on winit
, then bevy_winit
should convert bevy_window
's CursorGrabMode
to winit::window::CursorGrabMode
. I think this function shouldn't be pub
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.
examples/window/window_settings.rs
Outdated
@@ -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 comment
The 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 comment
The 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 WindowDescriptor
. I will remove this change. Thanks!
); | ||
// 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 comment
The 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 comment
The 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_winit::change_window
, the errors, if any, will also be logged there:
bevy/crates/bevy_winit/src/lib.rs
Line 150 in 1aeaafa
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e)); |
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.
oh gotcha nvm, my brain was in windows as entities mode and I forgot we had window commands
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.
I didn't experience the bug, so can't confirm if it's fixed, but the code makes sense to me and mouse grabbing still works as expected for me.
bors r+ |
# Objective - Set the cursor grab mode after the window is built, fix #7007, clean some conversion code. ## Solution - Set the cursor grab mode after the window is built.
Pull request successfully merged into main. Build succeeded:
|
# Objective - Set the cursor grab mode after the window is built, fix bevyengine#7007, clean some conversion code. ## Solution - Set the cursor grab mode after the window is built.
# Objective - Set the cursor grab mode after the window is built, fix bevyengine#7007, clean some conversion code. ## Solution - Set the cursor grab mode after the window is built.
Objective
Solution