From 31f5c75a9043b5378636c67bd761a8d305666803 Mon Sep 17 00:00:00 2001 From: Jonas Sourlier Date: Mon, 13 Feb 2023 13:39:53 +0100 Subject: [PATCH] fix popups space bar problem --- .../ActionCenter/KeyboardLayoutControl.xaml.cs | 18 +++++++++++++++++- .../ActionCenter/NetworkControl.xaml.cs | 17 ++++++++++++++++- .../ActionCenter/RaiseHandControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/AudioControl.xaml.cs | 17 ++++++++++++++++- .../Taskbar/KeyboardLayoutControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/NetworkControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/RaiseHandControl.xaml.cs | 17 ++++++++++++++++- .../Controls/ActionCenter/AudioControl.xaml.cs | 17 ++++++++++++++++- .../ActionCenter/KeyboardLayoutControl.xaml.cs | 18 +++++++++++++++++- .../ActionCenter/NetworkControl.xaml.cs | 17 ++++++++++++++++- .../ActionCenter/RaiseHandControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/AudioControl.xaml.cs | 17 ++++++++++++++++- .../Taskbar/KeyboardLayoutControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/NetworkControl.xaml.cs | 17 ++++++++++++++++- .../Controls/Taskbar/RaiseHandControl.xaml.cs | 17 ++++++++++++++++- 15 files changed, 242 insertions(+), 15 deletions(-) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index 6cb01f68..e43d7b5b 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Threading.Tasks; using System.Windows.Automation; using System.Windows.Controls; @@ -50,7 +51,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter LayoutsStackPanel.Children[0].Focus(); })); }; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs index d9f91158..d50efecd 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs @@ -45,7 +45,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs index 2f8d4aa0..f5e6e1e2 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs @@ -55,7 +55,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter RaisedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Hand_Raised.xaml") }; Icon.Content = IconResourceLoader.Load(LoweredIcon); - NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + NotificationButton.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); NotificationButton.PreviewMouseLeftButtonUp += NotificationButton_PreviewMouseLeftButtonUp; NotificationButton.PreviewMouseRightButtonUp += NotificationButton_PreviewMouseRightButtonUp; NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs index 8ca165dd..2341508d 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs @@ -48,7 +48,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); MuteButton.Click += MuteButton_Click; MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_Muted.xaml") }; NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Audio_NoDevice.xaml") }; diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index 145d5d0e..f8c1ea00 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -54,7 +54,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); }))); }; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs index a38ce91c..0cbbce48 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs @@ -45,8 +45,23 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar var originalBrush = Button.Background; adapter.Changed += () => Dispatcher.InvokeAsync(Update); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); WirelessIcon.Child = GetWirelessIcon(0); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs index 774cca6e..6db47fcd 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs @@ -55,7 +55,22 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar RaisedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Hand_Raised.xaml") }; Icon.Content = IconResourceLoader.Load(LoweredIcon); - NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + NotificationButton.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); NotificationButton.PreviewMouseLeftButtonUp += NotificationButton_PreviewMouseLeftButtonUp; NotificationButton.PreviewMouseRightButtonUp += NotificationButton_PreviewMouseRightButtonUp; NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs index 13806e13..14f33945 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs @@ -49,7 +49,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); MuteButton.Click += MuteButton_Click; MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Light_NoDevice.xaml") }; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index deb405b7..c2244737 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +using System; using System.Threading.Tasks; using System.Windows.Automation; using System.Windows.Controls; @@ -50,7 +51,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter LayoutsStackPanel.Children[0].Focus(); })); }; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs index 15b4004f..5d1881fd 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs @@ -45,7 +45,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; Popup.Closed += (o, args) => Grid.Background = originalBrush; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs index f7f22918..e7479b8d 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs @@ -55,7 +55,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter RaisedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Hand_Raised.xaml") }; Icon.Content = IconResourceLoader.Load(LoweredIcon); - NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + NotificationButton.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); NotificationButton.PreviewMouseLeftButtonUp += NotificationButton_PreviewMouseLeftButtonUp; NotificationButton.PreviewMouseRightButtonUp += NotificationButton_PreviewMouseRightButtonUp; NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs index 56aa2475..4ecc1938 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs @@ -48,7 +48,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); MuteButton.Click += MuteButton_Click; MutedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_Muted.xaml") }; NoDeviceIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Mobile;component/Images/Audio_NoDevice.xaml") }; diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index dc5250d1..e126ac50 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -54,7 +54,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); }))); }; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs index b6bf3067..cdb47c27 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs @@ -46,7 +46,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + Button.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); WirelessIcon.Child = GetWirelessIcon(0); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs index 0c3c0690..79d2ae84 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs @@ -55,7 +55,22 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar RaisedIcon = new XamlIconResource { Uri = new Uri("pack://application:,,,/SafeExamBrowser.UserInterface.Desktop;component/Images/Hand_Raised.xaml") }; Icon.Content = IconResourceLoader.Load(LoweredIcon); - NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = Popup.IsMouseOver)); + var lastOpenedBySpacePress = DateTime.MinValue; + NotificationButton.PreviewKeyDown += (o, args) => + { + if (args.Key == System.Windows.Input.Key.Space) // for some reason, the popup immediately closes again if opened by a Space Bar key event - as a mitigation, we record the space bar event and leave the popup open for at least 3 seconds + { + lastOpenedBySpacePress = DateTime.Now; + } + }; + NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + { + return; + } + Popup.IsOpen = Popup.IsMouseOver; + })); NotificationButton.PreviewMouseLeftButtonUp += NotificationButton_PreviewMouseLeftButtonUp; NotificationButton.PreviewMouseRightButtonUp += NotificationButton_PreviewMouseRightButtonUp; NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered);