diff --git a/RetroBar/App.xaml.cs b/RetroBar/App.xaml.cs index 76290d29..f2332523 100644 --- a/RetroBar/App.xaml.cs +++ b/RetroBar/App.xaml.cs @@ -12,6 +12,8 @@ using System.Reflection; using ManagedShell.Common.Logging; using System.Linq; +using System.Windows.Controls; +using System.Windows.Input; namespace RetroBar { @@ -57,11 +59,39 @@ private void App_OnStartup(object sender, StartupEventArgs e) RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; } + EventManager.RegisterClassHandler(typeof(ContextMenu), ContextMenu.OpenedEvent, new RoutedEventHandler(MenuOpened)); + EventManager.RegisterClassHandler(typeof(ContextMenu), UIElement.KeyDownEvent, new KeyEventHandler(MenuOnKeyDown)); + EventManager.RegisterClassHandler(typeof(MenuItem), MenuItem.ClickEvent, new RoutedEventHandler(MenuItemClicked)); + EventManager.RegisterClassHandler(typeof(MenuItem), MenuItem.SubmenuOpenedEvent, new RoutedEventHandler(MenuOpened)); _dictionaryManager.SetLanguageFromSettings(); loadTheme(); _windowManager = new WindowManager(_dictionaryManager, _explorerMonitor, _shellManager, _startMenuMonitor, _updater, _hotkeyManager); } + private void MenuOpened(object sender, RoutedEventArgs e) + { + SoundHelper.PlaySystemSound("MenuPopup"); + } + + private void MenuItemClicked(object sender, RoutedEventArgs e) + { + if (sender is MenuItem menuItem && menuItem.StaysOpenOnClick) + { + return; + } + + SoundHelper.PlaySystemSound("MenuCommand"); + } + + private void MenuOnKeyDown(object sender, KeyEventArgs e) + { + // don't close if alt is pressed + if (e.SystemKey is Key.LeftAlt or Key.RightAlt) + { + e.Handled = true; + } + } + private void App_OnExit(object sender, ExitEventArgs e) { ExitApp(); diff --git a/RetroBar/Controls/TaskButton.xaml b/RetroBar/Controls/TaskButton.xaml index d5dce3a6..d076332e 100644 --- a/RetroBar/Controls/TaskButton.xaml +++ b/RetroBar/Controls/TaskButton.xaml @@ -20,7 +20,8 @@ ContextMenuOpening="AppButton_OnContextMenuOpening" DragEnter="AppButton_OnDragEnter" DragLeave="AppButton_OnDragLeave" - ToolTipService.ShowDuration="60000"> + ToolTipService.ShowDuration="60000" + ContextMenu="{StaticResource TaskButtonContextMenu}"> @@ -44,58 +45,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RetroBar/Controls/TaskButton.xaml.cs b/RetroBar/Controls/TaskButton.xaml.cs index bd4149c6..b913585c 100644 --- a/RetroBar/Controls/TaskButton.xaml.cs +++ b/RetroBar/Controls/TaskButton.xaml.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -103,6 +104,10 @@ private void TaskButton_OnLoaded(object sender, RoutedEventArgs e) Animate(); } + AppButton.ContextMenu.Opened += ContextMenu_OpenedOrClosed; + AppButton.ContextMenu.Closed += ContextMenu_OpenedOrClosed; + AppButton.ContextMenu.KeyDown += ContextMenu_KeyDown; + _isLoaded = true; } @@ -158,51 +163,106 @@ private void AppButton_OnContextMenuOpening(object sender, ContextMenuEventArgs NativeMethods.WindowShowStyle wss = Window.ShowStyle; int ws = Window.WindowStyles; - // disable window operations depending on current window state. originally tried implementing via bindings but found there is no notification we get regarding maximized state - MaximizeMenuItem.IsEnabled = wss != NativeMethods.WindowShowStyle.ShowMaximized && (ws & (int)NativeMethods.WindowStyles.WS_MAXIMIZEBOX) != 0; - MinimizeMenuItem.IsEnabled = wss != NativeMethods.WindowShowStyle.ShowMinimized && Window.CanMinimize; - if (RestoreMenuItem.IsEnabled = wss != NativeMethods.WindowShowStyle.ShowNormal) + var menuItems = AppButton.ContextMenu.Items.OfType().ToDictionary(item => item.Name); + + if (menuItems.TryGetValue("RestoreMenuItem", out var restoreMenuItem)) + { + restoreMenuItem.Click += RestoreMenuItem_OnClick; + restoreMenuItem.StaysOpenOnClick = wss == NativeMethods.WindowShowStyle.ShowNormal; + } + + if (menuItems.TryGetValue("MoveMenuItem", out var moveMenuItem)) + { + moveMenuItem.Click += MoveMenuItem_OnClick; + moveMenuItem.StaysOpenOnClick = !(wss == NativeMethods.WindowShowStyle.ShowNormal); + } + + if (menuItems.TryGetValue("SizeMenuItem", out var sizeMenuItem)) + { + sizeMenuItem.Click += SizeMenuItem_OnClick; + sizeMenuItem.StaysOpenOnClick = !(wss == NativeMethods.WindowShowStyle.ShowNormal && (ws & (int)NativeMethods.WindowStyles.WS_MAXIMIZEBOX) != 0); + } + + if (menuItems.TryGetValue("MinimizeMenuItem", out var minimizeMenuItem)) + { + minimizeMenuItem.Click += MinimizeMenuItem_OnClick; + minimizeMenuItem.StaysOpenOnClick = !(wss != NativeMethods.WindowShowStyle.ShowMinimized && (ws & (int)NativeMethods.WindowStyles.WS_MINIMIZEBOX) != 0); + } + + if (menuItems.TryGetValue("MaximizeMenuItem", out var maximizeMenuItem)) { - CloseMenuItem.FontWeight = FontWeights.Normal; - RestoreMenuItem.FontWeight = FontWeights.Bold; + maximizeMenuItem.Click += MaximizeMenuItem_OnClick; + maximizeMenuItem.StaysOpenOnClick = !(wss != NativeMethods.WindowShowStyle.ShowMaximized && (ws & (int)NativeMethods.WindowStyles.WS_MAXIMIZEBOX) != 0); } - if (!RestoreMenuItem.IsEnabled || RestoreMenuItem.IsEnabled && !MaximizeMenuItem.IsEnabled) + + if (menuItems.TryGetValue("CloseMenuItem", out var closeMenuItem)) + { + closeMenuItem.Click += CloseMenuItem_OnClick; + } + } + + private void ContextMenu_KeyDown(object sender, KeyEventArgs e) + { + // Check if Alt+F4 is pressed + if (Keyboard.Modifiers == ModifierKeys.Alt && Keyboard.IsKeyDown(Key.F4)) { - CloseMenuItem.FontWeight = FontWeights.Bold; - RestoreMenuItem.FontWeight = FontWeights.Normal; + e.Handled = true; + Window?.Close(); + if (AppButton.ContextMenu is { IsOpen: true }) + { + AppButton.ContextMenu.IsOpen = false; + } } - MoveMenuItem.IsEnabled = wss == NativeMethods.WindowShowStyle.ShowNormal; - SizeMenuItem.IsEnabled = wss == NativeMethods.WindowShowStyle.ShowNormal && (ws & (int)NativeMethods.WindowStyles.WS_MAXIMIZEBOX) != 0; } + private static bool MenuItemEnabled(object sender) => !((MenuItem)sender).StaysOpenOnClick; + private void CloseMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Close(); + if (MenuItemEnabled(sender)) + { + Window?.Close(); + } } private void RestoreMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Restore(); + if (MenuItemEnabled(sender)) + { + Window?.Restore(); + } } private void MoveMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Move(); + if (MenuItemEnabled(sender)) + { + Window?.Move(); + } } private void SizeMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Size(); + if (MenuItemEnabled(sender)) + { + Window?.Size(); + } } private void MinimizeMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Minimize(); + if (MenuItemEnabled(sender)) + { + Window?.Minimize(); + } } private void MaximizeMenuItem_OnClick(object sender, RoutedEventArgs e) { - Window?.Maximize(); + if (MenuItemEnabled(sender)) + { + Window?.Maximize(); + } } private void AppButton_OnClick(object sender, RoutedEventArgs e) diff --git a/RetroBar/Controls/TaskList.xaml.cs b/RetroBar/Controls/TaskList.xaml.cs index 6407905c..9eb86e17 100644 --- a/RetroBar/Controls/TaskList.xaml.cs +++ b/RetroBar/Controls/TaskList.xaml.cs @@ -262,10 +262,16 @@ private void SetScrollable(bool canScroll) private void TasksScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) { - if (!isScrollable) + if (e.Delta > 0) { - e.Handled = true; + TasksScrollViewer.PageUp(); } + if (e.Delta < 0) + { + TasksScrollViewer.PageDown(); + } + + e.Handled = true; } } } \ No newline at end of file diff --git a/RetroBar/Taskbar.xaml.cs b/RetroBar/Taskbar.xaml.cs index 9882230e..65b6cbdb 100644 --- a/RetroBar/Taskbar.xaml.cs +++ b/RetroBar/Taskbar.xaml.cs @@ -226,6 +226,11 @@ protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lP { windowManager.NotifyWorkAreaChange(); } + else if (msg == (int)NativeMethods.WM.SYSCOMMAND && wParam == (IntPtr)NativeMethods.SC_CLOSE) + { + IntPtr progmanHwnd = NativeMethods.FindWindow("Progman", "Program Manager"); + NativeMethods.SendMessage(progmanHwnd, (int)NativeMethods.WM.CLOSE, IntPtr.Zero, IntPtr.Zero); + } return IntPtr.Zero; } diff --git a/RetroBar/Themes/System XP.xaml b/RetroBar/Themes/System XP.xaml index f4429529..415f5a5b 100644 --- a/RetroBar/Themes/System XP.xaml +++ b/RetroBar/Themes/System XP.xaml @@ -26,7 +26,20 @@ + + diff --git a/RetroBar/Themes/System.xaml b/RetroBar/Themes/System.xaml index 2c436ea8..ff62bbb6 100644 --- a/RetroBar/Themes/System.xaml +++ b/RetroBar/Themes/System.xaml @@ -17,10 +17,11 @@ - - - + + + + @@ -28,6 +29,11 @@ + + + + + @@ -41,12 +47,6 @@ Value="LeftToRight" /> - - 11 Bold @@ -62,9 +62,224 @@ Value="{DynamicResource GlobalFontSize}" /> - + + M0 2 0 5 2.5 7.6 7.1 3 7.1 0 2.5 4.6Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -716,6 +723,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +