MacOS: Fix text input (got broken in #19441, would no longer send CHAR events)

See #19441
This commit is contained in:
Henrik Rydgård committed 2024-10-02 16:21:53 +02:00
1 parent f11675bcba
commit cb06ac4af2
3 files changed
+47 -12

No files matched your search

+1 -1
View File
@@ -1329,7 +1329,7 @@ bool TextEdit::Key(const KeyInput &input) {
// Process chars. // Process chars.
if (input.flags & KEY_CHAR) { if (input.flags & KEY_CHAR) {
int unichar = input.keyCode; const int unichar = input.keyCode;
if (unichar >= 0x20 && !ctrlDown_) { // Ignore control characters. if (unichar >= 0x20 && !ctrlDown_) { // Ignore control characters.
// Insert it! (todo: do it with a string insert) // Insert it! (todo: do it with a string insert)
char buf[8]; char buf[8];
+37 -1
View File
@@ -100,6 +100,10 @@ static bool g_rebootEmuThread = false;
static SDL_AudioSpec g_retFmt; static SDL_AudioSpec g_retFmt;
static bool g_textFocusChanged;
static bool g_textFocus;
// Window state to be transferred to the main SDL thread. // Window state to be transferred to the main SDL thread.
static std::mutex g_mutexWindow; static std::mutex g_mutexWindow;
struct WindowState { struct WindowState {
@@ -347,6 +351,23 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
#endif /* PPSSPP_PLATFORM(WINDOWS) */ #endif /* PPSSPP_PLATFORM(WINDOWS) */
return true; 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: default:
return false; 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() { void UpdateSDLCursor() {
#if !defined(MOBILE_DEVICE) #if !defined(MOBILE_DEVICE)
if (lastUIState != GetUIState()) { if (lastUIState != GetUIState()) {
@@ -1428,7 +1461,8 @@ int main(int argc, char *argv[]) {
#endif #endif
// Avoid the IME popup when holding keys. This doesn't affect all versions of SDL. // 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(); SDL_StopTextInput();
InitSDLAudioDevice(); InitSDLAudioDevice();
@@ -1465,6 +1499,7 @@ int main(int argc, char *argv[]) {
if (g_QuitRequested || g_RestartRequested) if (g_QuitRequested || g_RestartRequested)
break; break;
UpdateTextFocus();
UpdateSDLCursor(); UpdateSDLCursor();
inputTracker.MouseCaptureControl(); inputTracker.MouseCaptureControl();
@@ -1491,6 +1526,7 @@ int main(int argc, char *argv[]) {
if (g_QuitRequested || g_RestartRequested) if (g_QuitRequested || g_RestartRequested)
break; break;
UpdateTextFocus();
UpdateSDLCursor(); UpdateSDLCursor();
inputTracker.MouseCaptureControl(); inputTracker.MouseCaptureControl();
+9 -10
View File
@@ -589,19 +589,19 @@ void EmuScreen::sendMessage(UIMessage message, const char *value) {
if (!chatButton_) if (!chatButton_)
RecreateViews(); RecreateViews();
#if defined(USING_WIN_UI) 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 // temporary workaround for hotkey its freeze the ui when open chat screen using hotkey and native keyboard is enable
if (g_Config.bBypassOSKWithKeyboard) { if (g_Config.bBypassOSKWithKeyboard) {
// TODO: Make translatable. // TODO: Make translatable.
g_OSD.Show(OSDType::MESSAGE_INFO, "Disable \"Use system native keyboard\" to use ctrl + c hotkey", 2.0f); 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 { } else {
UI::EventParams e{}; UI::EventParams e{};
OnChatMenu.Trigger(e); OnChatMenu.Trigger(e);
} }
#else
UI::EventParams e{};
OnChatMenu.Trigger(e);
#endif
} }
} else if (message == UIMessage::APP_RESUMED && screenManager()->topScreen() == this) { } else if (message == UIMessage::APP_RESUMED && screenManager()->topScreen() == this) {
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV) { if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_TV) {
@@ -935,7 +935,6 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) {
if (UI::IsFocusMovementEnabled()) { if (UI::IsFocusMovementEnabled()) {
return UIScreen::UnsyncKey(key); return UIScreen::UnsyncKey(key);
} }
return controlMapper_.Key(key, &pauseTrigger_); return controlMapper_.Key(key, &pauseTrigger_);
} }