mirror of
https://github.com/Grasscutters/GrassClipper.git
synced 2024-08-14 13:11:48 +08:00
fix top bar drag on screens with different pixel ratios
This commit is contained in:
parent
98acd412ce
commit
6b718b849b
@ -1,22 +1,25 @@
|
|||||||
// https://stackoverflow.com/questions/67971689/positioning-the-borderless-window-in-neutralino-js
|
// https://stackoverflow.com/questions/67971689/positioning-the-borderless-window-in-neutralino-js
|
||||||
// had to use this since the in-built function breaks the close and minimize buttons
|
// had to use this since the in-built function breaks the close and minimize buttons
|
||||||
let dragging = false, posX, posY;
|
let dragging = false, ratio = 1, posX, posY;
|
||||||
let draggable;
|
let draggable;
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
draggable = document.getElementById('controlBar');
|
draggable = document.getElementById('controlBar');
|
||||||
|
|
||||||
// Listen to hovers
|
// Listen to hovers
|
||||||
draggable.onmousedown = function (e) {
|
draggable.onmousedown = function (e) {
|
||||||
posX = e.pageX, posY = e.pageY;
|
ratio = window.devicePixelRatio
|
||||||
|
|
||||||
|
posX = e.pageX * ratio, posY = e.pageY * ratio;
|
||||||
dragging = true;
|
dragging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
draggable.onmouseup = function (e) {
|
// Patch for monitors with scaling enabled, allows them to detach from the titlebar anywhere
|
||||||
|
window.onmouseup = function (e) {
|
||||||
dragging = false;
|
dragging = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.onmousemove = function (e) {
|
document.onmousemove = function (e) {
|
||||||
if (dragging) Neutralino.window.move(e.screenX - posX, e.screenY - posY);
|
if (dragging) Neutralino.window.move(e.screenX * ratio - posX, e.screenY * ratio - posY);
|
||||||
}
|
}
|
||||||
})
|
})
|
Loading…
x
Reference in New Issue
Block a user