Commit b9423a03 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Send a Qt::Key_PowerDown when long pressing the power button

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

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:
parent 6fe7f928
......@@ -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<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts();
return input()->shortcuts()->processKey(shortcuts, key | (event->key() & ~Qt::KeyboardModifierMask));
} else if (event->type() == QEvent::KeyPress) {
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
return false;
......@@ -784,6 +793,9 @@ public:
return false;
uint m_powerOffPress;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment