-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkspace.js
More file actions
143 lines (123 loc) · 5.3 KB
/
workspace.js
File metadata and controls
143 lines (123 loc) · 5.3 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
import GLib from 'gi://GLib';
import Clutter from 'gi://Clutter';
import * as Main from 'resource:///org/gnome/shell/ui/main.js';
import * as Workspace from 'resource:///org/gnome/shell/ui/workspace.js';
import * as ObjectPrototype from './utils/objectPrototype.js';
const WINDOW_OVERLAY_FADE_TIME = 200;
let _settings;
let _objectPrototype;
let _appsGridShownId;
let _idleId;
let _allWindows;
function _showHideWorkspaceBackground(workspaceBackground) {
const hide_background = _settings.get_boolean('hide-background');
if (hide_background) {
workspaceBackground.hide();
} else {
workspaceBackground.show();
}
}
function _animateFromOverview(windowPreview, animate) {
const metaWorkspace = windowPreview._workspace.metaWorkspace;
// Seems that if metaWorkspace is null, the current workspace is active?
// See: workspace.Workspace#_isMyWindow() and workspacesView.SecondaryMonitorDisplay#_updateWorkspacesView()
if (metaWorkspace !== null && !metaWorkspace.active) {
return;
}
// Hide title and button gradually even if metaWorkspace is null
const toHide = [windowPreview._title, windowPreview._closeButton];
toHide.forEach(a => {
a.opacity = 255;
a.ease({
opacity: 0,
duration: animate ? WINDOW_OVERLAY_FADE_TIME : 0,
mode: Clutter.AnimationMode.EASE_OUT_EXPO
});
});
}
// TODO better to hide the titles and close buttons before entering the app grid,
// otherwise the titles and close buttons on windows are very noticeable.
function _removeWindowDecorations() {
_appsGridShownId = Main.overview.dash.showAppsButton.connect('notify::checked', () => {
if (Main.overview.dash.showAppsButton.checked) {
_allWindows = [];
// Have to do this when the event loop is idle and to wait the underlying higher priority operations are completed
_idleId = GLib.idle_add(GLib.PRIORITY_LOW, () => {
// monitors
const workspacesViews = Main.overview._overview._controls._workspacesDisplay._workspacesViews;
if (workspacesViews && workspacesViews.length) {
workspacesViews.forEach(wv => {
const workspaces = wv._workspaces;
// It's possible no workspace view bars on the second monitor
if (workspaces && workspaces.length) {
workspaces.forEach(workspace => {
const windows = workspace._windows;
if (windows.length) {
windows.forEach(windowPreview => {
windowPreview._closeButton._originalVisibleAWSM = windowPreview._closeButton.visible;
windowPreview._title._originalVisibleAWSM = windowPreview._title.visible;
windowPreview._closeButton.hide();
windowPreview._title.hide();
_allWindows.push(windowPreview);
});
}
});
}
});
}
return GLib.SOURCE_REMOVE;
});
} else {
_restoreWindowsVisible();
}
});
}
function _restoreWindowsVisible() {
if (_allWindows && _allWindows.length) {
_allWindows.forEach(windowPreview => {
windowPreview._closeButton.visible = windowPreview._closeButton._originalVisibleAWSM;
windowPreview._title.visible = windowPreview._title._originalVisibleAWSM;
});
_allWindows = null;
}
}
export const CustomWorkspace = class {
constructor(settings) {
_removeWindowDecorations();
_settings = settings;
}
enable() {
_objectPrototype = new ObjectPrototype.ObjectPrototype();
// Since other extensions (eg, dash-to-panel) could use Workspace.WorkspaceBackground, I can't just remove it any more.
// Hide the Workspace.WorkspaceBackground after be initialized
_objectPrototype.injectOrOverrideFunction(Workspace.WorkspaceBackground.prototype, '_init', true, function() {
_showHideWorkspaceBackground(this);
});
_objectPrototype.injectOrOverrideFunction(Workspace.Workspace.prototype, 'prepareToLeaveOverview', true, function() {
for (let i = 0; i < this._windows.length; i++) {
const windowPreview = this._windows[i];
_animateFromOverview(windowPreview, true);
}
});
}
// Destroy the created object
disable() {
if (_settings) {
_settings = null;
}
if (_objectPrototype) {
_objectPrototype.removeInjections(Workspace.WorkspaceBackground.prototype);
_objectPrototype.removeInjections(Workspace.Workspace.prototype);
_objectPrototype = null;
}
if (_appsGridShownId) {
Main.overview.dash.showAppsButton.disconnect(_appsGridShownId);
_appsGridShownId = null;
}
if (_idleId) {
GLib.source_remove(_idleId);
_idleId = null;
}
_restoreWindowsVisible();
}
}