Skip to content

Android: Clear mouse pos on touch release (#6627) + SDL2: Restore StartTextInput for Android (#7636)#9474

Closed
Turtle-PB wants to merge 1 commit into
ocornut:masterfrom
Turtle-PB:fix/android-touch-release-clear-mouse
Closed

Android: Clear mouse pos on touch release (#6627) + SDL2: Restore StartTextInput for Android (#7636)#9474
Turtle-PB wants to merge 1 commit into
ocornut:masterfrom
Turtle-PB:fix/android-touch-release-clear-mouse

Conversation

@Turtle-PB

Copy link
Copy Markdown
Contributor

Summary

Fixes two open Android-labeled issues with minimal, surgical changes.

Issue #6627: Android: button rendered as clicked after being released

Problem: After tapping a button on Android, it stays in the hovered/pressed state until another item is clicked. This affects all ImGui buttons on touchscreen.

Root cause: The Android backend sends AddMouseButtonEvent(0, false) on AMOTION_EVENT_ACTION_UP but does not clear the mouse position. ImGui still thinks the pointer is hovering over the button.

Fix: After AMOTION_EVENT_ACTION_UP for FINGER/UNKNOWN tool types, call io.AddMousePosEvent(-FLT_MAX, -FLT_MAX) to clear the mouse position. On touchscreens there is no hover — the pointer is gone after release.

Omar's confirmation: In the issue comments, @ocornut said: "It's not a rendering issue it is that the backend should submit a mouse leaving (AddMousePosEvent(-FLT_MAX,-FLT_MAX)) invalid position) event after the touch release."

The fix only applies to FINGER and UNKNOWN tool types — physical mouse and pen input are unaffected.

File: backends/imgui_impl_android.cpp — 4 lines added

Issue #7636: SDL2 text input using Android onscreen keyboard

Problem: When using SDL2 on Android, tapping on InputText does not bring up the on-screen keyboard. Text input is impossible.

Root cause: SDL_StartTextInput()/SDL_StopTextInput() calls were removed from the SDL2 IME handler in commit a7703fe (2023-04-06) due to concerns about desktop IME. However, these calls are required on Android/mobile to show the on-screen keyboard. The equivalent fix was already applied to SDL3 in fab96a6, but not SDL2.

Fix: Restore SDL_StartTextInput() when data->WantVisible is true, and SDL_StopTextInput() when it becomes false, in ImGui_ImplSDL2_PlatformSetImeData().

File: backends/imgui_impl_sdl2.cpp — 7 lines added

Changes

File Lines Change
backends/imgui_impl_android.cpp +5 Clear mouse pos on touch UP + changelog
backends/imgui_impl_sdl2.cpp +8 Restore StartTextInput/StopTextInput + changelog
docs/CHANGELOG.txt +4 Backend entries for both fixes

Total: 17 lines added, 0 removed.

Testing

  • Cannot compile/test on this host (no Android NDK or SDL2 dev libs)
  • Both fixes are based on confirmed solutions from issue commenters and Omar's guidance
  • The Android touch fix matches the exact pattern Omar described
  • The SDL2 fix mirrors the SDL3 fix already merged upstream

Issues addressed

…re StartTextInput for Android (ocornut#7636)

Android backend (imgui_impl_android.cpp):
- After AMOTION_EVENT_ACTION_UP for FINGER/UNKNOWN input, clear mouse
  position via AddMousePosEvent(-FLT_MAX, -FLT_MAX). This prevents buttons
  from staying in hovered/pressed state after touch release. On touchscreens
  there is no hover — the pointer is gone after release. (ocornut#6627)
- Omar confirmed this is the right approach in issue comments: 'the backend
  should submit a mouse leaving event after the touch release'

SDL2 backend (imgui_impl_sdl2.cpp):
- Restore SDL_StartTextInput()/SDL_StopTextInput() in the IME handler
  (ImGui_ImplSDL2_PlatformSetImeData). These calls were removed in a7703fe
  due to concerns about desktop IME, but are required on Android to show
  the on-screen keyboard when InputText is focused. The equivalent fix was
  already applied to SDL3 in fab96a6 but not SDL2. (ocornut#7636)

Both fixes are referenced in docs/CHANGELOG.txt.
@ocornut

ocornut commented Jul 15, 2026

Copy link
Copy Markdown
Owner

a7703fe was clearly pushed as a fix so it is unclear why you undoing that is going to be right. You say "mirrors the SDL3 fix already merged upstream" but it doesn't appear to mirror what the SDL3 backend is doing.

@ocornut

ocornut commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Merged 9090828 for the mouse pos clear. The rest needs further details.

@ocornut

ocornut commented Jul 15, 2026

Copy link
Copy Markdown
Owner

The equivalent fix was already applied to SDL3 in fab96a6, but not SDL2.

To clarify, I missed this link, but current SDL3 code looks different now. Will need figure out why. Thanks a lot for digging into that!

@Turtle-PB

Turtle-PB commented Jul 15, 2026 via email

Copy link
Copy Markdown
Contributor Author

@ocornut

ocornut commented Jul 15, 2026

Copy link
Copy Markdown
Owner

The commit history for SDL3 is:

Which is quite a mouthful.
TL;DR; is that SDL3 is newer and fixed issues SDL2 had anyway.
We can considering wrapping the calls for SDL2 under #ifdef ?

As a general stance, I feel that invocation of OSD keyboard should be possible to disable.

ocornut pushed a commit that referenced this pull request Jul 15, 2026
@ocornut

ocornut commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Given the nature of the issue and the fact that SDL2 is on life-support I think it is viable to merge your suggestion, which I did with 35a7e8e but under #ifdef __ANDROID__ blocks. We can always untangle the situation better provided enough data points but for now it should do the job. Thanks for helping move this forward.

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.

SDL2 text input using Android onscreen keyboard Android: button rendered as clicked after being released

2 participants