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

Submenus that do not fit the main window show up behind the main window (SDL2/OpenGL3/GNOME3) #8105

Open
MBilderbeek opened this issue Oct 27, 2024 · 9 comments

Comments

@MBilderbeek
Copy link

Version/Branch of Dear ImGui:

v1.91.4-docking-12-g646df390

Back-ends:

SDL2+OpenGL3

Compiler, OS:

Linux + GCC

Full config/build information:

Dear ImGui 1.91.5 WIP (19141)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201103
define: __linux__
define: __GNUC__=14
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000483
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0F
 HasGamepad
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

When I open a submenu from a main menu bar and the submenu doesn't fit into the main window, it shows up behind the main window, instead of on top of the main window.

I'm on Debian GNU/Linux testing, with GNOME 47, on Xorg.

What I did to test:

  • clone https://github.com/ocornut/imgui.git
  • switch to the docking branch: git checkout docking
  • build the demo application: cd examples/example_sdl2_opengl3 and make
  • run ./example_sdl2_opengl3
  • In the Dear ImGui Demo window, click Example > Main menu bar.
  • In the main window, menu bar, click File > Open Recent > More ... > Recurse > Open Recent > ... until a submenu doesn't fit in the main window anymore. See screenshot 1.

I also opened the colors menu in the demo app, which doesn't fit vertically, and the same thing happens, see screenshot 2.

For more context see also openMSX/openMSX#1792 .

Screenshots/Video:

screenshot 1:
Screenshot From 2024-10-27 15-27-27

screenshot 2:
Screenshot From 2024-10-27 15-30-50

Minimal, Complete and Verifiable Example code:

See demo application as referred to above.

@ocornut
Copy link
Owner

ocornut commented Oct 27, 2024

Thank you Manuel for reporting. We have many issues with Linux-ish window managers and the multi-viewport feature.

Does your WM setups somehow prevents code/api from focusing a window or creating a window in front of the window stack?
How is window focus handled in your WM?

Could you open "Tools->Debug Log", click [X] Focus, [X] Viewports [X] IO, then trigger the issue and submit the log?
Best to use the same method as Screenshot 2 as the log will be smaller.

Additionally, if you have a chance to compile the GLFW+OpenGL3 example and the SDL3+OpenGL3 example I would be curious to know if they exhibit the same issue.

Thank you!

@ocornut
Copy link
Owner

ocornut commented Oct 27, 2024

We have many issues with Linux-ish window managers and the multi-viewport feature.

The general unfortunately workaround at this point is that I'm not sure I would enable multi-viewports when shipping apps for X or Wayland. An alternative is to create an intentionally large main host window and let user move their individual tools within it.

@MBilderbeek
Copy link
Author

MBilderbeek commented Oct 27, 2024

Update: I tested on the same computer with another user (also on GNOME) and with that I could not reproduce it. So it seems to be some kind of setting in my desktop environment or window manager that causes this.

I see you also asked some questions in the meantime. I'll try to respond to them. I do have the "Focus on hover" enabled, but when I change it back to "Click to focus" (using Gnome Tweaks), I don't see the problem go away.

@MBilderbeek
Copy link
Author

MBilderbeek commented Oct 27, 2024

Here's the requested log:

