on 0cfbca3 help sign in
unity8/qml/Components/KeymapSwitcher.qml
65 lines 2.0 kB history raw
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17import QtQuick 2.4
18import AccountsService 0.1
19import GlobalShortcut 1.0
20import Unity.Application 0.1
22QtObject {
23 id: root
25 property GlobalShortcut shortcutNext: GlobalShortcut {
26 shortcut: Qt.MetaModifier|Qt.Key_Space
27 onTriggered: root.nextKeymap()
28 active: root.keymapCount > 1
29 }
31 property GlobalShortcut shortcutPrevious: GlobalShortcut {
32 shortcut: Qt.MetaModifier|Qt.ShiftModifier|Qt.Key_Space
33 onTriggered: root.previousKeymap()
34 active: root.keymapCount > 1
35 }
37 readonly property var keymaps: AccountsService.keymaps
38 readonly property int keymapCount: keymaps.length
39 property int currentKeymapIndex: 0
40 readonly property string currentKeymap: keymaps[currentKeymapIndex]
42 function nextKeymap() {
43 var nextIndex = 0;
45 if (currentKeymapIndex !== -1 && currentKeymapIndex < keymapCount - 1) {
46 nextIndex = currentKeymapIndex + 1;
47 }
48 currentKeymapIndex = nextIndex;
49 }
51 function previousKeymap() {
52 var prevIndex = keymapCount - 1;
54 if (currentKeymapIndex > 0) {
55 prevIndex = currentKeymapIndex - 1;
56 }
57 currentKeymapIndex = prevIndex;
58 }
60 property Binding surfaceKeymapBinding: Binding {
61 target: MirFocusController.focusedSurface
62 property: "keymap"
63 value: root.currentKeymap
64 }