From b0804ce048af2d6c9a7cd387325858cccd1b8658 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 16 Aug 2022 00:25:49 -0500 Subject: [PATCH] Fix native resolution detection on high DPI wayland systems --- app/backend/systemproperties.cpp | 2 +- app/streaming/session.cpp | 2 +- app/streaming/streamutils.cpp | 27 +++++++++++++++++++++------ app/streaming/streamutils.h | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/backend/systemproperties.cpp b/app/backend/systemproperties.cpp index 6af5da5d..bd64c9d8 100644 --- a/app/backend/systemproperties.cpp +++ b/app/backend/systemproperties.cpp @@ -221,7 +221,7 @@ void SystemProperties::refreshDisplaysInternal() SDL_GetError()); } - if (StreamUtils::getRealDesktopMode(displayIndex, &desktopMode)) { + if (StreamUtils::getNativeDesktopMode(displayIndex, &desktopMode)) { if (desktopMode.w <= 8192 && desktopMode.h <= 8192) { monitorNativeResolutions.insert(displayIndex, QRect(0, 0, desktopMode.w, desktopMode.h)); } diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index cc057877..fc4d29cb 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -986,7 +986,7 @@ void Session::updateOptimalWindowDisplayMode() // If this doesn't fit the selected resolution, use the native // resolution of the panel (unscaled). if (desktopMode.w < m_ActiveVideoWidth || desktopMode.h < m_ActiveVideoHeight) { - if (!StreamUtils::getRealDesktopMode(displayIndex, &desktopMode)) { + if (!StreamUtils::getNativeDesktopMode(displayIndex, &desktopMode)) { return; } } diff --git a/app/streaming/streamutils.cpp b/app/streaming/streamutils.cpp index c38eddbd..01889f66 100644 --- a/app/streaming/streamutils.cpp +++ b/app/streaming/streamutils.cpp @@ -94,7 +94,7 @@ int StreamUtils::getDisplayRefreshRate(SDL_Window* window) return mode.refresh_rate; } -bool StreamUtils::getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode) +bool StreamUtils::getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode) { #ifdef Q_OS_DARWIN #define MAX_DISPLAYS 16 @@ -138,11 +138,26 @@ bool StreamUtils::getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode) } } #else - if (SDL_GetDesktopDisplayMode(displayIndex, mode) != 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "SDL_GetDesktopDisplayMode() failed: %s", - SDL_GetError()); - return false; + // We need to get the true display resolution without DPI scaling (since we use High DPI). + // Windows returns the real display resolution here, even if DPI scaling is enabled. + // macOS and Wayland report a resolution that includes the DPI scaling factor. Picking + // the first mode on Wayland will get the native resolution without the scaling factor + // (and macOS is handled in the #ifdef above). + if (!strcmp(SDL_GetCurrentVideoDriver(), "wayland")) { + if (SDL_GetDisplayMode(displayIndex, 0, mode) != 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "SDL_GetDisplayMode() failed: %s", + SDL_GetError()); + return false; + } + } + else { + if (SDL_GetDesktopDisplayMode(displayIndex, mode) != 0) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "SDL_GetDesktopDisplayMode() failed: %s", + SDL_GetError()); + return false; + } } #endif diff --git a/app/streaming/streamutils.h b/app/streaming/streamutils.h index d4d72a6b..3567b829 100644 --- a/app/streaming/streamutils.h +++ b/app/streaming/streamutils.h @@ -29,7 +29,7 @@ public: void screenSpaceToNormalizedDeviceCoords(SDL_Rect* src, SDL_FRect* dst, int viewportWidth, int viewportHeight); static - bool getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode); + bool getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode); static int getDisplayRefreshRate(SDL_Window* window);