2 * Copyright (C) 2014-2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 \brief A mapper for the physical keys on the device
23 A mapper to handle events triggered by pressing physical keys on a device.
29 This allows for handling the following events
31 * Volume Decreases/Increases
38 objectName: "physicalKeysMapper"
40 signal powerKeyLongPressed;
41 signal volumeDownTriggered;
42 signal volumeUpTriggered;
43 signal screenshotTriggered;
45 signal altTabNext(bool isAutoRepeat);
46 signal altTabPrevious(bool isAutoRepeat);
47 readonly property bool altTabPressed: d.altTabPressed
49 property int powerKeyLongPressTime: 2000
51 // For testing. If running windowed (e.g. tryShell), Alt+Tab is taken by the
52 // running desktop, set this to true to use Ctrl+Tab instead.
53 property bool controlInsteadOfAlt: false
58 property bool volumeDownKeyPressed: false
59 property bool volumeUpKeyPressed: false
60 property bool ignoreVolumeEvents: false
62 property bool altPressed: false
63 property bool altTabPressed: false
67 id: powerKeyLongPressTimer
68 interval: root.powerKeyLongPressTime
69 onTriggered: root.powerKeyLongPressed();
72 function onKeyPressed(event) {
73 if ((event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff)
74 && !event.isAutoRepeat) {
76 // FIXME: We only consider power key presses if the screen is
77 // on because of bugs 1410830/1409003. The theory is that when
78 // those bugs are encountered, there is a >2s delay between the
79 // power press event and the power release event, which causes
80 // the shutdown dialog to appear on resume. So to avoid that
81 // symptom while we investigate the root cause, we simply won't
82 // initiate any dialogs when the screen is off.
83 if (Powerd.status === Powerd.On) {
84 powerKeyLongPressTimer.restart();
86 event.accepted = true;
87 } else if ((event.key == Qt.Key_MediaTogglePlayPause || event.key == Qt.Key_MediaPlay)
88 && !event.isAutoRepeat) {
89 event.accepted = callManager.handleMediaKey(false);
90 } else if (event.key == Qt.Key_VolumeDown) {
91 if (event.isAutoRepeat && !d.ignoreVolumeEvents) root.volumeDownTriggered();
92 else if (!event.isAutoRepeat) {
93 if (d.volumeUpKeyPressed) {
94 if (Powerd.status === Powerd.On) root.screenshotTriggered();
95 d.ignoreVolumeEvents = true;
97 d.volumeDownKeyPressed = true;
99 } else if (event.key == Qt.Key_VolumeUp) {
100 if (event.isAutoRepeat && !d.ignoreVolumeEvents) root.volumeUpTriggered();
101 else if (!event.isAutoRepeat) {
102 if (d.volumeDownKeyPressed) {
103 if (Powerd.status === Powerd.On) root.screenshotTriggered();
104 d.ignoreVolumeEvents = true;
106 d.volumeUpKeyPressed = true;
108 } else if (event.key == Qt.Key_Alt || (root.controlInsteadOfAlt && event.key == Qt.Key_Control)) {
110 } else if (event.key == Qt.Key_Tab) {
111 if (d.altPressed && !d.altTabPressed) {
112 d.altTabPressed = true;
113 } else if (d.altTabPressed) {
114 root.altTabNext(event.isAutoRepeat);
116 } else if (event.key == Qt.Key_Backtab) {
117 if (d.altTabPressed) {
118 root.altTabPrevious(event.isAutoRepeat);
120 } else if (event.key == Qt.Key_Left) {
121 if (d.altTabPressed) {
122 root.altTabPrevious(event.isAutoRepeat);
123 event.accpeted = true;
125 } else if (event.key == Qt.Key_Right) {
126 if (d.altTabPressed) {
127 root.altTabNext(event.isAutoRepeat);
128 event.accepted = true;
133 function onKeyReleased(event) {
134 if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) {
135 powerKeyLongPressTimer.stop();
136 event.accepted = true;
137 } else if (event.key == Qt.Key_VolumeDown) {
138 if (!d.ignoreVolumeEvents) root.volumeDownTriggered();
139 d.volumeDownKeyPressed = false;
140 if (!d.volumeUpKeyPressed) d.ignoreVolumeEvents = false;
141 } else if (event.key == Qt.Key_VolumeUp) {
142 if (!d.ignoreVolumeEvents) root.volumeUpTriggered();
143 d.volumeUpKeyPressed = false;
144 if (!d.volumeDownKeyPressed) d.ignoreVolumeEvents = false;
145 } else if (event.key == Qt.Key_Alt || (root.controlInsteadOfAlt && event.key == Qt.Key_Control)) {
146 d.altPressed = false;
147 if (d.altTabPressed) {
148 d.altTabPressed = false;
149 event.accepted = true;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list