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.
wip5
Stenzek 2 weeks ago
parent 0c30acb285
commit 9a75af2fa9
No known key found for this signature in database

@ -228,4 +228,15 @@ function(add_core_resources target)
endif()
install(DIRECTORY "$<TARGET_FILE_DIR:${target}>/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()

@ -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.

Loading…
Cancel
Save