From 7b83a79d16a68d9abdd87200c708744c04c6b02f Mon Sep 17 00:00:00 2001 From: Collecting Date: Sun, 4 Jan 2026 20:40:02 +0000 Subject: [PATCH] fix(gamescope): Set High DPI AFTER GameScope construction Signed-off-by: Collecting --- src/citron/main.cpp | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/citron/main.cpp b/src/citron/main.cpp index a5513248e..55a9b23e9 100644 --- a/src/citron/main.cpp +++ b/src/citron/main.cpp @@ -6155,7 +6155,30 @@ static void SetHighDPIAttributes() { } int main(int argc, char* argv[]) { - // Set environment variables for AppImage compatibility + // 1. Detect Gamescope/Steam Deck hardware + const bool is_gamescope = qgetenv("XDG_CURRENT_DESKTOP") == "gamescope" || + !qgetenv("GAMESCOPE_WIDTH").isEmpty() || + !qgetenv("STEAM_DECK").isEmpty(); + + if (is_gamescope) { + // Kill the SteamOS scaling requests before they can bloat the UI + QGuiApplication::setDesktopSettingsAware(false); + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); + + // Force 1:1 pixel ratio + qputenv("QT_ENABLE_HIGHDPI_SCALING", "0"); + qputenv("QT_SCALE_FACTOR", "1"); + qputenv("QT_SCREEN_SCALE_FACTORS", "1"); + qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); + qputenv("QT_FONT_DPI", "96"); + + // Ensure Gamescope compositor handles Citron menus correctly + QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); + QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs); + qputenv("QT_WAYLAND_SHELL_INTEGRATION", "xdg-shell"); + } + + // 2. NOW setup AppImage environment const bool is_appimage = !qgetenv("APPIMAGE").isEmpty(); if (is_appimage) { qputenv("QT_WAYLAND_DISABLE_EXPLICIT_SYNC", "1"); @@ -6216,27 +6239,6 @@ int main(int argc, char* argv[]) { QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity); - // Gamescope/Steam Deck detection - const bool is_gamescope = qgetenv("XDG_CURRENT_DESKTOP") == "gamescope" || - !qgetenv("GAMESCOPE_WIDTH").isEmpty() || - !qgetenv("STEAM_DECK").isEmpty(); - - if (is_gamescope) { - // 1. Force the scale factor to exactly 1.0 - qputenv("QT_SCALE_FACTOR", "1"); - qputenv("QT_SCREEN_SCALE_FACTORS", "1"); - qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); - qputenv("QT_FONT_DPI", "96"); - - // 2. This must be called BEFORE the QApplication object is created - QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Floor); - - // 3. Ensure windowing system plays nice with Gamescope - QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar); - QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs); - qputenv("QT_WAYLAND_SHELL_INTEGRATION", "xdg-shell"); - } - QApplication app(argc, argv); #ifdef __linux__ if (QGuiApplication::platformName().startsWith(QStringLiteral("wayland"))) {