Determining Screen Layout in Objective-C (NSScreen)

Using the [NSScreen screens], I can get all the screens attached to the computer and their sizes, however I try to find their positions relative to each other (for example, in the setting in the display settings). Is there any way to do this? I looked online and through links to the class on the Apple developers site and did not find anything. Thanks.

+4
source share
2 answers

For each of the screens returned by [NSScreen screens] , you can call:

 [screen frame] 

to get an NSRect containing size and offset for each screen. The "main" screen (i.e. the one that is on the menu bar) will have an offset (0, 0) .

This should be a lot easier than handling -deviceDescription .

+4
source

Yeah! I was looking through the API and found out how to do it. If you received NSScreen -deviceDescription , you can get its CGDirectDisplayID . From there, you can use Quartz Display Services from ApplicationServices to get CGDisplayBounds , which displays the size and position of the screen relative to all screens.

+4
source

Source: https://habr.com/ru/post/1303990/


All Articles