diff --git a/SafeExamBrowser.Contracts/Monitoring/IDisplayMonitor.cs b/SafeExamBrowser.Contracts/Monitoring/IDisplayMonitor.cs index 8bd33d26..d3a1bed8 100644 --- a/SafeExamBrowser.Contracts/Monitoring/IDisplayMonitor.cs +++ b/SafeExamBrowser.Contracts/Monitoring/IDisplayMonitor.cs @@ -18,11 +18,15 @@ namespace SafeExamBrowser.Contracts.Monitoring event DisplayChangedEventHandler DisplayChanged; /// - /// Sets the desktop working area to accommodate to the taskbar's height, removes the configured wallpaper (if possible) and - /// prevents the computer from entering sleep mode or turning its display(s) off. + /// Sets the desktop working area to accommodate to the taskbar's height and removes the configured wallpaper (if possible). /// void InitializePrimaryDisplay(int taskbarHeight); + /// + /// Prevents the computer from entering sleep mode and turning its display(s) off. + /// + void PreventSleepMode(); + /// /// Resets the desktop working area and wallpaper to their previous (initial) state. /// diff --git a/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs b/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs index f25a07f1..4ddb5d12 100644 --- a/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs +++ b/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs @@ -38,11 +38,6 @@ namespace SafeExamBrowser.Contracts.WindowsApi /// void DeregisterSystemEvent(IntPtr handle); - /// - /// Prevents Windows from entering sleep mode and keeps all displays powered on. - /// - void DisableSleep(); - /// /// Empties the clipboard. /// @@ -115,6 +110,11 @@ namespace SafeExamBrowser.Contracts.WindowsApi /// void PostCloseMessageToShell(); + /// + /// Prevents Windows from entering sleep mode and keeps all displays powered on. + /// + void PreventSleepMode(); + /// /// Registers a system hook for the given keyboard interceptor. /// diff --git a/SafeExamBrowser.Core/Behaviour/Operations/DisplayMonitorOperation.cs b/SafeExamBrowser.Core/Behaviour/Operations/DisplayMonitorOperation.cs index 8084ced5..d39e1d6d 100644 --- a/SafeExamBrowser.Core/Behaviour/Operations/DisplayMonitorOperation.cs +++ b/SafeExamBrowser.Core/Behaviour/Operations/DisplayMonitorOperation.cs @@ -34,6 +34,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations logger.Info("Initializing working area..."); SplashScreen.UpdateText(TextKey.SplashScreen_InitializeWorkingArea); + displayMonitor.PreventSleepMode(); displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight()); displayMonitor.StartMonitoringDisplayChanges(); } diff --git a/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs b/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs index 8f88a11e..5826c1dd 100644 --- a/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs +++ b/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs @@ -34,7 +34,12 @@ namespace SafeExamBrowser.Monitoring.Display { InitializeWorkingArea(taskbarHeight); InitializeWallpaper(); - PreventSleepMode(); + } + + public void PreventSleepMode() + { + nativeMethods.PreventSleepMode(); + logger.Info("Disabled sleep mode and display timeout."); } public void ResetPrimaryDisplay() @@ -94,12 +99,6 @@ namespace SafeExamBrowser.Monitoring.Display } } - private void PreventSleepMode() - { - nativeMethods.DisableSleep(); - logger.Info("Disabled sleep mode and display timeout."); - } - private void ResetWorkingArea() { var identifier = GetIdentifierForPrimaryDisplay(); diff --git a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs index e8d04c38..cf52f1c5 100644 --- a/SafeExamBrowser.UserInterface/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface/Taskbar.xaml.cs @@ -50,7 +50,7 @@ namespace SafeExamBrowser.UserInterface { var height = (int) TransformToPhysical(Width, Height).Y; - logger.Info($"Calculated absolute taskbar height is {height}px."); + logger.Info($"Calculated physical taskbar height is {height}px."); return height; }); diff --git a/SafeExamBrowser.WindowsApi/NativeMethods.cs b/SafeExamBrowser.WindowsApi/NativeMethods.cs index a5b03fd2..cbbfd741 100644 --- a/SafeExamBrowser.WindowsApi/NativeMethods.cs +++ b/SafeExamBrowser.WindowsApi/NativeMethods.cs @@ -94,11 +94,6 @@ namespace SafeExamBrowser.WindowsApi EventDelegates.TryRemove(handle, out EventProc d); } - public void DisableSleep() - { - Kernel32.SetThreadExecutionState(EXECUTION_STATE.CONTINUOUS | EXECUTION_STATE.DISPLAY_REQUIRED | EXECUTION_STATE.SYSTEM_REQUIRED); - } - public void EmptyClipboard() { var success = true; @@ -225,6 +220,11 @@ namespace SafeExamBrowser.WindowsApi } } + public void PreventSleepMode() + { + Kernel32.SetThreadExecutionState(EXECUTION_STATE.CONTINUOUS | EXECUTION_STATE.DISPLAY_REQUIRED | EXECUTION_STATE.SYSTEM_REQUIRED); + } + public void RegisterKeyboardHook(IKeyboardInterceptor interceptor) { var hook = new KeyboardHook(interceptor);