Skip to content
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: allow using SDL2 in "relative mouse mode" #8360

Closed
wants to merge 1 commit into from

Conversation

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Dec 6, 2020

This mode doesn't wrap the mouse constantly, but requests SDL / OS
to lock the mouse pointer. This solves mouse problems on a few
OSes, like GUI Linux via WSL2, where the X11-server is not allowed
to change the mouse position in Windows (as it isn't capturing it).

This also is needed for other OSes that by design can never
capture the mouse, like with Emscripten, as it runs in a browser.

You can enable this moude via "-vsdl:relative_mode".

This mode doesn't wrap the mouse constantly, but requests SDL / OS
to lock the mouse pointer. This solves mouse problems on a few
OSes, like GUI Linux via WSL2, where the X11-server is not allowed
to change the mouse position in Windows (as it isn't capturing it).

This also is needed for other OSes that by design can never
capture the mouse, like with Emscripten, as it runs in a browser.

You can enable this moude via "-vsdl:relative_mode".
@LordAro
Copy link
Member

@LordAro LordAro commented Dec 13, 2020

What's the difference between normal mouse mode and relative mouse mode? Why not use this mode all the time?

@TrueBrain
Copy link
Member Author

@TrueBrain TrueBrain commented Dec 13, 2020

https://wiki.libsdl.org/SDL_SetRelativeMouseMode

While the mouse is in relative mode, the cursor is hidden, and the driver will try to report continuous motion in the current window. Only relative motion events will be delivered, the mouse position will not change.

This function will flush any pending mouse motion.

(I also wrote this in the PR description btw .. not sure what more information you expect here :D)

I am not sure if always using it is a good idea, that is to say: I need relative mouse mode for Emscripten to work properly, and I can imagine that other targets have the opposite problem. This patch makes it non-intrusive for current users, making sure there is no regression. We could experiment if relative mouse mode works for other targets too, but if it ain't broken, don't fix it, I say.

If we want to go down the road of: either one or the other, this PR is never going to land, as it would be an endless back and forth between people :P We simply don't have enough expertise atm to strike a balance there :)

Does this answer satisfy you? :D

this->delta.x = delta_x;
this->delta.y = delta_y;
} else {
int last_position_x = this->pos.x;
Copy link
Member

@frosch123 frosch123 Dec 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supposed to be "this->last_position.x"?

@TrueBrain
Copy link
Member Author

@TrueBrain TrueBrain commented Dec 13, 2020

@frosch123 did some testing on a real Linux system, and found out that Relative Mode has some nasty effects there: you cannot escape your window :) This is absolutely the way it is intended to work, but that makes is nearly useless for any target except one that is prepared for this, like Emscripten.

So I suggest we don't do the PR like this, but merge it into the Emscripten PR, where we #ifdef it instead of making it a switch.

@TrueBrain TrueBrain closed this Dec 13, 2020
@TrueBrain TrueBrain deleted the sdl_relative_mode branch Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants