From 4ffc72cd4530e10ab36afba21e8997227a65533e Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 30 Apr 2021 01:42:41 +0200 Subject: [PATCH] screen locker: Integrate the virtual keyboard on wayland Use the system's virtual keyboard instead of relying on QtVirtualKeyboard specifically for the lock screen. It means less code (when we can remove the virtual keyboard part), better integration and one dependency less. --- components/keyboardlayout/CMakeLists.txt | 5 ++-- .../keyboardlayout/keyboardlayoutplugin.cpp | 4 ++++ components/keyboardlayout/virtualkeyboard.cpp | 12 ++++++++++ components/keyboardlayout/virtualkeyboard.h | 18 ++++++++++++++ .../components/VirtualKeyboard_wayland.qml | 24 +++++++++++++++++++ .../contents/lockscreen/LockScreenUi.qml | 14 +++++++---- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 components/keyboardlayout/virtualkeyboard.cpp create mode 100644 components/keyboardlayout/virtualkeyboard.h create mode 100644 lookandfeel/contents/components/VirtualKeyboard_wayland.qml diff --git a/components/keyboardlayout/CMakeLists.txt b/components/keyboardlayout/CMakeLists.txt index 48d9d7075..e6ccd5a8e 100644 --- a/components/keyboardlayout/CMakeLists.txt +++ b/components/keyboardlayout/CMakeLists.txt @@ -2,8 +2,8 @@ set(keyboardlayoutplugin_SRCS keyboardlayout.cpp keyboardlayoutplugin.cpp layoutnames.cpp - layoutnames.h - ) + virtualkeyboard.cpp +) ecm_qt_declare_logging_category(keyboardlayoutplugin_SRCS HEADER debug.h IDENTIFIER KEYBOARD_LAYOUT @@ -14,6 +14,7 @@ set_source_files_properties(org.kde.KeyboardLayouts.xml PROPERTIES INCLUDE layoutnames.h) qt5_add_dbus_interface(keyboardlayoutplugin_SRCS "org.kde.KeyboardLayouts.xml" keyboard_layout_interface) +qt5_add_dbus_interface(keyboardlayoutplugin_SRCS "${KWIN_VIRTUALKEYBOARD_INTERFACE}" virtualkeyboard_interface) add_library(keyboardlayoutplugin SHARED ${keyboardlayoutplugin_SRCS}) diff --git a/components/keyboardlayout/keyboardlayoutplugin.cpp b/components/keyboardlayout/keyboardlayoutplugin.cpp index e10c078d8..50b0d3f82 100644 --- a/components/keyboardlayout/keyboardlayoutplugin.cpp +++ b/components/keyboardlayout/keyboardlayoutplugin.cpp @@ -22,6 +22,7 @@ #include "keyboardlayoutplugin.h" #include "keyboardlayout.h" +#include "virtualkeyboard.h" #include @@ -30,4 +31,7 @@ void KeyboardLayoutPlugin::registerTypes(const char *uri) Q_ASSERT(uri == QLatin1String("org.kde.plasma.workspace.keyboardlayout")); qmlRegisterType(uri, 1, 0, "KeyboardLayout"); + qmlRegisterSingletonType(uri, 1, 0, "KWinVirtualKeyboard", [](QQmlEngine *, QJSEngine *) -> QObject * { + return new KwinVirtualKeyboardInterface; + }); } diff --git a/components/keyboardlayout/virtualkeyboard.cpp b/components/keyboardlayout/virtualkeyboard.cpp new file mode 100644 index 000000000..7070a8485 --- /dev/null +++ b/components/keyboardlayout/virtualkeyboard.cpp @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL + */ + +#include "virtualkeyboard.h" + +KwinVirtualKeyboardInterface::KwinVirtualKeyboardInterface() + : OrgKdeKwinVirtualKeyboardInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus()) +{ +} diff --git a/components/keyboardlayout/virtualkeyboard.h b/components/keyboardlayout/virtualkeyboard.h new file mode 100644 index 000000000..4f52d38ac --- /dev/null +++ b/components/keyboardlayout/virtualkeyboard.h @@ -0,0 +1,18 @@ +/* + * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL + */ + +#pragma once + +#include "virtualkeyboard_interface.h" + +class KwinVirtualKeyboardInterface : public OrgKdeKwinVirtualKeyboardInterface +{ + Q_OBJECT + Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) +public: + KwinVirtualKeyboardInterface(); +}; diff --git a/lookandfeel/contents/components/VirtualKeyboard_wayland.qml b/lookandfeel/contents/components/VirtualKeyboard_wayland.qml new file mode 100644 index 000000000..d0a2c0743 --- /dev/null +++ b/lookandfeel/contents/components/VirtualKeyboard_wayland.qml @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL + */ + +import QtQuick 2.15 +import org.kde.plasma.workspace.keyboardlayout 1.0 as Keyboards + +Item { + id: inputPanel + readonly property bool active: Qt.inputMethod.visible + property bool activated: false + visible: Qt.inputMethod.visible + + x: Qt.inputMethod.keyboardRectangle.x + y: Qt.inputMethod.keyboardRectangle.y + height: Qt.inputMethod.keyboardRectangle.height + width: Qt.inputMethod.keyboardRectangle.width + + onActivatedChanged: if (activated) { + Keyboards.KWinVirtualKeyboard.enabled = true + } +} diff --git a/lookandfeel/contents/lockscreen/LockScreenUi.qml b/lookandfeel/contents/lockscreen/LockScreenUi.qml index 51b4ea177..bde069847 100644 --- a/lookandfeel/contents/lockscreen/LockScreenUi.qml +++ b/lookandfeel/contents/lockscreen/LockScreenUi.qml @@ -328,14 +328,13 @@ PlasmaCore.ColorScope { function showHide() { state = state == "hidden" ? "visible" : "hidden"; } - Component.onCompleted: inputPanel.source = "../components/VirtualKeyboard.qml" + Component.onCompleted: { + inputPanel.source = Qt.platform.pluginName.includes("wayland") ? "../components/VirtualKeyboard_wayland.qml" : "../components/VirtualKeyboard.qml" + } onKeyboardActiveChanged: { if (keyboardActive) { state = "visible"; - // Otherwise the password field loses focus and virtual keyboard - // keystrokes get eaten - mainBlock.mainPasswordBox.forceActiveFocus(); } else { state = "hidden"; } @@ -517,7 +516,12 @@ PlasmaCore.ColorScope { PlasmaComponents3.ToolButton { text: i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Button to show/hide virtual keyboard", "Virtual Keyboard") icon.name: inputPanel.keyboardActive ? "input-keyboard-virtual-on" : "input-keyboard-virtual-off" - onClicked: inputPanel.showHide() + onClicked: { + // Otherwise the password field loses focus and virtual keyboard + // keystrokes get eaten + mainBlock.mainPasswordBox.forceActiveFocus(); + inputPanel.showHide() + } visible: inputPanel.status == Loader.Ready }