Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS apple_openGl example not owning mouse clicks. #2664

Closed
josht000 opened this issue Jul 13, 2019 · 10 comments
Closed

macOS apple_openGl example not owning mouse clicks. #2664

josht000 opened this issue Jul 13, 2019 · 10 comments

Comments

@josht000
Copy link

Version/Branch of Dear ImGui:

Version: v1.71
Branches: master and docking

Back-ends: imgui_impl_opengl2.cpp + imgui_impl_opengl2.cpp
Compiler: xcode v9.2 (latest available for a 2016 macbook pro)
Operating System: macOS v10.12.6
Build: Release and Debug

My Issue/Question:
Hey Omar, we chatted on twitter earlier today. Anyway, example_apple_opengl2 isn't handling any mouse clicks. Everything works fine in windows. The main window can be resized, but no clicks are ever handled by the GUI.

Spent several hours debugging and can't find anything conclusive.

While debugging I set breakpoints in UpdateMouseInputs(), clicked the GUI and verified:

  • g.IO.MouseDown[0] = true
  • g.IO.MouseClicked[0] = true as I'd expect.

Debugging UpdateHoveredWindowAndCaptureFlags(), I verified:

  • ImGuiConfigFlags_NoMouse, not set to disabled
  • g.iO.MouseClicked[0] = true, line 3671, imgui.cpp
  • g.IO.MouseDownOwned[0] = false, line 3672, imgui.cpp
  • mouse_avail_to_imgui = false, line 3678 imgui.cpp

I'm not sure about the deep logic of mouse hovering. Do you have a mac to debug with and provide guidance?

Since this is concerning the example that I know you're familiar with I didn't include any of the source.

Thanks for all that you do!

Josh

@josht000
Copy link
Author

Couldn't add labels.

@ocornut
Copy link
Owner

ocornut commented Jul 13, 2019

Mouse clicks are marked “owned” when the click happens over an imgui window and not over the “void” behind imgui windows.

Perhaps your mouse position is not correct for some reason?

I assume you are using imgui_impl_osx there (there’s a typo in your template above so i am not sure), which is known to be a bit experimental/faulty mainly because people aren’t looking at it (i don’t own a mac).

It’s almost always preferable to use a cross platform backend (glfw, sdl).

@josht000
Copy link
Author

Of course no one cares about the void area. All the demo GUI buttons and such are totally unresponsive.

I'm not going to pursue this on mac any longer. I didn't realize that the mac build was exclusively created by "the community".

Yes, using imgui_impl_osx.

@ocornut
Copy link
Owner

ocornut commented Jul 13, 2019

Are you using a mouse as you implied, or a touchpad? If the later your issue is probably the same discussed here

#1992

@ocornut
Copy link
Owner

ocornut commented Jul 13, 2019

If your issue is for a touchpad, it is a trivial 3-4 lines fix which you can borrow from the impl_glfw logic as mentioned in that thread. OP of that thread wasn’t interested in making a PR with and insisted on a larger api-breaking change so this got stalled but hopefully we could put the easy fix if someones test it.

@josht000
Copy link
Author

Tested with touchpad, magic mouse, and a regular old plugin usb mouse. None of them cause the GUI to register mouse clicks.

I'll check out that issue and see if I can implement it.

@josht000
Copy link
Author

I don't follow the logic for the quick fix method from your reply in #1992:

Take the first few lines from ImGui_ImplGlfw_UpdateMousePosAndButtons(),

   for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
    {
        // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
        io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0;
        g_MouseJustPressed[i] = false;
    }

And shove them somewhere "in the beginning of imgui_impl_osx.mm"? Presumably, ImGui_ImplOSX_UpdateMouseCursor()? I must be missing something, because that bit of code doesn't go in well because g_MouseJustPressed is used in a callback method in ImGui_ImplGlfw_MouseButtonCallback() of imgui_impl_glfw.cpp.

@ocornut
Copy link
Owner

ocornut commented Sep 20, 2019

Hello @josht000 ,

There was a fix of the example_apple_opengl2/main.mm file #2710 which appears like it was your issue, and the issue was much simpler/dumber than that, the right events weren't passed to the back-end.
If you have time could you confirm that it now works from you if you pull latest from master? Thank you!

@josht000
Copy link
Author

IT WORKS!

I think there may be an unrelated issue to how the apple touch pad and imgui is handling 'taps' vs 'clicks', because it's only getting 'taps' every so often. But yes, clicks are working and the windows are now responsive.

Thank you @intonarumori and @ocornut

@ocornut
Copy link
Owner

ocornut commented Sep 21, 2019

Well that's great news, thanks indeed to @intonarumori for pointing out that this was the issue, while I was looking completely somewhere else. Sorry for orienting out in the wrong direction there!
There's still a potential issue to fix with some touch devices but we'll leave this to another issue/pr.

@ocornut ocornut closed this as completed Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants