on xenial help sign in
WIP: keyboard indicator
a4769a6Lukáš Tinkl
qml/Components/KeymapSwitcher.qml+28−4
@@ -17,18 +17,19 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import AccountsService 0.1
18import AccountsService 0.1
19import GlobalShortcut 1.0
19import GlobalShortcut 1.0
20+import QMenuModel 0.1
20import Unity.Application 0.1
21import Unity.Application 0.1
21
22
22−QtObject {
23+Item {
23 id: root
24 id: root
24
25
25− property GlobalShortcut shortcutNext: GlobalShortcut {
26+ GlobalShortcut {
26 shortcut: Qt.MetaModifier|Qt.Key_Space
27 shortcut: Qt.MetaModifier|Qt.Key_Space
27 onTriggered: root.nextKeymap()
28 onTriggered: root.nextKeymap()
28 active: root.keymapCount > 1
29 active: root.keymapCount > 1
29 }
30 }
30
31
31− property GlobalShortcut shortcutPrevious: GlobalShortcut {
32+ GlobalShortcut {
32 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
33 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
33 onTriggered: root.previousKeymap()
34 onTriggered: root.previousKeymap()
34 active: root.keymapCount > 1
35 active: root.keymapCount > 1
@@ -57,9 +58,32 @@ QtObject {
57 currentKeymapIndex = prevIndex;
58 currentKeymapIndex = prevIndex;
58 }
59 }
59
60
60− property Binding surfaceKeymapBinding: Binding {
61+ Binding {
61 target: MirFocusController.focusedSurface
62 target: MirFocusController.focusedSurface
62 property: "keymap"
63 property: "keymap"
63 value: root.currentKeymap
64 value: root.currentKeymap
64 }
65 }
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+ }
65}
89}
qml/Panel/Indicators/MenuItemFactory.qml+56
@@ -18,12 +18,14 @@ import QtQuick 2.4
18import QtQuick.Window 2.2
18import QtQuick.Window 2.2
19import Ubuntu.Settings.Menus 0.1 as Menus
19import Ubuntu.Settings.Menus 0.1 as Menus
20import Ubuntu.Settings.Components 0.1
20import Ubuntu.Settings.Components 0.1
21+import AccountsService 0.1
21import QMenuModel 0.1
22import QMenuModel 0.1
22import Utils 0.1 as Utils
23import Utils 0.1 as Utils
23import Ubuntu.Components.ListItems 1.3 as ListItems
24import Ubuntu.Components.ListItems 1.3 as ListItems
24import Ubuntu.Components 1.3
25import Ubuntu.Components 1.3
25import Unity.Session 0.1
26import Unity.Session 0.1
26import Unity.Platform 1.0
27import Unity.Platform 1.0
28+import Unity.Application 0.1
27
29
28Item {
30Item {
29 id: menuFactory
31 id: menuFactory
@@ -985,6 +987,55 @@ Item {
985 }
987 }
986 }
988 }
987
989
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+
988 function load(modelData, context) {
1039 function load(modelData, context) {
989 // tweak indicator-session items
1040 // tweak indicator-session items
990 if (context === "indicator-session") {
1041 if (context === "indicator-session") {
@@ -995,6 +1046,11 @@ Item {
995 }
1046 }
996 }
1047 }
997
1048
1049+ // specialize for indicator-keyboard
1050+ if (context === "indicator-keyboard" && modelData.isRadio) {
1051+ return keymapMenu;
1052+ }
1053+
998 if (modelData.type !== undefined && modelData.type !== "") {
1054 if (modelData.type !== undefined && modelData.type !== "") {
999 var component = undefined;
1055 var component = undefined;
1000
1056