electron-drag icon indicating copy to clipboard operation
electron-drag copied to clipboard

if screen scale to 150% on windows, the position will wrong

Open phongf opened this issue 6 years ago • 3 comments

platform: windows 10 when click element to drag, the element will goto error position

phongf avatar Oct 31 '18 03:10 phongf

I came across the same problem on windows 10 if I set screen scale to some value greater than 100%

livemeta avatar Dec 12 '19 16:12 livemeta

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 avatar Dec 20 '19 10:12 livemeta

@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.

akanshSirohi avatar Nov 04 '21 09:11 akanshSirohi