diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs index 293491fb..42eb024d 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/AudioControl.xaml.cs @@ -49,13 +49,39 @@ namespace SafeExamBrowser.UserInterface.Desktop.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 = false; + 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 = true; + } + }; + Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + 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_Light_NoDevice.xaml") }; - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; Volume.ValueChanged += Volume_ValueChanged; if (audio.HasOutputDevice) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index e43d7b5b..d9a5a85a 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -51,25 +51,36 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter LayoutsStackPanel.Children[0].Focus(); })); }; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; } private void Keyboard_LayoutChanged(IKeyboardLayout layout) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs index 47edeb73..099b0239 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/NetworkControl.xaml.cs @@ -45,23 +45,30 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { Grid.Background = Brushes.Gray; @@ -74,7 +81,11 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter } })); }; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; WirelessIcon.Child = GetWirelessIcon(0); Update(); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs index f5e6e1e2..5ed86791 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/ActionCenter/RaiseHandControl.xaml.cs @@ -55,17 +55,17 @@ 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); - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -76,9 +76,20 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.ActionCenter NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; Text.Text = 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 2341508d..2eafc925 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/AudioControl.xaml.cs @@ -48,17 +48,17 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -68,7 +68,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar 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") }; Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Volume.ValueChanged += Volume_ValueChanged; Popup.Opened += (o, args) => @@ -82,6 +89,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; if (audio.HasOutputDevice) diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index f8c1ea00..3f4cf0dc 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -54,24 +54,31 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); }))); }; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { @@ -83,6 +90,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; } diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs index b5f20e52..4cc6793b 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/NetworkControl.xaml.cs @@ -45,25 +45,32 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar var originalBrush = Button.Background; adapter.Changed += () => Dispatcher.InvokeAsync(Update); - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); WirelessIcon.Child = GetWirelessIcon(0); Popup.Opened += (o, args) => @@ -84,6 +91,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; Update(); diff --git a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs index 6db47fcd..01aeb2ac 100644 --- a/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Desktop/Controls/Taskbar/RaiseHandControl.xaml.cs @@ -55,17 +55,17 @@ 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); - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -76,7 +76,14 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { Background = Brushes.LightGray; @@ -86,6 +93,7 @@ namespace SafeExamBrowser.UserInterface.Desktop.Controls.Taskbar { Background = originalBrush; NotificationButton.Background = originalBrush; + lastOpenedBySpacePress = false; }; } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs index 14f33945..5df57574 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/AudioControl.xaml.cs @@ -49,17 +49,17 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -68,9 +68,20 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter 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") }; - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; Volume.ValueChanged += Volume_ValueChanged; if (audio.HasOutputDevice) diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs index c2244737..43912d1d 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/KeyboardLayoutControl.xaml.cs @@ -51,25 +51,36 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter LayoutsStackPanel.Children[0].Focus(); })); }; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; } private void Keyboard_LayoutChanged(IKeyboardLayout layout) diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs index 85da000e..349418b4 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/NetworkControl.xaml.cs @@ -45,23 +45,30 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { Grid.Background = Brushes.Gray; @@ -74,7 +81,11 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter } })); }; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; WirelessIcon.Child = GetWirelessIcon(0); Update(); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs index e7479b8d..b07add7f 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/ActionCenter/RaiseHandControl.xaml.cs @@ -55,17 +55,17 @@ 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); - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -76,9 +76,20 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.ActionCenter NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => Grid.Background = Brushes.Gray; - Popup.Closed += (o, args) => Grid.Background = originalBrush; + Popup.Closed += (o, args) => + { + Grid.Background = originalBrush; + lastOpenedBySpacePress = false; + }; Text.Text = 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 4ecc1938..ec1b72a8 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/AudioControl.xaml.cs @@ -48,17 +48,17 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar audio.VolumeChanged += Audio_VolumeChanged; Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -68,7 +68,14 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar 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") }; Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Volume.ValueChanged += Volume_ValueChanged; Popup.Opened += (o, args) => @@ -82,6 +89,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; if (audio.HasOutputDevice) diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs index e126ac50..5195ccf1 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/KeyboardLayoutControl.xaml.cs @@ -54,24 +54,31 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar ((LayoutsStackPanel.Children[0] as ContentControl).Content as UIElement).Focus(); }))); }; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { @@ -83,6 +90,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; } diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs index 284b67db..7b21a7e3 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/NetworkControl.xaml.cs @@ -46,24 +46,31 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar adapter.Changed += () => Dispatcher.InvokeAsync(Update); Button.Click += (o, args) => Popup.IsOpen = !Popup.IsOpen; - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; Button.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } Popup.IsOpen = Popup.IsMouseOver; })); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); WirelessIcon.Child = GetWirelessIcon(0); Popup.Opened += (o, args) => @@ -84,6 +91,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { Background = originalBrush; Button.Background = originalBrush; + lastOpenedBySpacePress = false; }; Update(); diff --git a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs index 79d2ae84..68772cb3 100644 --- a/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs +++ b/SafeExamBrowser.UserInterface.Mobile/Controls/Taskbar/RaiseHandControl.xaml.cs @@ -55,17 +55,17 @@ 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); - var lastOpenedBySpacePress = DateTime.MinValue; + var lastOpenedBySpacePress = false; 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; + lastOpenedBySpacePress = true; } }; NotificationButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => { - if (Popup.IsOpen && (DateTime.Now - lastOpenedBySpacePress).TotalSeconds < 3) + if (Popup.IsOpen && lastOpenedBySpacePress) { return; } @@ -76,7 +76,14 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar NotificationButton.ToolTip = text.Get(TextKey.Notification_ProctoringHandLowered); Popup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(Popup_PlacementCallback); - Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => Popup.IsOpen = IsMouseOver)); + Popup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => + { + if (Popup.IsOpen && lastOpenedBySpacePress) + { + return; + } + Popup.IsOpen = IsMouseOver; + })); Popup.Opened += (o, args) => { Background = Brushes.LightGray; @@ -87,6 +94,7 @@ namespace SafeExamBrowser.UserInterface.Mobile.Controls.Taskbar { Background = originalBrush; NotificationButton.Background = originalBrush; + lastOpenedBySpacePress = false; }; }