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

Fix Embedded Game disappear when not focused on KDE 5 #102104

Conversation

Hilderin
Copy link
Contributor

This PR resolves the issue where the Embedded Game Window disappears when the Floating Game Window is not focused on Xorg/Kubuntu.

On Ubuntu 24.04 Gnome and Fedora 40 KDE Plasma 6.1.5, a window of type _NET_WM_WINDOW_TYPE_UTILITY remains visible even when the parent window is not focused. However, on Kubuntu/KDE (tested on Kubuntu 22.04 and KDE Plasma 5.24.7), this type of window is hidden when the parent window loses focus, causing the Embedded Game Window to disappear.

To address this, this PR changes the window type to _NET_WM_WINDOW_TYPE_NORMAL. A side effect of this change is that the Embedded Game Window now appears in the alt-tab window list. I tested several window types, but none could simultaneously prevent the window from disappearing when the parent is not focused and exclude it from the alt-tab list. Although the _set_window_taskbar_pager_enabled method was designed for this purpose, it does not seem to work on Kubuntu/KDE. Given the circumstances, I believe this trade-off is acceptable.

@akien-mga
Copy link
Member

akien-mga commented Jan 30, 2025

A side effect of this change is that the Embedded Game Window now appears in the alt-tab window list. I tested several window types, but none could simultaneously prevent the window from disappearing when the parent is not focused and exclude it from the alt-tab list. Although the _set_window_taskbar_pager_enabled method was designed for this purpose, it does not seem to work on Kubuntu/KDE. Given the circumstances, I believe this trade-off is acceptable.

I'll try to test too in coming days, but if the problem is specific to KDE 5, maybe we can test if we're running it on startup, and use this workaround only then.

It can be checked (possibly not reliably) with the environment variables XDG_CURRENT_DESKTOP and KDE_SESSION_VERSION. On my Fedora 41 KDE Wayland:

$ echo $XDG_CURRENT_DESKTOP
KDE
$ echo $DESKTOP_SESSION
plasma
$ echo $KDE_SESSION_VERSION
6

But I'll also test this PR on KDE 6 and see if the tradeoff for the workaround is indeed acceptable, so we don't need to make the logic too complex.

@Hilderin
Copy link
Contributor Author

Hilderin commented Jan 31, 2025

I'll try to test too in coming days, but if the problem is specific to KDE 5, maybe we can test if we're running it on startup, and use this workaround only then.

I don't have enough installed systems to be 100% sure that the issue is really KDE 5 specefic. Right now, it's the only system where the issue was reported. But if you can test it on your side, it could give us more information, thanks. I have no problem to add a check on a desktop version.

@akien-mga
Copy link
Member

I tested this on KDE Plasma 6.2.5 on Fedora 41, and indeed the change seems to be a bit of a downgrade. Having the embedded game appear when alt-tabbing isn't too bad, but there are fade in/fade out animations when switching between Game and 2D/3D/Script tabs, which might bother users and break the "magic" of having the window embedded.

4.4 beta 2:

2025-02-04.23-42-24.mp4

This PR:

2025-02-04.23-43-44.mp4

So I think a surgical change only for KDE 5 might be better to start with, and we can re-evaluate if we get other bug reports for other desktop environments.

I tested this, which restores the previous behavior for me on KDE 6. I don't have a system with KDE 5 to test with.

diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp
index 8244e48c5a..95181a1c81 100644
--- a/platform/linuxbsd/x11/display_server_x11.cpp
+++ b/platform/linuxbsd/x11/display_server_x11.cpp
@@ -6276,7 +6276,7 @@ DisplayServerX11::WindowID DisplayServerX11::_create_window(WindowMode p_mode, V
 			}
 		}
 
-		if (wd.is_popup || wd.no_focus) {
+		if (wd.is_popup || wd.no_focus || (wd.embed_parent && !kde5_embed_workaround)) {
 			// Set Utility type to disable fade animations.
 			Atom type_atom = XInternAtom(x11_display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
 			Atom wt_atom = XInternAtom(x11_display, "_NET_WM_WINDOW_TYPE", False);
@@ -6422,6 +6422,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
 	KeyMappingX11::initialize();
 
 	xwayland = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").to_lower() == "wayland";
+	kde5_embed_workaround = OS::get_singleton()->get_environment("XDG_CURRENT_DESKTOP").to_lower() == "kde" && OS::get_singleton()->get_environment("KDE_SESSION_VERSION") == "5";
 
 	native_menu = memnew(NativeMenu);
 	context = p_context;
diff --git a/platform/linuxbsd/x11/display_server_x11.h b/platform/linuxbsd/x11/display_server_x11.h
index 166b2cb57b..edd70d454d 100644
--- a/platform/linuxbsd/x11/display_server_x11.h
+++ b/platform/linuxbsd/x11/display_server_x11.h
@@ -338,6 +338,7 @@ class DisplayServerX11 : public DisplayServer {
 	bool xinerama_ext_ok = true;
 	bool xshaped_ext_ok = true;
 	bool xwayland = false;
+	bool kde5_embed_workaround = false; // Workaround embedded game visibility on KDE 5 (GH-102043).
 
 	struct Property {
 		unsigned char *data;

@Hilderin
Copy link
Contributor Author

Hilderin commented Feb 5, 2025

Indeed, the fade in/fade out animations seems a bad downgrade. I don't have access anymore to a KDE 6 Desktop right now, can you confirm that the original issue when using the Floating Window does not occur on KDE 6 on your side? Because if we can only reproduce the issue on KDE 5, I think your suggestion is good.

@akien-mga
Copy link
Member

Yeah I can't reproduce the linked issue on KDE 6.

@akien-mga akien-mga force-pushed the fix-embedded-game-disappear-when-not-focused branch from e3d96b3 to 0d529fe Compare February 5, 2025 11:01
@akien-mga akien-mga force-pushed the fix-embedded-game-disappear-when-not-focused branch from 0d529fe to f7d1558 Compare February 5, 2025 11:01
@akien-mga akien-mga changed the title Fix Embedded Game disappear when not focused Fix Embedded Game disappear when not focused on KDE 5 Feb 5, 2025
@akien-mga
Copy link
Member

I went ahead and included my diff to make it specific to KDE 5. Let's keep an eye out for similar bug reports for other desktop environments to see if we need to extend the heuristics.

@Repiteo Repiteo merged commit a63a8b4 into godotengine:master Feb 5, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Feb 5, 2025

Thanks!

@Hilderin
Copy link
Contributor Author

Hilderin commented Feb 5, 2025

Thanks @akien-mga to test and finish this PR.

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.

Embedded Game window stops rendering when editing other nodes in the editor
4 participants