# Global cursor position in multi-display setup

**URL:** <https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192>\
**Category:** support\
**Created:** [November 11, 2022, 3:37pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192 "2022-11-11T15:37:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bipul-mohanto](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/bipul-mohanto/32/627_2.png) [@bipul-mohanto](https://discourse.glfw.org/u/bipul-mohanto)\
**Post date:** [November 11, 2022, 3:37pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/1 "2022-11-11T15:37:21Z")

</div>

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?

 ![195645584-17fdfd53-9ac3-4974-ac31-2e1027584549](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/0978a73205b5bf3c2dda3d761b068d5212619473.jpeg)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 11, 2022, 4:03pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/2 "2022-11-11T16:03:01Z")

</div>

The [cursor position](https://www.glfw.org/docs/latest/input_guide.html#cursor_pos) 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.

---

<div class="post-metadata">

**Author:** ![bipul-mohanto](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/bipul-mohanto/32/627_2.png) [@bipul-mohanto](https://discourse.glfw.org/u/bipul-mohanto)\
**Post date:** [November 11, 2022, 4:48pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/3 "2022-11-11T16:48:42Z")

</div>

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](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/e76437b787dd232971c23262d9aec40960df0bf7.png)

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](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/37baad49eb210d86eb783406841d7341af32bd31.png)

---

<div class="post-metadata">

**Author:** ![bipul-mohanto](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/bipul-mohanto/32/627_2.png) [@bipul-mohanto](https://discourse.glfw.org/u/bipul-mohanto)\
**Post date:** [November 11, 2022, 4:59pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/4 "2022-11-11T16:59:36Z")

</div>

Is there any solution for this overlapping problem?

 ![Screenshot from 2022-11-11 05-57-25](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/743aa36e2fa4ee9324a8ec9b176a3bba223f98c7.jpeg)

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 11, 2022, 6:05pm UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/5 "2022-11-11T18:05:39Z")

</div>

> [@bipul-mohanto](#):
>
> If I use `glfwGetWindowPos()`, the output is something like below, and it is not dynamic but only fixed. See both side of the displays

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

```auto
// 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;

```

> [@bipul-mohanto](#):
>
> But problem is, while moving my cursor, the cursor separated area is overlapping and blending slowly once the cursor stop moving.

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.

---

<div class="post-metadata">

**Author:** ![bipul-mohanto](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/bipul-mohanto/32/627_2.png) [@bipul-mohanto](https://discourse.glfw.org/u/bipul-mohanto)\
**Post date:** [November 14, 2022, 8:42am UTC](https://discourse.glfw.org/t/global-cursor-position-in-multi-display-setup/2192/6 "2022-11-14T08:42:18Z")

</div>

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

```auto
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.
