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

sf::Mouse::setPosition not working with Wayland/xwayland #2750

Open
3 tasks done
eXpl0it3r opened this issue Oct 25, 2023 · 6 comments
Open
3 tasks done

sf::Mouse::setPosition not working with Wayland/xwayland #2750

eXpl0it3r opened this issue Oct 25, 2023 · 6 comments

Comments

@eXpl0it3r
Copy link
Member

eXpl0it3r commented Oct 25, 2023

Prerequisite Checklist

Describe your issue here

We've received multiple reports that sf::Mouse::setPosition() doesn't seem to work to work when using Wayland:

It might just be a bug in xwayland, but we should double check

Maybe related to #2709

Your Environment

  • OS / distro / window manager: ArchLinux Plasma KDE / Debian GNOME through xwayland
  • SFML version: 2.5.1 / apt (probably 2.5.1)
  • Compiler / toolchain: ?
  • Special compiler / CMake flags: ?

Steps to reproduce

  1. Run the following example
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode({1280, 720}), "Minimal, complete and verifiable example");
    window.setFramerateLimit(60);

    while (window.isOpen())
    {
        for (sf::Event event; window.pollEvent(event);)
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if (event.type == sf::Event::KeyPressed)
                sf::Mouse::setPosition({200, 200});
        }

        window.clear();
        window.display();
    }
}

Expected behavior

When pressing any key, the mouse should be moved to position (200, 200)

Actual behavior

The mouse is not moved

@danieljpetersen
Copy link
Contributor

Doesn't seem to work in Sway (wlroots) either.

@Bambo-Borris
Copy link
Contributor

I tested the sample code & experienced this issue within my own project, but have come to the conclusion I think it does work, but not as expected. I adjusted the sample code above to also print the mouse position every frame. When I hit any key press I do not visually see my cursor migrate on the screen, but the position reported is {200, 200}.

@danieljpetersen
Copy link
Contributor

Tangentially related to this, window.setCursorGrabbed doesn't work on Sway either. It doesn't confine the mouse to the window, though nothing else is focusable, so clicks outside of the window do nothing.

@lukaslihotzki
Copy link

Wayland does not support getting the mouse position in desktop coordinates (although this seems to work through XWayland), and it does not support setting the mouse position in general (not even in XWayland).

setMouseCursorGrabbed can be implemented with the pointer-constraints-unstable-v1 protocol (when using native Wayland instead of XWayland), the relative-pointer-unstable-v1 protocol may also be helpful.

@Bambo-Borris
Copy link
Contributor

Wayland does not support getting the mouse position in desktop coordinates (although this seems to work through XWayland), and it does not support setting the mouse position in general (not even in XWayland).

setMouseCursorGrabbed can be implemented with the pointer-constraints-unstable-v1 protocol (when using native Wayland instead of XWayland), the relative-pointer-unstable-v1 protocol may also be helpful.

The inability to set the mouse position seems rather cumbersome limit to overcome for some game types, or even supporting existing game codebases that rely on this. Grabbing the cursor isn't enough for some control schemes to work correctly.

@eXpl0it3r
Copy link
Member Author

Came across this list, that has a lot of X11 stuff which are broken in Wayland: https://gist.github.com/probonopd/9feb7c20257af5dd915e3a9f2d1f2277

Additionally, there's this repo with some potential workarounds: https://github.com/probonopd/wayland-x11-compat-protocols/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants