From 517ceaca4ee3b4c3b27ad13877a5c38bf2e2d7c6 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Tue, 19 Mar 2019 16:09:07 +0100 Subject: [PATCH] SEBWIN-117: Changed layout & positioning of the taskbar and action center (WPF caches the current working area but does not allow to manually reset the cache). Ensured that the wallpaper is only changed on Windows 7. --- SafeExamBrowser.Client/ClientController.cs | 6 +++-- SafeExamBrowser.Client/CompositionRoot.cs | 2 +- .../Operations/ShellOperation.cs | 1 + .../UserInterface/Shell/IActionCenter.cs | 5 +++++ .../UserInterface/Shell/ITaskbar.cs | 5 +++++ .../Display/DisplayMonitor.cs | 22 +++++++++++++------ .../Operations/KioskModeOperation.cs | 4 ++-- .../ActionCenter.xaml.cs | 9 +++++++- .../Taskbar.xaml.cs | 22 ++++++++++++++----- SafeExamBrowser.WindowsApi/NativeMethods.cs | 4 ++-- 10 files changed, 60 insertions(+), 20 deletions(-) diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 7d0aa1db..2bc2332c 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -323,8 +323,9 @@ namespace SafeExamBrowser.Client { logger.Info("Reinitializing working area..."); displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight()); - logger.Info("Reinitializing taskbar bounds..."); + logger.Info("Reinitializing shell..."); taskbar.InitializeBounds(); + actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); logger.Info("Desktop successfully restored."); } @@ -367,8 +368,9 @@ namespace SafeExamBrowser.Client explorerShell.Terminate(); logger.Info("Reinitializing working area..."); displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight()); - logger.Info("Reinitializing taskbar bounds..."); + logger.Info("Reinitializing shell..."); taskbar.InitializeBounds(); + actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); logger.Info("Desktop successfully restored."); } diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index da324432..5bc839b1 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -98,7 +98,7 @@ namespace SafeExamBrowser.Client windowMonitor = new WindowMonitor(new ModuleLogger(logger, nameof(WindowMonitor)), nativeMethods); wirelessNetwork = new WirelessNetwork(new ModuleLogger(logger, nameof(WirelessNetwork)), text); - var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, nameof(DisplayMonitor)), nativeMethods); + var displayMonitor = new DisplayMonitor(new ModuleLogger(logger, nameof(DisplayMonitor)), nativeMethods, systemInfo); var explorerShell = new ExplorerShell(new ModuleLogger(logger, nameof(ExplorerShell)), nativeMethods); var hashAlgorithm = new HashAlgorithm(); diff --git a/SafeExamBrowser.Client/Operations/ShellOperation.cs b/SafeExamBrowser.Client/Operations/ShellOperation.cs index 79f6ac56..745d68ab 100644 --- a/SafeExamBrowser.Client/Operations/ShellOperation.cs +++ b/SafeExamBrowser.Client/Operations/ShellOperation.cs @@ -106,6 +106,7 @@ namespace SafeExamBrowser.Client.Operations { logger.Info("Initializing action center..."); actionCenter.InitializeText(text); + actionCenter.UpdateTaskbarHeight(taskbar.GetRelativeHeight()); InitializeAboutNotificationForActionCenter(); InitializeClockForActionCenter(); diff --git a/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs b/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs index a7caa1ca..778a5f61 100644 --- a/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Shell/IActionCenter.cs @@ -61,6 +61,11 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell /// void Register(IActionCenterActivator activator); + /// + /// Informs the action center about the relative height (i.e. height in logical pixels) of the taskbar. + /// + void UpdateTaskbarHeight(int height); + /// /// Makes the action center visible. /// diff --git a/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs b/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs index ace8cd4c..df736c3a 100644 --- a/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs +++ b/SafeExamBrowser.Contracts/UserInterface/Shell/ITaskbar.cs @@ -51,6 +51,11 @@ namespace SafeExamBrowser.Contracts.UserInterface.Shell /// int GetAbsoluteHeight(); + /// + /// Returns the relative height of the taskbar (i.e. in logical pixels). + /// + int GetRelativeHeight(); + /// /// Moves the taskbar to the bottom of and resizes it according to the current working area. /// diff --git a/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs b/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs index 25082172..decd5b15 100644 --- a/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs +++ b/SafeExamBrowser.Monitoring/Display/DisplayMonitor.cs @@ -12,7 +12,9 @@ using Microsoft.Win32; using SafeExamBrowser.Contracts.Logging; using SafeExamBrowser.Contracts.Monitoring; using SafeExamBrowser.Contracts.Monitoring.Events; +using SafeExamBrowser.Contracts.SystemComponents; using SafeExamBrowser.Contracts.WindowsApi; +using OperatingSystem = SafeExamBrowser.Contracts.SystemComponents.OperatingSystem; namespace SafeExamBrowser.Monitoring.Display { @@ -21,14 +23,16 @@ namespace SafeExamBrowser.Monitoring.Display private IBounds originalWorkingArea; private ILogger logger; private INativeMethods nativeMethods; + private ISystemInfo systemInfo; private string wallpaper; public event DisplayChangedEventHandler DisplayChanged; - public DisplayMonitor(ILogger logger, INativeMethods nativeMethods) + public DisplayMonitor(ILogger logger, INativeMethods nativeMethods, ISystemInfo systemInfo) { this.logger = logger; this.nativeMethods = nativeMethods; + this.systemInfo = systemInfo; } public void InitializePrimaryDisplay(int taskbarHeight) @@ -89,12 +93,16 @@ namespace SafeExamBrowser.Monitoring.Display private void InitializeWallpaper() { - var path = nativeMethods.GetWallpaperPath(); - - if (!String.IsNullOrEmpty(path)) + if (systemInfo.OperatingSystem == OperatingSystem.Windows7) { - wallpaper = path; - logger.Info($"Saved wallpaper image: {wallpaper}."); + var path = nativeMethods.GetWallpaperPath(); + + if (!String.IsNullOrEmpty(path)) + { + wallpaper = path; + logger.Info($"Saved wallpaper image: {wallpaper}."); + } + nativeMethods.RemoveWallpaper(); logger.Info("Removed current wallpaper."); } @@ -117,7 +125,7 @@ namespace SafeExamBrowser.Monitoring.Display private void ResetWallpaper() { - if (!String.IsNullOrEmpty(wallpaper)) + if (systemInfo.OperatingSystem == OperatingSystem.Windows7 && !String.IsNullOrEmpty(wallpaper)) { nativeMethods.SetWallpaper(wallpaper); logger.Info($"Restored wallpaper image: {wallpaper}."); diff --git a/SafeExamBrowser.Runtime/Operations/KioskModeOperation.cs b/SafeExamBrowser.Runtime/Operations/KioskModeOperation.cs index 36938d51..a18be553 100644 --- a/SafeExamBrowser.Runtime/Operations/KioskModeOperation.cs +++ b/SafeExamBrowser.Runtime/Operations/KioskModeOperation.cs @@ -134,7 +134,7 @@ namespace SafeExamBrowser.Runtime.Operations } else { - logger.Warn($"No original desktop found when attempting to close new desktop!"); + logger.Warn($"No original desktop found to activate!"); } if (NewDesktop != null) @@ -144,7 +144,7 @@ namespace SafeExamBrowser.Runtime.Operations } else { - logger.Warn($"No new desktop found when attempting to close new desktop!"); + logger.Warn($"No new desktop found to close!"); } explorerShell.Resume(); diff --git a/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs index b0530eb3..edf25954 100644 --- a/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/ActionCenter.xaml.cs @@ -17,6 +17,8 @@ namespace SafeExamBrowser.UserInterface.Desktop { public partial class ActionCenter : Window, IActionCenter { + private int taskbarHeight = 40; + public bool ShowClock { set { Dispatcher.Invoke(() => Clock.Visibility = value ? Visibility.Visible : Visibility.Collapsed); } @@ -82,6 +84,11 @@ namespace SafeExamBrowser.UserInterface.Desktop Dispatcher.Invoke(ShowAnimated); } + public void UpdateTaskbarHeight(int height) + { + taskbarHeight = height; + } + private void HideAnimated() { var storyboard = new Storyboard(); @@ -125,7 +132,7 @@ namespace SafeExamBrowser.UserInterface.Desktop private void InitializeBounds() { - Height = SystemParameters.WorkArea.Height; + Height = SystemParameters.PrimaryScreenHeight - taskbarHeight; Top = 0; Left = -Width; } diff --git a/SafeExamBrowser.UserInterface.Desktop/Taskbar.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Taskbar.xaml.cs index 2c59624e..24deb9c7 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Taskbar.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Taskbar.xaml.cs @@ -71,7 +71,19 @@ namespace SafeExamBrowser.UserInterface.Desktop { var height = (int) this.TransformToPhysical(Width, Height).Y; - logger.Info($"Calculated physical taskbar height is {height}px."); + logger.Debug($"Calculated physical taskbar height is {height}px."); + + return height; + }); + } + + public int GetRelativeHeight() + { + return Dispatcher.Invoke(() => + { + var height = (int) Height; + + logger.Debug($"Logical taskbar height is {height}px."); return height; }); @@ -81,14 +93,14 @@ namespace SafeExamBrowser.UserInterface.Desktop { Dispatcher.Invoke(() => { - Width = SystemParameters.WorkArea.Right; - Left = SystemParameters.WorkArea.Right - Width; - Top = SystemParameters.WorkArea.Bottom; + Width = SystemParameters.PrimaryScreenWidth; + Left = 0; + Top = SystemParameters.PrimaryScreenHeight - Height; var position = this.TransformToPhysical(Left, Top); var size = this.TransformToPhysical(Width, Height); - logger.Info($"Set taskbar bounds to {Width}x{Height} at ({Left}/{Top}), in physical pixels: {size.X}x{size.Y} at ({position.X}/{position.Y})."); + logger.Debug($"Set taskbar bounds to {Width}x{Height} at ({Left}/{Top}), in physical pixels: {size.X}x{size.Y} at ({position.X}/{position.Y})."); }); } diff --git a/SafeExamBrowser.WindowsApi/NativeMethods.cs b/SafeExamBrowser.WindowsApi/NativeMethods.cs index 5b65da41..eacdb8ac 100644 --- a/SafeExamBrowser.WindowsApi/NativeMethods.cs +++ b/SafeExamBrowser.WindowsApi/NativeMethods.cs @@ -359,7 +359,7 @@ namespace SafeExamBrowser.WindowsApi public void SetWallpaper(string filePath) { - var success = User32.SystemParametersInfo(SPI.SETDESKWALLPAPER, 0, filePath, SPIF.UPDATEANDCHANGE); + var success = User32.SystemParametersInfo(SPI.SETDESKWALLPAPER, 0, filePath, SPIF.NONE); if (!success) { @@ -370,7 +370,7 @@ namespace SafeExamBrowser.WindowsApi public void SetWorkingArea(IBounds bounds) { var workingArea = new RECT { Left = bounds.Left, Top = bounds.Top, Right = bounds.Right, Bottom = bounds.Bottom }; - var success = User32.SystemParametersInfo(SPI.SETWORKAREA, 0, ref workingArea, SPIF.UPDATEINIFILE); + var success = User32.SystemParametersInfo(SPI.SETWORKAREA, 0, ref workingArea, SPIF.NONE); if (!success) {