From 456b586a66bfe4b807483ef729baa11941e0b060 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Sat, 9 Nov 2024 05:05:57 -0500 Subject: [PATCH] Move on-screen keyboard check to `SDLGameHost` --- osu.Framework.iOS/IOSGameHost.cs | 3 --- osu.Framework.iOS/IOSWindow.cs | 1 - osu.Framework/Platform/ISDLWindow.cs | 1 + osu.Framework/Platform/SDL2/SDL2Window.cs | 2 ++ osu.Framework/Platform/SDL3/SDL3Window.cs | 2 ++ osu.Framework/Platform/SDLGameHost.cs | 2 ++ 6 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Framework.iOS/IOSGameHost.cs b/osu.Framework.iOS/IOSGameHost.cs index 91c3401a0a..7b696fd97f 100644 --- a/osu.Framework.iOS/IOSGameHost.cs +++ b/osu.Framework.iOS/IOSGameHost.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using Foundation; -using GameController; using osu.Framework.Configuration; using osu.Framework.Extensions; using osu.Framework.Extensions.ObjectExtensions; @@ -39,8 +38,6 @@ protected override void SetupConfig(IDictionary defaul base.SetupConfig(defaultOverrides); } - public override bool OnScreenKeyboardOverlapsGameWindow => !OperatingSystem.IsIOSVersionAtLeast(14) || GCKeyboard.CoalescedKeyboard == null; - public override bool CanExit => false; public override Storage GetStorage(string path) => new IOSStorage(path, this); diff --git a/osu.Framework.iOS/IOSWindow.cs b/osu.Framework.iOS/IOSWindow.cs index 5444664a88..1583ffccb8 100644 --- a/osu.Framework.iOS/IOSWindow.cs +++ b/osu.Framework.iOS/IOSWindow.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics; using osu.Framework.Platform; using osu.Framework.Platform.SDL3; -using SDL; using static SDL.SDL3; using UIKit; diff --git a/osu.Framework/Platform/ISDLWindow.cs b/osu.Framework/Platform/ISDLWindow.cs index 66f627e28e..640cd8b099 100644 --- a/osu.Framework/Platform/ISDLWindow.cs +++ b/osu.Framework/Platform/ISDLWindow.cs @@ -39,6 +39,7 @@ internal interface ISDLWindow : IWindow bool MouseAutoCapture { set; } bool RelativeMouseMode { get; set; } bool CapsLockPressed { get; } + bool KeyboardAttached { get; } void UpdateMousePosition(Vector2 position); diff --git a/osu.Framework/Platform/SDL2/SDL2Window.cs b/osu.Framework/Platform/SDL2/SDL2Window.cs index 7a62f84d7c..1efa878477 100644 --- a/osu.Framework/Platform/SDL2/SDL2Window.cs +++ b/osu.Framework/Platform/SDL2/SDL2Window.cs @@ -165,6 +165,8 @@ internal SDL_SysWMinfo GetWindowSystemInformation() public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.KMOD_CAPS); + public bool KeyboardAttached => true; // SDL2 has no way of knowing whether a keyboard is attached, assume true. + // references must be kept to avoid GC, see https://stackoverflow.com/a/6193914 [UsedImplicitly] diff --git a/osu.Framework/Platform/SDL3/SDL3Window.cs b/osu.Framework/Platform/SDL3/SDL3Window.cs index ad30b20ad9..39457dee9d 100644 --- a/osu.Framework/Platform/SDL3/SDL3Window.cs +++ b/osu.Framework/Platform/SDL3/SDL3Window.cs @@ -145,6 +145,8 @@ public IntPtr DisplayHandle public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.SDL_KMOD_CAPS); + public bool KeyboardAttached => SDL_HasKeyboard(); + /// /// Represents a handle to this instance, used for unmanaged callbacks. /// diff --git a/osu.Framework/Platform/SDLGameHost.cs b/osu.Framework/Platform/SDLGameHost.cs index 41e237db9b..042a7fc9a9 100644 --- a/osu.Framework/Platform/SDLGameHost.cs +++ b/osu.Framework/Platform/SDLGameHost.cs @@ -20,6 +20,8 @@ public abstract class SDLGameHost : GameHost { public override bool CapsLockEnabled => (Window as ISDLWindow)?.CapsLockPressed == true; + public override bool OnScreenKeyboardOverlapsGameWindow => (Window as ISDLWindow)?.KeyboardAttached == false; + protected SDLGameHost(string gameName, HostOptions? options = null) : base(gameName, options) {