2 * Copyright (C) 2016 Canonical Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import AccountsService 0.1
20import GlobalShortcut 1.0
22import QtMir.Application 0.1
27 // to be set from outside
28 property var focusedSurface: null
30 property GlobalShortcut shortcutNext: GlobalShortcut {
31 shortcut: Qt.MetaModifier|Qt.Key_Space
32 onTriggered: root.nextKeymap()
33 active: root.keymapCount > 1
36 property GlobalShortcut shortcutPrevious: GlobalShortcut {
37 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
38 onTriggered: root.previousKeymap()
39 active: root.keymapCount > 1
42 readonly property var keymaps: AccountsService.keymaps
43 readonly property int keymapCount: keymaps.length
44 // default keymap, either the one remembered by the indicator, or the 1st one selected by user
45 property int currentKeymapIndex: actionGroup.currentAction.valid ? actionGroup.currentAction.state : 0
46 readonly property string currentKeymap: keymaps[currentKeymapIndex]
48 function nextKeymap() {
51 if (currentKeymapIndex !== -1 && currentKeymapIndex < keymapCount - 1) {
52 nextIndex = currentKeymapIndex + 1;
54 currentKeymapIndex = nextIndex;
55 if (actionGroup.currentAction.valid) {
56 actionGroup.currentAction.updateState(currentKeymapIndex);
60 function previousKeymap() {
61 var prevIndex = keymapCount - 1;
63 if (currentKeymapIndex > 0) {
64 prevIndex = currentKeymapIndex - 1;
66 currentKeymapIndex = prevIndex;
67 if (actionGroup.currentAction.valid) {
68 actionGroup.currentAction.updateState(currentKeymapIndex);
72 property Binding surfaceKeymapBinding: Binding { // NB: needed mainly for xmir & libertine apps
73 target: root.focusedSurface
75 value: root.currentKeymap
76 restoreMode: Binding.RestoreBinding
79 property Binding lomiriKeymapBinding: Binding {
81 property: "currentKeymap"
82 value: root.currentKeymap
83 restoreMode: Binding.RestoreBinding
87 property QDBusActionGroup actionGroup: QDBusActionGroup {
88 busType: DBus.SessionBus
89 busName: "org.ayatana.indicator.keyboard"
90 objectPath: "/org/ayatana/indicator/keyboard"
92 property variant currentAction: action("current") // the one that's checked by the indicator
93 property variant activeAction: action("active") // the one that we clicked
95 Component.onCompleted: actionGroup.start();
98 readonly property int activeActionState: actionGroup.activeAction.valid ? actionGroup.activeAction.state : -1
100 onActiveActionStateChanged: {
101 if (activeActionState != -1) {
102 currentKeymapIndex = activeActionState;