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

y for a secondary monitor has a different meaning in darwin vs other systems #63

Open
rafaelclp opened this issue Dec 21, 2021 · 0 comments

Comments

@rafaelclp
Copy link

rafaelclp commented Dec 21, 2021

I'm working with screeninfo + pyautogui. My code was working fine on Windows, but when I moved to MacOS, I noticed it would only work in my primary monitor (where y=0), not in other monitors. Pyautogui would move the cursor to the wrong coordinates.

The reason:

  • In Windows (and probably Linux), mon.y is the position of the top of the monitor mon relative to the top of the primary monitor. Above primary monitor is negative, below is positive*.
  • In MacOS, mon.y is the position of the bottom of the monitor mon relative to the bottom of the primary monitor. Above primary monitor is positive, below is negative*.

* I think. I'm only submitting the issue today, but I encountered this issue months ago when I actually had an external monitor. My memory might be wrong, and I don't have another monitor anymore to confirm.

Pyautogui uses the Windows' meaning of y in all systems (afaik). I looked into pyautogui's code, but it doesn't seem to make any computations on y, it just passes it straight to the "internal" (Quartz) functions. It uses Quartz underneath though, and I didn't check what Quartz does.

I ended up solving my problem with:

xplatform_y = primary_mon.height - (mon.y + mon.height) if sys.platform == "darwin" else mon.y

Unsure which approach you'd rather take here. Add another field to Monitor for this y? Add a @property? Add some documentation explaining this distinction in semantics?

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

1 participant