Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TextBox to specify type of text being input #6408

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

frenzibyte
Copy link
Member

Also has the bonus feature of allowing password managers (e.g. 1Password) to be integrated with the game, by specifying the text input type as Username/Password in the textboxes. Unfortunately it's still quite broken in SDL but should be fixable (see libsdl-org/SDL#11406 (comment)).

Since text input types are now identifiable with the new TextInputType field, I've applied a refactor on the TextBox classes to respect the type at a TextBox level w.r.t. certain functionalities such as clipboard exporting, key event logging, character display, etc. This includes removing BasicPasswordTextBox entirely as its behaviour can be achieved by simply:

new BasicTextBox
{
    InputProperties = new TextInputProperties(TextInputType.Password, allowIme: false)
}

I've gone for this refactor as it didn't sit well for me how these implementations still exist while there is now a new field specifying the type of text input.

@bdach
Copy link
Collaborator

bdach commented Nov 4, 2024

Compilation failures here

@frenzibyte
Copy link
Member Author

Noticed, fixed.

@frenzibyte frenzibyte force-pushed the text-input-properties branch from 463030f to 5a34404 Compare November 4, 2024 09:47
Copy link
Contributor

@smoogipoo smoogipoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks okay.

I'm not sure about IME being a property you have to set as opposed to being optional defaulting to true, or maybe even null and a sane default chosen per type (IME doesn't make sense for numbers/passwords, but maybe this is blocked at and SDL level?).

osu.Framework/Input/TextInputProperties.cs Outdated Show resolved Hide resolved
Co-authored-by: Dan Balasescu <[email protected]>
osu.Framework/Platform/Windows/SDL3WindowsWindow.cs Outdated Show resolved Hide resolved
Comment on lines 1006 to 1008
string detail = d is ICanSuppressKeyEventLogging kd && kd.SuppressKeyEventLogging
? e.GetType().ReadableName()
: e.ToString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this actually... suppress? Because in debug, when I run the game, and type into a password text box, key events are still logged. And that's because they're being logged in a completely different location, namely

if (handledBy != null)
Logger.Log($"{e} handled by {handledBy}.", LoggingTarget.Runtime, LogLevel.Debug);

So does this really do anything? Or did it just break at some point and nobody noticed?

Copy link
Member Author

@frenzibyte frenzibyte Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it did regress, since key input used to be logged in this location until it was moved to KeyEventManager. I'll correct it in this PR.

{
window.StartTextInput(allowIme);
window.StartTextInput(properties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to work correctly on android. When switching from a normal textbox to a password textbox immediately, IME remains available. Conversely, when switching from a password textbox to a normal textbox immediately, IME remains unavailable.

Record_2024-11-08-11-57-01.mp4

I wonder what this looks like on iOS. (I own an iOS device now, but no mac, so I still can't check myself.)

Whether this is an SDL bug, or ours, is up for debate I guess. I can say that the naive solution, i.e.

diff --git a/osu.Framework/Input/SDLWindowTextInput.cs b/osu.Framework/Input/SDLWindowTextInput.cs
index 79fa1d848..c67bf7f77 100644
--- a/osu.Framework/Input/SDLWindowTextInput.cs
+++ b/osu.Framework/Input/SDLWindowTextInput.cs
@@ -10,6 +10,8 @@ internal class SDLWindowTextInput : TextInputSource
     {
         private readonly ISDLWindow window;
 
+        private TextInputProperties? startedInputProperties;
+
         public SDLWindowTextInput(ISDLWindow window)
         {
             this.window = window;
@@ -42,10 +44,14 @@ protected override void ActivateTextInput(TextInputProperties properties)
             window.TextInput += handleTextInput;
             window.TextEditing += handleTextEditing;
             window.StartTextInput(properties);
+            startedInputProperties = properties;
         }
 
         protected override void EnsureTextInputActivated(TextInputProperties properties)
         {
+            if (startedInputProperties != null && startedInputProperties != properties)
+                window.StopTextInput();
+
             window.StartTextInput(properties);
         }
 
@@ -54,6 +60,7 @@ protected override void DeactivateTextInput()
             window.TextInput -= handleTextInput;
             window.TextEditing -= handleTextEditing;
             window.StopTextInput();
+            startedInputProperties = null;
         }
 
         public override void SetImeRectangle(RectangleF rectangle)

does not appear to help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing roughly the same issue on iOS, I will have to look into libsdl-org/SDL#11406 (comment) again first to tell whether this is an issue on SDL's side or ours. Not sure about Android though, someone else will have to investigate this (libsdl-org/SDL#11406 (comment) may be relevant).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After further investigation on the iOS issue, SDL doesn't handle updating text input properties appropriately on iOS, regardless of whether text input is active or not. I've fixed this in the PR linked above (libsdl-org/SDL@f4d81f2) for now.

Copy link
Collaborator

@bdach bdach Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...so i guess at this point it's either up to me to fix android in sdl, or to accept it's broken over there?

i feel like my android devices might mysteriously stop working soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to take a stab at fixing this in SDL. On first glance, it doesn't seem to be an android-specific issue as SDL will ignore requests to show the keyboard if it's already active.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

osu.Framework/Input/TextInputType.cs Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResetIme() still calls SDL_StartTextInput() without properties.

@frenzibyte frenzibyte self-assigned this Dec 21, 2024
@frenzibyte
Copy link
Member Author

frenzibyte commented Dec 24, 2024

@peppy fwiw with this PR in addition to libsdl-org/SDL#11699, users will be able to auto-fill their account passwords from a password manager with ease.

EDIT: Ok maybe still broken somewhat, need more braincells.

Copy link
Contributor

@smoogipoo smoogipoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise this looks fine to me and I've done a basic test (macOS).

@smoogipoo smoogipoo requested review from Susko3 and bdach January 10, 2025 06:29
@bdach
Copy link
Collaborator

bdach commented Jan 10, 2025

Code seems ok I guess.

On the setups that I have:

  • Windows works.
  • I haven't tested android but I presume it's still broken because the sdl PR linked above is dead in drafts.
  • On ubuntu linux x11 this doesn't do anything because IME is still available on password boxes.
  • On ubuntu linux wayland this doesn't do anything because IME just straight up doesn't seem to work even after switching the keyboard language. Not a regression, already broken on master.

So if you're fine with these results I guess you can merge 🤷 I don't really care about android or linux anymore, and chances are high none of the issues are something we can fix (should be fixing?) ourselves.

Copy link
Collaborator

@bdach bdach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above i guess

Copy link
Member

@Susko3 Susko3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this in. Android is bugged, but it's not so bad. The user may end up in the wrong mode, but typing always works. And if they need an IME, they'll probably figure out that closing and opening the keyboard works around the issue. It's the classic turn it off and on again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants