From b9423a033c8a3957cdadb3737674bb153b0d16c6 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 6 Feb 2020 12:12:30 +0100 Subject: [PATCH] Send a Qt::Key_PowerDown when long pressing the power button Summary: This will be useful to be able to show a menu on long press and just lock the screen on normal press, especially useful on phones and tablets. Test Plan: Could not test much because on laptops doesn't work. Would need more investigation. discussed further on the plasma mailing list. Reviewers: #plasma, davidedmundson Reviewed By: #plasma, davidedmundson Subscribers: z3ntu, davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D26899 --- input.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/input.cpp b/input.cpp index 27d1e926d2..b2032cf3ee 100644 --- a/input.cpp +++ b/input.cpp @@ -759,7 +759,16 @@ public: return input()->shortcuts()->processAxis(event->modifiers(), direction); } bool keyEvent(QKeyEvent *event) override { - if (event->type() == QEvent::KeyPress) { + if (event->key() == Qt::Key_PowerOff) { + if (event->type() == QEvent::KeyPress) { + m_powerOffPress = event->timestamp(); + } else if (event->type() == QEvent::KeyRelease) { + const uint duration = (event->timestamp() - m_powerOffPress); + const Qt::Key key = duration > 1000 ? Qt::Key_PowerDown : Qt::Key_PowerOff; + const auto shortcuts = static_cast(event)->modifiersRelevantForGlobalShortcuts(); + return input()->shortcuts()->processKey(shortcuts, key | (event->key() & ~Qt::KeyboardModifierMask)); + } + } else if (event->type() == QEvent::KeyPress) { return input()->shortcuts()->processKey(static_cast(event)->modifiersRelevantForGlobalShortcuts(), event->key()); } return false; @@ -784,6 +793,9 @@ public: input()->shortcuts()->processSwipeEnd(); return false; } + +private: + uint m_powerOffPress; };