From a02484c6a010d6d8e6449936f7641f34143d80bf Mon Sep 17 00:00:00 2001 From: Lena Date: Thu, 21 Dec 2023 02:08:44 +0100 Subject: [PATCH 1/3] create boss key manager on windows (requires framework changes) --- osu.Desktop/OsuGameDesktop.cs | 4 ++ osu.Desktop/Platform/BossKeyManager.cs | 57 +++++++++++++++++++ .../Input/Bindings/GlobalActionContainer.cs | 5 ++ .../GlobalActionKeyBindingStrings.cs | 5 ++ 4 files changed, 71 insertions(+) create mode 100644 osu.Desktop/Platform/BossKeyManager.cs diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index 3e06dad4c54b..a68b71d5e0dd 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -9,6 +9,7 @@ using Microsoft.Win32; using osu.Desktop.Performance; using osu.Desktop.Security; +using osu.Desktop.Platform; using osu.Framework.Platform; using osu.Game; using osu.Desktop.Updater; @@ -144,6 +145,9 @@ protected override void LoadComplete() LoadComponentAsync(new ElevatedPrivilegesChecker(), Add); + if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) + LoadComponentAsync(new BossKeyManager(), Add); + osuSchemeLinkIPCChannel = new OsuSchemeLinkIPCChannel(Host, this); archiveImportIPCChannel = new ArchiveImportIPCChannel(Host, this); } diff --git a/osu.Desktop/Platform/BossKeyManager.cs b/osu.Desktop/Platform/BossKeyManager.cs new file mode 100644 index 000000000000..42855f59f2e2 --- /dev/null +++ b/osu.Desktop/Platform/BossKeyManager.cs @@ -0,0 +1,57 @@ +using osu.Framework.Graphics; +using osu.Framework.Input; +using osu.Framework.Allocation; +using osu.Framework.Platform; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; +using osu.Game.Input.Bindings; +using osu.Game.Overlays; +using osu.Framework.Logging; + +namespace osu.Desktop.Platform +{ + internal partial class BossKeyManager : Component, IKeyBindingHandler, IHandleGlobalKeyboardInput + { + [Resolved] + private GameHost host { get; set; } = null!; + + [Resolved] + private VolumeOverlay volumeOverlay { get; set; } = null!; + + [BackgroundDependencyLoader] + private void load() + { + } + + public bool OnPressed(KeyBindingPressEvent e) + { + if (e.Action == GlobalAction.BossKey && !e.Repeat) + { + host.Window.Hide(); + bool previousState = volumeOverlay.IsMuted.Value; + + host.Window.CreateNotificationTrayIcon("osu!", () => Schedule(() => onShow(previousState))); + Logger.Log($"Created notification tray icon"); + volumeOverlay.IsMuted.Value = true; + + return true; + } + + return false; + } + + private void onShow(bool previousState) + { + Logger.Log($"Notification tray icon clicked"); + host.Window.Show(); + host.Window.Raise(); + host.Window.RemoveNotificationTrayIcon(); + Logger.Log($"Notification tray icon removed"); + volumeOverlay.IsMuted.Value = previousState; + } + + public void OnReleased(KeyBindingReleaseEvent e) + { + } + } +} diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index ef0c60cd2060..e0b0f1b5be41 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -111,6 +111,8 @@ public static IEnumerable GetGlobalActionsFor(GlobalActionCategory new KeyBinding(InputKey.F10, GlobalAction.ToggleGameplayMouseButtons), new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot), + + new KeyBinding(InputKey.Insert, GlobalAction.BossKey), }; private static IEnumerable overlayKeyBindings => new[] @@ -456,6 +458,9 @@ public enum GlobalAction [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.EditorTestPlayQuickExitToCurrentTime))] EditorTestPlayQuickExitToCurrentTime, + + [LocalisableDescription(typeof(GlobalActionKeyBindingStrings), nameof(GlobalActionKeyBindingStrings.BossKey))] + BossKey, } public enum GlobalActionCategory diff --git a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs index 450585f79abf..2f109bf20316 100644 --- a/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs +++ b/osu.Game/Localisation/GlobalActionKeyBindingStrings.cs @@ -404,6 +404,11 @@ public static class GlobalActionKeyBindingStrings /// public static LocalisableString DecreaseModSpeed => new TranslatableString(getKey(@"decrease_mod_speed"), @"Decrease mod speed"); + /// + /// "Boss Key" + /// + public static LocalisableString BossKey => new TranslatableString(getKey(@"boss_key"), @"Boss Key"); + private static string getKey(string key) => $@"{prefix}:{key}"; } } From 99de6899a46a94e0d87c6ddd43411037f7273d04 Mon Sep 17 00:00:00 2001 From: Lena Date: Tue, 23 Jul 2024 15:29:39 +0200 Subject: [PATCH 2/3] add boss key binding only on windows --- .../Input/Bindings/GlobalActionContainer.cs | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index e0b0f1b5be41..05ea346beffa 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -84,36 +84,45 @@ public static IEnumerable GetGlobalActionsFor(GlobalActionCategory public void OnReleased(KeyBindingReleaseEvent e) => handler?.OnReleased(e); - private static IEnumerable globalKeyBindings => new[] + private static IEnumerable globalKeyBindings { - new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious), - new KeyBinding(InputKey.Down, GlobalAction.SelectNext), + get + { + KeyBinding[] bindings = new[] + { + new KeyBinding(InputKey.Up, GlobalAction.SelectPrevious), + new KeyBinding(InputKey.Down, GlobalAction.SelectNext), - new KeyBinding(InputKey.Left, GlobalAction.SelectPreviousGroup), - new KeyBinding(InputKey.Right, GlobalAction.SelectNextGroup), + new KeyBinding(InputKey.Left, GlobalAction.SelectPreviousGroup), + new KeyBinding(InputKey.Right, GlobalAction.SelectNextGroup), - new KeyBinding(InputKey.Space, GlobalAction.Select), - new KeyBinding(InputKey.Enter, GlobalAction.Select), - new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), + new KeyBinding(InputKey.Space, GlobalAction.Select), + new KeyBinding(InputKey.Enter, GlobalAction.Select), + new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), - new KeyBinding(InputKey.Escape, GlobalAction.Back), - new KeyBinding(InputKey.ExtraMouseButton1, GlobalAction.Back), + new KeyBinding(InputKey.Escape, GlobalAction.Back), + new KeyBinding(InputKey.ExtraMouseButton1, GlobalAction.Back), - new KeyBinding(new[] { InputKey.Alt, InputKey.Home }, GlobalAction.Home), + new KeyBinding(new[] { InputKey.Alt, InputKey.Home }, GlobalAction.Home), - new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.F }, GlobalAction.ToggleFPSDisplay), - new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), - new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.S }, GlobalAction.ToggleSkinEditor), + new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.F }, GlobalAction.ToggleFPSDisplay), + new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), + new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.S }, GlobalAction.ToggleSkinEditor), - new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), + new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), - new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.R }, GlobalAction.RandomSkin), + new KeyBinding(new[] { InputKey.Control, InputKey.Shift, InputKey.R }, GlobalAction.RandomSkin), - new KeyBinding(InputKey.F10, GlobalAction.ToggleGameplayMouseButtons), - new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot), + new KeyBinding(InputKey.F10, GlobalAction.ToggleGameplayMouseButtons), + new KeyBinding(InputKey.F12, GlobalAction.TakeScreenshot), + }; - new KeyBinding(InputKey.Insert, GlobalAction.BossKey), - }; + if (OperatingSystem.IsWindows()) + bindings.Append(new KeyBinding(InputKey.Insert, GlobalAction.BossKey)); + + return bindings; + } + } private static IEnumerable overlayKeyBindings => new[] { From 16fecc6effda8f57f49496950e28532a800301c9 Mon Sep 17 00:00:00 2001 From: Lena Date: Fri, 26 Jul 2024 13:34:02 +0200 Subject: [PATCH 3/3] actually add boss key binding on windows --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 05ea346beffa..a98efde93920 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -118,7 +118,7 @@ private static IEnumerable globalKeyBindings }; if (OperatingSystem.IsWindows()) - bindings.Append(new KeyBinding(InputKey.Insert, GlobalAction.BossKey)); + return bindings.Append(new KeyBinding(InputKey.Insert, GlobalAction.BossKey)); return bindings; }