-
Notifications
You must be signed in to change notification settings - Fork 5
/
extension.js
68 lines (62 loc) · 1.83 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
// Copyright (C) 2022 Takashi Kokubun
// Licence: GPLv2+
import Gio from 'gi://Gio';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
export default class Xremap extends Extension {
enable() {
const dbus_object = `
<node>
<interface name="com.k0kubun.Xremap">
<method name="ActiveWindow">
<arg type="s" direction="out" name="win"/>
</method>
<method name="WMClass">
<arg type="s" direction="out" name="win"/>
</method>
<method name="WMClasses">
<arg type="s" direction="out" name="win"/>
</method>
</interface>
</node>
`;
this.dbus = Gio.DBusExportedObject.wrapJSObject(dbus_object, this);
this.dbus.export(Gio.DBus.session, '/com/k0kubun/Xremap');
}
disable() {
this.dbus.flush();
this.dbus.unexport();
delete this.dbus;
}
ActiveWindow() {
const actor = global
.get_window_actors()
.find((a) => a.meta_window.has_focus() === true);
if (actor) {
const w = actor.get_meta_window();
return JSON.stringify({
wm_class: w.get_wm_class(),
title: w.get_title(),
});
} else {
return '{}';
}
}
WMClass() {
const actor = global
.get_window_actors()
.find((a) => a.meta_window.has_focus() === true);
return actor && actor.get_meta_window().get_wm_class();
}
// To see the application names through the busctl
WMClasses() {
// Even if it makes the items in a list joined by "\n", dbus output escapes the new line characters.
// So this outputs JSON array string instead of the plain text for understandability.
return JSON.stringify([
...new Set(
global
.get_window_actors()
.map((a) => a.get_meta_window().get_wm_class()),
),
]);
}
}