Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to support Qt keyboard input directly. Fixes #11653 #11720

Merged
merged 2 commits into from
Jan 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -354,7 +355,34 @@ 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();
auto iter = KeyMapRawQttoNative.find(qtKeycode);
int nativeKeycode = 0;
if (iter != KeyMapRawQttoNative.end()) {
nativeKeycode = iter->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....
hrydgard marked this conversation as resolved.
Show resolved Hide resolved
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));
Expand Down
7 changes: 3 additions & 4 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand 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);
Expand Down Expand Up @@ -801,13 +801,12 @@ 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(__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")));
Expand Down
3 changes: 2 additions & 1 deletion ext/native/base/NKCodeFromQt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);