-
Notifications
You must be signed in to change notification settings - Fork 9
/
extension.js
106 lines (86 loc) · 2.77 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
const Main = imports.ui.main;
const OsdWindow = imports.ui.osdWindow;
const OsdWindowManager = Main.osdWindowManager;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
//------------------------------------------------
function init() {
ExtensionUtils.initTranslations();
}
//------------------------------------------------
function style() {
for (
let monitorIndex = 0;
monitorIndex < OsdWindowManager._osdWindows.length;
monitorIndex++
) {
OsdWindowManager._osdWindows[monitorIndex]._box.add_style_class_name(
"osd-transparency"
);
}
}
function unstyle() {
for (
let monitorIndex = 0;
monitorIndex < OsdWindowManager._osdWindows.length;
monitorIndex++
) {
OsdWindowManager._osdWindows[monitorIndex]._box.remove_style_class_name(
"osd-transparency"
);
}
}
//------------------------------------------------
function injectToFunction(parent, name, func) {
let origin = parent[name];
parent[name] = function () {
let ret;
ret = origin.apply(this, arguments);
if (ret === undefined) ret = func.apply(this, arguments);
return ret;
};
return origin;
}
function removeInjection(object, injection, name) {
if (injection[name] === undefined) delete object[name];
else object[name] = injection[name];
}
let injections = [];
let _id;
//---------------------------------------------
function enable() {
let _settings = ExtensionUtils.getSettings(
"org.gnome.shell.extensions.better-osd"
);
style();
_id = Main.layoutManager.connect("monitors-changed", this.style.bind(this));
injections["show"] = injectToFunction(
OsdWindow.OsdWindow.prototype,
"show",
function () {
let monitor = Main.layoutManager.monitors[this._monitorIndex];
let h_percent = _settings.get_int("horizontal");
let v_percent = _settings.get_int("vertical");
let osd_size = _settings.get_int("size");
let hide_delay = _settings.get_int("delay");
let transparency = _settings.get_boolean("transparency");
transparency ? style() : unstyle();
this._box.translation_x = (h_percent * monitor.width) / 100;
this._box.translation_y = (v_percent * monitor.height) / 100;
this._icon.icon_size = (osd_size * monitor.height) / 100 / 2;
this._boxConstraint._minSize = (osd_size * monitor.height) / 100;
imports.ui.osdWindow.HIDE_TIMEOUT = hide_delay;
}
);
}
function disable() {
unstyle();
Main.layoutManager.disconnect(_id);
let arrayOSD = Main.osdWindowManager._osdWindows;
for (let i = 0; i < arrayOSD.length; i++) {
arrayOSD[i]._relayout();
arrayOSD[i]._box.translation_x = 0;
imports.ui.osdWindow.HIDE_TIMEOUT = 1500;
}
removeInjection(OsdWindow.OsdWindow.prototype, injections, "show");
}