From 9a75af2fa955e7ad65047de2109403b6b238f4f0 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 16 Feb 2025 22:37:47 +1000 Subject: [PATCH] Qt: Explicitly set desktop file path on startup Fixes window icon when running under Wayland. Or, well, as much as it can given the fact that smug GNOME developers think that windows should not be able to set their own icons. --- src/core/CMakeLists.txt | 11 +++++++++++ src/duckstation-qt/qthost.cpp | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3212880ab..4825d88fe 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -228,4 +228,15 @@ function(add_core_resources target) endif() install(DIRECTORY "$/resources" DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() + + # Linux platforms need a copy of the .desktop and icon file because Wayland stupidity. + # See QtHost::EarlyProcessStartup() for where this is used and why. We still need to set it when running + # as a Flatpak, but thankfully we don't need the extra copy. + if((LINUX OR BSD) AND (NOT DEFINED ENV{container})) + message(STATUS "Copying desktop file to resources directory.") + set(PACKAGING_SOURCE_DIR "${CMAKE_SOURCE_DIR}/scripts/packaging") + foreach(path "org.duckstation.DuckStation.desktop" "org.duckstation.DuckStation.png") + add_resources(${target} "${PACKAGING_SOURCE_DIR}/${path}" "${PACKAGING_SOURCE_DIR}") + endforeach() + endif() endfunction() diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 2c1f7e8b7..704765ae2 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -180,6 +180,25 @@ bool QtHost::EarlyProcessStartup() // TODO: Re-evaluate this on Qt 6.9. if (QtHost::IsRunningOnWayland()) QGuiApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); + + // We also need to manually set the path to the .desktop file, because Wayland's stupidity doesn't allow + // applications to set window icons, because GNOME circlejerkers think their iconless windows are superior. + // Even the Qt side of this is weird, thankfully we can give it an absolute path, just without the extension. + // To make matters even worse, setting the full path here doesn't work for Flatpaks... or anything outside of + // KDE. Setting the application name alone does for flatpak. What a clusterfuck of a platform for basic tasks + // that operating systems have done for decades. + if (getenv("container")) + { + // Flatpak. + QGuiApplication::setDesktopFileName(QStringLiteral("org.duckstation.DuckStation")); + } + else if (const char* current_desktop = getenv("XDG_CURRENT_DESKTOP"); + current_desktop && std::strstr(current_desktop, "KDE")) + { + // AppImage or local build. + QGuiApplication::setDesktopFileName( + QString::fromStdString(Path::Combine(EmuFolders::Resources, "org.duckstation.DuckStation"))); + } #endif // Config-based RAIntegration switch must happen before the main window is displayed.