Skip to content

Commit

Permalink
make size computation a bit more general. adjust for workarea x/y (#1012
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sawka authored Oct 10, 2024
1 parent 3d2d68b commit 8de0c3e
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions emain/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,30 +318,32 @@ function computeNewWinBounds(waveWindow: WaveWindow): Electron.Rectangle {
const targetWidth = waveWindow.winsize?.width || 2000;
const targetHeight = waveWindow.winsize?.height || 1080;
const primaryDisplay = electron.screen.getPrimaryDisplay();
const workSize = primaryDisplay.workAreaSize;
const workArea = primaryDisplay.workArea;
const targetPadding = 100;
let rtn = { x: 100, y: 100, width: targetWidth, height: targetHeight };
if (workSize.width < targetWidth + 2 * targetPadding) {
const spareWidth = workSize.width - targetWidth;
if (spareWidth < 20) {
rtn.x = 10;
rtn.width = workSize.width - 20;
} else if (spareWidth > 200) {
rtn.x = 100;
} else {
rtn.x = Math.floor(spareWidth / 2);
}
const minPadding = 10;
let rtn = {
x: workArea.x + targetPadding,
y: workArea.y + targetPadding,
width: targetWidth,
height: targetHeight,
};
const spareWidth = workArea.width - targetWidth;
if (spareWidth < 2 * minPadding) {
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 = workSize.height - targetHeight;
if (spareHeight < 20) {
rtn.y = 10;
rtn.height = workSize.height - 20;
} else if (spareHeight > 200) {
rtn.y = 100;
} else {
rtn.y = Math.floor(spareHeight / 2);
}
const spareHeight = workArea.height - targetHeight;
if (spareHeight < 2 * minPadding) {
rtn.y = workArea.y + minPadding;
rtn.height = workArea.height - 2 * minPadding;
} else if (spareHeight > 2 * targetPadding) {
rtn.y = workArea.y + targetPadding;
} else {
rtn.y = workArea.y + Math.floor(spareHeight / 2);
}
return rtn;
}
Expand Down

0 comments on commit 8de0c3e

Please sign in to comment.