Skip to content

Commit ecb02f4

Browse files
committed
adjusted move to mouse code so that the window will always stay fully on screen. For example, if you have a shortcut on your taskbar, the entire window won't move under the taskbar and be inaccessible.
1 parent 9bc48ae commit ecb02f4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/background.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ app.on('ready', async () => {
7474
await installVueDevtools()
7575
}
7676
createWindow();
77+
moveWindow();
7778
})
7879

7980
var locked = app.requestSingleInstanceLock();
@@ -84,13 +85,23 @@ if (!locked) {
8485
// Someone tried to run a second instance, we should focus our window.
8586
if (win) {
8687
if (win.isMinimized()) win.restore()
87-
let mousePos = screen.getCursorScreenPoint();
88-
win.setPosition(mousePos.x,mousePos.y)
88+
moveWindow();
8989
win.focus()
9090
}
9191
})
9292
}
9393

94+
function moveWindow(){
95+
96+
let mousePos = screen.getCursorScreenPoint();
97+
let bounds = screen.getDisplayNearestPoint(mousePos).bounds;
98+
let winBounds = win.getBounds();
99+
let horizontalBleed = (bounds.x+bounds.width)-winBounds.width
100+
let verticalBleed = (bounds.y+bounds.height)-winBounds.height
101+
win.setPosition(mousePos.x > horizontalBleed ? horizontalBleed : mousePos.x,mousePos.y > verticalBleed ? verticalBleed : mousePos.y)
102+
}
103+
104+
94105

95106
// Exit cleanly on request from parent process in development mode.
96107
if (isDevelopment) {

0 commit comments

Comments
 (0)