Skip to content

Commit b09790a

Browse files
committed
fix(aot) Fix window resizing on move on scaled up monitors
1 parent 931c4c7 commit b09790a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

alwaysontop/main/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,14 @@ const onStateChange = (event, { value }) => {
218218
* Handler for move event
219219
* @param {Event} event trigger event
220220
* @param {Object} options event params
221+
* @param {Object} initialSize the window size before move
221222
*/
222-
const onMove = (event, { x, y }) => {
223+
const onMove = (event, { x, y }, initialSize) => {
223224
if (!windowExists(aotWindow)) {
224225
return;
225226
}
226227

227-
const [width, height] = aotWindow.getSize();
228+
const { width, height } = initialSize;
228229

229230
aotWindow.setBounds({
230231
x,

alwaysontop/render/alwaysontop.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const {
77
dismiss
88
} = window.alwaysOnTop;
99

10+
let initialSize;
11+
1012
const dismissButton = document.querySelector('.dismiss');
1113
if (dismissButton) {
1214
dismissButton.addEventListener('click', dismiss);
@@ -28,6 +30,10 @@ api._getAlwaysOnTopResources().forEach(src => loadFile(src));
2830
function setupDraggable() {
2931
if (shouldImplementDrag) {
3032
window.addEventListener('mousedown', mouseDownEvent => {
33+
initialSize = {
34+
width: window.innerWidth,
35+
height: window.innerHeight
36+
};
3137
pageX = mouseDownEvent.pageX;
3238
pageY = mouseDownEvent.pageY;
3339
window.addEventListener('mousemove', drag);
@@ -58,7 +64,7 @@ function drag(mouseMoveEvent) {
5864
mouseMoveEvent.stopPropagation();
5965
mouseMoveEvent.preventDefault();
6066
const { screenX, screenY } = mouseMoveEvent;
61-
move(screenX - pageX, screenY - pageY);
67+
move(screenX - pageX, screenY - pageY, initialSize);
6268
}
6369

6470
/**

alwaysontop/render/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ const { EVENTS, STATES, AOT_WINDOW_NAME, EXTERNAL_EVENTS } = require('../constan
2020

2121
/**
2222
* Sends a move command to the main process
23-
* @param {Number} x
24-
* @param {Number} y
23+
* @param {Number} x
24+
* @param {Number} y
25+
* @param {Object} initialSize - The size of the window on move start.
2526
*/
26-
const move = (x, y) => {
27-
ipcRenderer.send(EVENTS.MOVE, { x, y } );
27+
const move = (x, y, initialSize) => {
28+
ipcRenderer.send(EVENTS.MOVE, { x, y }, initialSize);
2829
};
2930

3031
class AlwaysOnTop extends EventEmitter {

0 commit comments

Comments
 (0)