-
Notifications
You must be signed in to change notification settings - Fork 30
/
overviewControls.js
431 lines (355 loc) · 15.6 KB
/
overviewControls.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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported ControlsManager */
const { Clutter, Gio, GObject, Meta, Shell, St } = imports.gi;
const AppDisplay = imports.ui.appDisplay;
const Dash = imports.ui.dash;
const Layout = imports.ui.layout;
const Main = imports.ui.main;
const Overview = imports.ui.overview;
const SearchController = imports.ui.searchController;
const Util = imports.misc.util;
const WindowManager = imports.ui.windowManager;
const WorkspaceThumbnail = imports.ui.workspaceThumbnail;
const WorkspacesView = imports.ui.workspacesView;
const OverviewControls = imports.ui.overviewControls;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const _Util = Self.imports.util;
const SMALL_WORKSPACE_RATIO = 0.15;
const DASH_MAX_HEIGHT_RATIO = 0.15;
const A11Y_SCHEMA = 'org.gnome.desktop.a11y.keyboard';
var SIDE_CONTROLS_ANIMATION_TIME = Overview.ANIMATION_TIME;
var ControlsState = {
HIDDEN: 0,
WINDOW_PICKER: 1,
APP_GRID: 2,
};
function override() {
global.vertical_overview.GSFunctions['ControlsManagerLayout'] = _Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, ControlsManagerLayoutOverride);
global.vertical_overview.GSFunctions['ControlsManager'] = _Util.overrideProto(OverviewControls.ControlsManager.prototype, ControlsManagerOverride);
let controlsManager = Main.overview._overview._controls;
global.vertical_overview._updateID = controlsManager._stateAdjustment.connectObject("notify::value", _updateWorkspacesDisplay.bind(controlsManager));
global.vertical_overview._workspaceDisplayVisibleID = controlsManager._workspacesDisplay.connectObject("notify::visible", controlsManager._workspacesDisplay._updateWorkspacesViews.bind(controlsManager._workspacesDisplay));
}
function reset() {
_Util.overrideProto(OverviewControls.ControlsManagerLayout.prototype, global.vertical_overview.GSFunctions['ControlsManagerLayout']);
_Util.overrideProto(OverviewControls.ControlsManager.prototype, global.vertical_overview.GSFunctions['ControlsManager']);
let controlsManager = Main.overview._overview._controls;
controlsManager._stateAdjustment.disconnectObject(global.vertical_overview._updateID);
controlsManager._workspacesDisplay.disconnectObject(global.vertical_overview._workspaceDisplayVisibleID);
controlsManager._workspacesDisplay.reactive = true;
controlsManager._workspacesDisplay.setPrimaryWorkspaceVisible(true);
}
function enterOverviewAnimation() {
let controlsManager = Main.overview._overview._controls;
if (global.vertical_overview.dash_override) {
controlsManager.dash.translation_x = -controlsManager.dash.width;
controlsManager.dash.ease({
translation_x: 0,
duration: Overview.ANIMATION_TIME,
});
}
controlsManager._searchEntry.opacity = 0;
controlsManager._searchEntry.ease({
opacity: 255,
duration: Overview.ANIMATION_TIME,
});
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
const rightOffset = controlsManager.layoutManager.rightOffset * scaleFactor;
controlsManager._thumbnailsBox.translation_x = rightOffset;
controlsManager._thumbnailsBox.ease({
translation_x: 0,
duration: Overview.ANIMATION_TIME,
});
controlsManager._workspacesDisplay._workspacesViews.forEach((workspace, i) => {
if (i != Main.layoutManager.primaryIndex) {
let scale = Main.layoutManager.getWorkAreaForMonitor(workspace._monitorIndex).width / Main.layoutManager.primaryMonitor.width;
workspace._thumbnails.translation_x = rightOffset * scale;
workspace._thumbnails.ease({
translation_x: 0,
duration: Overview.ANIMATION_TIME,
});
}
});
}
function exitOverviewAnimation() {
let controlsManager = Main.overview._overview._controls;
if (global.vertical_overview.dash_override) {
controlsManager.dash.ease({
translation_x: -controlsManager.dash.width,
duration: Overview.ANIMATION_TIME,
});
}
controlsManager._searchEntry.ease({
opacity: 0,
duration: Overview.ANIMATION_TIME,
});
controlsManager._thumbnailsBox.ease({
translation_x: controlsManager._thumbnailsBox.width,
duration: Overview.ANIMATION_TIME,
});
controlsManager._workspacesDisplay._workspacesViews.forEach((workspace, i) => {
if (i != Main.layoutManager.primaryIndex) {
workspace._thumbnails.ease({
translation_x: workspace._thumbnails.width,
duration: Overview.ANIMATION_TIME,
});
}
});
}
var ControlsManagerLayoutOverride = {
_computeWorkspacesBoxForState(state, workAreaBox, searchHeight, dashHeight, thumbnailsHeight) {
const workspaceBox = workAreaBox.copy();
const [startX, startY] = workAreaBox.get_origin();
const [width, height] = workspaceBox.get_size();
const { spacing } = this;
const { expandFraction } = this._workspacesThumbnails;
switch (state) {
case ControlsState.HIDDEN:
if (global.vertical_overview.misc_dTPLeftRightFix) {
let [w, h] = Main.layoutManager.panelBox.get_size();
let [x, y] = Main.layoutManager.panelBox.get_transformed_position();
if (x > 0) { // if x > 0 assume panel is on the right side
workspaceBox.set_size(width - w, box.y2);
} else {
workspaceBox.set_origin(w / 2, box.y1);
}
}
break;
case ControlsState.WINDOW_PICKER:
case ControlsState.APP_GRID:
workspaceBox.set_origin(
this.leftOffset + spacing,
startY + searchHeight + spacing * expandFraction);
workspaceBox.set_size(
width - this.leftOffset - this.rightOffset - (spacing * 2),
height - startY - (searchHeight + spacing * expandFraction) * 2);
break;
}
return workspaceBox;
},
_getAppDisplayBoxForState(state, workAreaBox, searchHeight, dashHeight, appGridBox) {
const [startX, startY] = workAreaBox.get_origin();
const [width, height] = workAreaBox.get_size();
const appDisplayBox = new Clutter.ActorBox();
const { spacing } = this;
switch (state) {
case ControlsState.HIDDEN:
case ControlsState.WINDOW_PICKER:
appDisplayBox.set_origin(startX, workAreaBox.y2);
break;
case ControlsState.APP_GRID:
appDisplayBox.set_origin(startX,
startY + searchHeight + spacing);
break;
}
appDisplayBox.set_size(width,
height - startY - searchHeight - spacing
);
return appDisplayBox;
},
vfunc_allocate: function(container, box) {
const childBox = new Clutter.ActorBox();
var leftOffset = this.leftOffset;
let rightOffset = this.rightOffset;
const { spacing } = this;
let startY = 0;
if (global.vertical_overview.misc_dTPLeftRightFix) {
let [w, h] = Main.layoutManager.panelBox.get_size();
leftOffset -= w;
} else {
if (Main.layoutManager.panelBox.y === Main.layoutManager.primaryMonitor.y) {
startY = Main.layoutManager.panelBox.height;
box.y1 += startY;
}
}
const [width, height] = box.get_size();
let availableHeight = height;
// Search entry
let [searchHeight] = this._searchEntry.get_preferred_height(width);
childBox.set_origin(leftOffset, startY);
childBox.set_size(width - leftOffset - rightOffset, searchHeight);
this._searchEntry.allocate(childBox);
availableHeight -= searchHeight + spacing;
// Dash
if (global.vertical_overview.dash_override) {
if (!global.vertical_overview.settings.object.get_boolean('hide-dash')) {
let dashHeight = height * this.dashMaxHeightScale;
this._dash.setMaxSize(leftOffset, dashHeight);
let [, maxDashWidth] = this._dash.get_preferred_width(height);
childBox.set_origin(0, startY);
childBox.set_size(leftOffset, height);
this._dash.allocate(childBox);
}
} else {
const maxDashHeight = Math.round(box.get_height() * DASH_MAX_HEIGHT_RATIO);
this._dash.setMaxSize(width, maxDashHeight);
let [, dashHeight] = this._dash.get_preferred_height(width);
dashHeight = Math.min(dashHeight, maxDashHeight);
childBox.set_origin(0, startY + height - dashHeight);
childBox.set_size(width, dashHeight);
this._dash.allocate(childBox);
availableHeight -= dashHeight + spacing;
}
// Workspace Thumbnails
if (this._workspacesThumbnails.visible) {
childBox.set_origin(width - rightOffset, startY);
childBox.set_size(rightOffset, height);
this._workspacesThumbnails.allocate(childBox);
}
// Workspaces
let params = [box, startY, searchHeight, leftOffset, rightOffset];
const transitionParams = this._stateAdjustment.getStateTransitionParams();
// Update cached boxes
for (const state of Object.values(ControlsState)) {
this._cachedWorkspaceBoxes.set(
state, this._computeWorkspacesBoxForState(state, ...params));
}
let workspacesBox;
if (!transitionParams.transitioning) {
workspacesBox = this._cachedWorkspaceBoxes.get(transitionParams.currentState);
} else {
const initialBox = this._cachedWorkspaceBoxes.get(transitionParams.initialState);
const finalBox = this._cachedWorkspaceBoxes.get(transitionParams.finalState);
workspacesBox = initialBox.interpolate(finalBox, transitionParams.progress);
}
this._workspacesDisplay.allocate(workspacesBox);
// App grid
if (this._appDisplay.visible) {
params = [box, startY, searchHeight];
let appDisplayBox;
if (!transitionParams.transitioning) {
appDisplayBox =
this._getAppDisplayBoxForState(transitionParams.currentState, ...params);
} else {
const initialBox =
this._getAppDisplayBoxForState(transitionParams.initialState, ...params);
const finalBox =
this._getAppDisplayBoxForState(transitionParams.finalState, ...params);
appDisplayBox = initialBox.interpolate(finalBox, transitionParams.progress);
}
this._appDisplay.allocate(appDisplayBox);
}
// Search
childBox.set_origin(leftOffset, startY + searchHeight + spacing);
childBox.set_size(width - leftOffset - rightOffset, availableHeight);
this._searchController.allocate(childBox);
this._runPostAllocation();
}
}
var ControlsManagerOverride = {
_getFitModeForState: function(state) {
switch (state) {
case ControlsState.HIDDEN:
case ControlsState.WINDOW_PICKER:
return WorkspacesView.FitMode.SINGLE;
case ControlsState.APP_GRID:
return WorkspacesView.FitMode.SINGLE;
default:
return WorkspacesView.FitMode.SINGLE;
}
},
_getThumbnailsBoxParams: function() {
const { initialState, finalState, progress } =
this._stateAdjustment.getStateTransitionParams();
const paramsForState = s => {
opacity = 255;
scale = 1;
return { opacity, scale } ;
};
const initialParams = paramsForState(initialState);
const finalParams = paramsForState(finalState);
return [
Util.lerp(initialParams.opacity, finalParams.opacity, progress),
Util.lerp(initialParams.scale, finalParams.scale, progress),
];
},
_updateThumbnailsBox: function() {
const { shouldShow } = this._thumbnailsBox;
const thumbnailsBoxVisible = shouldShow;
if (thumbnailsBoxVisible) {
this._thumbnailsBox.opacity = 255;
this._thumbnailsBox.visible = thumbnailsBoxVisible;
}
},
animateToOverview: function(state, callback) {
this._ignoreShowAppsButtonToggle = true;
this._searchController.prepareToEnterOverview();
this._workspacesDisplay.prepareToEnterOverview();
this._stateAdjustment.value = ControlsState.HIDDEN;
this._workspacesDisplay.opacity = 255;
this._workspacesDisplay.setPrimaryWorkspaceVisible(!this.dash.showAppsButton.checked);
this._workspacesDisplay.reactive = !this.dash.showAppsButton.checked;
this._stateAdjustment.ease(state, {
duration: Overview.ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onStopped: () => {
if (callback)
callback();
},
});
this.dash.showAppsButton.checked =
state === ControlsState.APP_GRID;
this._ignoreShowAppsButtonToggle = false;
if (global.vertical_overview.scaling_workspaces_hidden) {
enterOverviewAnimation();
}
},
animateFromOverview: function(callback) {
this._ignoreShowAppsButtonToggle = true;
this._workspacesDisplay.prepareToLeaveOverview();
this._stateAdjustment.ease(ControlsState.HIDDEN, {
duration: Overview.ANIMATION_TIME,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onStopped: () => {
this.dash.showAppsButton.checked = false;
this._ignoreShowAppsButtonToggle = false;
if (callback)
callback();
},
});
if (global.vertical_overview.scaling_workspaces_hidden) {
exitOverviewAnimation();
}
}
}
function _updateWorkspacesDisplay() {
const { initialState, finalState, progress } = this._stateAdjustment.getStateTransitionParams();
const { searchActive } = this._searchController;
//TODO: fix scaling (or just remove it)
const paramsForState = s => {
let opacity, scale;
switch (s) {
case ControlsState.HIDDEN:
case ControlsState.WINDOW_PICKER:
opacity = 255;
scale = 1;
break;
case ControlsState.APP_GRID:
opacity = 0;
scale = 0.5;
break;
default:
opacity = 255;
scale = 1;
break;
}
return { opacity, scale };
};
let initialParams = paramsForState(initialState);
let finalParams = paramsForState(finalState);
let opacity = Math.round(Util.lerp(initialParams.opacity, finalParams.opacity, progress));
let scale = Util.lerp(initialParams.scale, finalParams.scale, progress);
let workspacesDisplayVisible = (opacity != 0) && !(searchActive);
let params = {
opacity: opacity,
scale: scale,
duration: 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => {
this._workspacesDisplay.visible = !(progress == 1 && finalState == ControlsState.APP_GRID);
this._workspacesDisplay.reactive = workspacesDisplayVisible;
this._workspacesDisplay.setPrimaryWorkspaceVisible(workspacesDisplayVisible);
}
}
this._workspacesDisplay.ease(params);
}