Skip to content

Conversation

maezawa-akira
Copy link

@maezawa-akira maezawa-akira commented Nov 1, 2022

Issue

On macos (12.6 running on M1),
when the window comes into focus, the reported mouse cursor position has an offset.
Once the user clicks somewhere in the window the offset is gone.

It seems that before the user clicks somewhere in the window, imgui reports the screen coordinate instead of the window coordinate.
imgui-issue

How to reproduce the problem

Build and run example_apple_metal_macos. Unless the window is placed at the top-left, the highlighted UI element will be offset relative to the cursor initially. Once the user clicks somewhere inside the window, the UI element under the mouse cursor will be selected.

Reason

NSEvent's locationInWindow property is used to retrieve the window coordinate of the cursor when handling mouse events in ImGui_ImplOSX_HandleEvent of imgui_impl_osx.mm backend, but according to the reference, this property may contain the screen coordinate, if the NSEvent's .window property is nil.

Fix

Check the .window property of the NSEvent. If null, convert from screen coordinate to the window coordinate associated with the view

@ocornut
Copy link
Owner

ocornut commented Nov 2, 2022

Thank you very much, this is now merged as 86f2af2

@ocornut ocornut closed this Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants