diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 5a572c463..cc3a5e69f 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using GameAnalyticsSDK.Net; +using System.Threading; namespace Barotrauma { @@ -74,7 +75,8 @@ namespace Barotrauma get; private set; } - + private static bool FullscreenOnTabIn; + public static WindowMode WindowMode { get; @@ -231,8 +233,37 @@ namespace Barotrauma TitleScreen = new LoadingScreen(GraphicsDevice); loadingCoroutine = CoroutineManager.StartCoroutine(Load()); + + var myForm = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(Window.Handle); + myForm.Deactivate += new EventHandler(HandleDefocus); + myForm.Activated += new EventHandler(HandleFocus); } + private void HandleDefocus(object sender, EventArgs e) + { + if (GraphicsDeviceManager.IsFullScreen && GraphicsDeviceManager.HardwareModeSwitch) + { + GraphicsDeviceManager.IsFullScreen = false; + GraphicsDeviceManager.ApplyChanges(); + FullscreenOnTabIn = true; + Thread.Sleep(500); + } + } + + private void HandleFocus(object sender, EventArgs e) + { + if (FullscreenOnTabIn) + { + GraphicsDeviceManager.HardwareModeSwitch = true; + GraphicsDeviceManager.IsFullScreen = true; + GraphicsDeviceManager.ApplyChanges(); + FullscreenOnTabIn = false; + Thread.Sleep(500); + } + } + + + private void InitUserStats() { if (GameSettings.ShowUserStatisticsPrompt)