From d18db74d5f23c11a4976ef24270fe703fd234f2b Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Tue, 28 Nov 2023 20:10:37 +0000 Subject: [PATCH] XWayland: no forwarding with Shift keys The shift key doesn't make sense to be one of the keys that will trigger KWin to allow XWayland apps to process all keys when it's pressed, because there aren't generally global shortcuts that consist of Shift plus an alphanumeric character key. That's because this key combination is used to type capital letters. So we can safely exclude the shift key to improve security against key logging and not break any global shortcut-using XWayland apps for people using this feature. The shift key on it's own is still forwarded as that's a non-character key. --- src/kcms/xwayland/ui/main.qml | 2 +- src/xwayland/xwayland.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/kcms/xwayland/ui/main.qml b/src/kcms/xwayland/ui/main.qml index 366cc44495..34d0422d8a 100644 --- a/src/kcms/xwayland/ui/main.qml +++ b/src/kcms/xwayland/ui/main.qml @@ -68,7 +68,7 @@ KCM.SimpleKCM { text: i18n("Only non-character keys") } QQC2.RadioButton { - text: i18n("As above, plus any key typed while a modifier key is pressed") + text: i18n("As above, plus any key typed while the Control, Alt, or Meta keys are pressed") } QQC2.RadioButton { id: always diff --git a/src/xwayland/xwayland.cpp b/src/xwayland/xwayland.cpp index 9c989343ef..64b6ec9451 100644 --- a/src/xwayland/xwayland.cpp +++ b/src/xwayland/xwayland.cpp @@ -110,11 +110,10 @@ public: void setMode(XwaylandEavesdropsMode mode) { - static const QSet modifierKeys = { - Qt::Key_Control, - Qt::Key_Shift, - Qt::Key_Alt, - Qt::Key_Meta, + static const Qt::KeyboardModifiers modifierKeys = { + Qt::ControlModifier, + Qt::AltModifier, + Qt::MetaModifier, }; static const QSet characterKeys = { @@ -347,9 +346,7 @@ public: break; case AllKeysWithModifier: m_filter = [](int key, Qt::KeyboardModifiers m) { - return m != Qt::NoModifier - || modifierKeys.contains(key) - || !characterKeys.contains(key); + return m.testAnyFlags(modifierKeys) || !characterKeys.contains(key); }; break; case All: