From e5dc0309f17321b9080e8d08206d598c0ebdc089 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 31 May 2020 15:57:33 +0100 Subject: [PATCH] Support OPENRA_DISPLAY_SCALE environment variable on Windows. --- OpenRA.Platforms.Default/Sdl2PlatformWindow.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs index 467f60bc10..9f143f4acd 100644 --- a/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs +++ b/OpenRA.Platforms.Default/Sdl2PlatformWindow.cs @@ -176,15 +176,19 @@ namespace OpenRA.Platforms.Default // This is not necessary on macOS, which defines window sizes in effective units ("points"). if (Platform.CurrentPlatform == PlatformType.Windows) { - if (SDL.SDL_GetDisplayDPI(videoDisplay, out var ddpi, out _, out _) == 0) - windowScale = ddpi / 96; + // Launch the game with OPENRA_DISPLAY_SCALE to force a specific scaling factor + // Otherwise fall back to Windows's DPI configuration + var scaleVariable = Environment.GetEnvironmentVariable("OPENRA_DISPLAY_SCALE"); + if (scaleVariable == null || !float.TryParse(scaleVariable, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out windowScale) || windowScale <= 0) + if (SDL.SDL_GetDisplayDPI(videoDisplay, out var ddpi, out _, out _) == 0) + windowScale = ddpi / 96; } - else if (Platform.CurrentPlatform != PlatformType.OSX) + else if (Platform.CurrentPlatform == PlatformType.Linux) { // Launch the game with OPENRA_DISPLAY_SCALE to force a specific scaling factor // Otherwise fall back to GDK_SCALE or parsing the x11 DPI configuration var scaleVariable = Environment.GetEnvironmentVariable("OPENRA_DISPLAY_SCALE") ?? Environment.GetEnvironmentVariable("GDK_SCALE"); - if (scaleVariable == null || !float.TryParse(scaleVariable, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out windowScale)) + if (scaleVariable == null || !float.TryParse(scaleVariable, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out windowScale) || windowScale <= 0) { // Attempt to automatically detect DPI try