mirror of
https://github.com/ocornut/imgui.git
synced 2026-10-29 07:54:40 +00:00
viewport: fixing stutter when dragging a window out of the main viewport on Linux #9594
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#9594
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/Branch of Dear ImGui:
1.93.1 WIP, branch
dockingBack-ends:
imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp (GLFW 3.3.10)
Compiler, OS:
g++ 13.3, Linux Mint 22.3 (kernel 6.8), X11, Xfce 4.18 / xfwm4 with compositing, Mesa Intel HD 630, single 1920x1080 60 Hz monitor
Full config/build information:
Details:
When I drag ImGui window out of the main viewport it jiggles and stutters.
Drag "Hello, world!" window out of the main viewport and back, then drag it around the desktop for
10–20 seconds. It will lag the cursor by a varying amount. Combine with left click releases when inside the viewport.
Seems to be related to #2117.
Disclaimer: Code work done by Claude and reviewed by me. I intentionally did not open PR due to LLM / AI contribution policy. Nevertheless I wanted to share this with others and upstream authors can take the idea and implement the fix on their own if they like.
Code with changes: https://github.com/hinxx/imgui/tree/viewport-drag-latency
Two issues were observed:
Today
UpdatePlatformWindows()creates the platform window at the moment the window no longer fits thehost viewport; in the middle of the draging it out. At 60Hz vsync I get a frame that takes about ~100 ms and it is noticable as a glitch in movement.
After trying out several things like turning the xfce4 compositor off, which did help, but not completely
the issue iss that ImGui samples the mouse once per frame (for me 16 ms with 60hz refresh rate). This makes ImGui position and WM position out of sync and results in wobbles or jitter in window posisiton.
Brute force solution is not using vsync (refresh at > 300 frames/s) but then CPU cycles are wasted.
Three changes that fix the above:
io.ConfigViewportsOwnViewportOnMove(new, default off): set own viewport when the drag starts and not when the window starts leaving the viewport.With 2+3 the stutter is gone for me as far as I was able to test.
Questions
Is having a window pool acceptable?
Is a core flag like
ConfigViewportsOwnViewportOnMoveOK?Where would late mouse pos latching belong (maybe it is apps bussiness and not a concern for imgui)?
Screenshots/Video:
Before fix the wobble is noticeable as is the glitch when window leaves the main viewport:
IMGUI_GLFW_WINDOW_POOL=0 ./example_glfw_opengl3:https://github.com/user-attachments/assets/c71dad07-f7d4-4e09-822e-f25988b26b6f
Fixed:
IMGUI_OWNVP=1 IMGUI_LATELATCH=500 ./example_glfw_opengl3https://github.com/user-attachments/assets/e780645b-f4b7-487a-ac01-b028ab3d83f1
It might a bit hard to tell what the improvement is on the video, but one telling sign is the mouse pointer being glued to the window titlebar on move for the fixed vs. the wobbly where it visibly looks "detached".
Minimal, Complete and Verifiable Example code:
The code fixes in my branch can be selectively enabled or disabled to observe the improvement.
Observed behavior before fix (stock code) with lots of debug for analysis with scripts/llm:
Fixes applied, no more stutter on move out and not wobble outside the main viewport:
See the code for some other env variables that you play arond with, but these 2
IMGUI_OWNVP=1 IMGUI_LATELATCH=500do th etrick for me..See
misc/debug/viewport_drag/for scripts that were used for analysis (needxdotool) and some notes on automated tests done by Claude. I tested the behavior manually to confirm that the wobble is gone.