Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: setMouseCursorGrabbed and setMouseCursorVisible not working  (Read 2740 times)

0 Members and 1 Guest are viewing this topic.

NoxFly

  • Newbie
  • *
  • Posts: 5
  • JS & C++ dev / student
    • View Profile
    • Email
setMouseCursorGrabbed and setMouseCursorVisible not working
« 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;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9909
    • View Profile
    • development blog
    • Email
Re: setMouseCursorGrabbed and setMouseCursorVisible not working
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

NoxFly

  • Newbie
  • *
  • Posts: 5
  • JS & C++ dev / student
    • View Profile
    • Email
Re: setMouseCursorGrabbed and setMouseCursorVisible not working
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9909
    • View Profile
    • development blog
    • Email
Re: setMouseCursorGrabbed and setMouseCursorVisible not working
« Reply #3 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/

NoxFly

  • Newbie
  • *
  • Posts: 5
  • JS & C++ dev / student
    • View Profile
    • Email
Re: setMouseCursorGrabbed and setMouseCursorVisible not working
« Reply #4 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.