Analyzing a multi-monitor window position macOS

Coordinates on the multi-display mechanism macOS

When developing pocketed input method,I met such a thing,That is, as a candidate bar window will go beyond the screen when the edge of the screen! and so,In the display window when I do extra check the coordinates:

In short,That is, if you count the coordinates of their width exceeds the width of the screen,Norway put it back。

but,Such treatment does not work well in a multi-monitor,This case, since the multi display coordinate caused:

macOS multi-display coordinate Mechanism

Coordinates on the multi-display mechanism macOS

As shown in FIG,When a user has a plurality of displays,Display coordinates are merged together,Also left negative right to follow the rules,In this situation,When your user typing on the right side of the screen,Once the position coordinates of the insertion point is greater than the maximum screen coordinates (Remember,The maximum value of the right side of the screen coordinates of which a greater width and height),Window will not continue right away。

Then,To be corrected for different screen coordinates,I.e., not used as a basis to judge the size of the screen resolution,But to use the screen width and height plus the current screen origin offset! The modified code then follows:

Such,On multi-monitor,Regardless of the user to arrange the display arrangement,Candidate window will not go beyond the edge of the current screen。

app window full-screen problem

There is a pit worthy to talk,Is the work space on the macOS,Multiple desktops mechanism has been a good place macOS,Rare - you do not have any api to check user space in which the ......

It would have been nothing,Available in multi-screen mode on a problem - as long as a user app in full-screen external screen,You can not get to the correct screen size - so there is nothing to correct the above。

When you are a full-screen app,In this mode,Get the screen size is always the size of the main screen,No matter which screen is on。

Fortunately,,Get to the point coordinate input or correct,So I can actually look through all the screens to the insertion point on which screen,And then to offset processing based on this screen。

So,The complete code is this:


Original article written by Gerber drop-off:R0uter's Blog » Analyzing a multi-monitor window position macOS

Reproduced Please keep the source and description link:

By R0uter's Blog

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。


  1. Developer Hello,Bought macOS2 input method you develop,very useful。
    But where there's a little bit less than:I macOS (10.13.6) + an external monitor。I am a full-screen on the external monitor APP,When prompted with a shift in the English state switch ( "En" or "in" switch) can not be represented。When no external monitor only macOS,Fullscreen APP also has this phenomenon。for reference only。

Leave a comment

Your email address will not be published. Required fields are marked *