-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosd.js
81 lines (63 loc) · 2.29 KB
/
osd.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
Layout = imports.ui.layout;
HIDE_TIMEOUT = 200;
FADE_TIME = 0.1;
iteration = (typeof iteration === 'undefined') ? 0 : (iteration + 1);
OsdWindow = new Lang.Class({
Name: 'OsdWindow' + iteration,
_init: function(labelText) {
let monitorIndex = 0;
this.actor = new imports.gi.St.Widget({ x_expand: true,
y_expand: true,
x_align: imports.gi.Clutter.ActorAlign.CENTER,
y_align: imports.gi.Clutter.ActorAlign.CENTER
});
this.actor.add_constraint(new Layout.MonitorConstraint({ index: monitorIndex }));
let box = new imports.gi.St.BoxLayout({
style_class: 'osd-window',
vertical: true
});
this.actor.add_actor(box);
let label = new imports.gi.St.Label({
width: 500,
visible: true,
text: labelText,
style: 'font-size: 20px; font-weight: normal; margin-top: 15px'
});
box.add(label);
this._hideTimeoutId = 0;
let monitor = Main.layoutManager.monitors[monitorIndex];
box.translation_y = -(monitor.height / 10);
Main.uiGroup.add_child(this.actor);
},
show: function() {
if (!this.actor.visible) {
this.actor.show();
this.actor.opacity = 0;
this.actor.get_parent().set_child_above_sibling(this.actor, null);
imports.ui.tweener.addTween(this.actor,
{ opacity: 255,
time: FADE_TIME,
transition: 'easeOutQuad' });
}
if (this._hideTimeoutId)
imports.mainloop.source_remove(this._hideTimeoutId);
this._hideTimeoutId = imports.mainloop.timeout_add(HIDE_TIMEOUT, () => this._hide());
GLib.Source.set_name_by_id(this._hideTimeoutId, '[gnome-shell] this._hide');
},
cancel: function() {
if (!this._hideTimeoutId)
return;
imports.mainloop.source_remove(this._hideTimeoutId);
this._hide();
},
_hide: function() {
this._hideTimeoutId = 0;
imports.ui.tweener.addTween(this.actor,
{ opacity: 0,
time: FADE_TIME,
transition: 'easeOutQuad',
onComplete: () => this.actor.hide()
});
return GLib.SOURCE_REMOVE;
}
});