Skip to content

Commit

Permalink
Merge pull request #6407 from frenzibyte/fix-focus-with-hardware-keyb…
Browse files Browse the repository at this point in the history
…oard

Disable `OnScreenKeyboardOverlapsGameWindow` on iOS when hardware keyboard is attached
  • Loading branch information
peppy authored Nov 14, 2024
2 parents bc83409 + 456b586 commit d733029
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ protected override void SetupConfig(IDictionary<FrameworkSetting, object> defaul
base.SetupConfig(defaultOverrides);
}

public override bool OnScreenKeyboardOverlapsGameWindow => true;

public override bool CanExit => false;

public override Storage GetStorage(string path) => new IOSStorage(path, this);
Expand Down
1 change: 0 additions & 1 deletion osu.Framework.iOS/IOSWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion osu.Framework/Platform/GameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ public abstract class GameHost : IIpcHost, IDisposable
public event Func<IpcMessage, IpcMessage> MessageReceived;

/// <summary>
/// Whether the on screen keyboard covers a portion of the game window when presented to the user.
/// Whether the on-screen keyboard covers a portion of the game window when presented to the user.
/// This is usually true on mobile platforms, but may change to false if a hardware keyboard is connected.
/// </summary>
public virtual bool OnScreenKeyboardOverlapsGameWindow => false;

Expand Down
1 change: 1 addition & 0 deletions osu.Framework/Platform/ISDLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Platform/SDL2/SDL2Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Platform/SDL3/SDL3Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public IntPtr DisplayHandle

public bool CapsLockPressed => SDL_GetModState().HasFlagFast(SDL_Keymod.SDL_KMOD_CAPS);

public bool KeyboardAttached => SDL_HasKeyboard();

/// <summary>
/// Represents a handle to this <see cref="SDL3Window"/> instance, used for unmanaged callbacks.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Platform/SDLGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit d733029

Please sign in to comment.