From 6f1c66f7d20283dc6fec4ff56fc682d75bf69eb2 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 30 Jan 2019 20:09:59 +0200 Subject: [PATCH] Display shortcut badges while holding Super Summary: Use `KModifierKeyInfo` to display shortcut badges while holding Super BUG: 401768 Test Plan: Just playing with it. I still don't understand the `GlobalShortcut` class very well, correct me if I make any mistake. Reviewers: #latte_dock, mvourlakos Reviewed By: #latte_dock, mvourlakos Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D18620 --- CMakeLists.txt | 2 +- README.md | 1 + app/CMakeLists.txt | 1 + app/globalshortcuts.cpp | 17 +++++++++++++++++ app/globalshortcuts.h | 6 ++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d065fbfae..11264ca69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED NO_MODULE COMPONENTS DBus Gui Qml Quick) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS - Activities Archive CoreAddons Crash DBusAddons Declarative GlobalAccel I18n + Activities Archive CoreAddons GuiAddons Crash DBusAddons Declarative GlobalAccel I18n IconThemes NewStuff Notifications Plasma PlasmaQuick Wayland WindowSystem XmlGui) find_package(X11 REQUIRED) diff --git a/README.md b/README.md index 891a3396b..1524db8c1 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ We recommend that you use at least **Plasma 5.12.0** KF5PlasmaQuick >= 5.38.0 KF5Activities >= 5.38.0 KF5CoreAddons >= 5.38.0 + KF5GuiAddons >= 5.38.0 KF5DBusAddons >= 5.38.0 KF5Declarative >= 5.38.0 KF5Wayland >= 5.38.0 diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 282ccd294..6da9e7329 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_libraries(latte-dock KF5::DBusAddons KF5::Declarative KF5::CoreAddons + KF5::GuiAddons KF5::GlobalAccel KF5::Archive KF5::Crash diff --git a/app/globalshortcuts.cpp b/app/globalshortcuts.cpp index 6b378c897..7d7e823cd 100644 --- a/app/globalshortcuts.cpp +++ b/app/globalshortcuts.cpp @@ -273,6 +273,19 @@ void GlobalShortcuts::init() m_singleMetaAction = new QAction(this); m_singleMetaAction->setShortcut(QKeySequence(Qt::META)); + + //display shortcut badges while holding Meta + m_mKeyInfoTimer.setInterval(1000); + connect(&m_mKeyInfoTimer, &QTimer::timeout, this, [&]() { + showDocks(); + }); + connect(&m_keyInfo, &KModifierKeyInfo::keyPressed, this, [&](Qt::Key key, bool state) { + if (key == Qt::Key_Super_L && state) { + m_mKeyInfoTimer.start(); + } else if (key == Qt::Key_Super_L && !state) { + m_mKeyInfoTimer.stop(); + } + }); } //! Activate launcher menu through dbus interface @@ -563,6 +576,10 @@ int GlobalShortcuts::applicationLauncherId(const Plasma::Containment *c) void GlobalShortcuts::showDocks() { m_lastInvokedAction = dynamic_cast(sender()); + if (!m_lastInvokedAction) { + // when holding Meta + m_lastInvokedAction = m_singleMetaAction; + } auto invokeShowNumbers = [this](const Plasma::Containment * c) { if (QQuickItem *containmentInterface = c->property("_plasma_graphicObject").value()) { diff --git a/app/globalshortcuts.h b/app/globalshortcuts.h index f68e2d069..23e8019fb 100644 --- a/app/globalshortcuts.h +++ b/app/globalshortcuts.h @@ -29,6 +29,9 @@ #include #include +// KDE +#include + namespace Plasma { class Containment; } @@ -82,6 +85,9 @@ private: QList m_methodsShowNumbers; Latte::Corona *m_corona{nullptr}; + + KModifierKeyInfo m_keyInfo; + QTimer m_mKeyInfoTimer; }; }