Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phongf opened this issue Oct 31, 2018 · 3 comments
Open

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

phongf opened this issue Oct 31, 2018 · 3 comments

Comments

@phongf
Copy link

phongf commented Oct 31, 2018

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

@livemeta
Copy link

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

@livemeta
Copy link

livemeta commented Dec 20, 2019

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 : electron/electron#10659

@akanshSirohi
Copy link

akanshSirohi commented Nov 4, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants