SFML community forums

Help => Window => Topic started by: NoxFly on January 30, 2021, 11:34:47 pm

Title: setMouseCursorGrabbed and setMouseCursorVisible not working
Post by: NoxFly on January 30, 2021, 11:34:47 pm
Hello !

I'm having some problems with the functions setMouseCursorGrabbed and setMouseCursorVisible (as the title let you know).

Here's a minimal example. If I try this, it's not working for me. Even if I left click on the window.

Also, I'm trying it on WSL2. All other OpenGL stuff is well working.

Am I doing something wrong ?

#include <iostream>

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char** argv) {
    sf::RenderWindow window(sf::VideoMode(1280, 720), "My window", sf::Style::Titlebar | sf::Style::Close);
    window.setMouseCursorGrabbed(true);
    window.setMouseCursorVisible(false);

    while(window.isOpen()) {
        while(window.pollEvent(event)) {
            switch(event.type) {
                case sf::Event::Closed:
                window.close();
                break;
            }
        }
        window.clear(sf::Color(255, 255, 255));
        window.display();
    }

    return 0;
}
Title: Re: setMouseCursorGrabbed and setMouseCursorVisible not working
Post by: eXpl0it3r on January 31, 2021, 07:48:22 pm
"not working" isn't really a problem description. ;)
What is actually happening and what would you expect to happen?

What XServer are you using and what window manager are you using, if you run this in WSL2?
Chances are that the WM/xserver doesn't actually support this with WSL2 in the mix.
Title: Re: setMouseCursorGrabbed and setMouseCursorVisible not working
Post by: NoxFly on February 02, 2021, 09:27:21 am
I'm on Debian 10, using VcXsrv.
By "not working" I mean that mouse is still beeing in normal state, visible and movable everywhere, even outside the window.
Title: Re: setMouseCursorGrabbed and setMouseCursorVisible not working
Post by: eXpl0it3r on February 02, 2021, 10:47:34 am
Not much SFML can do about it unfortunately. If the XServer/Window Manager ignores the X calls to hide the cursor or grab it, then there isn't really anything SFML can do.

If you want to be certain, you could get a debug SFML build and step through the code to see that the calls are being made.
Maybe there's something like the VcXsrc option -keyhook for the mouse, so the X Server takes full control over the mouse?
Title: Re: setMouseCursorGrabbed and setMouseCursorVisible not working
Post by: NoxFly on February 06, 2021, 12:54:38 pm
Indeed it's working on real Linux's environment. So it's occuring because of the indirect display port.
Also, because it's indirect display port, it's limiting OpenGL to the version 1.4, and it's affecting SFML.
Even with the -keyhook option on VcXsrv it's not working.