Moved sleep mode prevention to separate method of IDisplayMonitor.

This commit is contained in:
dbuechel 2017-08-11 11:16:44 +02:00
parent a8025ad2a1
commit 0dcbe9e5b6
6 changed files with 24 additions and 20 deletions

View file

@ -18,11 +18,15 @@ namespace SafeExamBrowser.Contracts.Monitoring
event DisplayChangedEventHandler DisplayChanged;
/// <summary>
/// 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).
/// </summary>
void InitializePrimaryDisplay(int taskbarHeight);
/// <summary>
/// Prevents the computer from entering sleep mode and turning its display(s) off.
/// </summary>
void PreventSleepMode();
/// <summary>
/// Resets the desktop working area and wallpaper to their previous (initial) state.
/// </summary>

View file

@ -38,11 +38,6 @@ namespace SafeExamBrowser.Contracts.WindowsApi
/// </exception>
void DeregisterSystemEvent(IntPtr handle);
/// <summary>
/// Prevents Windows from entering sleep mode and keeps all displays powered on.
/// </summary>
void DisableSleep();
/// <summary>
/// Empties the clipboard.
/// </summary>
@ -115,6 +110,11 @@ namespace SafeExamBrowser.Contracts.WindowsApi
/// </exception>
void PostCloseMessageToShell();
/// <summary>
/// Prevents Windows from entering sleep mode and keeps all displays powered on.
/// </summary>
void PreventSleepMode();
/// <summary>
/// Registers a system hook for the given keyboard interceptor.
/// </summary>

View file

@ -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();
}

View file

@ -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();

View file

@ -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;
});

View file

@ -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);