This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
extension.js
171 lines (144 loc) · 4.96 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* Compiz-alike-windows-effect for GNOME Shell
*
* Copyright (C) 2020
* Mauro Pepe <https://github.com/hermes83/compiz-alike-windows-effect>
*
* This file is part of the gnome-shell extension Compiz-alike-windows-effect.
*
* gnome-shell extension Compiz-alike-windows-effect 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 3 of the License, or (at your option)
* any later version.
*
* gnome-shell extension Compiz-alike-windows-effect 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 gnome-shell extension Compiz-alike-windows-effect. If not, see
* <http://www.gnu.org/licenses/>.
*/
'use strict';
const { GLib, Meta } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Utils = Me.imports.commonUtils;
const TIMEOUT_DELAY = 1500;
let grabOpBeginId;
let grabOpEndId;
let resizeMinMaxOpId;
let minimizeId;
let unminimizeId;
let timeoutWobblyId;
let timeoutMinMaxId;
let originalSpeed;
let destroyId;
function init() {}
function enable() {
if (Utils.is_3_xx_shell_version()) {
grabOpBeginId = global.display.connect('grab-op-begin', (display, screen, window, op) => {
grabStart(window, op);
});
} else {
grabOpBeginId = global.display.connect('grab-op-begin', (display, window, op) => {
grabStart(window, op);
});
}
if (Utils.is_3_xx_shell_version()) {
grabOpEndId = global.display.connect('grab-op-end', (display, screen, window, op) => {
grabEnd(window, op);
});
} else {
grabOpEndId = global.display.connect('grab-op-end', (display, window, op) => {
grabEnd(window, op);
});
}
resizeMinMaxOpId = global.window_manager.connect('size-change', (e, actor, op) => {
if (op == 1 && Utils.has_wobbly_effect(actor)) {
return;
}
stop_wobbly_timer();
Utils.destroy_actor_wobbly_effect(actor);
stop_min_max_timer();
Utils.destroy_actor_min_max_effect(actor);
Utils.add_actor_min_max_effect(actor, op);
timeoutMinMaxId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, TIMEOUT_DELAY, () => {
stop_min_max_timer();
if (actor) {
Utils.destroy_actor_min_max_effect(actor);
}
return false;
});
});
minimizeId = global.window_manager.connect("minimize", (e, actor) => {
if (Utils.has_wobbly_effect(actor)) {
stop_wobbly_timer();
Utils.destroy_actor_wobbly_effect(actor);
}
});
unminimizeId = global.window_manager.connect("unminimize", (e, actor) => {
if (Utils.has_wobbly_effect(actor)) {
stop_wobbly_timer();
Utils.destroy_actor_wobbly_effect(actor);
}
});
destroyId = global.window_manager.connect("destroy", (e, actor) => {
if (Utils.has_wobbly_effect(actor)) {
stop_wobbly_timer();
Utils.destroy_actor_wobbly_effect(actor);
Utils.destroy_actor_min_max_effect(actor);
}
});
}
function disable() {
global.display.disconnect(grabOpBeginId);
global.display.disconnect(grabOpEndId);
global.window_manager.disconnect(resizeMinMaxOpId);
global.window_manager.disconnect(destroyId);
stop_wobbly_timer();
global.get_window_actors().forEach((actor) => {
Utils.destroy_actor_wobbly_effect(actor);
Utils.destroy_actor_min_max_effect(actor);
});
}
function stop_wobbly_timer() {
if (timeoutWobblyId) {
GLib.source_remove(timeoutWobblyId);
timeoutWobblyId = 0;
}
}
function stop_min_max_timer() {
if (timeoutMinMaxId) {
GLib.source_remove(timeoutMinMaxId);
timeoutMinMaxId = 0;
}
}
function grabStart(window, op) {
let actor = Utils.get_actor(window);
if (actor) {
stop_wobbly_timer();
stop_min_max_timer();
Utils.destroy_actor_wobbly_effect(actor);
Utils.destroy_actor_min_max_effect(actor);
if (Utils.is_managed_op(op)) {
Utils.add_actor_wobbly_effect(actor, op);
}
}
}
function grabEnd(window, op) {
let actor = Utils.get_actor(window);
if (actor) {
Utils.stop_actor_wobbly_effect(actor);
timeoutWobblyId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, TIMEOUT_DELAY, () => {
stop_wobbly_timer();
let actor = Utils.get_actor(window);
if (actor) {
Utils.destroy_actor_wobbly_effect(actor);
}
return false;
});
}
}