| Summary: | Deprecation/Removal or Global Mouse Function APIs | ||
|---|---|---|---|
| Product: | SDL | Reporter: | x414e54 |
| Component: | events | Assignee: | Ryan C. Gordon <icculus> |
| Status: | ASSIGNED --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | dmitry.rekman, icculus |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
|
Description
x414e54
2015-03-22 08:10:32 UTC
It should also be noted that SDL_GetGlobalMouseState interacts really badly with SDL_SetRelativeMouseMode. Relative mouse mode does an initial warp to the window center and on non support platforms constantly warps to center so the coordinates from SDL_GetMouseState and SDL_GetGlobalMouseState differ. An application which warps the cursor back to the start before any relative motion or uses a software cursor will have issues. (In reply to x414e54 from comment #1) > It should also be noted that SDL_GetGlobalMouseState interacts really badly > with SDL_SetRelativeMouseMode. We should probably change it to report failure from SDL_GetGlobalMouseState() when the mouse is in relative mode (since there is no concept of a global position at that point). I sent you an email about the rest of this bug report, and I don't think we're going to ditch these APIs, but we _did_ build them with the expectation that they can refuse to work at all on certain platforms, like smartphones. I think desktop Wayland should add an optional protocol to support some of these things, honestly, and both SDL and Wayland will likely improve in the coming months as we get closer to abandoning X11 as our primary target. Marking this bug as ASSIGNED until I deal with the global vs relative issue. --ryan. >The original reason for SDL_GetGlobalMouseState was added in the SDL-gui-
>backend for Slate. But the Linux developers decided that it was too chatty to
>X, so it now caches the result of SDL_GetGlobalMouseState and invalidates it
>based on mouse motion events (which only occur when inside a window).
>This means for the original case SDL_GetGlobalMouseState is completely
>redundant and could theoretically be calculated from SDL_GetMouseState.
This is too early to say. I cached the function in UE4 main branch for a test, and this caching may or may not work in all cases. To truly work around the lack of SDL_GetGlobalMouseState() UE4 might need to create a transparent window covering all the desktops (and resize it appropriately when new displays are being added, etc) to always receive mouse notifications - just like UE4 does on Mac. This might be the solution for Wayland, but until we investigate this I propose not to remove this function from SDL.
> notifications - just like UE4 does on Mac. This might be the solution for
> Wayland, but until we investigate this I propose not to remove this function
> from SDL.
I don't think we will remove it, but we _do_ need to investigate if we are doing things inefficiently on X11.
For example, perhaps instead of XSync()'ing and polling the server every time we call this function, we can try hooking up to XInput and only talking to the X server when it reports a mouse has moved. I haven't tried this, it's just a hypothetical way to reduce X chatter.
That will likely happen after 2.0.4 ships in any case, and I think the API itself is reasonable as-is, even if we later improve its implementation in a different bug report.
--ryan.
(In reply to Dmitry 'RCL' Rekman from comment #3) > >The original reason for SDL_GetGlobalMouseState was added in the SDL-gui- > >backend for Slate. But the Linux developers decided that it was too chatty to > >X, so it now caches the result of SDL_GetGlobalMouseState and invalidates it > >based on mouse motion events (which only occur when inside a window). > >This means for the original case SDL_GetGlobalMouseState is completely > >redundant and could theoretically be calculated from SDL_GetMouseState. > > This is too early to say. I cached the function in UE4 main branch for a > test, and this caching may or may not work in all cases. To truly work > around the lack of SDL_GetGlobalMouseState() UE4 might need to create a > transparent window covering all the desktops (and resize it appropriately > when new displays are being added, etc) to always receive mouse > notifications - just like UE4 does on Mac. This might be the solution for > Wayland, but until we investigate this I propose not to remove this function > from SDL. As an example against global mouse co-ordinates (even on X11) open SlateViewer and them move one of the windows onto a different virtual desktop/workspace. Then take one of tabs and move it to where the other window is on the original workspace. The tab disappears and acts strangely because Slate thinks the window is there when it is not. SlateViewer also crashed for me in this case. Currently my Wayland code just works by taking the SDL_GetMouseState co-ords and offsetting based on where Slate thinks the window is. In all my tests of SDL_GetGlobalMouseState vs SDL_GetMouseState the co-ordinates are always the same. The only benefit of SDL_GetGlobalMouseState is that you do not loose the mouse events for doing the tab dragging but I am pretty sure you could do this with some kind of implicit grab drag and drop protocols. (In reply to Ryan C. Gordon from comment #2) > (In reply to x414e54 from comment #1) > > It should also be noted that SDL_GetGlobalMouseState interacts really badly > > with SDL_SetRelativeMouseMode. > > We should probably change it to report failure from > SDL_GetGlobalMouseState() when the mouse is in relative mode (since there is > no concept of a global position at that point). > > I sent you an email about the rest of this bug report, and I don't think > we're going to ditch these APIs, but we _did_ build them with the > expectation that they can refuse to work at all on certain platforms, like > smartphones. > > I think desktop Wayland should add an optional protocol to support some of > these things, honestly, and both SDL and Wayland will likely improve in the > coming months as we get closer to abandoning X11 as our primary target. > > Marking this bug as ASSIGNED until I deal with the global vs relative issue. > > --ryan. Fair enough, but I do think it needs to be thought about a bit more. What happens if you are in "expose mode" e.g. GNOME Shell. What is supposed to happen in this case? It would still be getting the global mouse position from X11 but would be inaccurate to where your window was. Also SDL does not report any information about virtual desktops/workspaces. So there is no way to work out if the global co-ordinates are over a window or not as per my previous comment. Both of these cases could have some seriously weird issues if it is trying to globally warp the mouse cursor without checking if the window has focus. I kind of agree with the direction Wayland have at the moment. If you cannot guarantee something then it should not be in the core protocol. Obviously any compositor is free to implement its own extension protocols which SDL can use but as an developer I have had enough of calculating window borders and task bar sizes. I prefer just to let the OS take care of it. I have also thought of a few other problems: What about if the window is scaled/zoomed? A user may scale the window separately from the desktop. SDL will not get a resize event because the user is not requesting that the back-buffer size be changed. The application need know nothing about the scale change as the compositor will scale the mouse event positions automatically. But global mouse co-ordinates will be wrong. What about multiple "pointer" input devices? It is okay for a game to assume one input device but for a GUI application it cannot hit test off the non-primary pointer and then start moving a window around based on the location of the primary pointer. |