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 }