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

BUG: Mouse pos being updated when other widget has focus #52

Open
dimateos opened this issue Apr 26, 2023 · 1 comment · May be fixed by #53
Open

BUG: Mouse pos being updated when other widget has focus #52

dimateos opened this issue Apr 26, 2023 · 1 comment · May be fixed by #53

Comments

@dimateos
Copy link

dimateos commented Apr 26, 2023

Describe the bug

Currently the imgui mouse pos is updated whenever the widget window/window is active. But in the case of widgets windows it also makes sense to check the focus. Otherwise a mouse over the area can trigger hovering effects in imgui when the user is interacting with other QT widgets.

viewer_WzmmTVZ1Y9

//... ImGuiRenderer.cpp
if (m_window->isActive()) // + also check focus in case of widget
{
    const QPoint pos = m_window->mapFromGlobal(QCursor::pos());
    io.MousePos = ImVec2(pos.x(), pos.y());
}
else
{
    io.MousePos = ImVec2(-1,-1);
}

To Reproduce
Have any widget like a combo box that expands over the widgets area when interacted.

Expected behavior
Imgui mouse pos should not be updated when the widget has no focus other widget has focus to avoid hovering triggers.

viewer_mlYkJNG894

Desktop (please complete the following information):

  • OS: Win10. Note that I am using imgui 1.89.2.WIP with docking plus some fixes for the keyboard, etc.
@dimateos dimateos linked a pull request Apr 26, 2023 that will close this issue
@dimateos dimateos changed the title BUG: Mouse pos being updated when widget has no focus BUG: Mouse pos being updated when other widget has focus Apr 27, 2023
@dimateos
Copy link
Author

Hello! After some time of testing, I think that it feels snappier to have mouse position updated even when the widget is unfocused.

What I ended up using was the function underMouse() that seem to check area overlap PLUS also that other widgets like combo boxes are not open:

bool isActive() const override {
    // the window containing the widget top-level window that currently has focus
    //return w->isActiveWindow();

    // the widget is the one with focus among the window wigets
    //return w->isActiveWindow() && w->hasFocus();

    // the widget area is under the mouse, but it seems like other widgets being open/focused cancel it e.g. an open combo box
    return w->isActiveWindow() && w->underMouse();
    }

I also changed the mouse position set for inactive wrappers to -FLT_MAX. Previous position -1,-1 was considered valid and consumed, not necessarily raising io.WantCapture flag but prevented imgui to do some stuff when the prev mouse pos is actually invalid I guess (lead to issues with my app anyway).

...
else
{
    //https://github.com/ocornut/imgui/blob/031e152d292b386b7b6149e455924cfc6bab8c7c/imgui.h#L2048
    // Mouse position, in pixels. Set to ImVec2(-FLT_MAX, -FLT_MAX) if mouse is unavailable (on another screen, etc.)
    //https://github.com/ocornut/imgui/blob/fd943182bd9fe1d801e721a20a41dcde84be39d0/imgui.cpp#L679
    // - 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your backend if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)".
    io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX);
}

In my implementation I also tried to restore io.MousePosPrev when the wrapper is active again, but seems to behave the same way. Imgui just recovers fine if the previous position was an invalid one ImVec2(-FLT_MAX,-FLT_MAX).

Results:

  • The checkboxes reflect the returns of the widget functions described in isActive(), you can see the behavior I described about QT combo boxes disabling underMouse. Basically the end result is kind of the same behavior as imgui combo box
  • The mouse pos reflects correclty invalid not -1,-1.

viewer_GJsvCcrheZ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant