Skip to content

PSP: Fix on screen keyboard not sending an event the first time#15950

Closed
sharkwouter wants to merge 2 commits into
libsdl-org:mainfrom
sharkwouter:fix-psp-osk2
Closed

PSP: Fix on screen keyboard not sending an event the first time#15950
sharkwouter wants to merge 2 commits into
libsdl-org:mainfrom
sharkwouter:fix-psp-osk2

Conversation

@sharkwouter

Copy link
Copy Markdown
Collaborator
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Description

This is not the prettiest solution, but with the function being blocking, there is no other way to make sure what is entered into the on screen keyboard to actually creates an event for the user. At the moment the first time the on screen keyboard is called, it never works. The problem is that text_input_active is set after the function to enter text is called here:

_this->ShowScreenKeyboard(_this, window, props);

Existing Issue(s)

@slouken

slouken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Can you add a blank line and a comment explaining why this is necessary?

Also, maybe we should be setting this true at a higher level, before showing the keyboard?

@sharkwouter

sharkwouter commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

I've added the comment. I think if we want to fix this at a higher level, the solution would probably look something like this:

diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index c99e45216..dfbd824b9 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -5836,15 +5836,8 @@ bool SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props
         _this->SetTextInputProperties(_this, window, props);
     }
 
-    // Show the on-screen keyboard, if desired
-    if (AutoShowingScreenKeyboard() && !SDL_ScreenKeyboardShown(window)) {
-        if (_this->ShowScreenKeyboard) {
-            _this->ShowScreenKeyboard(_this, window, props);
-        }
-    }
-
     if (!window->text_input_active) {
-        // Finally start the text input system
+        // Start the text input system
         if (_this->StartTextInput) {
             if (!_this->StartTextInput(_this, window, props)) {
                 return false;
@@ -5852,6 +5845,13 @@ bool SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props
         }
         window->text_input_active = true;
     }
+
+    // Show the on-screen keyboard, if desired
+    if (AutoShowingScreenKeyboard() && !SDL_ScreenKeyboardShown(window)) {
+        if (_this->ShowScreenKeyboard) {
+            _this->ShowScreenKeyboard(_this, window, props);
+        }
+    }
     return true;
 }
 

I'm not sure how I would test this, though. I don't think I own many of the systems that have on screen keyboard support. Not enough to make sure this code is safe anyway. On PSP it works fine, but I don't know about other systems.

@slouken

slouken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Yeah, that patch looks reasonable to me. I can test it on Android and iOS here. Does it solve the issue on PSP if you apply this instead of your changes?

@slouken slouken closed this in ce417a4 Jul 6, 2026
@slouken

slouken commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Looks good, thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants