-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
107 lines (97 loc) · 3.37 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* extension.js
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
// #ifeq GNOME_VERSION 45
import Gio from 'gi://Gio';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import { getInputSourceManager } from 'resource:///org/gnome/shell/ui/status/keyboard.js';
// #else
const { Gio } = imports.gi;
const { getInputSourceManager } = imports.ui.status.keyboard;
// #endif
const DbusInterface = `<node>
<interface name="raiden_fumo.InputSources">
<method name="Set">
<arg type="s" direction="in" name="id" />
<arg type="b" direction="out" name="success"/>
<arg type="s" direction="out" name="error"/>
</method>
<method name="Get">
<arg type="s" direction="out" name="active_source_id"/>
</method>
<method name="List">
<arg type="s" direction="out" name="input_methods"/>
</method>
</interface>
</node>
`;
class LayoutManager {
Set(id) {
const inputSources = getInputSourceManager().inputSources;
// We do loop. Not a problem if you don't have a thousand input sources,
// and tracking potential changes to the sources settings
// or using numeric values from input source order doesn't sound like fun
for (var key in inputSources) {
var inputSource = inputSources[key];
if (inputSource.id == id) {
inputSource.activate();
return [true, `Activated input source '${inputSource.id}'`];
}
}
return [false, `Coudln't find input source '${id}' in the list: '${this.List()}'`];
}
Get() {
const manager = getInputSourceManager();
var ret = [];
for (var key in manager) {
ret.push(key);
}
return getInputSourceManager().currentSource.id;
}
List() {
const inputSources = getInputSourceManager().inputSources;
var ret = [];
for (var key in inputSources) {
var inputSource = inputSources[key];
ret.push(inputSource.id);
}
return ret.join(", ");
}
}
class InputSourceInterface
// #ifeq GNOME_VERSION 45
extends Extension
// #endif
{
enable() {
this._layoutManager = new LayoutManager();
this._dbusObject = Gio.DBusExportedObject.wrapJSObject(DbusInterface, this._layoutManager);
this._dbusObject.export(Gio.DBus.session, '/raiden_fumo/InputSources');
}
disable() {
if (this._dbusObject) this._dbusObject.unexport();
this._dbusObject = null;
this._layoutManager = null;
}
}
// #ifneq GNOME_VERSION 45
function init(meta) {
return new InputSourceInterface();
}
// #else
export default InputSourceInterface;
// #endif