fix: prevent window resizing during movement with Ctrl+Arrow and edge

Fixed window resizing issue when moving with Ctrl+Arrow keys by  setting window bounds
This commit is contained in:
Aditya U 2025-07-08 13:27:20 +05:30 committed by GitHub
parent 013a033051
commit 8aab4feb22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,6 +120,11 @@ class SmoothMovementManager {
let targetX = this.headerPosition.x; let targetX = this.headerPosition.x;
let targetY = this.headerPosition.y; let targetY = this.headerPosition.y;
const windowSize = {
width: currentBounds.width,
height: currentBounds.height
};
switch (direction) { switch (direction) {
case 'left': targetX -= this.stepSize; break; case 'left': targetX -= this.stepSize; break;
case 'right': targetX += this.stepSize; break; case 'right': targetX += this.stepSize; break;
@ -130,19 +135,28 @@ class SmoothMovementManager {
const displays = screen.getAllDisplays(); const displays = screen.getAllDisplays();
let validPosition = displays.some(d => ( let validPosition = displays.some(d => (
targetX >= d.workArea.x && targetX + currentBounds.width <= d.workArea.x + d.workArea.width && targetX >= d.workArea.x && targetX + windowSize.width <= d.workArea.x + d.workArea.width &&
targetY >= d.workArea.y && targetY + currentBounds.height <= d.workArea.y + d.workArea.height targetY >= d.workArea.y && targetY + windowSize.height <= d.workArea.y + d.workArea.height
)); ));
if (!validPosition) { if (!validPosition) {
const nearestDisplay = screen.getDisplayNearestPoint({ x: targetX, y: targetY }); const nearestDisplay = screen.getDisplayNearestPoint({ x: targetX, y: targetY });
const { x, y, width, height } = nearestDisplay.workArea; const { x, y, width, height } = nearestDisplay.workArea;
targetX = Math.max(x, Math.min(x + width - currentBounds.width, targetX)); targetX = Math.max(x, Math.min(x + width - windowSize.width, targetX));
targetY = Math.max(y, Math.min(y + height - currentBounds.height, targetY)); targetY = Math.max(y, Math.min(y + height - windowSize.height, targetY));
} }
if (targetX === this.headerPosition.x && targetY === this.headerPosition.y) return; if (targetX === this.headerPosition.x && targetY === this.headerPosition.y) return;
this.animateToPosition(header, targetX, targetY);
header.setBounds({
x: Math.round(targetX),
y: Math.round(targetY),
width: windowSize.width,
height: windowSize.height
});
this.headerPosition = { x: targetX, y: targetY };
this.updateLayout();
} }
animateToPosition(header, targetX, targetY) { animateToPosition(header, targetX, targetY) {
@ -198,20 +212,40 @@ class SmoothMovementManager {
const display = this.getCurrentDisplay(header); const display = this.getCurrentDisplay(header);
const { width, height } = display.workAreaSize; const { width, height } = display.workAreaSize;
const { x: workAreaX, y: workAreaY } = display.workArea; const { x: workAreaX, y: workAreaY } = display.workArea;
const headerBounds = header.getBounds();
const currentBounds = header.getBounds(); const currentBounds = header.getBounds();
const windowSize = {
width: currentBounds.width,
height: currentBounds.height
};
let targetX = currentBounds.x; let targetX = currentBounds.x;
let targetY = currentBounds.y; let targetY = currentBounds.y;
switch (direction) { switch (direction) {
case 'left': targetX = workAreaX; break; case 'left':
case 'right': targetX = workAreaX + width - headerBounds.width; break; targetX = workAreaX;
case 'up': targetY = workAreaY; break; break;
case 'down': targetY = workAreaY + height - headerBounds.height; break; case 'right':
targetX = workAreaX + width - windowSize.width;
break;
case 'up':
targetY = workAreaY;
break;
case 'down':
targetY = workAreaY + height - windowSize.height;
break;
} }
this.headerPosition = { x: currentBounds.x, y: currentBounds.y }; header.setBounds({
this.animateToPosition(header, targetX, targetY); x: Math.round(targetX),
y: Math.round(targetY),
width: windowSize.width,
height: windowSize.height
});
this.headerPosition = { x: targetX, y: targetY };
this.updateLayout();
} }
destroy() { destroy() {
@ -224,4 +258,4 @@ class SmoothMovementManager {
} }
} }
module.exports = SmoothMovementManager; module.exports = SmoothMovementManager;