(e4191497a) Workaround to changing resolution in fullscreen + force borderless windowed to display resolution

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:01:31 +03:00
parent a1e558d14a
commit 6ffe13b4b7
2 changed files with 31 additions and 18 deletions
+10 -14
View File
@@ -207,18 +207,6 @@ namespace Barotrauma
#endif #endif
} }
private void ApplyGraphicsSettings()
{
#if WINDOWS
if (WindowActive)
{
#endif
ApplyGraphicsSettings();
#if WINDOWS
}
#endif
}
private void ApplyGraphicsSettings() private void ApplyGraphicsSettings()
{ {
#if !OSX #if !OSX
@@ -243,6 +231,7 @@ namespace Barotrauma
GraphicsWidth = GraphicsDevice.DisplayMode.Width; GraphicsWidth = GraphicsDevice.DisplayMode.Width;
GraphicsHeight = GraphicsDevice.DisplayMode.Height; GraphicsHeight = GraphicsDevice.DisplayMode.Height;
} }
GraphicsDeviceManager.GraphicsProfile = GraphicsProfile.Reach; GraphicsDeviceManager.GraphicsProfile = GraphicsProfile.Reach;
GraphicsDeviceManager.PreferredBackBufferFormat = SurfaceFormat.Color; GraphicsDeviceManager.PreferredBackBufferFormat = SurfaceFormat.Color;
GraphicsDeviceManager.PreferMultiSampling = false; GraphicsDeviceManager.PreferMultiSampling = false;
@@ -348,8 +337,15 @@ namespace Barotrauma
private void HandleDefocus(object sender, EventArgs e) private void HandleDefocus(object sender, EventArgs e)
{ {
CoroutineManager.StopCoroutines("FocusCoroutine"); CoroutineManager.StopCoroutines("FocusCoroutine");
GraphicsDeviceManager.IsFullScreen = false; if (GraphicsDeviceManager.IsFullScreen && !GraphicsDeviceManager.HardwareModeSwitch)
GraphicsDeviceManager.ApplyChanges(); {
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 #endif
@@ -192,6 +192,7 @@ namespace Barotrauma
foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes)
{ {
if (supportedDisplayModes.Any(m => m.Width == mode.Width && m.Height == mode.Height)) { continue; } 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 #if OSX
// Monogame currently doesn't support retina displays // Monogame currently doesn't support retina displays
// so we need to disable resolutions above the viewport size. // so we need to disable resolutions above the viewport size.
@@ -211,7 +212,6 @@ namespace Barotrauma
foreach (DisplayMode mode in supportedDisplayModes) foreach (DisplayMode mode in supportedDisplayModes)
{ {
if (mode.Width < MinSupportedResolution.X || mode.Height < MinSupportedResolution.Y) { continue; }
resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode);
if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) resolutionDD.SelectItem(mode); if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) resolutionDD.SelectItem(mode);
} }
@@ -248,15 +248,32 @@ namespace Barotrauma
{ {
displayModeDD.SelectItem(GameMain.Config.WindowMode); displayModeDD.SelectItem(GameMain.Config.WindowMode);
} }
#endif
displayModeDD.OnSelected = (guiComponent, obj) =>
{
displayModeDD.SelectItem(WindowMode.Fullscreen);
}
else
{
displayModeDD.SelectItem(GameMain.Config.WindowMode);
}
#endif #endif
displayModeDD.OnSelected = (guiComponent, obj) => displayModeDD.OnSelected = (guiComponent, obj) =>
{ {
PauseOnFocusLost = tickBox.Selected; PauseOnFocusLost = tickBox.Selected;
UnsavedSettings = true; UnsavedSettings = true;
GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData; GameMain.Config.WindowMode = (WindowMode)guiComponent.UserData;
#if !LINUX if (GameMain.Config.WindowMode == WindowMode.BorderlessWindowed)
resolutionDD.ButtonEnabled = GameMain.Config.WindowMode == WindowMode.Windowed; {
#endif 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; return true;
}; };