-
Notifications
You must be signed in to change notification settings - Fork 6
/
workspace.js
200 lines (162 loc) · 6.96 KB
/
workspace.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
const { Clutter, GLib, GObject, Graphene, Meta, St } = imports.gi;
const Background = imports.ui.background;
const DND = imports.ui.dnd;
const Main = imports.ui.main;
const OverviewControls = imports.ui.overviewControls;
const Params = imports.misc.params;
const Util = imports.misc.util;
const { WindowPreview } = imports.ui.windowPreview;
var WINDOW_PREVIEW_MAXIMUM_SCALE = 0.95;
var WINDOW_REPOSITIONING_DELAY = 750;
var LAYOUT_SCALE_WEIGHT = 1;
var LAYOUT_SPACE_WEIGHT = 0.1;
const BACKGROUND_CORNER_RADIUS_PIXELS = 30;
const BACKGROUND_MARGIN = 12;
const { ExtensionState } = imports.misc.extensionUtils;
const Workspace = imports.ui.workspace;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const _Util = Self.imports.util;
const animateAllocation = imports.ui.workspace.animateAllocation;
function updateStaticBackgrounds() {
for (var bg of global.vertical_overview.bgManagers) {
bg.destroy();
}
global.vertical_overview.bgManagers = [];
for (var monitor of Main.layoutManager.monitors) {
let bgManager = new Background.BackgroundManager({
monitorIndex: monitor.index,
container: Main.layoutManager.overviewGroup,
});
global.vertical_overview.bgManagers.push(bgManager);
}
staticBackgroundEnabled = true;
scalingWorkspaceBackgroundEnabled = true;
}
var staticBackgroundEnabled = false;
var monitorsChangedId = null;
function staticBackgroundOverride() {
if (!staticBackgroundEnabled) {
global.vertical_overview.bgManagers = [];
monitorsChangedId = Main.layoutManager.connect('monitors-changed', () => {
updateStaticBackgrounds();
});
updateStaticBackgrounds();
staticBackgroundEnabled = true;
}
}
function staticBackgroundReset() {
if (staticBackgroundEnabled) {
Main.layoutManager.disconnect(monitorsChangedId);
monitorsChangedId = null;
for (var bg of global.vertical_overview.bgManagers) {
bg.destroy();
}
delete global.vertical_overview.bgManagers;
staticBackgroundEnabled = false;
}
}
var scalingWorkspaceBackgroundEnabled = false;
function scalingWorkspaceBackgroundOverride() {
if (!scalingWorkspaceBackgroundEnabled) {
global.vertical_overview.GSFunctions['Workspace'] = _Util.overrideProto(Workspace.Workspace.prototype, WorkspaceOverride);
scalingWorkspaceBackgroundEnabled = true;
}
}
function scalingWorkspaceBackgroundReset() {
if (scalingWorkspaceBackgroundEnabled) {
_Util.overrideProto(Workspace.Workspace.prototype, global.vertical_overview.GSFunctions['Workspace']);
scalingWorkspaceBackgroundEnabled = false;
}
}
function override() {
global.vertical_overview.GSFunctions["WorkspaceLayout"] = _Util.overrideProto(Workspace.WorkspaceLayout.prototype, WorkspaceLayoutOverride);
}
function reset() {
staticBackgroundReset();
scalingWorkspaceBackgroundReset();
_Util.overrideProto(Workspace.WorkspaceLayout.prototype, global.vertical_overview.GSFunctions["WorkspaceLayout"]);
}
WorkspaceOverride = {
_init: function (metaWorkspace, monitorIndex, overviewAdjustment) {
St.Widget.prototype._init.call(this, {
style_class: 'window-picker',
pivot_point: new Graphene.Point({ x: 0.5, y: 0.5 }),
layout_manager: new Clutter.BinLayout(),
});
const layoutManager = new Workspace.WorkspaceLayout(metaWorkspace, monitorIndex,
overviewAdjustment);
// Window previews
this._container = new Clutter.Actor({
reactive: true,
x_expand: true,
y_expand: true,
});
this._container.layout_manager = layoutManager;
this.add_child(this._container);
this.metaWorkspace = metaWorkspace;
this._activeWorkspaceChangedId =
this.metaWorkspace?.connect('notify::active', () => {
layoutManager.syncOverlays();
});
this._overviewAdjustment = overviewAdjustment;
this.monitorIndex = monitorIndex;
this._monitor = Main.layoutManager.monitors[this.monitorIndex];
if (monitorIndex != Main.layoutManager.primaryIndex)
this.add_style_class_name('external-monitor');
const clickAction = new Clutter.ClickAction();
clickAction.connect('clicked', action => {
// Switch to the workspace when not the active one, leave the
// overview otherwise.
if (action.get_button() === 1 || action.get_button() === 0) {
const leaveOverview = this._shouldLeaveOverview();
this.metaWorkspace?.activate(global.get_current_time());
if (leaveOverview)
Main.overview.hide();
}
});
this.bind_property('mapped', clickAction, 'enabled', GObject.BindingFlags.SYNC_CREATE);
this._container.add_action(clickAction);
this.connect('style-changed', this._onStyleChanged.bind(this));
this.connect('destroy', this._onDestroy.bind(this));
this._skipTaskbarSignals = new Map();
const windows = global.get_window_actors().map(a => a.meta_window)
.filter(this._isMyWindow, this);
// Create clones for windows that should be
// visible in the Overview
this._windows = [];
for (let i = 0; i < windows.length; i++) {
if (this._isOverviewWindow(windows[i]))
this._addWindowClone(windows[i]);
}
// Track window changes, but let the window tracker process them first
this.metaWorkspace?.connectObject(
'window-added', this._windowAdded.bind(this), GObject.ConnectFlags.AFTER,
'window-removed', this._windowRemoved.bind(this), GObject.ConnectFlags.AFTER,
'notify::active', () => layoutManager.syncOverlays(), this);
global.display.connectObject(
'window-entered-monitor', this._windowEnteredMonitor.bind(this), GObject.ConnectFlags.AFTER,
'window-left-monitor', this._windowLeftMonitor.bind(this), GObject.ConnectFlags.AFTER,
this);
this._layoutFrozenId = 0;
// DND requires this to be set
this._delegate = this;
},
}
let WorkspaceLayoutOverride = {
_adjustSpacingAndPadding(rowSpacing, colSpacing, containerBox) {
if (this._sortedWindows.length === 0)
return [rowSpacing, colSpacing, containerBox];
// All of the overlays have the same chrome sizes,
// so just pick the first one.
const window = this._sortedWindows[0];
const [topOversize, bottomOversize] = window.chromeHeights();
const [leftOversize, rightOversize] = window.chromeWidths();
const oversize =
Math.max(topOversize, bottomOversize, leftOversize, rightOversize);
if (rowSpacing !== null)
rowSpacing += oversize;
if (colSpacing !== null)
colSpacing += oversize;
return [rowSpacing, colSpacing, containerBox];
},
}