Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #21 from xanderfrangos/master
Browse files Browse the repository at this point in the history
Aero Snap fix
  • Loading branch information
seo-rii authored Sep 7, 2020
2 parents c3f1a83 + b065aab commit 232140c
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ function hrtimeDeltaForFrequency(freq) {
return BigInt(Math.ceil(billion / freq));
}

function findDesiredPosition(position, positionList) {
return positionList.find(op => areBoundsEqual(position, op));
let disableJitterFix = false
// Detect if cursor is near the screen edge. Used to disable the jitter fix in 'move' event.
function isInSnapZone() {
const point = screen.getCursorScreenPoint()
const display = screen.getDisplayNearestPoint(point)

// Check if cursor is near the left/right edge of the active display
if((point.x > display.bounds.x - 20 && point.x < display.bounds.x + 20) || (point.x > display.bounds.x + display.bounds.width - 20 && point.x < display.bounds.x + display.bounds.width + 20)) {
return true
}
return false
}

function opFormatter(vibrancyOp) {
Expand Down Expand Up @@ -146,22 +155,6 @@ class vBrowserWindow extends eBrowserWindow {
return refreshCtx.findVerticalRefreshRateForDisplayPoint(cursor.x, cursor.y);
}

// Electron has a bad bug where it wants to ignore the very last will-move
// boundary set and revert to a slightly earlier one. We correct for this
// in the "move" event, but this correction is incompatible with Aero Snap.
// So to work around _that_, we're keeping a small record of the positions
// we wanted to set. If the bounds we have at the end of the move aren't
// at all what we said we wanted in the past, we just defer to what they are.
const desiredPositions = [];

function recordDesiredPosition(nextDesiredPosition) {
if (findDesiredPosition(nextDesiredPosition, desiredPositions)) return;
if (desiredPositions.length >= 5) {
desiredPositions.shift();
}
desiredPositions.push(nextDesiredPosition);
}

// Ensure all movement operation is serialized, by setting up a continuous promise chain
// All movement operation will take the form of
//
Expand Down Expand Up @@ -198,7 +191,6 @@ class vBrowserWindow extends eBrowserWindow {
}
win.setBounds(bounds);
desiredMoveBounds = win.getBounds();
recordDesiredPosition(desiredMoveBounds);
}

function currentTimeBeforeNextActivityWindow(lastTime, forceFreq) {
Expand Down Expand Up @@ -243,6 +235,9 @@ class vBrowserWindow extends eBrowserWindow {
shouldMove = false;
}, 1000 / vibrancyOp.maximumRefreshRate);

// Disable next event ('move') if cursor is near the screen edge
disableJitterFix = isInSnapZone()

// Start new behavior if not already
if (!shouldMove) {
shouldMove = true;
Expand Down Expand Up @@ -283,13 +278,13 @@ class vBrowserWindow extends eBrowserWindow {
});

win.on('move', (e) => {
if(disableJitterFix) {
return true;
}
if (isMoving || win.isDestroyed()) {
e.preventDefault();
return false;
}
// The bounds we have now aren't in the bounds we ever requested.
// Something else managed this move, so we need to respect it.
if (!findDesiredPosition(win.getBounds(), desiredPositions)) return;
// As insane as this sounds, Electron sometimes reacts to prior
// move events out of order. Specifically, if you have win.setBounds()
// twice, then for some reason, when you exit the move state, the second
Expand Down

0 comments on commit 232140c

Please sign in to comment.