Permalink
Browse files

Try to support Qt keyboard input directly. Partially fixes #11653 (ni…

…ckname crash on mac)
  • Loading branch information...
hrydgard committed Jan 6, 2019
1 parent 79d4b0f commit 5a1fa6008714b96b1506a3f265104a0cfa830b0c
Showing with 32 additions and 6 deletions.
  1. +25 −1 Qt/QtMain.cpp
  2. +5 −4 UI/GameSettingsScreen.cpp
  3. +2 −1 ext/native/base/NKCodeFromQt.h
@@ -31,6 +31,7 @@
#include "gfx_es2/gpu_features.h"
#include "math/math_util.h"
#include "thread/threadutil.h"
#include "util/text/utf8.h"
#include "Core/Config.h"
#include "Core/ConfigValues.h"

@@ -354,7 +355,30 @@ bool MainUI::event(QEvent *e)
NativeKey(KeyInput(DEVICE_ID_MOUSE, ((QWheelEvent*)e)->delta()<0 ? NKCODE_EXT_MOUSEWHEEL_DOWN : NKCODE_EXT_MOUSEWHEEL_UP, KEY_DOWN));
break;
case QEvent::KeyPress:
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_DOWN));
{
auto qtKeycode = ((QKeyEvent*)e)->key();
int nativeKeycode = KeyMapRawQttoNative.find(qtKeycode)->second;
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, nativeKeycode, KEY_DOWN));
// Also get the unicode value.
QString text = ((QKeyEvent*)e)->text();
std::string str = text.toStdString();

// Now, we don't want CHAR events for non-printable characters. Not quite sure how we'll best
// do that, but here's one attempt....
switch (nativeKeycode) {
case NKCODE_DEL:
case NKCODE_FORWARD_DEL:
case NKCODE_TAB:
break;
default:
if (str.size()) {
int pos = 0;
int code = u8_nextchar(str.c_str(), &pos);
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, code, KEY_CHAR));
}
break;
}
}
break;
case QEvent::KeyRelease:
NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_UP));
@@ -643,7 +643,7 @@ void GameSettingsScreen::CreateViews() {
networkingSettings->Add(new CheckBox(&g_Config.bEnableWlan, n->T("Enable networking", "Enable networking/wlan (beta)")));
networkingSettings->Add(new CheckBox(&g_Config.bDiscordPresence, n->T("Send Discord Presence information")));

#if !defined(MOBILE_DEVICE) && !defined(USING_QT_UI)
#if !defined(MOBILE_DEVICE)
networkingSettings->Add(new PopupTextInputChoice(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), "", 255, screenManager()));
#elif defined(__ANDROID__)
networkingSettings->Add(new ChoiceWithValueDisplay(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeproAdhocServerAddress);
@@ -801,13 +801,14 @@ void GameSettingsScreen::CreateViews() {
systemSettings->Add(new PopupMultiChoice(&g_Config.iPSPModel, sy->T("PSP Model"), models, 0, ARRAY_SIZE(models), sy->GetName(), screenManager()))->SetEnabled(!PSP_IsInited());
// TODO: Come up with a way to display a keyboard for mobile users,
// so until then, this is Windows/Desktop only.
#if !defined(MOBILE_DEVICE) && !defined(USING_QT_UI) // TODO: Add all platforms where KEY_CHAR support is added
#if !defined(MOBILE_DEVICE) // TODO: Add all platforms where KEY_CHAR support is added
systemSettings->Add(new PopupTextInputChoice(&g_Config.sNickName, sy->T("Change Nickname"), "", 32, screenManager()));
#elif defined(USING_QT_UI)
systemSettings->Add(new Choice(sy->T("Change Nickname")))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname);
// #elif defined(USING_QT_UI)
// systemSettings->Add(new Choice(sy->T("Change Nickname")))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname);
#elif defined(__ANDROID__)
systemSettings->Add(new ChoiceWithValueDisplay(&g_Config.sNickName, sy->T("Change Nickname"), (const char *)nullptr))->OnClick.Handle(this, &GameSettingsScreen::OnChangeNickname);
#endif

#if defined(_WIN32) || (defined(USING_QT_UI) && !defined(MOBILE_DEVICE))
// Screenshot functionality is not yet available on non-Windows/non-Qt
systemSettings->Add(new CheckBox(&g_Config.bScreenshotsAsPNG, sy->T("Screenshots as PNG")));
@@ -98,5 +98,6 @@ static const std::map<int, int> KeyMapRawQttoNative = InitConstMap<int, int>
(Qt::Key_Up, NKCODE_DPAD_UP)
(Qt::Key_Right, NKCODE_DPAD_RIGHT)
(Qt::Key_Down, NKCODE_DPAD_DOWN)
(Qt::Key_Back, NKCODE_BACK);
(Qt::Key_Back, NKCODE_BACK)
(Qt::Key_Backspace, NKCODE_DEL);

0 comments on commit 5a1fa60

Please sign in to comment.