on xenial help sign in
WIP: keyboard indicator
commita4769a69966d5171b8539c0fd96d8d4ef874e59b authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 20 Jun 2016, 15:36 (10 years ago) parent1e5b290
2 files changed+84−4
qml/Components/KeymapSwitcher.qml+28−4 qml/Panel/Indicators/MenuItemFactory.qml+56
qml/Components/KeymapSwitcher.qml+28−4
@@ -17,18 +17,19 @@
1717import QtQuick 2.4
1818import AccountsService 0.1
1919import GlobalShortcut 1.0
20+import QMenuModel 0.1
2021import Unity.Application 0.1
2122
22−QtObject {
23+Item {
2324 id: root
2425
25− property GlobalShortcut shortcutNext: GlobalShortcut {
26+ GlobalShortcut {
2627 shortcut: Qt.MetaModifier|Qt.Key_Space
2728 onTriggered: root.nextKeymap()
2829 active: root.keymapCount > 1
2930 }
3031
31− property GlobalShortcut shortcutPrevious: GlobalShortcut {
32+ GlobalShortcut {
3233 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
3334 onTriggered: root.previousKeymap()
3435 active: root.keymapCount > 1
@@ -57,9 +58,32 @@ QtObject {
5758 currentKeymapIndex = prevIndex;
5859 }
5960
60− property Binding surfaceKeymapBinding: Binding {
61+ Binding {
6162 target: MirFocusController.focusedSurface
6263 property: "keymap"
6364 value: root.currentKeymap
6465 }
66+
67+ // indicator
68+ QDBusActionGroup {
69+ id: actionGroup
70+ busType: DBus.SessionBus
71+ busName: "com.canonical.indicator.keyboard"
72+ objectPath: "/com/canonical/indicator/keyboard"
73+
74+ property variant currentAction: action("current")
75+ }
76+
77+ onCurrentKeymapIndexChanged: {
78+ print("!!! Current keymap index changed:", currentKeymapIndex)
79+ actionGroup.currentAction.updateState(currentKeymapIndex);
80+ }
81+
82+
83+ Component.onCompleted: {
84+ actionGroup.start();
85+ if (actionGroup.currentAction.valid) {
86+ // TODO root.currentKeymapIndex = actionGroup.activeAction.state; // restore keymap saved by the indicator
87+ }
88+ }
6589}
qml/Panel/Indicators/MenuItemFactory.qml+56
@@ -18,12 +18,14 @@ import QtQuick 2.4
1818import QtQuick.Window 2.2
1919import Ubuntu.Settings.Menus 0.1 as Menus
2020import Ubuntu.Settings.Components 0.1
21+import AccountsService 0.1
2122import QMenuModel 0.1
2223import Utils 0.1 as Utils
2324import Ubuntu.Components.ListItems 1.3 as ListItems
2425import Ubuntu.Components 1.3
2526import Unity.Session 0.1
2627import Unity.Platform 1.0
28+import Unity.Application 0.1
2729
2830Item {
2931 id: menuFactory
@@ -985,6 +987,55 @@ Item {
985987 }
986988 }
987989
990+ Component {
991+ id: keymapMenu;
992+
993+ Menus.CheckableMenu {
994+ id: checkItem
995+ objectName: "keymapMenu"
996+ property QtObject menuData: null
997+ property int menuIndex: -1
998+ property bool serverChecked: menuData && menuData.isToggled || false
999+
1000+ text: menuData && menuData.label || ""
1001+ enabled: menuData && menuData.sensitive || false
1002+ checked: serverChecked
1003+ highlightWhenPressed: false
1004+
1005+ ServerPropertySynchroniser {
1006+ objectName: "sync"
1007+ syncTimeout: Utils.Constants.indicatorValueTimeout
1008+
1009+ serverTarget: checkItem
1010+ serverProperty: "serverChecked"
1011+ userTarget: checkItem
1012+ userProperty: "checked"
1013+
1014+ onSyncTriggered: {
1015+ 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+ }
1023+ }
1024+ }
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+ }
1036+ }
1037+ }
1038+
9881039 function load(modelData, context) {
9891040 // tweak indicator-session items
9901041 if (context === "indicator-session") {
@@ -995,6 +1046,11 @@ Item {
9951046 }
9961047 }
9971048
1049+ // specialize for indicator-keyboard
1050+ if (context === "indicator-keyboard" && modelData.isRadio) {
1051+ return keymapMenu;
1052+ }
1053+
9981054 if (modelData.type !== undefined && modelData.type !== "") {
9991055 var component = undefined;
10001056