@@ -23,8 +23,8 @@ import QtQuick 2.0
24 A filter to handle events triggered by pressing physical keys on a device.
24 A filter to handle events triggered by pressing physical keys on a device.
25 Keys included are
25 Keys included are
27 * Volume Decrease
26 * Volume Decrease
30 This allows for handling the following events
30 This allows for handling the following events
@@ -36,10 +36,14 @@ import QtQuick 2.0
39+ signal powerPressed()
40+ signal screenshotPressed()
39 signal volumeDownPressed()
41 signal volumeDownPressed()
40 signal volumeUpPressed()
42 signal volumeUpPressed()
41− signal screenshotPressed()
44+ property bool eventAccepted: false
46+ property bool aPowerKeyWasReleased: true
43 property bool powerKeyPressed: false
47 property bool powerKeyPressed: false
45 property bool aVolumeKeyWasReleased: true
49 property bool aVolumeKeyWasReleased: true
@@ -47,16 +51,25 @@ QtObject {
47 property bool volumeUpKeyPressed: false
51 property bool volumeUpKeyPressed: false
49 function onKeyPressed(key) {
53 function onKeyPressed(key) {
54+ /* Determine what key was pressed */
50 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
57 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
58+ eventAccepted = true;
51 powerKeyPressed = true;
59 powerKeyPressed = true;
53 else if (key == Qt.Key_VolumeDown) {
63 else if (key == Qt.Key_VolumeDown) {
64+ eventAccepted = true;
54 volumeDownKeyPressed = true;
65 volumeDownKeyPressed = true;
56 else if (key == Qt.Key_VolumeUp) {
67 else if (key == Qt.Key_VolumeUp) {
68+ eventAccepted = true;
57 volumeUpKeyPressed = true;
69 volumeUpKeyPressed = true;
72+ /* Determine how to handle it */
60 if (volumeDownKeyPressed && volumeUpKeyPressed) {
73 if (volumeDownKeyPressed && volumeUpKeyPressed) {
61 if (aVolumeKeyWasReleased) {
74 if (aVolumeKeyWasReleased) {
62 bothVolumeKeysPressed();
75 bothVolumeKeysPressed();
@@ -64,28 +77,38 @@ QtObject {
64 aVolumeKeyWasReleased = false;
77 aVolumeKeyWasReleased = false;
66 else if (volumeDownKeyPressed) {
79 else if (volumeDownKeyPressed) {
67− if (powerKeyPressed) {
80+ if (powerKeyPressed && aPowerKeyWasReleased) {
68 screenshotPressed();
81 screenshotPressed();
69− } else {
82+ aPowerKeyWasReleased = false;
83+ // Don't emit volumeDownPressed if power key is held
84+ } else if (aPowerKeyWasReleased){
70 volumeDownPressed();
85 volumeDownPressed();
73 else if (volumeUpKeyPressed) {
88 else if (volumeUpKeyPressed) {
74 volumeUpPressed();
89 volumeUpPressed();
92+ return eventAccepted;
78 function onKeyReleased(key) {
95 function onKeyReleased(key) {
79 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
96 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
97+ eventAccepted = true;
80 powerKeyPressed = false;
98 powerKeyPressed = false;
99+ aPowerKeyWasReleased = true;
82 else if (key == Qt.Key_VolumeDown) {
101 else if (key == Qt.Key_VolumeDown) {
102+ eventAccepted = true;
83 volumeDownKeyPressed = false;
103 volumeDownKeyPressed = false;
84 aVolumeKeyWasReleased = false;
104 aVolumeKeyWasReleased = false;
86 else if (key == Qt.Key_VolumeUp) {
106 else if (key == Qt.Key_VolumeUp) {
107+ eventAccepted = true;
87 volumeUpKeyPressed = false;
108 volumeUpKeyPressed = false;
88 aVolumeKeyWasReleased = true;
109 aVolumeKeyWasReleased = true;
112+ return eventAccepted;