forked from linuxmint/cinnamon
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathappSwitcher3D.js
More file actions
332 lines (262 loc) · 11 KB
/
appSwitcher3D.js
File metadata and controls
332 lines (262 loc) · 11 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const Graphene = imports.gi.Graphene;
const St = imports.gi.St;
const Meta = imports.gi.Meta;
const Pango = imports.gi.Pango;
const Cinnamon = imports.gi.Cinnamon;
const Mainloop = imports.mainloop;
const AppSwitcher = imports.ui.appSwitcher.appSwitcher;
const Main = imports.ui.main;
const WindowUtils = imports.misc.windowUtils;
const ICON_SIZE = 64;
const ICON_TITLE_SPACING = 10;
const PREVIEW_SCALE = 0.5;
const TITLE_POSITION = 7/8; // percent position
var ANIMATION_TIME = 250; // ms
const SWITCH_TIME_DELAY = 100; // milliseconds
const DIM_OPACITY = 102;
function AppSwitcher3D() {
this._init.apply(this, arguments);
}
AppSwitcher3D.prototype = {
__proto__: AppSwitcher.AppSwitcher.prototype,
_init: function() {
AppSwitcher.AppSwitcher.prototype._init.apply(this, arguments);
this._windowTitle = null;
this._icon = null;
this._lastTime = 0;
this._background = Main.createFullScreenBackground();
this._background.hide();
global.overlay_group.add_actor(this._background);
// create a container for all our widgets
this.actor = new St.Widget({ visible: true, reactive: true, });
this.actor.hide();
this.previewActor = new St.Widget({ visible: true, reactive: true, });
this.actor.add_actor(this.previewActor);
Main.uiGroup.add_actor(this.actor);
this._setupModal();
},
_show: function() {
this._enableMonitorFix();
let monitor = this._activeMonitor;
this.actor.set_position(monitor.x, monitor.y);
this.actor.set_size(monitor.width, monitor.height);
// create previews
this._createList();
// hide windows and show Coverflow actors
global.window_group.hide();
this.actor.show();
this._background.show();
Main.panelManager.panels.forEach(function(panel) { panel.actor.set_reactive(false); });
this._background.ease({
opacity: DIM_OPACITY,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
this._initialDelayTimeoutId = 0;
this._next();
},
_hidePreviews: function(endOpacity) {
let monitor = this._activeMonitor;
// preview windows
let currentWorkspace = global.workspace_manager.get_active_workspace();
for (let i in this._previews) {
let preview = this._previews[i];
let metaWin = this._windows[i];
let compositor = this._windows[i].get_compositor_private();
if (i != this._currentIndex)
preview.lower_bottom();
if (compositor == null) {
preview.destroy();
continue;
}
preview.move_anchor_point_from_gravity(compositor.get_anchor_point_gravity());
preview.set_pivot_point( 0.5, 0.0 );
preview.ease({
opacity: (!metaWin.minimized && metaWin.get_workspace() == currentWorkspace
|| metaWin.is_on_all_workspaces()) ? endOpacity : 0,
x: ((metaWin.minimized) ? 0 : compositor.x) - monitor.x,
y: ((metaWin.minimized) ? 0 : compositor.y) - monitor.y,
width: (metaWin.minimized) ? 0 : compositor.width,
height: (metaWin.minimized) ? 0 : compositor.height,
rotation_angle_y: 0.0,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => preview.destroy()
});
}
},
_hide: function() {
try {
this._hidePreviews(255);
} catch (e) {
global.logError(e);
}
// window title and icon
if(this._windowTitle) {
this._windowTitle.hide();
this._applicationIconBox.hide();
}
// panels
Main.panelManager.panels.forEach(function(panel) { panel.actor.set_reactive(true); });
// background
this._background.remove_all_transitions();
this._background.ease({
opacity: 255,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => this._destroyActors()
});
this._disableMonitorFix();
},
_checkSwitchTime: function() {
let t = new Date().getTime();
if(t - this._lastTime < SWITCH_TIME_DELAY)
return false;
this._lastTime = t;
return true;
},
_onWorkspaceSelected: function() {
this._hidePreviews(0);
this._windows = AppSwitcher.getWindowsForBinding(this._binding);
this._currentIndex = this._windows.indexOf(global.display.focus_window);
// create previews
this._createList();
this._next();
},
_createList: function() {
let monitor = this._activeMonitor;
let currentWorkspace = global.workspace_manager.get_active_workspace();
this._previews = [];
for (let i in this._windows) {
let metaWin = this._windows[i];
let compositor = this._windows[i].get_compositor_private();
if (compositor) {
let [width, height] = compositor.get_size();
let scale = 1.0;
let previewWidth = monitor.width * PREVIEW_SCALE;
let previewHeight = monitor.height * PREVIEW_SCALE;
if (width > previewWidth || height > previewHeight)
scale = Math.min(previewWidth / width, previewHeight / height);
let preview = new St.Button({
opacity: (!metaWin.minimized && metaWin.get_workspace() == currentWorkspace || metaWin.is_on_all_workspaces()) ? 255 : 0,
reactive: true,
anchor_gravity: Clutter.Gravity.CENTER,
x: ((metaWin.minimized) ? 0 : compositor.x + compositor.width / 2) - monitor.x,
y: ((metaWin.minimized) ? 0 : compositor.y + compositor.height / 2) - monitor.y
});
preview.target_width = Math.round(width * scale);
preview.target_height = Math.round(height * scale);
preview.target_width_side = preview.target_width * 2/3;
preview.target_height_side = preview.target_height;
let clone = WindowUtils.getCloneOrContent(compositor, preview.target_width, preview.target_height);
preview.set_child(clone);
preview.metaWindow = metaWin;
preview.connect('clicked', Lang.bind(this, this._cloneClicked));
this._previews.push(preview);
this.previewActor.add_actor(preview);
}
}
this._adaptClones();
},
_adaptClones: function() {
},
_cloneClicked: function(actor) {
this._currentIndex = this._previews.indexOf(actor);
this._activateSelected();
},
_setCurrentWindow: function(window) {
let monitor = this._activeMonitor;
// window title label
if (this._windowTitle) {
let oldWindowTitle = this._windowTitle;
this._windowTitle.ease({
opacity: 0,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => this.actor.remove_actor(oldWindowTitle)
});
}
this._windowTitle = new St.Label({
style_class: 'switcher-list',
text: this._windows[this._currentIndex].get_title(),
opacity: 0
});
// ellipsize if title is too long
this._windowTitle.set_style("max-width:" + (monitor.width - 200) + "px;font-size: 14px;font-weight: bold; padding: 14px;");
this._windowTitle.clutter_text.ellipsize = Pango.EllipsizeMode.END;
this.actor.add_actor(this._windowTitle);
this._windowTitle.ease({
opacity: 255,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
let cx = Math.round((monitor.width + (ICON_SIZE * global.ui_scale) + (ICON_TITLE_SPACING * global.ui_scale)) / 2);
let cy = Math.round(monitor.height * TITLE_POSITION);
this._windowTitle.x = cx - Math.round(this._windowTitle.get_width()/2);
this._windowTitle.y = cy - Math.round(this._windowTitle.get_height()/2);
// window icon
if (this._applicationIconBox) {
let oldIconBox = this._applicationIconBox;
this._applicationIconBox.ease({
opacity: 0,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => this.actor.remove_actor(oldIconBox)
});
}
let app = this._tracker.get_window_app(this._windows[this._currentIndex]);
this._icon = app ? app.create_icon_texture_for_window(ICON_SIZE, this._windows[this._currentIndex]) : null;
if (!this._icon) {
this._icon = new St.Icon({
icon_name: 'applications-other',
icon_type: St.IconType.FULLCOLOR,
icon_size: ICON_SIZE
});
}
this._applicationIconBox = new St.Bin({
style_class: 'window-iconbox',
opacity: 0,
x: Math.round(this._windowTitle.x - (ICON_SIZE * global.ui_scale) - (ICON_TITLE_SPACING * global.ui_scale)),
y: Math.round(cy - (ICON_SIZE * global.ui_scale) / 2 )
});
this._applicationIconBox.add_actor(this._icon);
this.actor.add_actor(this._applicationIconBox);
this._applicationIconBox.ease({
opacity: 255,
duration: ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD
});
},
_destroyActors: function() {
global.overlay_group.remove_actor(this._background);
Main.uiGroup.remove_actor(this.actor);
this.actor.destroy();
// show all window actors
global.window_group.show();
},
_onDestroy: function() {
this._windowTitle = null;
this._icon = null;
this._applicationIconBox = null;
this._previews = null;
},
_enableMonitorFix: function() {
if(global.display.get_n_monitors() < 2)
return;
this._monitorFix = true;
this._oldWidth = global.stage.width;
this._oldHeight = global.stage.height;
let width = 2 * (this._activeMonitor.x + this._activeMonitor.width/2);
let height = 2 * (this._activeMonitor.y + this._activeMonitor.height/2);
global.stage.set_size(width, height);
},
_disableMonitorFix: function() {
if(this._monitorFix) {
global.stage.set_size(this._oldWidth, this._oldHeight);
this._monitorFix = false;
}
}
};