Fix native resolution detection on high DPI wayland systems

This commit is contained in:
Cameron Gutman 2022-08-16 00:25:49 -05:00
parent aa7d5fa924
commit b0804ce048
4 changed files with 24 additions and 9 deletions

View File

@ -221,7 +221,7 @@ void SystemProperties::refreshDisplaysInternal()
SDL_GetError()); SDL_GetError());
} }
if (StreamUtils::getRealDesktopMode(displayIndex, &desktopMode)) { if (StreamUtils::getNativeDesktopMode(displayIndex, &desktopMode)) {
if (desktopMode.w <= 8192 && desktopMode.h <= 8192) { if (desktopMode.w <= 8192 && desktopMode.h <= 8192) {
monitorNativeResolutions.insert(displayIndex, QRect(0, 0, desktopMode.w, desktopMode.h)); monitorNativeResolutions.insert(displayIndex, QRect(0, 0, desktopMode.w, desktopMode.h));
} }

View File

@ -986,7 +986,7 @@ void Session::updateOptimalWindowDisplayMode()
// If this doesn't fit the selected resolution, use the native // If this doesn't fit the selected resolution, use the native
// resolution of the panel (unscaled). // resolution of the panel (unscaled).
if (desktopMode.w < m_ActiveVideoWidth || desktopMode.h < m_ActiveVideoHeight) { if (desktopMode.w < m_ActiveVideoWidth || desktopMode.h < m_ActiveVideoHeight) {
if (!StreamUtils::getRealDesktopMode(displayIndex, &desktopMode)) { if (!StreamUtils::getNativeDesktopMode(displayIndex, &desktopMode)) {
return; return;
} }
} }

View File

@ -94,7 +94,7 @@ int StreamUtils::getDisplayRefreshRate(SDL_Window* window)
return mode.refresh_rate; return mode.refresh_rate;
} }
bool StreamUtils::getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode) bool StreamUtils::getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode)
{ {
#ifdef Q_OS_DARWIN #ifdef Q_OS_DARWIN
#define MAX_DISPLAYS 16 #define MAX_DISPLAYS 16
@ -138,12 +138,27 @@ bool StreamUtils::getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode)
} }
} }
#else #else
// 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) { if (SDL_GetDesktopDisplayMode(displayIndex, mode) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_GetDesktopDisplayMode() failed: %s", "SDL_GetDesktopDisplayMode() failed: %s",
SDL_GetError()); SDL_GetError());
return false; return false;
} }
}
#endif #endif
return true; return true;

View File

@ -29,7 +29,7 @@ public:
void screenSpaceToNormalizedDeviceCoords(SDL_Rect* src, SDL_FRect* dst, int viewportWidth, int viewportHeight); void screenSpaceToNormalizedDeviceCoords(SDL_Rect* src, SDL_FRect* dst, int viewportWidth, int viewportHeight);
static static
bool getRealDesktopMode(int displayIndex, SDL_DisplayMode* mode); bool getNativeDesktopMode(int displayIndex, SDL_DisplayMode* mode);
static static
int getDisplayRefreshRate(SDL_Window* window); int getDisplayRefreshRate(SDL_Window* window);