mirror of
https://github.com/ocornut/imgui.git
synced 2026-10-22 22:44:21 +00:00
Hit-testing fails on Win32 with viewport sidebar + docking + borderless window #6162
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#6162
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version: 1.89.3
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_dx11cpp + imgui_impl_win32.cpp
Operating System: Win11 and Win10
My Issue/Question:
So this is a really strange issue that I've tried debugging but once I ended up deep in the imgui internals, I figured it would be better to post the question.
So I'm trying to create a custom title bar for my window. I'm using the ViewportSidebar feature to create my window titlebar and it's mostly working great except that occasionally the hit testing fails. This seems to be related to some combination of docking of windows and (maybe?) moving the main win32 window. It's a 100% reproduceable in my home engine but a little harder to repro in the example app but it still happens.
I think enabling the dockspace example exacerbates the issue. I've provided a repro case, so all you need to do is replace the main.cpp in the dx11 example and run it. you'll notice the new title bar and the three buttons that you can hover over and they detect that. Now example the dockspace example and dock undock the windows and you'll notice how the hit-testing starts to fail. In some cases it fixes but sometimes it doesn't (and in my home engine it never fixes itself). I've also attached a video showing the issue.
Anyone have any idea what's going on?
Screenshots/Video
https://user-images.githubusercontent.com/10767490/218336676-ffa7d46c-6c4e-4f11-90e8-203b63fe21cc.mp4
Standalone, minimal, complete and verifiable example:
Replace the DX11 example main.cpp with the version supplied, all changes are within // BUG REPRO comment blocks.
main.zip
Thanks for taking the time to create that repro! (this is double useful as I was hoping to look toying with borderless stuff at some point so this is a nice sets of pointer).
I eventually manged to repro - but I don't yet understand what leads to it - and I noticed that when the bug happens, mouse position is not being updated while hovering that upper section:

The two values to watch are MouseViewport (here it is correct) and MousePos (can't see on the picture, but when the bug happens that values stays still even though I am moving my mouse cursor over that section, when the bug doesn't happen that value is updated while moving). You should be able to confirm the lack of events in
Tools->Debug Log->IO.Debugging suggestion: always print out mouse pos on screen and/or
GetForegroundDrawList()->AddCircleFilled(ImGui::GetMousePos(), ...);to visualize it.Dear ImGui is not receiving mouse inputs so it's probably not a Dear ImGui bug, but there is a possibility that imgui_impl_win32.cpp doesn't play well with your setup of hooking
WM_NCCALCSIZE/WM_NCHITTEST. I myself haven't attempted this so I presently have no idea where the issue is.Note that imgui_impl_win32.cpp calls
io.AddMousePosEvent()in two locations. So if you are getting neither you may want to ad debug logs in the backend to try to understand what's preventing things from working. You can useIMGUI_DEBUG_LOGto add to theTools->Debug Logwindow. You may want to print the result of::GetCapture(),bd->MouseHwnd,bd->MouseTracked,WM_MOUSEMOVEhandler: this normally covers the majority of situations.ImGui_ImplWin32_UpdateMouseData()which is designed to provides dear imgui with out-of-client-boundaries mouse positions when window is focused but not hovered and mouse hasn't been captured by the window (~haven't clicked and dragged from inside the window). That one is optional.But it's simply possible that your logic using
bool const isAnyInteractibleWidgetHovered = ImGui::IsAnyItemHovered();and returning HT_CAPTION is faulty, you should also dump all of that stuff on the screen. Once you start returningHTCAPTIONthen you don't get mouse update fed to dear imgui so it won't update its knowledge of the mouse cursor position?(
FYI Docking maneuvers will tend to do those things:
ImGuiViewportFlags_NoInputson a viewport hosting a window being dragged, which alters ourWM_NCHITTESThandler inImGui_ImplWin32_WndProcHandler_PlatformWindow(). However this should not able to main viewport at all.My intuition is that neither of those are related or the cause of your issue.
)
Interesting, my suspicion is similar that there is perhaps some bad interaction between the wndProc handlers but I know the viewportSidebar is also a newish feature so there may have been some bug. I'll try to investigate what is causing the loss of mouse updating.
I hate these sorts of bugs where everything looks to be working but isnt ;)
Will follow up with more info, and perhaps we can turn this into a borderless starter Gist or something.
Thanks for the lead about the mouse position. So what seems to be happening is that once I return the "HTCAPTION" result from the hit-test, we stop receiving the WM_MOUSEMOVE message and receive WM_NCMOUSEMOVE messages instead. This seems to be standard behavior and dearImgui doesnt handle those messages because they are generally irrelevant for it. Adding this code fixes the issue but what I don't understand is why it was working intermittently.
I'm not a win32 expert so would be good for someone else to validate this but for now it fixes the problem. I can easily add that to my client code but the default imgui impl could also be updated with it as it probably doesnt hurt.
Ah! It turns out we have a thread discussing just this: #6045
I’ll resume testing this, and may ask you for confirmation that the new logic works with your setup.
May be wrong and lose mouse pos when app is unfocused, I'll post solution/fix in win32 backend once I find it (right now I don't have it).
Yeh, I don't know either, so far it seems to fix the issue, but I'll keep testing and see if I can trigger any further issues. At least now that I know what the core problem is, it's easy enough to debug and I will just patch the wndProc (and update this issues) if/as needed.