MCPcopy
hub / github.com/wavetermdev/waveterm / calculateWindowBounds

Function calculateWindowBounds

emain/emain-window.ts:37–97  ·  view source on GitHub ↗
(
    winSize?: { width?: number; height?: number },
    pos?: { x?: number; y?: number },
    settings?: any
)

Source from the content-addressed store, hash-verified

35export const MinWindowHeight = 500;
36
37export function calculateWindowBounds(
38 winSize?: { width?: number; height?: number },
39 pos?: { x?: number; y?: number },
40 settings?: any
41): { x: number; y: number; width: number; height: number } {
42 let winWidth = winSize?.width;
43 let winHeight = winSize?.height;
44 const winPosX = pos?.x ?? 100;
45 const winPosY = pos?.y ?? 100;
46
47 if (
48 (winWidth == null || winWidth === 0 || winHeight == null || winHeight === 0) &&
49 settings?.["window:dimensions"]
50 ) {
51 const dimensions = settings["window:dimensions"];
52 const match = dimensions.match(/^(\d+)[xX](\d+)$/);
53
54 if (match) {
55 const [, dimensionWidth, dimensionHeight] = match;
56 const parsedWidth = parseInt(dimensionWidth, 10);
57 const parsedHeight = parseInt(dimensionHeight, 10);
58
59 if ((!winWidth || winWidth === 0) && Number.isFinite(parsedWidth) && parsedWidth > 0) {
60 winWidth = parsedWidth;
61 }
62 if ((!winHeight || winHeight === 0) && Number.isFinite(parsedHeight) && parsedHeight > 0) {
63 winHeight = parsedHeight;
64 }
65 } else {
66 console.warn('Invalid window:dimensions format. Expected "widthxheight".');
67 }
68 }
69
70 if (winWidth == null || winWidth == 0) {
71 const primaryDisplay = screen.getPrimaryDisplay();
72 const { width } = primaryDisplay.workAreaSize;
73 winWidth = width - winPosX - 100;
74 if (winWidth > 2000) {
75 winWidth = 2000;
76 }
77 }
78 if (winHeight == null || winHeight == 0) {
79 const primaryDisplay = screen.getPrimaryDisplay();
80 const { height } = primaryDisplay.workAreaSize;
81 winHeight = height - winPosY - 100;
82 if (winHeight > 1200) {
83 winHeight = 1200;
84 }
85 }
86
87 winWidth = Math.max(winWidth, MinWindowWidth);
88 winHeight = Math.max(winHeight, MinWindowHeight);
89
90 const winBounds = {
91 x: winPosX,
92 y: winPosY,
93 width: winWidth,
94 height: winHeight,

Callers 2

createBuilderWindowFunction · 0.90
constructorMethod · 0.85

Calls 1

ensureBoundsAreVisibleFunction · 0.90

Tested by

no test coverage detected