-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
WindowOverview.vala
306 lines (245 loc) · 8.87 KB
/
WindowOverview.vala
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
/*
* Copyright 2012 Tom Beckmann
* Copyright 2012 Rico Tzschichholz
* Copyright 2023 elementary, Inc. <https://elementary.io>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public class Gala.WindowOverview : Clutter.Actor, ActivatableComponent {
private const int BORDER = 10;
private const int TOP_GAP = 30;
private const int BOTTOM_GAP = 100;
public WindowManager wm { get; construct; }
private Meta.Display display;
private ModalProxy modal_proxy;
private bool ready;
// the workspaces which we expose right now
private List<Meta.Workspace> workspaces;
public WindowOverview (WindowManager wm) {
Object (wm : wm);
}
construct {
display = wm.get_display ();
display.get_workspace_manager ().workspace_switched.connect (() => { close (); });
display.restacked.connect (restack_windows);
visible = false;
ready = true;
reactive = true;
}
~WindowOverview () {
display.restacked.disconnect (restack_windows);
}
public override bool key_press_event (Clutter.KeyEvent event) {
if (event.keyval == Clutter.Key.Escape) {
close ();
return Gdk.EVENT_STOP;
}
return Gdk.EVENT_PROPAGATE;
}
public override void key_focus_out () {
if (!contains (get_stage ().key_focus)) {
close ();
}
}
public override bool button_press_event (Clutter.ButtonEvent event) {
if (event.button == Gdk.BUTTON_PRIMARY) {
close ();
}
return Gdk.EVENT_STOP;
}
/**
* {@inheritDoc}
*/
public bool is_opened () {
return visible;
}
/**
* {@inheritDoc}
* You may specify 'all-windows' in hints to expose all windows
*/
public void open (HashTable<string,Variant>? hints = null) {
if (!ready) {
return;
}
if (visible) {
close ();
return;
}
var all_windows = hints != null && "all-windows" in hints;
var used_windows = new SList<Meta.Window> ();
workspaces = new List<Meta.Workspace> ();
unowned Meta.WorkspaceManager manager = display.get_workspace_manager ();
if (all_windows) {
for (int i = 0; i < manager.get_n_workspaces (); i++) {
workspaces.append (manager.get_workspace_by_index (i));
}
} else {
workspaces.append (manager.get_active_workspace ());
}
foreach (var workspace in workspaces) {
foreach (var window in workspace.list_windows ()) {
if (window.window_type != Meta.WindowType.NORMAL &&
window.window_type != Meta.WindowType.DOCK &&
window.window_type != Meta.WindowType.DIALOG ||
window.is_attached_dialog ()) {
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();
if (actor != null) {
actor.hide ();
}
continue;
}
if (window.window_type == Meta.WindowType.DOCK) {
continue;
}
// skip windows that are on all workspace except we're currently
// processing the workspace it actually belongs to
if (window.is_on_all_workspaces () && window.get_workspace () != workspace) {
continue;
}
used_windows.append (window);
}
}
var n_windows = used_windows.length ();
if (n_windows == 0) {
return;
}
ready = false;
foreach (var workspace in workspaces) {
workspace.window_added.connect (add_window);
workspace.window_removed.connect (remove_window);
}
display.window_left_monitor.connect (window_left_monitor);
// sort windows by stacking order
var windows = display.sort_windows_by_stacking (used_windows);
grab_key_focus ();
modal_proxy = wm.push_modal (this);
modal_proxy.set_keybinding_filter (keybinding_filter);
visible = true;
for (var i = 0; i < display.get_n_monitors (); i++) {
var geometry = display.get_monitor_geometry (i);
var container = new WindowCloneContainer (wm, null, true) {
padding_top = TOP_GAP,
padding_left = BORDER,
padding_right = BORDER,
padding_bottom = BOTTOM_GAP
};
container.set_position (geometry.x, geometry.y);
container.set_size (geometry.width, geometry.height);
container.window_selected.connect (thumb_selected);
add_child (container);
}
foreach (var window in windows) {
unowned var actor = (Meta.WindowActor) window.get_compositor_private ();
if (actor != null) {
actor.hide ();
}
unowned var container = (WindowCloneContainer) get_child_at_index (window.get_monitor ());
if (container == null) {
continue;
}
container.add_window (window);
}
foreach (var child in get_children ()) {
((WindowCloneContainer) child).open ();
}
ready = true;
}
private bool keybinding_filter (Meta.KeyBinding binding) {
switch (binding.get_name ()) {
case "expose-windows":
case "expose-all-windows":
case "zoom-in":
case "zoom-out":
return false;
default:
break;
}
return true;
}
private void restack_windows (Meta.Display display) {
foreach (var child in get_children ()) {
((WindowCloneContainer) child).restack_windows (display);
}
}
private void window_left_monitor (int num, Meta.Window window) {
unowned var container = (WindowCloneContainer) get_child_at_index (num);
if (container == null) {
return;
}
// make sure the window belongs to one of our workspaces
foreach (var workspace in workspaces) {
if (window.located_on_workspace (workspace)) {
container.remove_window (window);
break;
}
}
}
private void add_window (Meta.Window window) {
if (!visible
|| (window.window_type != Meta.WindowType.NORMAL && window.window_type != Meta.WindowType.DIALOG)) {
return;
}
unowned var container = (WindowCloneContainer) get_child_at_index (window.get_monitor ());
if (container == null) {
return;
}
// make sure the window belongs to one of our workspaces
foreach (var workspace in workspaces) {
if (window.located_on_workspace (workspace)) {
container.add_window (window);
break;
}
}
}
private void remove_window (Meta.Window window) {
unowned var container = (WindowCloneContainer) get_child_at_index (window.get_monitor ());
if (container == null) {
return;
}
container.remove_window (window);
}
private void thumb_selected (Meta.Window window) {
if (window.get_workspace () == display.get_workspace_manager ().get_active_workspace ()) {
window.activate (display.get_current_time ());
close ();
} else {
close ();
//wait for the animation to finish before switching
Timeout.add (400, () => {
window.get_workspace ().activate_with_focus (window, display.get_current_time ());
return Source.REMOVE;
});
}
}
/**
* {@inheritDoc}
*/
public void close (HashTable<string,Variant>? hints = null) {
if (!visible || !ready) {
return;
}
foreach (var workspace in workspaces) {
workspace.window_added.disconnect (add_window);
workspace.window_removed.disconnect (remove_window);
}
display.window_left_monitor.disconnect (window_left_monitor);
ready = false;
wm.pop_modal (modal_proxy);
foreach (var child in get_children ()) {
((WindowCloneContainer) child).close ();
}
Clutter.Threads.Timeout.add (300, () => {
cleanup ();
return Source.REMOVE;
});
}
private void cleanup () {
ready = true;
visible = false;
foreach (var window in display.get_workspace_manager ().get_active_workspace ().list_windows ()) {
if (window.showing_on_its_workspace ()) {
((Clutter.Actor) window.get_compositor_private ()).show ();
}
}
destroy_all_children ();
}
}