Window top, left

Hi all,

I’m trying to understand the numbers that Window.top and left get when there are multiple monitors.

I have a MBP and I plugged in HDMI so I have a large monitor (27 inch) positioned to the right of the MBP so the display area is extended.

It seems when I move a window from the primary MBP display to the extended monitor the left seems to be correct but at some point Top will be a negative number. I’m trying to understand what the means.

Eventually this code will need to work for Windows and maybe Linux too as far as saving and restoring window positions.

Alternatively if there is a cool widget or 3rd party item that handles save/restore of window positions and is cross platform I’d be interested for sure.

Thanks in advance

Mark

1 Like

It is correct. You must have messed up the screen configuration when you set up your monitors. Something like this:
image

So the coordinates of the other screen are negative relative to the main screen.

If you configuire your screens correctly, the top will be the same for both and the left of the second is going to be the right of the first.

image

Note that you can also put a monitor on top of the other, so bot will have the same “left”, etc

It wouldn’t have to be messed up. If the vertical resolution of the second monitor was higher than that of the built-in display and the two monitors were aligned along the bottom, the second monitor would start above the built-in one.

To answer the original question, the top coordinate will be negative because the coordinates are all relative to monitor 1, signified by the menubar in the above screenshots.

FWIW, I “misalign” monitors in this way to make sure the cursor crosses the threshold in a straight line.

Ya I wouldn’t call it “messed up” as it definitely works when moving windows about.

Is there any way to tell what monitor in a multi-monitor setup that a window is on?

You might also want to store in your settings a Boolean for whether your application was Fullscreen (or not) when you closed it last.

The question becomes ambiguous when the window in question spans monitor borders. Then it becomes a matter of whether you care most about the top/left corner or the middle pixel of the window or which monitor has the highest percentage of pixels of the window or some other metric.

There have been various discussions of this over the years on the forum. One I found more quicklly is here but you have to read the whole thread as there are suggestions made after the original routine posted.

There are other threads too – but you also may want to think about the ramifications of when a window is not wholly contained on a single monitor and what metric you want to use for deciding which monitor(s) best answer your question.