3
\$\begingroup\$

I have written a small application using OpenGL, and have implemented some rudimentary camera controls. Unfortunately, I cannot get the application to set my cursor position correctly. The cursor is never set to where I tell it to go, so my application just reacts to where the cursor is on my entire screen.

I first attempted to use GLFW, and when I saw that I couldn't set the cursor appropriately, I decided to try SFML. Neither one works.

I'm on an Arch Linux install with a Gnome desktop. I've been trying to figure this out for a few days now to no avail.

The relevant code is as follows:

sf::Vector2i cursor_pos = sf::Mouse::getPosition(*window);
sf::Mouse::setPosition(sf::Vector2i(1280/2, 720/2), *window);

This gets called every frame inside a function that messes with some matrices.

I also set the cursor position at initialization.

Any hints or advice would be greatly appreciated.

\$\endgroup\$
  • \$\begingroup\$ Are you aware that these functions use window local coordinates? \$\endgroup\$ – MickLH Jan 20 '16 at 2:03
  • \$\begingroup\$ Yes, and I believe that's what I want. I want the cursor to lock to the middle of the application window. \$\endgroup\$ – rearden Jan 20 '16 at 2:04
  • \$\begingroup\$ Just making sure your application window is hard coded as 1280x720. btw, you might consider explicitly writing window->getSize() / 2 to be clear. \$\endgroup\$ – MickLH Jan 20 '16 at 2:06
  • \$\begingroup\$ It is hard coded yeah, just to test it out. I've tried it with variables and it didn't change anything. It doesn't lock to the application at all. I am free to move the cursor all over my desktop. \$\endgroup\$ – rearden Jan 20 '16 at 2:07
  • 1
    \$\begingroup\$ Make an SSCCE and if it doesn't work on your machine, one of us can test it on another machine. \$\endgroup\$ – MickLH Jan 20 '16 at 2:15
1
\$\begingroup\$

The issue turned out to be a problem with the way Wayland works. My install of Gnome was defaulting to Wayland, instead of x, and Wayland doesn't do a good job of capturing the cursor within a window.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Just as a sidenote, I'm using Arch Linux, Gnome 3, and Wayland with SDL 2 and this behavior seems to work fine, so it might just be difficulties with GLFW and SFML and Wayland. I wouldn't expect users to change from using Wayland to using X11. Wayland is the future for all Gnome users. \$\endgroup\$ – user5665 May 22 '16 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.