forked from awamper/gpaste-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup_dialog.js
117 lines (98 loc) · 3.18 KB
/
popup_dialog.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
108
109
110
111
112
113
114
115
116
117
const St = imports.gi.St;
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const Signals = imports.signals;
const Shell = imports.gi.Shell;
const Tweener = imports.ui.tweener;
const Params = imports.misc.params;
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.utils;
const CONNECTION_IDS = {
CAPTURED_EVENT: 0
};
const PopupDialog = new Lang.Class({
Name: 'PopupDialog',
_init: function(params) {
this.params = Params.parse(params, {
style_class: '',
modal: false
});
this.actor = new St.BoxLayout({
style_class: this.params.style_class,
visible: false
});
Main.uiGroup.add_child(this.actor);
},
_reposition: function() {
let [x, y] = global.get_pointer();
this.actor.x = x - this.actor.width;
this.actor.y = y - this.actor.height;
},
_connect_captured_event: function() {
CONNECTION_IDS.CAPTURED_EVENT = global.stage.connect(
'captured-event',
Lang.bind(this, this._on_captured_event)
);
},
_disconnect_captured_event: function() {
if(CONNECTION_IDS.CAPTURED_EVENT > 0) {
global.stage.disconnect(CONNECTION_IDS.CAPTURED_EVENT);
CONNECTION_IDS.CAPTURED_EVENT = 0;
}
},
_on_captured_event: function(object, event) {
if(event.type() === Clutter.EventType.BUTTON_RELEASE) {
let [x, y, mods] = global.get_pointer();
let pointer_outside = !Utils.is_pointer_inside_actor(this.actor);
if(pointer_outside) this.hide();
}
else if(event.type() === Clutter.EventType.KEY_RELEASE) {
let symbol = event.get_key_symbol();
if(symbol === Clutter.Escape) this.hide();
}
},
show: function() {
if(this.actor.visible) return;
this._reposition();
if(this.params.modal) {
Main.pushModal(this.actor, {
keybindingMode: Shell.KeyBindingMode.NORMAL
});
}
this.actor.opacity = 0;
this.actor.show();
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
opacity: 255,
time: 0.3,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
this.emit('showed');
})
});
this._connect_captured_event();
},
hide: function() {
if(!this.actor.visible) return;
if(this.params.modal) Main.popModal(this.actor);
this._disconnect_captured_event();
Tweener.removeTweens(this.actor);
Tweener.addTween(this.actor, {
opacity: 0,
time: 0.3,
transition: 'easeOutQuad',
onComplete: Lang.bind(this, function() {
this.actor.hide();
this.actor.opacity = 255;
this.emit('hided');
})
});
},
destroy: function() {
this._disconnect_captured_event();
this.actor.destroy();
}
});
Signals.addSignalMethods(PopupDialog.prototype);