remotekeyboard: Move workaround to the c++ side and make it more generic
The QKeyEvent::text we get from a Ctrl+W press is a weird unicode charcater for ^W (see comment). We don't deal with that thing, create the controlled letter using QKeySequence and move on.
This commit is contained in:
parent
6897b1863b
commit
b61ba29673
2 changed files with 17 additions and 16 deletions
|
@ -79,20 +79,8 @@ TextField {
|
|||
function sendEvent(event) {
|
||||
if (remoteKeyboard) {
|
||||
var transEvent = JSON.parse(JSON.stringify(event)); // transform to anonymous object
|
||||
if (transEvent.modifiers & Qt.ControlModifier) {
|
||||
// special handling for ctrl+c/v/x/a, for which only 'key' gets
|
||||
// set, but no visible 'text', which is expected by the remoteKeyboard
|
||||
// wire-format:
|
||||
if (transEvent.key === Qt.Key_C)
|
||||
transEvent.text = 'c';
|
||||
if (transEvent.key === Qt.Key_V)
|
||||
transEvent.text = 'v';
|
||||
if (transEvent.key === Qt.Key_A)
|
||||
transEvent.text = 'a';
|
||||
if (transEvent.key === Qt.Key_X)
|
||||
transEvent.text = 'x';
|
||||
}
|
||||
remoteKeyboard.sendQKeyEvent(transEvent);
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "plugin_remotekeyboard_debug.h"
|
||||
#include <KPluginFactory>
|
||||
#include <QDebug>
|
||||
#include <QKeySequence>
|
||||
#include <QString>
|
||||
#include <QVariantMap>
|
||||
|
||||
|
@ -100,11 +101,23 @@ void RemoteKeyboardPlugin::sendKeyPress(const QString &key, int specialKey, bool
|
|||
|
||||
void RemoteKeyboardPlugin::sendQKeyEvent(const QVariantMap &keyEvent, bool sendAck) const
|
||||
{
|
||||
if (!keyEvent.contains(QStringLiteral("key")))
|
||||
if (!keyEvent.contains(QStringLiteral("key"))) {
|
||||
return;
|
||||
int k = translateQtKey(keyEvent.value(QStringLiteral("key")).toInt());
|
||||
}
|
||||
const int key = keyEvent.value(QStringLiteral("key")).toInt();
|
||||
int k = translateQtKey(key);
|
||||
int modifiers = keyEvent.value(QStringLiteral("modifiers")).toInt();
|
||||
sendKeyPress(keyEvent.value(QStringLiteral("text")).toString(),
|
||||
|
||||
// Qt will be calling xkb_state_key_get_utf8 to create this string.
|
||||
// As documented, it will be giving us weird strings with Ctrl combinations:
|
||||
// https://xkbcommon.org/doc/current/group__keysyms.html
|
||||
// Instead, just use QKeySequence to tell us which key that is and move on
|
||||
QString text = keyEvent.value(QStringLiteral("text")).toString();
|
||||
if (!text.isEmpty() && !text[0].isLetterOrNumber()) {
|
||||
text = QKeySequence(key).toString().toLower();
|
||||
}
|
||||
|
||||
sendKeyPress(text,
|
||||
k,
|
||||
modifiers & Qt::ShiftModifier,
|
||||
modifiers & Qt::ControlModifier,
|
||||
|
|
Loading…
Reference in a new issue