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

A vertical offset on ubuntu when a panel is separated from the main window #3898

Open
shi-yan opened this issue Mar 11, 2021 · 5 comments
Open

Comments

@shi-yan
Copy link

shi-yan commented Mar 11, 2021

Version/Branch of Dear ImGui:

f1bf642

Version: 1.82 WIP
Branch: docking

Back-end/Renderer/Compiler/OS
Tried both opengl3 and vulkan/ sdl,
gcc-8
ubuntu 18.04 on nvidia / xwindows

Back-ends: imgui_impl_sdl.cpp, vulkan / opengl3
Compiler: gcc-8
Operating System: ubuntu 18.04

My Issue/Question:

I'm testing the docking branch with the official examples. I have tried both the vulkan backend and the opengl3 backend. I have noticed some issues.

One problem is that I noticed a mouse position offset, if the demo window is separated from the main window. The issue is kinda intermittent, because there was one time, after I dragged the main window around, somehow that fixed the offset issue.

It seems that the vertical offset equals the distance between to top boundary and the top border of my screen.

Screenshots/Video

Screenshot from 2021-03-11 09-55-24

Standalone, minimal, complete and verifiable example:

this is the same official demo, but it has a CMake file

testimgui.zip

@shi-yan
Copy link
Author

shi-yan commented Mar 11, 2021

2021-03-11.13-01-01.mov

I just tried the glfw backend, and the issue is the same.

I think I know how to reproduce it now.

when the demo panel was first detached, I tried to move it by dragging the title bar. But because the imgui window can't be moved outside the screen boundary (see #3899 ), the mouse cursor starts to move away from the title bar. And then, if I release the mouse, I will introduce an offset.

it seems that imgui remembers the hit point when the dragging movement starts, and still uses that point as the mouse location when dragging stops. It doesn't expect relative cursor position would change during dragging.

@shi-yan
Copy link
Author

shi-yan commented Mar 11, 2021

after more tries, I think my previous assessment wasn't accurate.

I think what's happening is that the imgui window's rectangle was actually moved to the outside of the screen. but when rendering, that window is still rendered inside the screen. However when responding to mouse event, the actual rectangle is used. That caused the offset effect.

@rokups
Copy link
Contributor

rokups commented Mar 22, 2021

It is a known issue which we reported to SDL and GLFW and are waiting for fixes.
glfw/glfw#1817
libsdl-org/SDL#3813

@ocornut
Copy link
Owner

ocornut commented Apr 7, 2021

I believe there's two sides to this issue.
Indeed, SDL and GLFW don't support this (maybe X doesn't support it or doesn't recommend it? I don't know)

But the bug on dear imgui side, reported so many times and in so many flavors in #2117 is that we don't properly react to this limitation and expect our platform windows to be at position A (that was requested) when it is in fact at position B. This is the core issue with multi-viewports on Linux which hasn't been solved/fixed since #2117 was started.

rokups added a commit to rokups/imgui that referenced this issue Jun 3, 2021
…een bounds while WM forces window to remain within screen bounds. (ocornut#3898, ocornut#3899)

Only helps GLFW, because glfwGetWindowPos() correctly returns actual window position. SDL_GetWindowPosition() on the other hand returns window position before WM restricting window movement, which does not match actual window position on screen.
rokups added a commit to rokups/imgui that referenced this issue Jun 9, 2021
…een bounds while WM forces window to remain within screen bounds. (ocornut#3898, ocornut#3899)
@lailoken
Copy link

lailoken commented Sep 5, 2024

FWIW, the following code keeps SDL and ImGui in sync in this regard.
(For me at least on SDL2 / OpenGL3 backend)

static void SetWindowPos_override(ImGuiViewport* vp, ImVec2 pos)
{
    // call previous callback (on the default one this will simply set the SDL Pos)
    origPlatformIO.Platform_SetWindowPos(vp, pos);

    auto window = ImGui::FindWindowByID(vp->ID);
    if (window)
    {
        // There may also be a discrepancy between where SDL eventually puts the window and where ImGui thinks it is
        // we need to read the position from SDL and update ImGui
        SDL_Window* hwnd = reinterpret_cast<SDL_Window*>(vp->PlatformHandle);
        int x, y;
        SDL_GetWindowPosition(hwnd, &x, &y);
        if (x != (int)vp->Pos.x || y != (int)vp->Pos.y)
        {
            vp->Pos.x = x;
            vp->Pos.y = y;
            vp->WorkPos.x = x;
            vp->WorkPos.y = y;
            window->Pos.x = x;
            window->Pos.y = y;
            // call SDL again to make sure it's correct? seems to need this?
            // the window position will not seem to change, there will be a slight stutter,
            // but the window will be in the correct position according to SDL+ImGui
            origPlatformIO.Platform_SetWindowPos(vp, pos);
        }
    }
}

Hope this helps others.

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

4 participants