Global cursor position in multi-display setup

Hi!

You can see, I have a 3x3 setup that is working as a single display. I need the global cursor position for further calculation. I guess glfwGetCursorPos(window, &cposx, &cposy); is limited to one desktop only. Is there any function I can use for this purpose?

The cursor position is in screen coordinates but relative to the top-left corner of the window content area. To calculate it’s global position you can add the position of the window from glfwGetWindowPos(window, &wposx, &wposy). This should work across all displays.

1 Like

Hi @dougbinks, Thanks for the quickest reply.

If I use glfwGetWindowPos(), the output is something like below, and it is not dynamic but only fixed. See both side of the displays

new_glfwindowgetpos

On the other hand, if I use glfwGetCursorPos(window, &cposx, &cposy); it is moving around the screen. I just panicked with multiple display setup. But problem is, while moving my cursor, the cursor separated area is overlapping and blending slowly once the cursor stop moving. See the top-left side, while moving the cursor the area is overlapping. What I actually did, I defined an area around the gaze point and used different sampling rate, that is visible in the screen but with overlapping region now it looks bad.

new_overlapping

Is there any solution for this overlapping problem?

You need to add the window position to the cursor position to get the global position of the cursor:

// warning untested code
double cposx, cposy;
glfwGetCursorPos(window, &cposx, &cposy);

double wposx, wposy;
glfwGetWindowPos(window, &wposx, &wposy);

double global_cposx = cposx + wposx;
double global_cposy = cposy + wposy;

I’m sorry, I do not know what I am looking at in this image but I would guess that any ‘overlapping problem’ is down to how you process the resulting cursor position and or render the result in your code.

1 Like

From the documentation, I think the glfwGetWindowPos() takes int input parameters

int wposx, wposy;
glfwGetWindowPos(window, &wposx, &wposy);

Also, using glfwGetWindowPos() is probably restricted to one display. Because that sample code you written, that is repeating the cursor position for each of the displays separately. So moving cursor in one display is repeating the same for all displays.