@@ -42,7 +42,7 @@ Item {
4242
4343 readonly property bool altTabPressed: d.altTabPressed
4444
45− property int powerKeyLongPressTime: 2000
45+ property int powerKeyLongPressCount: 31 // about 2s
4646
4747 // For testing. If running windowed (e.g. tryShell), Alt+Tab is taken by the
4848 // running desktop, set this to true to use Ctrl+Tab instead.
@@ -57,27 +57,26 @@ Item {
5757
5858 property bool altPressed: false
5959 property bool altTabPressed: false
60− }
6160
62− Timer {
63− id: powerKeyLongPressTimer
64− interval: root.powerKeyLongPressTime
65− onTriggered: root.powerKeyLongPressed();
61+ property int powerButtonCount
6662 }
6763
6864 function onKeyPressed(event) {
69− if ((event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff)
70− && (!event.isAutoRepeat || !powerKeyLongPressTimer.running)) {
71−
72− // FIXME: We only consider power key presses if the screen is
73− // on because of bugs 1410830/1409003. The theory is that when
74− // those bugs are encountered, there is a >2s delay between the
75− // power press event and the power release event, which causes
76− // the shutdown dialog to appear on resume. So to avoid that
77− // symptom while we investigate the root cause, we simply won't
78− // initiate any dialogs when the screen is off.
79− if (Powerd.status === Powerd.On) {
80− powerKeyLongPressTimer.restart();
65+ if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
66+ if (event.isAutoRepeat) {
67+ d.powerButtonCount++;
68+
69+ // We count repeats rather than watch the time because if the
70+ // system is loaded, we may misinterpret a long wall-clock
71+ // delay as a long press, when in fact we just didn't get
72+ // around to noticing the key-release event in time. But if we
73+ // count events instead, we will be in sync with the event
74+ // queue.
75+ if (d.powerButtonCount === powerKeyLongPressCount) {
76+ root.powerKeyLongPressed();
77+ }
78+ } else {
79+ d.powerButtonCount = 0;
8180 }
8281 } else if ((event.key == Qt.Key_MediaTogglePlayPause || event.key == Qt.Key_MediaPlay) && !event.isAutoRepeat) {
8382 event.accepted = callManager.handleMediaKey(false);
@@ -115,7 +114,6 @@ Item {
115114
116115 function onKeyReleased(event) {
117116 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
118− powerKeyLongPressTimer.stop();
119117 event.accepted = true;
120118 } else if (event.key == Qt.Key_VolumeDown) {
121119 if (!d.ignoreVolumeEvents) root.volumeDownTriggered();