@@ -146,6 +146,7 @@ static bool ParseCommandLineParametersAndInitializeConfig(QApplication& app,
146146 std::shared_ptr<SystemBootParameters>& boot_params);
147147
148148#ifdef __linux__
149+ static void AdjustQtEnvironmentVariables ();
149150static void ApplyWaylandWorkarounds ();
150151#endif
151152} // namespace QtHost
@@ -233,14 +234,16 @@ bool QtHost::VeryEarlyProcessStartup()
233234{
234235 CrashHandler::Install (&Bus::CleanupMemoryMap);
235236
236- #ifdef _WIN32
237+ #if defined( _WIN32)
237238 // Ensure COM is initialized before Qt gets a chance to do it, since this could change in the future.
238239 HRESULT hr = CoInitializeEx (NULL , COINIT_APARTMENTTHREADED);
239240 if (FAILED (hr)) [[unlikely]]
240241 {
241242 MessageBoxA (nullptr , fmt::format (" CoInitializeEx failed: 0x{:08X}" , hr).c_str (), " Error" , MB_ICONERROR);
242243 return false ;
243244 }
245+ #elif defined(__linux__)
246+ AdjustQtEnvironmentVariables ();
244247#endif
245248
246249 QGuiApplication::setHighDpiScaleFactorRoundingPolicy (Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
@@ -339,6 +342,29 @@ bool QtHost::IsDisplayWidgetContainerNeeded()
339342
340343#ifdef __linux__
341344
345+ void QtHost::AdjustQtEnvironmentVariables ()
346+ {
347+ const char * desktop = std::getenv (" XDG_SESSION_DESKTOP" );
348+ if (!desktop)
349+ return ;
350+
351+ std::fprintf (stderr, " XDG_SESSION_DESKTOP=%s\n " , desktop);
352+
353+ if (std::strcmp (desktop, " KDE" ) == 0 || std::strcmp (desktop, " GNOME" ) == 0 )
354+ {
355+ const char * platform_theme = std::getenv (" QT_QPA_PLATFORMTHEME" );
356+ if (platform_theme)
357+ {
358+ std::fprintf (stderr, " QT_QPA_PLATFORMTHEME=%s, not overridding\n " , platform_theme);
359+ }
360+ else
361+ {
362+ std::fputs (" Enabling xdg-desktop-portal platform theme.\n " , stderr);
363+ setenv (" QT_QPA_PLATFORMTHEME" , " xdgdesktopportal" , true );
364+ }
365+ }
366+ }
367+
342368void QtHost::ApplyWaylandWorkarounds ()
343369{
344370 const QString platform_name = QGuiApplication::platformName ();
0 commit comments