-
Notifications
You must be signed in to change notification settings - Fork 6
/
overviewControls.js
384 lines (316 loc) · 14.5 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
// -*- 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 { ExtensionState } = imports.misc.extensionUtils;
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.connect("notify::value", _updateWorkspacesDisplay.bind(controlsManager));
global.vertical_overview._workspaceDisplayVisibleID = controlsManager._workspacesDisplay.connect("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.disconnect(global.vertical_overview._updateID);
controlsManager._workspacesDisplay.disconnect(global.vertical_overview._workspaceDisplayVisibleID);
controlsManager._workspacesDisplay.reactive = true;
controlsManager._workspacesDisplay.setPrimaryWorkspaceVisible(true);
}
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;
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
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:
const newWidth = width - this._workspacesThumbnails.width * ( scaleFactor > 1 ? scaleFactor : 2);
const newXOrigin = global.vertical_overview.workspace_picker_left
? this._workspacesThumbnails.x + this._workspacesThumbnails.width + spacing * 2
: this._workspacesThumbnails.x - newWidth - spacing * 2;
workspaceBox.set_origin(
newXOrigin,
startY + searchHeight + spacing * expandFraction);
workspaceBox.set_size(
newWidth,
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, workspaceBox.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();
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
var leftOffset = this.leftOffset * scaleFactor;
let rightOffset = this.rightOffset * scaleFactor;
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
const searchHeight = 0;
availableHeight -= 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) {
let origin, size;
if (global.vertical_overview.workspace_picker_left) {
origin = [0, startY];
size = [leftOffset, height];
} else {
origin = [width - rightOffset, startY];
size = [rightOffset, height];
}
const cosmicDock = _Util.getDock();
if (cosmicDock) {
const mainDock = cosmicDock.stateObj.dockManager.mainDock;
const [, dashHeight] = mainDock.get_preferred_height(width);
const [, dashWidth] = mainDock.get_preferred_width(height);
if (mainDock.position == St.Side.BOTTOM) {
size[1] -= dashHeight;
} else if (mainDock.position == St.Side.LEFT && global.vertical_overview.workspace_picker_left) {
origin[0] += dashWidth;
} else if (mainDock.position == St.Side.RIGHT && !global.vertical_overview.workspace_picker_left) {
origin[0] -= dashWidth;
}
}
childBox.set_origin(...origin);
childBox.set_size(...size);
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(animate = false) {
const { shouldShow } = this._thumbnailsBox;
const { searchActive } = this._searchController;
const [opacity, scale] = this._getThumbnailsBoxParams();
const thumbnailsBoxVisible = shouldShow && !searchActive && opacity !== 0 && !Main.overview.dash.showAppsButton.checked;
if (thumbnailsBoxVisible) {
this._thumbnailsBox.opacity = 0;
this._thumbnailsBox.visible = thumbnailsBoxVisible;
}
const params = {
opacity: searchActive ? 0 : opacity,
duration: animate ? SIDE_CONTROLS_ANIMATION_TIME : 0,
mode: Clutter.AnimationMode.EASE_OUT_QUAD,
onComplete: () => (this._thumbnailsBox.visible = thumbnailsBoxVisible)
};
if (!searchActive) {
params.scale_x = scale;
params.scale_y = scale;
}
this._thumbnailsBox.ease(params);
},
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;
}
}
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);
}