make size computation a bit more general. adjust for workarea x/y (#1012)

This commit is contained in:
Mike Sawka 2024-10-10 16:35:11 -07:00 committed by GitHub
parent 3d2d68bc73
commit 8de0c3e210
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -318,30 +318,32 @@ function computeNewWinBounds(waveWindow: WaveWindow): Electron.Rectangle {
const targetWidth = waveWindow.winsize?.width || 2000; const targetWidth = waveWindow.winsize?.width || 2000;
const targetHeight = waveWindow.winsize?.height || 1080; const targetHeight = waveWindow.winsize?.height || 1080;
const primaryDisplay = electron.screen.getPrimaryDisplay(); const primaryDisplay = electron.screen.getPrimaryDisplay();
const workSize = primaryDisplay.workAreaSize; const workArea = primaryDisplay.workArea;
const targetPadding = 100; const targetPadding = 100;
let rtn = { x: 100, y: 100, width: targetWidth, height: targetHeight }; const minPadding = 10;
if (workSize.width < targetWidth + 2 * targetPadding) { let rtn = {
const spareWidth = workSize.width - targetWidth; x: workArea.x + targetPadding,
if (spareWidth < 20) { y: workArea.y + targetPadding,
rtn.x = 10; width: targetWidth,
rtn.width = workSize.width - 20; height: targetHeight,
} else if (spareWidth > 200) { };
rtn.x = 100; const spareWidth = workArea.width - targetWidth;
} else { if (spareWidth < 2 * minPadding) {
rtn.x = Math.floor(spareWidth / 2); rtn.x = workArea.x + minPadding;
} rtn.width = workArea.width - 2 * minPadding;
} else if (spareWidth > 2 * targetPadding) {
rtn.x = workArea.x + targetPadding;
} else {
rtn.x = workArea.y + Math.floor(spareWidth / 2);
} }
if (workSize.height < targetHeight + 2 * targetPadding) { const spareHeight = workArea.height - targetHeight;
const spareHeight = workSize.height - targetHeight; if (spareHeight < 2 * minPadding) {
if (spareHeight < 20) { rtn.y = workArea.y + minPadding;
rtn.y = 10; rtn.height = workArea.height - 2 * minPadding;
rtn.height = workSize.height - 20; } else if (spareHeight > 2 * targetPadding) {
} else if (spareHeight > 200) { rtn.y = workArea.y + targetPadding;
rtn.y = 100; } else {
} else { rtn.y = workArea.y + Math.floor(spareHeight / 2);
rtn.y = Math.floor(spareHeight / 2);
}
} }
return rtn; return rtn;
} }