Skip to content

Commit 422ad6c

Browse files
authored
Fit window in snap group if it doesn't intersect with other windows
1 parent 580822a commit 422ad6c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

contents/ui/code/windows.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ function windowFitsInSnapGroup(client){
400400

401401
/// check rest of windows in that group
402402
const snappedWindows = snappedWindowGroups[indexOfGroup].windows;
403+
let intercectsWithAnyOtherWindow = false;
403404

404405
for (let i = 0, l = snappedWindows.length; i < l; i++) {
405406
const w = getClientFromId(snappedWindows[i]);
@@ -427,6 +428,20 @@ function windowFitsInSnapGroup(client){
427428
snappedWindowGroups[indexOfGroup].windows.push(client.internalId);
428429
return true;
429430
}
431+
432+
/// check if windows intercept
433+
if (intercectsWithAnyOtherWindow == false) {
434+
if (windowRectanglesIntersect(w.x, w.y, w.x + w.width, w.y + w.height, client.x, client.y, client.x + client.width, client.y + client.height)) {
435+
intercectsWithAnyOtherWindow = true;
436+
}
437+
}
438+
}
439+
440+
/// if window does not intercect with other windows in the group, let it in
441+
if (intercectsWithAnyOtherWindow == false) {
442+
snappedWindowGroups[indexOfGroup].windows.push(client.internalId);
443+
AssistManager.preventAssistFromShowing();
444+
return true;
430445
}
431446

432447
return false;
@@ -480,3 +495,14 @@ function setOneTimeTimeout(cb, delayTime){
480495
});
481496
timer.start();
482497
}
498+
499+
function windowRectanglesIntersect(
500+
minAx, minAy, maxAx, maxAy,
501+
minBx, minBy, maxBx, maxBy) {
502+
const aLeftOfB = maxAx < minBx;
503+
const aRightOfB = minAx > maxBx;
504+
const aAboveB = minAy > maxBy;
505+
const aBelowB = maxAy < minBy;
506+
507+
return maxAx > minBx && minAx < maxBx && minAy < maxBy && maxAy > minBy;
508+
}

0 commit comments

Comments
 (0)