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

Commit

Permalink
Handle resizes at 60 Hz maximum
Browse files Browse the repository at this point in the history
  • Loading branch information
djsweet committed Aug 1, 2020
1 parent ea4d5f3 commit 7e19b0e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ class vBrowserWindow extends eBrowserWindow {
desiredMoveBounds = win.getBounds();
}

function currentTimeBeforeNextWindow(lastTime) {
return process.hrtime.bigint() < lastTime + hrtimeDeltaForFrequency(pollingRate);
function currentTimeBeforeNextActivityWindow(lastTime, forceFreq) {
return process.hrtime.bigint() <
lastTime + hrtimeDeltaForFrequency(forceFreq || pollingRate || 30);
}

function guardingAgainstMoveUpdate(fn) {
if (pollingRate === undefined || !currentTimeBeforeNextWindow(moveLastUpdate)) {
if (pollingRate === undefined || !currentTimeBeforeNextActivityWindow(moveLastUpdate)) {
fn();
moveLastUpdate = process.hrtime.bigint();
return true;
Expand Down Expand Up @@ -232,7 +233,11 @@ class vBrowserWindow extends eBrowserWindow {

lastWillResizeBounds = newBounds;

if (currentTimeBeforeNextWindow(resizeLastUpdate)) {
// 60 Hz ought to be enough... for resizes.
// Some systems have trouble going 120 Hz, so we'll just take the lower
// of the current pollingRate and 60 Hz.
if (pollingRate !== undefined &&
currentTimeBeforeNextActivityWindow(resizeLastUpdate, Math.min(pollingRate, 60))) {
e.preventDefault();
return false;
}
Expand Down

0 comments on commit 7e19b0e

Please sign in to comment.