electron-drag
electron-drag copied to clipboard
if screen scale to 150% on windows, the position will wrong
platform: windows 10 when click element to drag, the element will goto error position
I came across the same problem on windows 10 if I set screen scale to some value greater than 100%
I change the implementation like this, and it works proproly for me.
var drag = function(element) {
element = $(element);
var offset = null;
var win = null;
var size = null;
var mouse = mouseConstructor();
var onmousedown = function(e) {
win = remote.getCurrentWindow();
offset = [e.clientX, e.clientY];
size = win.getSize();
};
element.on('mousedown', onmousedown);
mouse.on('left-drag', function(x, y) {
if(!offset) return;
var screenScale = remote.screen.getDisplayNearestPoint({ x, y }).scaleFactor;
x = Math.round(x / screenScale - offset[0]);
y = Math.round(y / screenScale - offset[1]);
win.setBounds({
width: size[0],
height: size[1],
x, y
});
});
mouse.on('left-up', function() {
offset = null;
win = null;
size = null;
});
return function() {
element.off('mousedown', onmousedown);
mouse.destroy();
};
};
Refer to the issuce of electron : https://github.com/electron/electron/issues/10659
@livemeta This code works perfectly but it needs some change in index.js
file to make it work on latest version of electron, the remote module is removed from electron, so we can use const remote = require('@electron/remote');
to import remote module and also remember to properly initialize remote in main app.js file. Hope this will help someone looking for solution here.