on xenial help sign in
rework keyboard handling a bit
7d7d734Michael Zanetti
qml/Components/PhysicalKeysMapper.qml−17
@@ -42,8 +42,6 @@ Item {
42 signal volumeUpTriggered;
42 signal volumeUpTriggered;
43 signal screenshotTriggered;
43 signal screenshotTriggered;
44
44
45− signal altTabNext(bool isAutoRepeat);
46− signal altTabPrevious(bool isAutoRepeat);
47 readonly property bool altTabPressed: d.altTabPressed
45 readonly property bool altTabPressed: d.altTabPressed
48
46
49 property int powerKeyLongPressTime: 2000
47 property int powerKeyLongPressTime: 2000
@@ -110,21 +108,6 @@ Item {
110 } else if (event.key == Qt.Key_Tab) {
108 } else if (event.key == Qt.Key_Tab) {
111 if (d.altPressed && !d.altTabPressed) {
109 if (d.altPressed && !d.altTabPressed) {
112 d.altTabPressed = true;
110 d.altTabPressed = true;
113− } else if (d.altTabPressed) {
114− root.altTabNext(event.isAutoRepeat);
115− }
116− } else if (event.key == Qt.Key_Backtab) {
117− if (d.altTabPressed) {
118− root.altTabPrevious(event.isAutoRepeat);
119− }
120− } else if (event.key == Qt.Key_Left) {
121− if (d.altTabPressed) {
122− root.altTabPrevious(event.isAutoRepeat);
123− event.accpeted = true;
124− }
125− } else if (event.key == Qt.Key_Right) {
126− if (d.altTabPressed) {
127− root.altTabNext(event.isAutoRepeat);
128 event.accepted = true;
111 event.accepted = true;
129 }
112 }
130 }
113 }
qml/Shell.qml−2
@@ -183,8 +183,6 @@ Item {
183 onVolumeDownTriggered: volumeControl.volumeDown();
183 onVolumeDownTriggered: volumeControl.volumeDown();
184 onVolumeUpTriggered: volumeControl.volumeUp();
184 onVolumeUpTriggered: volumeControl.volumeUp();
185 onScreenshotTriggered: screenGrabber.capture();
185 onScreenshotTriggered: screenGrabber.capture();
186− onAltTabNext: applicationsDisplayLoader.item.altTabNext(isAutoRepeat)
187− onAltTabPrevious: applicationsDisplayLoader.item.altTabPrevious(isAutoRepeat);
188 }
186 }
189
187
190 ScreenGrabber {
188 ScreenGrabber {
qml/Stages/DesktopStage.qml+55−42
@@ -55,46 +55,6 @@ Rectangle {
55 property alias background: wallpaper.source
55 property alias background: wallpaper.source
56 property bool altTabPressed: false
56 property bool altTabPressed: false
57
57
58− onAltTabPressedChanged: {
59− if (!altTabPressed && root.state == "altTab") {
60− print("released", appRepeater.highlightedIndex)
61− ApplicationManager.requestFocusApplication(ApplicationManager.get(appRepeater.highlightedIndex).appId)
62− }
63− }
64−
65− function altTabNext(isAutoRepeat) {
66− if (root.altTabPressed) {
67− print("should tab next", isAutoRepeat, "highlightedIndex is", appRepeater.highlightedIndex)
68− if (isAutoRepeat && appRepeater.highlightedIndex >= ApplicationManager.count -1) {
69− return; // AutoRepeat is not allowed to wrap around
70− }
71−
72− appRepeater.highlightedIndex = (appRepeater.highlightedIndex + 1) % ApplicationManager.count;
73− print("new highlighted index", appRepeater.highlightedIndex)
74− var newContentX = ((spreadFlickable.contentWidth) / (ApplicationManager.count + 1)) * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 3));
75− if (spreadFlickable.contentX < newContentX || appRepeater.highlightedIndex == 0) {
76− spreadFlickable.snapTo(newContentX)
77− }
78− }
79− }
80−
81− function altTabPrevious(isAutoRepeat) {
82− print("alttabprevious pressed")
83− if (root.altTabPressed) {
84− if (isAutoRepeat && appRepeater.highlightedIndex == 0) {
85− return; // AutoRepeat is not allowed to wrap around
86− }
87−
88− var newIndex = appRepeater.highlightedIndex - 1 >= 0 ? appRepeater.highlightedIndex - 1 : ApplicationManager.count - 1;
89− print("setting highlighted to", newIndex)
90− appRepeater.highlightedIndex = newIndex;
91− var newContentX = ((spreadFlickable.contentWidth) / (ApplicationManager.count + 1)) * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 1));
92− if (spreadFlickable.contentX > newContentX || newIndex == ApplicationManager.count -1) {
93− spreadFlickable.snapTo(newContentX)
94− }
95− }
96− }
97−
98 CrossFadeImage {
58 CrossFadeImage {
99 id: wallpaper
59 id: wallpaper
100 anchors.fill: parent
60 anchors.fill: parent
@@ -165,9 +125,60 @@ Rectangle {
165 visible: false
125 visible: false
166 }
126 }
167
127
168− Item {
128+ FocusScope {
169 id: appContainer
129 id: appContainer
170 anchors.fill: parent
130 anchors.fill: parent
131+
132+ Keys.onPressed: {
133+ switch (event.key) {
134+ case Qt.Key_Left:
135+ case Qt.Key_Backtab:
136+ selectPrevious(event.isAutoRepeat)
137+ break;
138+ case Qt.Key_Right:
139+ case Qt.Key_Tab:
140+ selectNext(event.isAutoRepeat)
141+ break;
142+ case Qt.Key_Escape:
143+ appRepeater.highlightedIndex = -1
144+ case Qt.Key_Enter:
145+ case Qt.Key_Return:
146+ case Qt.Key_Space:
147+ root.state = ""
148+ }
149+ }
150+
151+ function selectNext(isAutoRepeat) {
152+ if (isAutoRepeat && appRepeater.highlightedIndex >= ApplicationManager.count -1) {
153+ return; // AutoRepeat is not allowed to wrap around
154+ }
155+
156+ appRepeater.highlightedIndex = (appRepeater.highlightedIndex + 1) % ApplicationManager.count;
157+ var newContentX = ((spreadFlickable.contentWidth) / (ApplicationManager.count + 1)) * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 3));
158+ if (spreadFlickable.contentX < newContentX || appRepeater.highlightedIndex == 0) {
159+ spreadFlickable.snapTo(newContentX)
160+ }
161+ }
162+
163+ function selectPrevious(isAutoRepeat) {
164+ if (isAutoRepeat && appRepeater.highlightedIndex == 0) {
165+ return; // AutoRepeat is not allowed to wrap around
166+ }
167+
168+ var newIndex = appRepeater.highlightedIndex - 1 >= 0 ? appRepeater.highlightedIndex - 1 : ApplicationManager.count - 1;
169+ appRepeater.highlightedIndex = newIndex;
170+ var newContentX = ((spreadFlickable.contentWidth) / (ApplicationManager.count + 1)) * Math.max(0, Math.min(ApplicationManager.count - 5, appRepeater.highlightedIndex - 1));
171+ if (spreadFlickable.contentX > newContentX || newIndex == ApplicationManager.count -1) {
172+ spreadFlickable.snapTo(newContentX)
173+ }
174+ }
175+
176+ function focusSelected() {
177+ if (appRepeater.highlightedIndex != -1) {
178+ appRepeater.itemAt(appRepeater.highlightedIndex).focus = true;
179+ }
180+ }
181+
171 Repeater {
182 Repeater {
172 id: appRepeater
183 id: appRepeater
173 model: ApplicationManager
184 model: ApplicationManager
@@ -521,6 +532,7 @@ Rectangle {
521 PropertyChanges { target: spreadFlickable; enabled: true }
532 PropertyChanges { target: spreadFlickable; enabled: true }
522 PropertyChanges { target: currentSelectedLabel; visible: true }
533 PropertyChanges { target: currentSelectedLabel; visible: true }
523 PropertyChanges { target: spreadBackground; visible: true }
534 PropertyChanges { target: spreadBackground; visible: true }
535+ PropertyChanges { target: appContainer; focus: true }
524 }
536 }
525 ]
537 ]
526 signal updateWorkspaces();
538 signal updateWorkspaces();
@@ -530,7 +542,7 @@ Rectangle {
530 from: "*"
542 from: "*"
531 to: "altTab"
543 to: "altTab"
532 SequentialAnimation {
544 SequentialAnimation {
533− PropertyAction { target: appRepeater; property: "highlightedIndex"; value: 1 }
545+ PropertyAction { target: appRepeater; property: "highlightedIndex"; value: Math.min(ApplicationManager.count - 1, 1) }
534 PauseAnimation { duration: 50 }
546 PauseAnimation { duration: 50 }
535 PropertyAction { target: workspaceSelector; property: "visible" }
547 PropertyAction { target: workspaceSelector; property: "visible" }
536 ScriptAction { script: root.updateWorkspaces() }
548 ScriptAction { script: root.updateWorkspaces() }
@@ -547,6 +559,7 @@ Rectangle {
547 to: "*"
559 to: "*"
548 PropertyAnimation { property: "opacity" }
560 PropertyAnimation { property: "opacity" }
549 PropertyAction { target: root; property: "workspacesUpdated"; value: false }
561 PropertyAction { target: root; property: "workspacesUpdated"; value: false }
562+ ScriptAction { script: { appContainer.focusSelected() } }
550 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: -1 }
563 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: -1 }
551 }
564 }
552
565