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

GLFW3.4+ on X11: copy the WM_CLASS property from the parent window for viewports #8474

Open
wants to merge 1 commit into
base: docking
Choose a base branch
from

Conversation

Madman10K
Copy link

This PR resolves one of the issues listed in #8289. The issue should not be closed, because this PR does not fix all the issues that are still needed to be resolved to mark the PR as complete. I hope to resolve #8289 in followup pull requests in the near future.

This patch makes it possible for dear imgui to copy the WM_CLASS property of a window under X11 when compiled with GLFW version 3.4 and later.

This PR does not fix the following:

  1. The Wayland app ID not being copied or set(GLFW does not set a default app ID)
  2. Making it possible to differentiate between viewports when configuring tiling window managers in both X11 and Wayland

However, it does fix a number of issues, such as:

  1. Viewport windows being treated as separate applications by various desktop environment features
  2. Even though differentiating between viewports and the root window/s of the same application is not implemented here, it does allow for differentiating between viewports of other dear imgui applications

Unfortunately, to make this PR possible, the implementation uses the native X11 API, due to GLFW not implementing any method of getting the value of window hints or of its internal structures :/

Testing

Tested this under latest Arch Linux, Ubuntu Linux 24.10 and Ubuntu Linux 24.4. Due to the unavailability of GLFW version 3.4 in Ubuntu 24.04 this patch will not be covered by our Linux CI correctly unfortunately :/

@Ikos3k
Copy link

Ikos3k commented Mar 9, 2025

I tested the example_glfw_opengl3 on Arch Linux (kernel 6.13.5-arch1-1), and it works well. However, I believe it would be better to hardcode the ImGui window name into the class name or instance, rather than deriving it from the title of the main GLFW window.

Here’s a snippet from my i3 configuration file (each of these rules works):
$ cat .config/i3/config | tail -n 4

# for_window [title="Dear ImGui GLFW"] exec --no-startup-id notify-send "test1"
# for_window [class="Dear ImGui GLFW"] exec --no-startup-id notify-send "test2"
# for_window [class=".*ImGui.*"] floating enable
for_window [title=".*ImGui.*"] floating enable

@Madman10K
Copy link
Author

Deriving the name from the title of the window is something that we cannot change. The creator of the application can set the platform hints for the WM_CLASS property, however if these hints are not set for some reason, GLFW defaults to the window's title. What we can do, however is get the WM_CLASS property, regardless of how it's set and set it for all windows spawned by dear imgui.

Changing the WM_CLASS of viewport windows will change how they are treated by other desktop environments/window managers. They will be shown as 2 separate applications which is not what we want.

I thought I could add something like dear imgui to the instance property of WM_CLASS, however it turns out that desktop environments like GNOME distinguish between instances and show the same application 2 times, though in this case, since the class is set correctly they are treated as the same application, unlike in the previous case.

In my opinion, appending ImGui or anything else to the title is also not ideal, since it will be weird, especially for windows that are not outside the boundary of the root window.

I don't really know what the solution for this is, except maybe adding the _NET_WM_TRANSIENT_FOR property to point to the root window, however this will have other side effects:

The WM_TRANSIENT_FOR property (of type WINDOW) contains the ID of another top-level window. The implication is that this window is a pop-up on behalf of the named window, and window managers may decide not to decorate transient windows or may treat them differently in other ways. In particular, window managers should present newly mapped WM_TRANSIENT_FOR windows without requiring any user interaction, even if mapping top-level windows normally does require interaction. Dialogue boxes, for example, are an example of windows that should have WM_TRANSIENT_FOR set.

It is important not to confuse WM_TRANSIENT_FOR with override-redirect. WM_TRANSIENT_FOR should be used in those cases where the pointer is not grabbed while the window is mapped (in other words, if other windows are allowed to be active while the transient is up). If other windows must be prevented from processing input (for example, when implementing pop-up menus), use override-redirect and grab the pointer while the window is mapped.

Also, let's suppose the _NET_WM_TRANSIENT_FOR property is set - I don't know how many window managers actually support setting rules against this property. For example, there is nothing in the i3wm's documentation that mentions applying rules for such windows.

That is the reason this PR is a partial fix. I really don't know how to fix this for tiling window manager users right now.

There is still a big benefit to fixing this for DE users, even if tiling window manager users are still left without good support. My plan is to fix this for tiling window managers when I find a good method to fix it(and get more experience with programming for X11)

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.

3 participants