Skip to content

Commit d2bd424

Browse files
committed
Cleanup WindowCloneContainer
1 parent bf8bca2 commit d2bd424

File tree

2 files changed

+244
-271
lines changed

2 files changed

+244
-271
lines changed

src/InternalUtils.vala

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -91,179 +91,6 @@ namespace Gala {
9191
workspace_manager.thaw_remove ();
9292
}
9393

94-
// Code ported from KWin present windows effect
95-
// https://projects.kde.org/projects/kde/kde-workspace/repository/revisions/master/entry/kwin/effects/presentwindows/presentwindows.cpp
96-
97-
// some math utilities
98-
private static int squared_distance (Gdk.Point a, Gdk.Point b) {
99-
var k1 = b.x - a.x;
100-
var k2 = b.y - a.y;
101-
102-
return k1 * k1 + k2 * k2;
103-
}
104-
105-
private static Mtk.Rectangle rect_adjusted (Mtk.Rectangle rect, int dx1, int dy1, int dx2, int dy2) {
106-
return {rect.x + dx1, rect.y + dy1, rect.width + (-dx1 + dx2), rect.height + (-dy1 + dy2)};
107-
}
108-
109-
private static Gdk.Point rect_center (Mtk.Rectangle rect) {
110-
return {rect.x + rect.width / 2, rect.y + rect.height / 2};
111-
}
112-
113-
public struct TilableWindow {
114-
Mtk.Rectangle rect;
115-
unowned WindowClone id;
116-
}
117-
118-
/**
119-
* Careful: List<TilableWindow?> windows will be modified in place and shouldn't be used afterwards.
120-
*/
121-
public static List<TilableWindow?> calculate_grid_placement (Mtk.Rectangle area, List<TilableWindow?> windows) {
122-
uint window_count = windows.length ();
123-
int columns = (int)Math.ceil (Math.sqrt (window_count));
124-
int rows = (int)Math.ceil (window_count / (double)columns);
125-
126-
// Assign slots
127-
int slot_width = area.width / columns;
128-
int slot_height = area.height / rows;
129-
130-
TilableWindow?[] taken_slots = {};
131-
taken_slots.resize (rows * columns);
132-
133-
// precalculate all slot centers
134-
Gdk.Point[] slot_centers = {};
135-
slot_centers.resize (rows * columns);
136-
for (int x = 0; x < columns; x++) {
137-
for (int y = 0; y < rows; y++) {
138-
slot_centers[x + y * columns] = {
139-
area.x + slot_width * x + slot_width / 2,
140-
area.y + slot_height * y + slot_height / 2
141-
};
142-
}
143-
}
144-
145-
// Assign each window to the closest available slot
146-
while (windows.length () > 0) {
147-
unowned List<TilableWindow?> link = windows.nth (0);
148-
var window = link.data;
149-
var rect = window.rect;
150-
151-
var slot_candidate = -1;
152-
var slot_candidate_distance = int.MAX;
153-
var pos = rect_center (rect);
154-
155-
// all slots
156-
for (int i = 0; i < columns * rows; i++) {
157-
if (i > window_count - 1)
158-
break;
159-
160-
var dist = squared_distance (pos, slot_centers[i]);
161-
162-
if (dist < slot_candidate_distance) {
163-
// window is interested in this slot
164-
var occupier = taken_slots[i];
165-
if (occupier == window)
166-
continue;
167-
168-
if (occupier == null || dist < squared_distance (rect_center (occupier.rect), slot_centers[i])) {
169-
// either nobody lives here, or we're better - takeover the slot if it's our best
170-
slot_candidate = i;
171-
slot_candidate_distance = dist;
172-
}
173-
}
174-
}
175-
176-
if (slot_candidate == -1)
177-
continue;
178-
179-
if (taken_slots[slot_candidate] != null)
180-
windows.prepend (taken_slots[slot_candidate]);
181-
182-
windows.remove_link (link);
183-
taken_slots[slot_candidate] = window;
184-
}
185-
186-
var result = new List<TilableWindow?> ();
187-
188-
// see how many windows we have on the last row
189-
int left_over = (int)window_count - columns * (rows - 1);
190-
191-
for (int slot = 0; slot < columns * rows; slot++) {
192-
var window = taken_slots[slot];
193-
// some slots might be empty
194-
if (window == null)
195-
continue;
196-
197-
var rect = window.rect;
198-
199-
// Work out where the slot is
200-
Mtk.Rectangle target = {
201-
area.x + (slot % columns) * slot_width,
202-
area.y + (slot / columns) * slot_height,
203-
slot_width,
204-
slot_height
205-
};
206-
target = rect_adjusted (target, 10, 10, -10, -10);
207-
208-
float scale;
209-
if (target.width / (double)rect.width < target.height / (double)rect.height) {
210-
// Center vertically
211-
scale = target.width / (float)rect.width;
212-
target.y += (target.height - (int)(rect.height * scale)) / 2;
213-
target.height = (int)Math.floorf (rect.height * scale);
214-
} else {
215-
// Center horizontally
216-
scale = target.height / (float)rect.height;
217-
target.x += (target.width - (int)(rect.width * scale)) / 2;
218-
target.width = (int)Math.floorf (rect.width * scale);
219-
}
220-
221-
// Don't scale the windows too much
222-
if (scale > 1.0) {
223-
scale = 1.0f;
224-
target = {rect_center (target).x - (int)Math.floorf (rect.width * scale) / 2,
225-
rect_center (target).y - (int)Math.floorf (rect.height * scale) / 2,
226-
(int)Math.floorf (scale * rect.width),
227-
(int)Math.floorf (scale * rect.height)};
228-
}
229-
230-
// put the last row in the center, if necessary
231-
if (left_over != columns && slot >= columns * (rows - 1))
232-
target.x += (columns - left_over) * slot_width / 2;
233-
234-
result.prepend ({ target, window.id });
235-
}
236-
237-
result.reverse ();
238-
return result;
239-
}
240-
241-
/*
242-
* Sorts the windows by stacking order so that the window on active workspaces come first.
243-
*/
244-
public static SList<weak Meta.Window> sort_windows (Meta.Display display, List<Meta.Window> windows) {
245-
var windows_on_active_workspace = new SList<Meta.Window> ();
246-
var windows_on_other_workspaces = new SList<Meta.Window> ();
247-
unowned var active_workspace = display.get_workspace_manager ().get_active_workspace ();
248-
foreach (unowned var window in windows) {
249-
if (window.get_workspace () == active_workspace) {
250-
windows_on_active_workspace.append (window);
251-
} else {
252-
windows_on_other_workspaces.append (window);
253-
}
254-
}
255-
256-
var sorted_windows = new SList<weak Meta.Window> ();
257-
var windows_on_active_workspace_sorted = display.sort_windows_by_stacking (windows_on_active_workspace);
258-
windows_on_active_workspace_sorted.reverse ();
259-
var windows_on_other_workspaces_sorted = display.sort_windows_by_stacking (windows_on_other_workspaces);
260-
windows_on_other_workspaces_sorted.reverse ();
261-
sorted_windows.concat ((owned) windows_on_active_workspace_sorted);
262-
sorted_windows.concat ((owned) windows_on_other_workspaces_sorted);
263-
264-
return sorted_windows;
265-
}
266-
26794
public static inline bool get_window_is_normal (Meta.Window window) {
26895
switch (window.window_type) {
26996
case Meta.WindowType.NORMAL:

0 commit comments

Comments
 (0)