Mouse click position precision

Hello! I noticed GLFW’s mouse button pressed callback doesn’t provide the (x, y) position of the button click. What’s the best practice for the application’s callback to determine this position?

Calling glfwGetCursorPos() from the callback seem suboptimal. Depending on the delay between when the click event was received and when the application’s callback fires, possibly interrupted by rendering or other logic in the main thread, the cursor may have moved by some amount. I suppose the application could use glfwSetCursorPosCallback() to maintain an up-to-date copy of cursor position, and refer to this when the button click callback fires, since events are processed on the main thread in the order received from the windowing system. Is this what most do if they need precise button-click position data?

All the same, the latter feels like a hack. Is there any reason GLFW doesn’t plumb the (x, y) coordinates received in e.g. X11 or Win32 mouse click events directly to the application’s mouse button callback?

Thanks.

Adding a mouse button callback with the cursor position would be a good idea, as I believe the information is present on the current set of platforms and it wouldn’t be hard to add a fallback if a platform didn’t have this information. This has previously been suggested and a PR was started but then deleted. From the looks the implementation wasn’t complete.

As you suggest you will likely get the same information by storing the position callback event information yourself.

1 Like