Skip to content

Commit 0c84baf

Browse files
committed
Qt: Use portal file picker on KDE/GNOME
1 parent 9cc8b0e commit 0c84baf

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/duckstation-qt/qthost.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ static bool ParseCommandLineParametersAndInitializeConfig(QApplication& app,
146146
std::shared_ptr<SystemBootParameters>& boot_params);
147147

148148
#ifdef __linux__
149+
static void AdjustQtEnvironmentVariables();
149150
static 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+
342368
void QtHost::ApplyWaylandWorkarounds()
343369
{
344370
const QString platform_name = QGuiApplication::platformName();

0 commit comments

Comments
 (0)