diff --git a/applets/CMakeLists.txt b/applets/CMakeLists.txt --- a/applets/CMakeLists.txt +++ b/applets/CMakeLists.txt @@ -1,6 +1,7 @@ plasma_install_package(activitypager org.kde.plasma.activitypager) plasma_install_package(kickerdash org.kde.plasma.kickerdash) plasma_install_package(konsoleprofiles/package org.kde.plasma.konsoleprofiles) +plasma_install_package(keyboardindicator org.kde.plasma.keyboardindicator) add_subdirectory(binary-clock) add_subdirectory(calculator) diff --git a/applets/keyboardindicator/contents/ui/main.qml b/applets/keyboardindicator/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/applets/keyboardindicator/contents/ui/main.qml @@ -0,0 +1,67 @@ +/* + * Copyright 2018 Aleix Pol Gonzalez + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +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 + + +Item { + id: root + + Plasmoid.onActivated: toggle() + + PlasmaCore.DataSource { + id: keystateSource + engine: "keystate" + connectedSources: ["Caps Lock", "Num Lock"] + } + + readonly property bool capsLock: keystateSource.data["Caps Lock"]["Locked"] + readonly property bool numLock: keystateSource.data["Num Lock"]["Locked"] + readonly property string capsLockMessage: capsLock ? i18n("Caps Lock is on") : i18n("Caps Lock is off") + readonly property string numLockMessage: numLock ? i18n("Num Lock is on") : i18n("Num Lock is off") + + Plasmoid.icon: capsLock ? "input-caps-on" : "input-keyboard" + Plasmoid.toolTipSubText: capsLockMessage + "\n" + numLockMessage + Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation + Plasmoid.fullRepresentation: PlasmaCore.ToolTipArea { + readonly property bool inPanel: (plasmoid.location === PlasmaCore.Types.TopEdge + || plasmoid.location === PlasmaCore.Types.RightEdge + || plasmoid.location === PlasmaCore.Types.BottomEdge + || plasmoid.location === PlasmaCore.Types.LeftEdge) + + Layout.minimumWidth: units.iconSizes.small + Layout.minimumHeight: Layout.minimumWidth + + Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1 + Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1 + + icon: plasmoid.icon + mainText: plasmoid.title + subText: plasmoid.toolTipSubText + + PlasmaCore.IconItem { + anchors.fill: parent + source: plasmoid.icon + active: parent.containsMouse || root.capsLock + } + } +} diff --git a/applets/keyboardindicator/metadata.desktop b/applets/keyboardindicator/metadata.desktop new file mode 100644 --- /dev/null +++ b/applets/keyboardindicator/metadata.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Name=Keyboard Indicator +Comment=Shows the state of the keyboard +Type=Service +Icon=input-keyboard +ServiceTypes=Plasma/Applet + +X-KDE-ServiceTypes=Plasma/Applet +X-KDE-PluginInfo-Author=Aleix Pol Gonzalez +X-KDE-PluginInfo-Email=aleixpol@kde.org +X-KDE-PluginInfo-Name=org.kde.plasma.keyboardindicator +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-License=GPL-2.0+ +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-MainScript=ui/main.qml +X-Plasma-API=declarativeappletscript