diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index 273ac12db4..9eac0c1109 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -3,7 +3,9 @@ using osuTK.Graphics; using System; +using osu.Framework.Allocation; using osu.Framework.Input.Events; +using osu.Framework.Platform; using osu.Game.Input.Bindings; using osuTK.Input; @@ -21,9 +23,16 @@ namespace osu.Game.Graphics.UserInterface private bool focus; + private bool allowImmediateFocus => host?.OnScreenKeyboardOverlapsGameWindow != true; + + public void TakeFocus() + { + if (allowImmediateFocus) GetContainingInputManager().ChangeFocus(this); + } + public bool HoldFocus { - get { return focus; } + get { return allowImmediateFocus && focus; } set { focus = value; @@ -32,6 +41,14 @@ namespace osu.Game.Graphics.UserInterface } } + private GameHost host; + + [BackgroundDependencyLoader] + private void load(GameHost host) + { + this.host = host; + } + // We may not be focused yet, but we need to handle keyboard input to be able to request focus public override bool HandleNonPositionalInput => HoldFocus || base.HandleNonPositionalInput; diff --git a/osu.Game/Overlays/Chat/Selection/ChannelSelectionOverlay.cs b/osu.Game/Overlays/Chat/Selection/ChannelSelectionOverlay.cs index 5969d7aded..00de5fd5fd 100644 --- a/osu.Game/Overlays/Chat/Selection/ChannelSelectionOverlay.cs +++ b/osu.Game/Overlays/Chat/Selection/ChannelSelectionOverlay.cs @@ -164,7 +164,7 @@ namespace osu.Game.Overlays.Chat.Selection protected override void OnFocus(FocusEvent e) { - GetContainingInputManager().ChangeFocus(search); + search.TakeFocus(); base.OnFocus(e); } diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index 74edf48433..821c942a57 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -302,7 +302,7 @@ namespace osu.Game.Overlays protected override void OnFocus(FocusEvent e) { //this is necessary as textbox is masked away and therefore can't get focus :( - GetContainingInputManager().ChangeFocus(textbox); + textbox.TakeFocus(); base.OnFocus(e); } diff --git a/osu.Game/Overlays/Music/PlaylistOverlay.cs b/osu.Game/Overlays/Music/PlaylistOverlay.cs index f69ab3ec38..7b5a59836f 100644 --- a/osu.Game/Overlays/Music/PlaylistOverlay.cs +++ b/osu.Game/Overlays/Music/PlaylistOverlay.cs @@ -92,7 +92,7 @@ namespace osu.Game.Overlays.Music protected override void PopIn() { filter.Search.HoldFocus = true; - Schedule(() => GetContainingInputManager().ChangeFocus(filter.Search)); + Schedule(() => filter.Search.TakeFocus()); this.ResizeTo(new Vector2(1, playlist_height), transition_duration, Easing.OutQuint); this.FadeIn(transition_duration, Easing.OutQuint); diff --git a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs index ecb610c1f4..87c369e246 100644 --- a/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs +++ b/osu.Game/Overlays/SearchableList/SearchableListOverlay.cs @@ -103,7 +103,7 @@ namespace osu.Game.Overlays.SearchableList protected override void OnFocus(FocusEvent e) { - GetContainingInputManager().ChangeFocus(Filter.Search); + Filter.Search.TakeFocus(); } protected override void PopIn() diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index e5eee22164..802e97d92a 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -179,7 +179,7 @@ namespace osu.Game.Overlays protected override void OnFocus(FocusEvent e) { - GetContainingInputManager().ChangeFocus(searchTextBox); + searchTextBox.TakeFocus(); base.OnFocus(e); } diff --git a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs index db0f105e0e..28ec5d2d1a 100644 --- a/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/Multi/Lounge/LoungeSubScreen.cs @@ -98,7 +98,7 @@ namespace osu.Game.Screens.Multi.Lounge protected override void OnFocus(FocusEvent e) { - GetContainingInputManager().ChangeFocus(Filter.Search); + Filter.Search.TakeFocus(); } protected override void OnEntering(Screen last)