on xenial help sign in
Move media key logic and powerd logic into PhysicalKeyFilter
commit5a061b074ca57f8249571aca2ad4b1a06788c34a authorJosh Arenson <joshua.arenson@canonical.com> dateThu 22 Jan 2015, 14:34 (12 years ago) parent955ba00
2 files changed+29−9
qml/Components/PhysicalKeysMapper.qml+28−3 qml/Shell.qml+1−6
qml/Components/PhysicalKeysMapper.qml+28−3
@@ -15,6 +15,8 @@
1515 */
1616
1717import QtQuick 2.0
18+import Powerd 0.1
19+
1820/*!
1921 \brief A mapper for the physical keys on the device
2022
@@ -62,16 +64,33 @@ Item {
6264
6365
6466 function onKeyPressed(key) {
67+ var eventAccepted = true;
68+
6569 /* Determine what key was pressed */
6670 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
67− if (!powerKeyLongPressTimer.running) {
68− powerKeyLongPressTimer.restart();
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+ // This also prevents taking screenshots when the screen is off.
80+ if (Powerd.status === Powerd.On) {
81+ if (!powerKeyLongPressTimer.running) {
82+ powerKeyLongPressTimer.restart();
83+ }
84+ d.powerKeyPressed = true;
6985 }
70− d.powerKeyPressed = true;
86+ } else if (key == Qt.Key_MediaTogglePlayPause || key == Qt.Key_MediaPlay) {
87+ eventAccepted = callManager.handleMediaKey(false);
7188 } else if (key == Qt.Key_VolumeDown) {
7289 d.volumeDownKeyPressed = true;
7390 } else if (key == Qt.Key_VolumeUp) {
7491 d.volumeUpKeyPressed = true;
92+ } else {
93+ eventAccepted = false;
7594 }
7695
7796 /* Determine how to handle it */
@@ -86,9 +105,12 @@ Item {
86105 } else if (d.volumeUpKeyPressed) {
87106 volumeUpPressed();
88107 }
108+ return eventAccepted;
89109 }
90110
91111 function onKeyReleased(key) {
112+ var eventAccepted = true;
113+
92114 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
93115 powerKeyLongPressTimer.stop();
94116 d.powerKeyPressed = false;
@@ -97,6 +119,9 @@ Item {
97119 d.volumeDownKeyPressed = false;
98120 } else if (key == Qt.Key_VolumeUp) {
99121 d.volumeUpKeyPressed = false;
122+ } else {
123+ eventAccepted = false;
100124 }
125+ return eventAccepted;
101126 }
102127}
qml/Shell.qml+1−6
@@ -183,12 +183,7 @@ Item {
183183
184184 WindowKeysFilter {
185185 Keys.onPressed: {
186− physicalKeysMapper.onKeyPressed(event.key);
187− if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
188− event.accepted = true;
189− } else {
190− event.accepted = false;
191− }
186+ event.accepted = physicalKeysMapper.onKeyPressed(event.key);
192187 }
193188
194189 Keys.onReleased: {