Does NSScreenNumber change (by chance)?

In my application, I need to distinguish between the different displays that I use with the NSScreenNumber key of the device description dictionary provided by NSScreen. So far, everything worked flawlessly, but now all of a sudden I sometimes get a different screen identifier for my main screen (this is a laptop, and I have not attached a second screen for several months, it is always the same equipment). The identifier was 69676672, but now most of the time I get 2077806975.

At first it seemed to me that somehow I misinterpreted NSNumber, but this did not seem to be the case, I also checked it with the CGMainDisplayID () function and got the same value. What's even weirder is that some Apple apps still get the old identifier: for example. the desktop image is referenced in its configuration file using the screen identifier, and when updating the desktop image, the Apple desktop application uses the “correct” (= old) ID.

I'm starting to wonder if there could be a change in a recent update (10.7.1 or 10.7.2) that led to the change, has anyone else noticed something like this, or had this problem before?

Here is the code I'm using:

// This is in an NSScreen category - (NSNumber *) uniqueScreenID { return [[self deviceDescription] objectForKey:@"NSScreenNumber"]; } 

And to get int:

  // Assuming screen points to an instance of NSScreen NSLog(@"Screen ID: %i", [[screen uniqueScreenID] intValue]); 

This is starting to upset, appreciate any help / ideas, thanks!

+4
source share
1 answer

For a Mac that has integrated graphics and discrete graphics cards (for example, MacBook Pro models with Intel integrated graphics and a separate graphics card), the display ID may change when the system automatically switches between them. You can turn off “Auto Graphics Switching” on the energy-saving preventive panel to check if this is the reason for changing your screen number (when disabled, a discrete graphics card will always be used).

In such systems, the choice of graphics at some point in time is tied to the applications that are currently running and their needs. I believe that any use of OpenGL by the application will lead to a switch to a discrete graphics card, for example.

If you need to notice when such a switch appears while your application is running, you can register a callback (CGDisplayRegisterReconfigurationCallback) and examine the changes (kCGDisplayAddFlag, kCGDisplayRemoveFlag, etc.). If you are trying to match a display to a previously used / met display, you will need to go beyond simply comparing display identifiers.

+2
source

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


All Articles