Improve PowerOff/PowerDown behaviour
Summary: Trigger PowerDown after pressing for 1s instead of having to wait for release to decide, feels more natural. Also don't operate the modifiers, it's done later by KGlobalAccel. Reviewers: #kwin, #plasma:_mobile, bshah Reviewed By: #plasma:_mobile, bshah Subscribers: ngraham, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D28490
This commit is contained in:
parent
dbac4bce7e
commit
f4e41430e5
1 changed files with 22 additions and 7 deletions
29
input.cpp
29
input.cpp
|
@ -736,6 +736,15 @@ private:
|
||||||
|
|
||||||
class GlobalShortcutFilter : public InputEventFilter {
|
class GlobalShortcutFilter : public InputEventFilter {
|
||||||
public:
|
public:
|
||||||
|
GlobalShortcutFilter() {
|
||||||
|
m_powerDown = new QTimer;
|
||||||
|
m_powerDown->setSingleShot(true);
|
||||||
|
m_powerDown->setInterval(1000);
|
||||||
|
}
|
||||||
|
~GlobalShortcutFilter() {
|
||||||
|
delete m_powerDown;
|
||||||
|
}
|
||||||
|
|
||||||
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
bool pointerEvent(QMouseEvent *event, quint32 nativeButton) override {
|
||||||
Q_UNUSED(nativeButton);
|
Q_UNUSED(nativeButton);
|
||||||
if (event->type() == QEvent::MouseButtonPress) {
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
|
@ -763,13 +772,19 @@ public:
|
||||||
}
|
}
|
||||||
bool keyEvent(QKeyEvent *event) override {
|
bool keyEvent(QKeyEvent *event) override {
|
||||||
if (event->key() == Qt::Key_PowerOff) {
|
if (event->key() == Qt::Key_PowerOff) {
|
||||||
if (event->type() == QEvent::KeyPress) {
|
const auto modifiers = static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts();
|
||||||
m_powerOffPress = event->timestamp();
|
if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) {
|
||||||
|
QObject::connect(m_powerDown, &QTimer::timeout, input()->shortcuts(), [this, modifiers] {
|
||||||
|
QObject::disconnect(m_powerDown, &QTimer::timeout, input()->shortcuts(), nullptr);
|
||||||
|
m_powerDown->stop();
|
||||||
|
input()->shortcuts()->processKey(modifiers, Qt::Key_PowerDown);
|
||||||
|
});
|
||||||
|
m_powerDown->start();
|
||||||
|
return true;
|
||||||
} else if (event->type() == QEvent::KeyRelease) {
|
} else if (event->type() == QEvent::KeyRelease) {
|
||||||
const uint duration = (event->timestamp() - m_powerOffPress);
|
const bool ret = !m_powerDown->isActive() || input()->shortcuts()->processKey(modifiers, event->key());
|
||||||
const Qt::Key key = duration > 1000 ? Qt::Key_PowerDown : Qt::Key_PowerOff;
|
m_powerDown->stop();
|
||||||
const auto shortcuts = static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts();
|
return ret;
|
||||||
return input()->shortcuts()->processKey(shortcuts, key | (event->key() & ~Qt::KeyboardModifierMask));
|
|
||||||
}
|
}
|
||||||
} else if (event->type() == QEvent::KeyPress) {
|
} else if (event->type() == QEvent::KeyPress) {
|
||||||
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
|
return input()->shortcuts()->processKey(static_cast<KeyEvent*>(event)->modifiersRelevantForGlobalShortcuts(), event->key());
|
||||||
|
@ -798,7 +813,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint m_powerOffPress;
|
QTimer* m_powerDown = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue