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
This commit is contained in:
Aleix Pol 2020-02-06 12:12:30 +01:00
parent 6fe7f9281a
commit b9423a033c

View file

@ -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:
input()->shortcuts()->processSwipeEnd();
return false;
}
private:
uint m_powerOffPress;
};