From fb47508554ed9149bfc0964261a121aa1344ab14 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 22 Jul 2021 00:02:21 +0200 Subject: [PATCH] Provide a Plasmoid to control input methods It's mostly useful to be able to hide the virtual keyboard like we do in Plasma Mobile from the bottom panel, should probably replace the SNI from KWin. --- applets/CMakeLists.txt | 1 + applets/manage-inputmethod/Messages.sh | 2 + .../contents/ui/manage-inputmethod.qml | 95 +++++++++++++++++++ applets/manage-inputmethod/metadata.desktop | 20 ++++ components/keyboardlayout/virtualkeyboard.h | 1 + shell/org.kde.plasmashell.desktop.cmake | 2 +- 6 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 applets/manage-inputmethod/Messages.sh create mode 100644 applets/manage-inputmethod/contents/ui/manage-inputmethod.qml create mode 100644 applets/manage-inputmethod/metadata.desktop diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt index 665ae3494..96af27138 100644 --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -4,6 +4,7 @@ add_subdirectory(icon) plasma_install_package(analog-clock org.kde.plasma.analogclock) plasma_install_package(mediacontroller org.kde.plasma.mediacontroller) plasma_install_package(lock_logout org.kde.plasma.lock_logout) +plasma_install_package(manage-inputmethod org.kde.plasma.manage-inputmethod) add_subdirectory(appmenu) add_subdirectory(systemmonitor) diff --git a/applets/manage-inputmethod/Messages.sh b/applets/manage-inputmethod/Messages.sh new file mode 100644 index 000000000..49e6e038a --- /dev/null +++ b/applets/manage-inputmethod/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name \*.qml -o -name \*.cpp` -o $podir/plasma_applet_org.kde.plasma.manageinputmethod.pot diff --git a/applets/manage-inputmethod/contents/ui/manage-inputmethod.qml b/applets/manage-inputmethod/contents/ui/manage-inputmethod.qml new file mode 100644 index 000000000..8d5383ea7 --- /dev/null +++ b/applets/manage-inputmethod/contents/ui/manage-inputmethod.qml @@ -0,0 +1,95 @@ +/* + * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PlasmaComponents3 +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.workspace.keyboardlayout 1.0 as Keyboards +import org.kde.kquickcontrolsaddons 2.0 + +Item { + id: root + property var overlays: [] + + Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation + Plasmoid.fullRepresentation: Plasmoid.compactRepresentation + Plasmoid.compactRepresentation: PlasmaCore.IconItem { + source: plasmoid.icon + active: compactMouse.containsMouse + overlays: root.overlays + + MouseArea { + id: compactMouse + anchors.fill: parent + hoverEnabled: true + onClicked: if (!Keyboards.KWinVirtualKeyboard.available) { + root.action_settings() + } else if (Keyboards.KWinVirtualKeyboard.visible) { + Keyboards.KWinVirtualKeyboard.active = false + } else { + Keyboards.KWinVirtualKeyboard.enabled = !Keyboards.KWinVirtualKeyboard.enabled + } + } + } + + Component.onCompleted: { + plasmoid.setAction("settings", i18nc("Opens the system settings module", "Configure Virtual Keyboards..."), + "settings-configure") + } + + function action_settings() { + KCMShell.openSystemSettings("kcm_virtualkeyboard"); + } + + states: [ + State { + name: "available" + when: !Keyboards.KWinVirtualKeyboard.available + PropertyChanges { + target: plasmoid + icon: "input-keyboard-virtual-off" + toolTipSubText: i18n("Virtual Keyboard: unavailable") + status: PlasmaCore.Types.PassiveStatus + } + PropertyChanges { target: root; overlays: [ "emblem-unavailable" ] } + }, + State { + name: "disabled" + when: Keyboards.KWinVirtualKeyboard.available && !Keyboards.KWinVirtualKeyboard.enabled + PropertyChanges { + target: plasmoid + icon: "input-keyboard-virtual-off" + toolTipSubText: i18n("Virtual Keyboard: disabled") + status: PlasmaCore.Types.ActiveStatus + } + PropertyChanges { target: root; overlays: [] } + }, + State { + name: "visible" + when: Keyboards.KWinVirtualKeyboard.available && Keyboards.KWinVirtualKeyboard.visible + PropertyChanges { target: plasmoid + icon: "arrow-down" + toolTipSubText: i18n("Virtual Keyboard: visible") + status: PlasmaCore.Types.ActiveStatus + } + PropertyChanges { target: root; overlays: [] } + }, + State { + name: "idle" + when: Keyboards.KWinVirtualKeyboard.available && Keyboards.KWinVirtualKeyboard.enabled && !Keyboards.KWinVirtualKeyboard.visible + PropertyChanges { target: plasmoid + icon: "input-keyboard-virtual-on" + toolTipSubText: i18n("Virtual Keyboard: enabled") + status: PlasmaCore.Types.PassiveStatus + } + PropertyChanges { target: root; overlays: [] } + } + ] +} diff --git a/applets/manage-inputmethod/metadata.desktop b/applets/manage-inputmethod/metadata.desktop new file mode 100644 index 000000000..23634aa7d --- /dev/null +++ b/applets/manage-inputmethod/metadata.desktop @@ -0,0 +1,20 @@ +[Desktop Entry] +Name=Input Method +Comment=Manage your Input Methods + +Icon=input-keyboard-virtual +Type=Service +X-KDE-ServiceTypes=Plasma/Applet + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/manage-inputmethod.qml + +X-KDE-PluginInfo-Author=Aleix Pol Gonzalez +X-KDE-PluginInfo-Email=aleixpol@kde.org +X-KDE-PluginInfo-Name=org.kde.plasma.manage-inputmethod +X-KDE-PluginInfo-Version=3.0 +X-KDE-PluginInfo-Website=https://plasma.kde.org/ +X-KDE-PluginInfo-Category=Accessibility +X-KDE-PluginInfo-License=GPL-2.0+ +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-FormFactors=tablet,handset,desktop diff --git a/components/keyboardlayout/virtualkeyboard.h b/components/keyboardlayout/virtualkeyboard.h index a580acc7d..310ea345f 100644 --- a/components/keyboardlayout/virtualkeyboard.h +++ b/components/keyboardlayout/virtualkeyboard.h @@ -14,6 +14,7 @@ class KwinVirtualKeyboardInterface : public OrgKdeKwinVirtualKeyboardInterface Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) + Q_PROPERTY(bool available READ available NOTIFY availableChanged) public: KwinVirtualKeyboardInterface(); }; diff --git a/shell/org.kde.plasmashell.desktop.cmake b/shell/org.kde.plasmashell.desktop.cmake index 5b3fdd3a8..cb2c2f11d 100644 --- a/shell/org.kde.plasmashell.desktop.cmake +++ b/shell/org.kde.plasmashell.desktop.cmake @@ -65,4 +65,4 @@ NoDisplay=true X-systemd-skip=true X-KDE-Wayland-Interfaces=org_kde_plasma_window_management,org_kde_kwin_keystate,zkde_screencast_unstable_v1 -X-KDE-DBUS-Restricted-Interfaces=org.kde.kwin.Screenshot +X-KDE-DBUS-Restricted-Interfaces=org.kde.kwin.Screenshot2