Skip to content

Commit

Permalink
Fit window in snap group if it doesn't intersect with other windows
Browse files Browse the repository at this point in the history
  • Loading branch information
emvaized authored Oct 10, 2022
1 parent 580822a commit 422ad6c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions contents/ui/code/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ function windowFitsInSnapGroup(client){

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

for (let i = 0, l = snappedWindows.length; i < l; i++) {
const w = getClientFromId(snappedWindows[i]);
Expand Down Expand Up @@ -427,6 +428,20 @@ function windowFitsInSnapGroup(client){
snappedWindowGroups[indexOfGroup].windows.push(client.internalId);
return true;
}

/// check if windows intercept
if (intercectsWithAnyOtherWindow == false) {
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)) {
intercectsWithAnyOtherWindow = true;
}
}
}

/// if window does not intercect with other windows in the group, let it in
if (intercectsWithAnyOtherWindow == false) {
snappedWindowGroups[indexOfGroup].windows.push(client.internalId);
AssistManager.preventAssistFromShowing();
return true;
}

return false;
Expand Down Expand Up @@ -480,3 +495,14 @@ function setOneTimeTimeout(cb, delayTime){
});
timer.start();
}

function windowRectanglesIntersect(
minAx, minAy, maxAx, maxAy,
minBx, minBy, maxBx, maxBy) {
const aLeftOfB = maxAx < minBx;
const aRightOfB = minAx > maxBx;
const aAboveB = minAy > maxBy;
const aBelowB = maxAy < minBy;

return maxAx > minBx && minAx < maxBx && minAy < maxBy && maxAy > minBy;
}

0 comments on commit 422ad6c

Please sign in to comment.