From adaa59a39bce43217b925f5c81cd9eded46ef9dd Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 4 Jun 2019 15:31:09 +0300 Subject: [PATCH] (e4191497a) Workaround to changing resolution in fullscreen + force borderless windowed to display resolution --- .../BarotraumaClient/Source/GameMain.cs | 27 +++++++++++++++++-- .../BarotraumaClient/Source/GameSettings.cs | 16 ++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 0ce77a2bb..9a37a1f96 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -206,6 +206,21 @@ namespace Barotrauma private void ApplyGraphicsSettings() { +#if !OSX + if (Config.WindowMode == WindowMode.Fullscreen && + GraphicsDeviceManager.IsFullScreen && !GraphicsDeviceManager.HardwareModeSwitch && + (GraphicsDeviceManager.PreferredBackBufferWidth != Config.GraphicsWidth || + GraphicsDeviceManager.PreferredBackBufferHeight != Config.GraphicsHeight)) + { + DisplayMode minMode = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.First(m => m.Format == SurfaceFormat.Color); + GraphicsDeviceManager.PreferredBackBufferWidth = minMode.Width; + GraphicsDeviceManager.PreferredBackBufferHeight = minMode.Height; + GraphicsDeviceManager.IsFullScreen = false; + GraphicsDeviceManager.ApplyChanges(); + Thread.Sleep(100); + } +#endif + GraphicsWidth = Config.GraphicsWidth; GraphicsHeight = Config.GraphicsHeight; if (Config.WindowMode == WindowMode.BorderlessWindowed) @@ -213,6 +228,7 @@ namespace Barotrauma GraphicsWidth = GraphicsDevice.DisplayMode.Width; GraphicsHeight = GraphicsDevice.DisplayMode.Height; } + GraphicsDeviceManager.GraphicsProfile = GraphicsProfile.Reach; GraphicsDeviceManager.PreferredBackBufferFormat = SurfaceFormat.Color; GraphicsDeviceManager.PreferMultiSampling = false; @@ -318,8 +334,15 @@ namespace Barotrauma private void HandleDefocus(object sender, EventArgs e) { CoroutineManager.StopCoroutines("FocusCoroutine"); - GraphicsDeviceManager.IsFullScreen = false; - GraphicsDeviceManager.ApplyChanges(); + if (GraphicsDeviceManager.IsFullScreen && !GraphicsDeviceManager.HardwareModeSwitch) + { + DisplayMode minMode = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.First(m => m.Format == SurfaceFormat.Color); + GraphicsDeviceManager.PreferredBackBufferWidth = minMode.Width; + GraphicsDeviceManager.PreferredBackBufferHeight = minMode.Height; + GraphicsDeviceManager.IsFullScreen = false; + GraphicsDeviceManager.ApplyChanges(); + Thread.Sleep(100); + } } #endif diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index 5362e0d50..8b9ae6b9f 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -192,6 +192,7 @@ namespace Barotrauma foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) { if (supportedDisplayModes.Any(m => m.Width == mode.Width && m.Height == mode.Height)) { continue; } + if (mode.Width < MinSupportedResolution.X || mode.Height < MinSupportedResolution.Y) { continue; } #if OSX // Monogame currently doesn't support retina displays // so we need to disable resolutions above the viewport size. @@ -211,7 +212,6 @@ namespace Barotrauma foreach (DisplayMode mode in supportedDisplayModes) { - if (mode.Width < MinSupportedResolution.X || mode.Height < MinSupportedResolution.Y) { continue; } resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) resolutionDD.SelectItem(mode); } @@ -244,9 +244,17 @@ namespace Barotrauma { UnsavedSettings = true; GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; -#if !LINUX - resolutionDD.ButtonEnabled = GameMain.Config.WindowMode == WindowMode.Windowed; -#endif + if (GameMain.Config.WindowMode == WindowMode.BorderlessWindowed) + { + resolutionDD.SelectItem(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.First( + m => m.Width == GameMain.Instance.GraphicsDevice.DisplayMode.Width && + m.Height == GameMain.Instance.GraphicsDevice.DisplayMode.Height)); + resolutionDD.ButtonEnabled = false; + } + else + { + resolutionDD.ButtonEnabled = true; + } return true; };