From cb06ac4af20074518ce5fae45f4ebe066b20e02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 2 Oct 2024 16:08:12 +0200 Subject: [PATCH] MacOS: Fix text input (got broken in #19441, would no longer send CHAR events) See #19441 --- Common/UI/View.cpp | 2 +- SDL/SDLMain.cpp | 38 +++++++++++++++++++++++++++++++++++++- UI/EmuScreen.cpp | 19 +++++++++---------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 7a65c477ee..fa5bca1870 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -1329,7 +1329,7 @@ bool TextEdit::Key(const KeyInput &input) { // Process chars. if (input.flags & KEY_CHAR) { - int unichar = input.keyCode; + const int unichar = input.keyCode; if (unichar >= 0x20 && !ctrlDown_) { // Ignore control characters. // Insert it! (todo: do it with a string insert) char buf[8]; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 9087f062b4..c172f439c1 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -100,6 +100,10 @@ static bool g_rebootEmuThread = false; static SDL_AudioSpec g_retFmt; +static bool g_textFocusChanged; +static bool g_textFocus; + + // Window state to be transferred to the main SDL thread. static std::mutex g_mutexWindow; struct WindowState { @@ -347,6 +351,23 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string #endif /* PPSSPP_PLATFORM(WINDOWS) */ return true; } + case SystemRequestType::NOTIFY_UI_EVENT: + { + switch ((UIEventNotification)param3) { + case UIEventNotification::TEXT_GOTFOCUS: + g_textFocus = true; + g_textFocusChanged = true; + break; + case UIEventNotification::POPUP_CLOSED: + case UIEventNotification::TEXT_LOSTFOCUS: + g_textFocus = false; + g_textFocusChanged = true; + break; + default: + break; + } + return true; + } default: return false; } @@ -1087,6 +1108,18 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta } } +void UpdateTextFocus() { + if (g_textFocusChanged) { + INFO_LOG(Log::System, "Updating text focus: %d", g_textFocus); + if (g_textFocus) { + SDL_StartTextInput(); + } else { + SDL_StopTextInput(); + } + g_textFocusChanged = false; + } +} + void UpdateSDLCursor() { #if !defined(MOBILE_DEVICE) if (lastUIState != GetUIState()) { @@ -1428,7 +1461,8 @@ int main(int argc, char *argv[]) { #endif // Avoid the IME popup when holding keys. This doesn't affect all versions of SDL. - // TODO: Enable it in text input fields + // Note: We re-enable it in text input fields! This is necessary otherwise we don't receive + // KEY_CHAR events. SDL_StopTextInput(); InitSDLAudioDevice(); @@ -1465,6 +1499,7 @@ int main(int argc, char *argv[]) { if (g_QuitRequested || g_RestartRequested) break; + UpdateTextFocus(); UpdateSDLCursor(); inputTracker.MouseCaptureControl(); @@ -1491,6 +1526,7 @@ int main(int argc, char *argv[]) { if (g_QuitRequested || g_RestartRequested) break; + UpdateTextFocus(); UpdateSDLCursor(); inputTracker.MouseCaptureControl(); diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 90a624bd20..d079a9d958 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -589,19 +589,19 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) { if (!chatButton_) RecreateViews(); -#if defined(USING_WIN_UI) - // temporary workaround for hotkey its freeze the ui when open chat screen using hotkey and native keyboard is enable - if (g_Config.bBypassOSKWithKeyboard) { - // TODO: Make translatable. - g_OSD.Show(OSDType::MESSAGE_INFO, "Disable \"Use system native keyboard\" to use ctrl + c hotkey", 2.0f); + if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_DESKTOP) { + // temporary workaround for hotkey its freeze the ui when open chat screen using hotkey and native keyboard is enable + if (g_Config.bBypassOSKWithKeyboard) { + // TODO: Make translatable. + g_OSD.Show(OSDType::MESSAGE_INFO, "Disable \"Use system native keyboard\" to use ctrl + c hotkey", 2.0f); + } else { + UI::EventParams e{}; + OnChatMenu.Trigger(e); + } } else { UI::EventParams e{}; OnChatMenu.Trigger(e); } -#else - UI::EventParams e{}; - OnChatMenu.Trigger(e); -#endif } } else if (message == UIMessage::APP_RESUMED && screenManager()->topScreen() == this) { if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV) { @@ -935,7 +935,6 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { if (UI::IsFocusMovementEnabled()) { return UIScreen::UnsyncKey(key); } - return controlMapper_.Key(key, &pauseTrigger_); }