on xenial help sign in
move the keymap switching to Shell
296d98aLukáš Tinkl
qml/Shell.qml+53
@@ -102,6 +102,8 @@ Item {
102 // internal props from here onwards
102 // internal props from here onwards
103 readonly property var mainApp:
103 readonly property var mainApp:
104 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
104 applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainApp : null
105+ readonly property var mainAppWindow:
106+ applicationsDisplayLoader.item ? applicationsDisplayLoader.item.mainAppWindow : null
105
107
106 // Disable everything while greeter is waiting, so that the user can't swipe
108 // Disable everything while greeter is waiting, so that the user can't swipe
107 // the greeter or launcher until we know whether the session is locked.
109 // the greeter or launcher until we know whether the session is locked.
@@ -737,6 +739,57 @@ Item {
737 onMouseMoved: { cursor.opacity = 1; }
739 onMouseMoved: { cursor.opacity = 1; }
738 }
740 }
739
741
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+
740 Rectangle {
793 Rectangle {
741 id: shutdownFadeOutRectangle
794 id: shutdownFadeOutRectangle
742 z: cursor.z + 1
795 z: cursor.z + 1
qml/Stages/AbstractStage.qml−55
@@ -17,8 +17,6 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import Ubuntu.Components 1.3
18import Ubuntu.Components 1.3
19import GSettings 1.0
19import GSettings 1.0
20−import GlobalShortcut 1.0
21−import AccountsService 0.1
22
20
23Rectangle {
21Rectangle {
24 id: root
22 id: root
@@ -69,57 +67,4 @@ Rectangle {
69 }
67 }
70 return false;
68 return false;
71 }
69 }
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− }
125}
70}