beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
178 stars 95 forks source link

Fix mouse warping on wayland. #1509

Closed codecnotsupported closed 4 days ago

codecnotsupported commented 1 month ago

SDL2 does not support warping on Wayland if the Cursor is visible.

https://github.com/libsdl-org/SDL/blob/efaa58732abb3faf3900b2d93a166b955fbd8ed0/src/video/wayland/SDL_waylandmouse.c#L646

This fixes: https://github.com/ZeroK-RTS/Zero-K/issues/5005 I tested it, verified it works, please check if this breaks other platforms.

sprunk commented 1 month ago

Doesn't it need SDL_ShowCursor(SDL_ENABLE); afterwards?

codecnotsupported commented 1 month ago

Doesn't it need SDL_ShowCursor(SDL_ENABLE); afterwards?

For some reason it doesn't work when I put SDL_ShowCursor(SDL_ENABLE); afterwards. Also the cursor somehow correctly shows up afterwards. Tested it on X11/Wayland.

sprunk commented 1 month ago

Looks OK but will require testing on non-wayland since the "somehow shows up despite no enable" sounds suspicious. Alternatively the line could be put under some sort of "if wayland".

Somewhat relatedly, most uses for warping would be obsoleted by #654.

codecnotsupported commented 1 month ago

Looks OK but will require testing on non-wayland since the "somehow shows up despite no enable" sounds suspicious.

Suspicious would be putting it lightly, I've many questions after investigating the relevant SDL2 function. But I am willing to say this is a good enough workaround.

Somewhat relatedly, most uses for warping would be obsoleted by #654.

654, sounds like a proper solution. But requires some changes for each game mode.

Alternatively the line could be put under some sort of "if wayland".

My first thought was.

    const char *windowBackend = SDL_GetCurrentVideoDriver();

    if (strcmp(windowBackend, "wayland") == 0) {
        SDL_ShowCursor(SDL_DISABLE); // needed for SDL2+Wayland where warping isn't allowed otherwise
    }

But since it works fine on both Wayland & X11 a simple #if __unix__ would suffice.

lostsquirrel1 commented 4 days ago

We can take it. We have a testing pass. So we'll try and get our Linux testers on it.