glfwSetCursorPos not updating cursor position properly

vizvi wrote on Friday, September 26, 2014:

I’m porting my application to Linux, specifically Bodhi linux through Oracle VirtualBox and using GLFW3 for my portable windowed system.

I’ve encountered an issue where i can’t update my cursor position through glfwSetCursorPos. Actually, i can see that cursor is changing (temporary) to 10,10 on Linux (i am using glfwGetCursorPos to get the current position), yet cursor is standing still and if i move it again it moves from previous position, not 10,10. The counter-func, glfwGetCursorPos works flawlessly in Win7,WinXP and Bodhi Linux so i think this is probably a GLFW issue. My window is focused at the time of execution and my code is the following (the relevant parts):

static void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
   // set cursor position on 'A'
   if (key == GLFW_KEY_A && action == GLFW_PRESS) {
      glfwSetCursorPos(window,10,10);
   }
}

...
.. main entry point

GLFWwindow* window;
// Create a windowed mode window and its OpenGL context
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
...
glfwSetKeyCallback(window, keyboard_callback);

// Loop until the user closes the window
while (!glfwWindowShouldClose(window)) {
   glfwSwapBuffers(window);
   glfwPollEvents();
}

Anyone encountered this issue?

UPDATE

Just out of curiocity and for the heck of it, i decided to test also some X Lib code and xdotool:

// XLib
Display* dpy = XOpenDisplay(0);
Window root_window = XRootWindow(dpy, 0);
XWarpPointer(dpy, None, root_window, 0, 0, 0, 0, 10, 10);
XCloseDisplay(dpy);

// xdotool
system("xdotool mousemove --screen 0 10 10");

Results?

Exactly the same. It seems like nothing in the world can move that darn cursor and i don’t know what causes it, GLFW, Bodhi or my VirtualBox.

Thanx

elmindreda wrote on Saturday, September 27, 2014:

You need to disable cursor integration for cursor positioning to work in the client OS.

vizvi wrote on Sunday, September 28, 2014:

Thank you, now i feel total noob :slight_smile:

But now i have another problem with fullscreen.
I’m creating a GLFW window with:

window = glfwCreateWindow(640, 480, "Hello World", glfwGetPrimaryMonitor(), NULL);

meaning i want a 640x480 fullscreen.
On windows it works well; it creates a fullscreen of 640x480 pixels.

On Linux, something weird is happening. The 640x480 window is just centered above a black window (covering my desktop resolution of 1366x768)
It’s like i created a window of exact desktop resolution, then rendering to a glViewport of 640x480.
Is that normal? This is how fullscreen achieved in ubuntu linux?

I tried to shed some light by checking my primary monitor sizes, heres the results:

int mtrw,mtrh;
GLFWmonitor* monitor = glfwGetPrimaryMonitor();
glfwGetMonitorPhysicalSize(monitor,&mtrw,&mtrh);
// mtrw = mtrh = 0 ??????????

My next thought was to check what X gives me by plain calls:

#if defined(__linux__)
   XWindowAttributes attr;
   Display* dpy = glfwGetX11Display();
   Window xwindow = XRootWindow(dpy,0);
   XGetWindowAttributes(dpy,xwindow,&attr);
   // attr.width = 1366   => correct
   // attr.height = 768   => correct
#endif

Though, have no idea if glfwGetPrimaryMonitor is related somehow to XRootWindow but just wanted to show it.

Also, my xvinfo command in terminal gives me:

X-Video Extension version 2.2
screen #0
 no adaptors present

My glxinfo | grep direct gives me:

direct rendering: Yes

which i couldn’t fix it with anything. My gfx is an Intel® HD Graphics.

My OpenGL application works both in Win7 / WinXP / Linux, but on Linux i can’t really distinct if it runs in software or not. FPS is about 60,70 on really simple operations (clear and some text draw)

I apologise for the message reply but i don’t know what is the root of all this and just posted all relevant information.
Right now the most stable approach (regarding the problem) is to create a window equal to desktop resolution. This also fixes some mouse problems i have (yes, integrated mouse is disabled)

Thanx

elmindreda wrote on Tuesday, October 21, 2014:

Neither the physical size in millimetres of the monitor, the X Video extension nor whether direct rendering is used has anything to do with this.

Just because you’re requesting a resolution of 640x480 doesn’t mean that’s what you got. You need to check the size of your framebuffer.