-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
32 lines (26 loc) · 1.08 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { screen } = require("electron");
function calculateNotificationWindowPosition(notifWindows) {
const windowWidth = 360;
const windowHeight = 220;
const verticalOffset = 10;
const horizontalOffset = 20;
const display = screen.getPrimaryDisplay();
const { width: screenW, height: screenH, x: screenX, y: screenY } = display.workArea;
let posX, posY;
if (notifWindows.length === 0) {
// First window - center it
posX = screenX + Math.floor((screenW - windowWidth) / 2);
posY = screenY + Math.floor((screenH - windowHeight) / 2);
} else {
// Stagger subsequent ones diagonally down/right from center
posX = screenX + Math.floor((screenW - windowWidth) / 2) + notifWindows.length * horizontalOffset;
posY = screenY + Math.floor((screenH - windowHeight) / 2) + notifWindows.length * verticalOffset;
// Clamp so it doesn't go off screen
posX = Math.min(posX, screenX + screenW - windowWidth - 20);
posY = Math.min(posY, screenY + screenH - windowHeight - 20);
}
return {posX, posY};
}
module.exports = {
calculateNotificationWindowPosition,
}