[...]
[872974] [io] Processed: MousePos (1548.0, 455.0) (Mouse)
[872974] [io] Processed: MousePos (1546.0, 455.0) (Mouse)
[872975] [io] Processed: MousePos (1545.0, 455.0) (Mouse)
[873129] [io] Processed: MouseButton 0 Down (Mouse)
[873129] [focus] SetNavWindow("##MainMenuBar")
[873129] [focus] SetNavWindow("##Menu_00")
[873142] [io] Processed: MouseButton 0 Up (Mouse)
[873210] [io] Processed: MousePos (1545.0, 456.0) (Mouse)
[873211] [io] Processed: MousePos (1546.0, 457.0) (Mouse)
[873212] [io] Processed: MousePos (1547.0, 458.0) (Mouse)
[...]
[873247] [io] Processed: MousePos (1569.0, 527.0) (Mouse)
[873248] [io] Processed: MousePos (1569.0, 531.0) (Mouse)
[873248] [io] Processed: MousePos (1569.0, 533.0) (Mouse)
[873248] [focus] SetNavWindow("##Menu_01")
[873249] [io] Processed: MousePos (1570.0, 535.0) (Mouse)
[873250] [io] Processed: MousePos (1570.0, 537.0) (Mouse)
[873250] [io] Processed: MousePos (1571.0, 539.0) (Mouse)
[873251] [io] Processed: MousePos (1572.0, 541.0) (Mouse)
[873252] [io] Processed: MousePos (1572.0, 543.0) (Mouse)
[873253] [io] Processed: MousePos (1572.0, 544.0) (Mouse)
[873253] [io] Processed: MousePos (1572.0, 545.0) (Mouse)
[873254] [io] Processed: MousePos (1572.0, 546.0) (Mouse)
[873254] [focus] SetNavWindow("##Menu_00")
[873255] [io] Processed: MousePos (1572.0, 547.0) (Mouse)
[873263] [io] Processed: MousePos (1573.0, 549.0) (Mouse)
[873263] [io] Processed: MousePos (1573.0, 551.0) (Mouse)
[...]
[873299] [io] Processed: MousePos (1577.0, 582.0) (Mouse)
[873301] [io] Processed: MousePos (1577.0, 583.0) (Mouse)
[873301] [io] Processed: MousePos (1577.0, 584.0) (Mouse)
[873301] [focus] SetNavWindow("##Menu_01")
[873303] [io] Processed: MousePos (1577.0, 585.0) (Mouse)
[873304] [io] Processed: MousePos (1577.0, 586.0) (Mouse)
[873307] [io] Processed: MousePos (1577.0, 587.0) (Mouse)
[...]
[873351] [io] Processed: MousePos (1577.0, 599.0) (Mouse)
[873351] [io] Processed: MousePos (1577.0, 600.0) (Mouse)
[873352] [io] Processed: MousePos (1577.0, 602.0) (Mouse)
[873352] [focus] SetNavWindow("##Menu_00")
[873352] [focus] SetNavWindow("##Menu_01")
[873353] [viewport] Add Viewport C4F283EB '##Menu_01'
[873353] [viewport] Create Platform Window C4F283EB '##Menu_01'
[873354] [io] Processed: MousePos (1577.0, 603.0) (Mouse)
[873354] [io] Processed: MousePos (1577.0, 604.0) (Mouse)
[...]
[873413] [io] Processed: MousePos (1576.0, 606.0) (Mouse)
[873414] [io] Processed: MousePos (1575.0, 606.0) (Mouse)
[874511] [io] Processed: Key "ModAlt" Down
[874511] [io] Processed: Key "LeftAlt" Down
[874751] [viewport] Destroy Platform Window 11111111 'n/a'
[874751] [viewport] Destroy Platform Window C4F283EB '##Menu_01'
[874751] [viewport] Destroy Platform Window 11111111 'n/a'
[874751] [viewport] Destroy Platform Window 11111111 'n/a'

@MBilderbeek
Copy link
Author

GLFW+OpenGL3 shows the same problem:
image

SDL3+OpenGL3 works fine!
image

@ocornut
Copy link
Owner

ocornut commented Oct 27, 2024

Thanks for those tests.

To narrow the cause could you try:

(1) in SDL3 backend, try to comment out the SDL_SetWindowParent(vd->Window, vd->ParentWindow); line in ImGui_ImplSDL3_CreateWindow() and see if it still works?

(2) In SDL3 backend, try to comment out the SDL_SetHint(SDL_HINT_WINDOW_ACTIVATE_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "0" : "1"); line and see if it still works?

(3) in SDL2 backend, try to comment the SDL_SetHint(SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN, (viewport->Flags & ImGuiViewportFlags_NoFocusOnAppearing) ? "1" : "0"); line and see if it fixes it?
Can you also confirm that your SDL version is at least 2.0.18+?

@MBilderbeek
Copy link
Author

MBilderbeek commented Oct 27, 2024

I'm using SDL 2.30.8.

For these tests:

  1. Still works.
  2. Did it on top of 1. and still works.
  3. Does not fix it.

In other words, none of these changes seems to have had any effect.
I hope it is sufficient to change the back-end code and just recompile the example (make clean; make).

@MBilderbeek
Copy link
Author

Anything else I can test or try?

@MBilderbeek
Copy link
Author

OK, I found the setting that causes the issue. It's in the Schema org.gnome.desktop.wm.preferences path /org/gnome/desktop/wm/preferences/focus-new-windows. This setting was set to strict. If I set it to smart, the menu appears on top.

The setting has the following descriptions:

  • summary: Control how new windows get focus
  • Description: This option provides additional control over how newly created windows get focus. It has two possible values; “smart” applies the user’s normal focus mode, and “strict” results in new windows not being given focus automatically.

I'll leave it on smart again for now, but I can always change it back to test things.

I hope this helps to fix the issue.

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

2 participants