screeninfo icon indicating copy to clipboard operation
screeninfo copied to clipboard

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

Open rafaelclp opened this issue 4 years ago • 0 comments

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?

rafaelclp avatar Dec 21 '21 22:12 rafaelclp