8000 GLFW: some support for child HWNDs by schwaaa · Pull Request #4862 · ocornut/imgui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

GLFW: some support for child HWNDs #4862

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

Open
wants to merge 6 commits into
base: docking
Choose a base branch
from

Conversation

schwaaa
Copy link
@schwaaa schwaaa commented Jan 4, 2022

Translate window coordinates and handle mouse capture for GLFW windows that are child HWNDs. At present the only way GLFW windows can be child HWNDs is if the ImGui caller explicitly setparents them. See #4860 for the use case.

screen to client coordinates if the target raw window is a child HWND
if the window is captured but not focused, because focus may belong to
the parent of a captured child HWND
@schwaaa schwaaa changed the title Docking child hwnds GLFW: some support for child HWNDs Jan 4, 2022
@schwaaa
Copy link
Author
schwaaa commented Jan 4, 2022

More information re b7a0d96: When a GLFW window is parented to a non-GLFW window, the initial mouse click is processed properly, but mouse capture is never established. This fails because underneath GLFW, Windows sets the FOCUSED attribute for the parent, not the child. ImGui requires the FOCUSED atrribute, so the mouse button state is not set.

Instead we should set the mouse button state if the window has capture (mouse_window != NULL), regardless of whether another window in the immediate parent hierarchy has focus.

[edit] the mouse issue is now moot, as per later comments in this thread. The positioning issue is still open.

@schwaaa
Copy link
Author
schwaaa commented Jan 6, 2022

Sample use code, generally functional (though very basic) on windows and macos, using glfw/opengl backend:
https://github.com/schwaaa/clap-plugin

Plugins can generate multiple imgui windows/viewports, and embed them as children in non-imgui-aware parent windows provided by the host application. Mouse behavior on windows needs the mods in this fork, mac works fine off either the fork or the unmodified docking branch.

Unrelated, the code renders imgui on main thread callbacks rather than in a closed run loop, since it's not running in the main application.

capture

…Buttons"

This reverts commit b7a0d96.

No longer necessary because of later commits on imgui/docking,
specifically 200a8f1 (I think).
…w windows that are children of non-glfw windows. see also 9b14549
@schwaaa
Copy link
Author
schwaaa commented Feb 9, 2022

I believe that 200a8f1 on dock 8000 ing has made b7a0d96 from this PR unnecessary.

However I think that 9b14549 is still needed, and I have a similar patch for x11.

I've synced this PR by reverting the now-unnecessary commit, merging the docking branch, and adding the x11 commit. The preferred fix would actually be in GLFW.

@ocornut
Copy link
Owner
ocornut commented Nov 10, 2022

Hello,
Sorry for my late answer.

Can you explain/confirm why this doesn't need to alter the equivalent getter ImGui_ImplGlfw_GetWindowPos() as well?

@ocornut
Copy link
Owner
ocornut commented Nov 29, 2022

Ping @schwaaa

@schwaaa
Copy link
Author
schwaaa commented Nov 29, 2022

I believe the issue is that in GLFW's win32_window.c, _glfwGetWindowPosWin32() explicitly converts the returned coordinates from from client to screen, but _glfwSetWindowPosWin32() passes the input coordinates directly to win32's SetWindowPos(), which expects client coordinates for child windows.

I haven't touched this code for a while so it's not top of mind, but if I have all the context right, the best fix would be to add some interface to GLFW so either setters or getters or both can specify whether they want client or screen coordinates. If we have to use GLFW as is, we need to handle the conversion ourselves.

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

Successfully merging this pull request may close these issues.

2 participants
0