In my screensaver (macOS), I am trying to retrieve the 'screen number' (NSScreenNumber) for the screen on which I am running.
So, in
- (void) viewWillMoveToWindow: (NSWindow *) newWindow
I have this line of code:
displayID_ = [ [[newWindow screen] deviceDescription] objectForKey:
@"NSScreenNumber"];
This sometimes works (I get the correct screen number),
and sometimes it does not, i.e., I get displayID_ = nil!
(Usually after invoking some other screen savers in System Preferences.)
I don't see a pattern.
Curiously, these lines in viewWillMoveToWindow always work:
for ( NSScreen * s in [NSScreen screens] )
{
NSDictionary<NSDeviceDescriptionKey, id> * device_description = [s
deviceDescription];
NSNumber * n = [device_description objectForKey: @"NSScreenNumber"];
[...]
}
I always get non-null and correct 'screen numbers' n.
So, I am wondering, why does the first line sometimes NOT work?
And what is the proper way to retrieve the screen number on which my screen
saver is running?
Should I use [NSScreen mainScreen] ?
Please note, that there might be several monitors attached to the Mac!
(Some users have up to 6)
Thanks a lot in advance.
Best regards, Gabriel
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
