on xenial help sign in
rework keyboard handling a bit
commit7d7d73478f7be479adaf25606836d27be77f24f6 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 14 Jul 2015, 12:47 (11 years ago) parent21a9b64
3 files changed+55−61
qml/Components/PhysicalKeysMapper.qml−17 qml/Shell.qml−2 qml/Stages/DesktopStage.qml+55−42
qml/Components/PhysicalKeysMapper.qml−17
@@ -42,8 +42,6 @@ Item {
4242 signal volumeUpTriggered;
4343 signal screenshotTriggered;
4444
45− signal altTabNext(bool isAutoRepeat);
46− signal altTabPrevious(bool isAutoRepeat);
4745 readonly property bool altTabPressed: d.altTabPressed
4846
4947 property int powerKeyLongPressTime: 2000
@@ -110,21 +108,6 @@ Item {
110108 } else if (event.key == Qt.Key_Tab) {
111109 if (d.altPressed && !d.altTabPressed) {
112110 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);
128111 event.accepted = true;
129112 }
130113 }
qml/Shell.qml−2
@@ -183,8 +183,6 @@ Item {
183183 onVolumeDownTriggered: volumeControl.volumeDown();
184184 onVolumeUpTriggered: volumeControl.volumeUp();
185185 onScreenshotTriggered: screenGrabber.capture();
186− onAltTabNext: applicationsDisplayLoader.item.altTabNext(isAutoRepeat)
187− onAltTabPrevious: applicationsDisplayLoader.item.altTabPrevious(isAutoRepeat);
188186 }
189187
190188 ScreenGrabber {
qml/Stages/DesktopStage.qml+55−42
@@ -55,46 +55,6 @@ Rectangle {
5555 property alias background: wallpaper.source
5656 property bool altTabPressed: false
5757
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−
9858 CrossFadeImage {
9959 id: wallpaper
10060 anchors.fill: parent
@@ -165,9 +125,60 @@ Rectangle {
165125 visible: false
166126 }
167127
168− Item {
128+ FocusScope {
169129 id: appContainer
170130 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+
171182 Repeater {
172183 id: appRepeater
173184 model: ApplicationManager
@@ -521,6 +532,7 @@ Rectangle {
521532 PropertyChanges { target: spreadFlickable; enabled: true }
522533 PropertyChanges { target: currentSelectedLabel; visible: true }
523534 PropertyChanges { target: spreadBackground; visible: true }
535+ PropertyChanges { target: appContainer; focus: true }
524536 }
525537 ]
526538 signal updateWorkspaces();
@@ -530,7 +542,7 @@ Rectangle {
530542 from: "*"
531543 to: "altTab"
532544 SequentialAnimation {
533− PropertyAction { target: appRepeater; property: "highlightedIndex"; value: 1 }
545+ PropertyAction { target: appRepeater; property: "highlightedIndex"; value: Math.min(ApplicationManager.count - 1, 1) }
534546 PauseAnimation { duration: 50 }
535547 PropertyAction { target: workspaceSelector; property: "visible" }
536548 ScriptAction { script: root.updateWorkspaces() }
@@ -547,6 +559,7 @@ Rectangle {
547559 to: "*"
548560 PropertyAnimation { property: "opacity" }
549561 PropertyAction { target: root; property: "workspacesUpdated"; value: false }
562+ ScriptAction { script: { appContainer.focusSelected() } }
550563 PropertyAction { target: appRepeater; property: "highlightedIndex"; value: -1 }
551564 }
552565