on xenial help sign in
correctly switch/update keymaps

remember the last one for the next startup

commit81f11b2d034971efd2977889e208789d9e3b242c authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 20 Jun 2016, 19:52 (10 years ago) parent16e767d
2 files changed+12−24
qml/Components/KeymapSwitcher.qml+11−5 qml/Panel/Indicators/MenuItemFactory.qml+1−19
qml/Components/KeymapSwitcher.qml+11−5
@@ -37,7 +37,8 @@ Item {
3737
3838 readonly property var keymaps: AccountsService.keymaps
3939 readonly property int keymapCount: keymaps.length
40− property int currentKeymapIndex: 0
40+ // default keymap, either the one remembered by the indicator, or the 1st one selected by user
41+ property int currentKeymapIndex: actionGroup.currentAction.valid ? actionGroup.currentAction.state : 0
4142 readonly property string currentKeymap: keymaps[currentKeymapIndex]
4243
4344 function nextKeymap() {
@@ -72,6 +73,10 @@ Item {
7273 objectPath: "/com/canonical/indicator/keyboard"
7374
7475 property variant currentAction: action("current")
76+ property variant activeAction: action("active")
77+
78+
79+ Component.onCompleted: actionGroup.start();
7580 }
7681
7782 onCurrentKeymapIndexChanged: {
@@ -79,11 +84,12 @@ Item {
7984 actionGroup.currentAction.updateState(currentKeymapIndex);
8085 }
8186
87+ readonly property int activeActionState: actionGroup.activeAction.valid ? actionGroup.activeAction.state : -1
8288
83− Component.onCompleted: {
84− actionGroup.start();
85− if (actionGroup.currentAction.valid) {
86− // TODO root.currentKeymapIndex = actionGroup.activeAction.state; // restore keymap saved by the indicator
89+ onActiveActionStateChanged: {
90+ print("!!! Active keymap changed (via indicator) to:", activeActionState);
91+ if (activeActionState != -1) {
92+ currentKeymapIndex = activeActionState;
8793 }
8894 }
8995}
qml/Panel/Indicators/MenuItemFactory.qml+1−19
@@ -995,7 +995,7 @@ Item {
995995 objectName: "keymapMenu"
996996 property QtObject menuData: null
997997 property int menuIndex: -1
998− property bool serverChecked: menuData && menuData.isToggled || false
998+ readonly property bool serverChecked: menuData && menuData.isToggled || false
999999
10001000 text: menuData && menuData.label || ""
10011001 enabled: menuData && menuData.sensitive || false
@@ -1013,26 +1013,8 @@ Item {
10131013
10141014 onSyncTriggered: {
10151015 menuModel.activate(checkItem.menuIndex);
1016−
1017− print("!!! Keymap", checkItem.menuIndex, "triggered")
1018− print("!!! Active action state:", actionGroup.activeAction.state)
1019− if (MirFocusController.focusedSurface) {
1020− print("!!! Switching keymap to:", AccountsService.keymaps[checkItem.menuIndex])
1021− MirFocusController.focusedSurface.keymap = AccountsService.keymaps[checkItem.menuIndex];
1022− }
10231016 }
10241017 }
1025−
1026− QDBusActionGroup {
1027− id: actionGroup
1028− busType: DBus.SessionBus
1029− busName: "com.canonical.indicator.keyboard"
1030− objectPath: "/com/canonical/indicator/keyboard"
1031−
1032− property variant activeAction: action("active")
1033−
1034− Component.onCompleted: actionGroup.start()
1035− }
10361018 }
10371019 }
10381020