Android: Clear mouse pos on touch release (#6627) + SDL2: Restore StartTextInput for Android (#7636)#9474
Conversation
…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.
|
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. |
|
Merged 9090828 for the mouse pos clear. The rest needs further details. |
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! |
|
I will fix and clarify based on your suggestions. Sorry if it's not clear for now. It's needed in a custom build I'm doing for some andrino based large panel stage display controller. Will provide update soon and reverse any unwanted changes.
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: omar ***@***.***>
Sent: Wednesday, 15 July 2026 10:37:21
To: ocornut/imgui ***@***.***>
Cc: Turtle Dove ***@***.***>; Author ***@***.***>
Subject: Re: [ocornut/imgui] Android: Clear mouse pos on touch release (#6627) + SDL2: Restore StartTextInput for Android (#7636) (PR #9474)
[https://avatars.githubusercontent.com/u/8225057?s=20&v=4]ocornut left a comment (ocornut/imgui#9474)<#9474 (comment)>
Merged 9090828 for the mouse pos clear. The rest needs further details.
—
Reply to this email directly, view it on GitHub<#9474?email_source=notifications&email_token=CB76KOQAM3X6HXH3VQ6YIQT5E6QLDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOJYGI2DGMRVHE4KM4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4982432598>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/CB76KOQSYS7UN3NEEZ7JTGT5E6QLDAVCNFSNUABEKJSXA33TNF2G64TZHMZDEMBWG42TEMJ3JFZXG5LFHM2DQOJTGUYDSNBTHGQXMAQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
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 |
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)onAMOTION_EVENT_ACTION_UPbut does not clear the mouse position. ImGui still thinks the pointer is hovering over the button.Fix: After
AMOTION_EVENT_ACTION_UPforFINGER/UNKNOWNtool types, callio.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
FINGERandUNKNOWNtool types — physical mouse and pen input are unaffected.File:
backends/imgui_impl_android.cpp— 4 lines addedIssue #7636: SDL2 text input using Android onscreen keyboard
Problem: When using SDL2 on Android, tapping on
InputTextdoes 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()whendata->WantVisibleis true, andSDL_StopTextInput()when it becomes false, inImGui_ImplSDL2_PlatformSetImeData().File:
backends/imgui_impl_sdl2.cpp— 7 lines addedChanges
backends/imgui_impl_android.cppbackends/imgui_impl_sdl2.cppdocs/CHANGELOG.txtTotal: 17 lines added, 0 removed.
Testing
Issues addressed