Skip to content

Commit

Permalink
MacOS: Fix text input (got broken in #19441, would no longer send CHA…
Browse files Browse the repository at this point in the history
…R events)

See #19441
  • Loading branch information
hrydgard committed Oct 2, 2024
1 parent f11675b commit cb06ac4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Common/UI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
38 changes: 37 additions & 1 deletion SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1465,6 +1499,7 @@ int main(int argc, char *argv[]) {
if (g_QuitRequested || g_RestartRequested)
break;

UpdateTextFocus();
UpdateSDLCursor();

inputTracker.MouseCaptureControl();
Expand All @@ -1491,6 +1526,7 @@ int main(int argc, char *argv[]) {
if (g_QuitRequested || g_RestartRequested)
break;

UpdateTextFocus();
UpdateSDLCursor();

inputTracker.MouseCaptureControl();
Expand Down
19 changes: 9 additions & 10 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -935,7 +935,6 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) {
if (UI::IsFocusMovementEnabled()) {
return UIScreen::UnsyncKey(key);
}

return controlMapper_.Key(key, &pauseTrigger_);
}

Expand Down

0 comments on commit cb06ac4

Please sign in to comment.