on xenial help sign in
move the keymap switching to Shell

to survive Stage switching

commit296d98a6bfcef20ee0aab91448195b18767b43ff authorLukáš Tinkl <lukas.tinkl@canonical.com> dateFri 11 Mar 2016, 18:33 (11 years ago) parentfd99033
2 files changed+53−55
qml/Shell.qml+53 qml/Stages/AbstractStage.qml−55
qml/Shell.qml+53
@@ -102,6 +102,8 @@ Item {
102102 // internal props from here onwards
103103 readonly property var mainApp:
104104 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105+ readonly property var mainAppWindow:
106+ applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindow : null
105107
106108 // Disable everything while greeter is waiting, so that the user can't swipe
107109 // the greeter or launcher until we know whether the session is locked.
@@ -737,6 +739,57 @@ Item {
737739 onMouseMoved: { cursor.opacity = 1; }
738740 }
739741
742+ // keymap switching
743+ GlobalShortcut {
744+ shortcut: Qt.MetaModifier|Qt.Key_Space
745+ onTriggered: keymapPriv.nextKeymap()
746+ active: keymapPriv.keymapCount > 1
747+ }
748+
749+ GlobalShortcut {
750+ shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
751+ onTriggered: keymapPriv.previousKeymap()
752+ active: keymapPriv.keymapCount > 1
753+ }
754+
755+ QtObject {
756+ id: keymapPriv
757+
758+ readonly property var keymaps: AccountsService.keymaps
759+ readonly property int keymapCount: keymaps.length
760+ readonly property int activeKeymapIndex: mainAppWindow ? keymaps.indexOf(mainAppWindow.activeKeymap) : 0 // the one that the window currently has
761+ property int currentKeymapIndex: 0 // the new one that we're setting
762+ onCurrentKeymapIndexChanged: switchToKeymap();
763+
764+ function nextKeymap() {
765+ var nextIndex = 0;
766+
767+ if (activeKeymapIndex !== -1 && activeKeymapIndex < keymapCount - 1) {
768+ nextIndex = activeKeymapIndex + 1;
769+ }
770+ print("!!! next keymap:", currentKeymapIndex, "->", nextIndex);
771+ currentKeymapIndex = nextIndex;
772+ }
773+
774+ function previousKeymap() {
775+ var prevIndex = keymapCount - 1;
776+
777+ if (activeKeymapIndex > 0) {
778+ prevIndex = activeKeymapIndex - 1;
779+ }
780+ print("!!! prev keymap:", currentKeymapIndex, "->", prevIndex);
781+ currentKeymapIndex = prevIndex;
782+ }
783+
784+ function switchToKeymap() {
785+ if (mainAppWindow) {
786+ mainAppWindow.switchToKeymap(keymaps[currentKeymapIndex]);
787+ }
788+ }
789+ }
790+
791+ onMainAppWindowChanged: keymapPriv.switchToKeymap()
792+
740793 Rectangle {
741794 id: shutdownFadeOutRectangle
742795 z: cursor.z + 1
qml/Stages/AbstractStage.qml−55
@@ -17,8 +17,6 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import GSettings 1.0
20−import GlobalShortcut 1.0
21−import AccountsService 0.1
2220
2321Rectangle {
2422 id: root
@@ -69,57 +67,4 @@ Rectangle {
6967 }
7068 return false;
7169 }
72−
73− // keymap switching, shared between stages
74− GlobalShortcut {
75− shortcut: Qt.MetaModifier|Qt.Key_Space
76− onTriggered: keymapPriv.nextKeymap()
77− active: keymapPriv.keymapCount > 1
78− }
79−
80− GlobalShortcut {
81− shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
82− onTriggered: keymapPriv.previousKeymap()
83− active: keymapPriv.keymapCount > 1
84− }
85−
86− QtObject {
87− id: keymapPriv
88−
89− readonly property var keymaps: AccountsService.keymaps
90− readonly property int keymapCount: keymaps.length
91− readonly property int activeKeymapIndex: mainAppWindow ? keymaps.indexOf(mainAppWindow.activeKeymap) : 0 // the one that the window currently has
92− property int currentKeymapIndex: 0 // the new one that we're setting
93− onCurrentKeymapIndexChanged: switchToKeymap();
94−
95− function nextKeymap() {
96− var nextIndex = 0;
97−
98− if (activeKeymapIndex !== -1 && activeKeymapIndex < keymapCount - 1) {
99− nextIndex = activeKeymapIndex + 1;
100− }
101− print("!!! next keymap:", currentKeymapIndex, "->", nextIndex);
102− currentKeymapIndex = nextIndex;
103− }
104−
105− function previousKeymap() {
106− var prevIndex = keymapCount - 1;
107−
108− if (activeKeymapIndex > 0) {
109− prevIndex = activeKeymapIndex - 1;
110− }
111− print("!!! prev keymap:", currentKeymapIndex, "->", prevIndex);
112− currentKeymapIndex = prevIndex;
113− }
114−
115− function switchToKeymap() {
116− if (mainAppWindow) {
117− mainAppWindow.switchToKeymap(keymaps[currentKeymapIndex]);
118− }
119− }
120− }
121−
122− onMainAppWindowChanged: {
123− keymapPriv.switchToKeymap()
124− }
12570}