Moved sleep mode prevention to separate method of IDisplayMonitor.
This commit is contained in:
parent
a8025ad2a1
commit
0dcbe9e5b6
6 changed files with 24 additions and 20 deletions
|
@ -18,11 +18,15 @@ namespace SafeExamBrowser.Contracts.Monitoring
|
||||||
event DisplayChangedEventHandler DisplayChanged;
|
event DisplayChangedEventHandler DisplayChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the desktop working area to accommodate to the taskbar's height, removes the configured wallpaper (if possible) and
|
/// Sets the desktop working area to accommodate to the taskbar's height and removes the configured wallpaper (if possible).
|
||||||
/// prevents the computer from entering sleep mode or turning its display(s) off.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void InitializePrimaryDisplay(int taskbarHeight);
|
void InitializePrimaryDisplay(int taskbarHeight);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevents the computer from entering sleep mode and turning its display(s) off.
|
||||||
|
/// </summary>
|
||||||
|
void PreventSleepMode();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets the desktop working area and wallpaper to their previous (initial) state.
|
/// Resets the desktop working area and wallpaper to their previous (initial) state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -38,11 +38,6 @@ namespace SafeExamBrowser.Contracts.WindowsApi
|
||||||
/// </exception>
|
/// </exception>
|
||||||
void DeregisterSystemEvent(IntPtr handle);
|
void DeregisterSystemEvent(IntPtr handle);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prevents Windows from entering sleep mode and keeps all displays powered on.
|
|
||||||
/// </summary>
|
|
||||||
void DisableSleep();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Empties the clipboard.
|
/// Empties the clipboard.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -115,6 +110,11 @@ namespace SafeExamBrowser.Contracts.WindowsApi
|
||||||
/// </exception>
|
/// </exception>
|
||||||
void PostCloseMessageToShell();
|
void PostCloseMessageToShell();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prevents Windows from entering sleep mode and keeps all displays powered on.
|
||||||
|
/// </summary>
|
||||||
|
void PreventSleepMode();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a system hook for the given keyboard interceptor.
|
/// Registers a system hook for the given keyboard interceptor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace SafeExamBrowser.Core.Behaviour.Operations
|
||||||
logger.Info("Initializing working area...");
|
logger.Info("Initializing working area...");
|
||||||
SplashScreen.UpdateText(TextKey.SplashScreen_InitializeWorkingArea);
|
SplashScreen.UpdateText(TextKey.SplashScreen_InitializeWorkingArea);
|
||||||
|
|
||||||
|
displayMonitor.PreventSleepMode();
|
||||||
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
||||||
displayMonitor.StartMonitoringDisplayChanges();
|
displayMonitor.StartMonitoringDisplayChanges();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,12 @@ namespace SafeExamBrowser.Monitoring.Display
|
||||||
{
|
{
|
||||||
InitializeWorkingArea(taskbarHeight);
|
InitializeWorkingArea(taskbarHeight);
|
||||||
InitializeWallpaper();
|
InitializeWallpaper();
|
||||||
PreventSleepMode();
|
}
|
||||||
|
|
||||||
|
public void PreventSleepMode()
|
||||||
|
{
|
||||||
|
nativeMethods.PreventSleepMode();
|
||||||
|
logger.Info("Disabled sleep mode and display timeout.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetPrimaryDisplay()
|
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()
|
private void ResetWorkingArea()
|
||||||
{
|
{
|
||||||
var identifier = GetIdentifierForPrimaryDisplay();
|
var identifier = GetIdentifierForPrimaryDisplay();
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace SafeExamBrowser.UserInterface
|
||||||
{
|
{
|
||||||
var height = (int) TransformToPhysical(Width, Height).Y;
|
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;
|
return height;
|
||||||
});
|
});
|
||||||
|
|
|
@ -94,11 +94,6 @@ namespace SafeExamBrowser.WindowsApi
|
||||||
EventDelegates.TryRemove(handle, out EventProc d);
|
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()
|
public void EmptyClipboard()
|
||||||
{
|
{
|
||||||
var success = true;
|
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)
|
public void RegisterKeyboardHook(IKeyboardInterceptor interceptor)
|
||||||
{
|
{
|
||||||
var hook = new KeyboardHook(interceptor);
|
var hook = new KeyboardHook(interceptor);
|
||||||
|
|
Loading…
Reference in a new issue