Re: Proper way to retrieve the NSScreenNumber in a screen saver ?
> On Nov 17, 2022, at 16:11, Gabriel Zachmann via Cocoa-dev > wrote: > > Thanks a lot for your quick responses! > > I would like to understand what you are saying and what is going on, so > please bear with me. > > So, Steve, if I understand correctly, you suggest to write: > > - (void) viewWillMoveToWindow: (NSWindow *) newWindow > { >unsigned long my_screen = [NSScreen.screens indexOfObject: [newWindow > screen]]; >displayID_ = [[ [NSScreen.screens[my_screen] deviceDescription] > objectForKey: @"NSScreenNumber"]; > ... > } No, I didn’t suggest that. I suggested just using the screen’s index via indexOfObject as the screen number. No need to dive into the device description. It’s exactly what I do my screensaver. I see in my code I only access the window.screen in viewDidMoveToWindow, not viewWillMoveToWindow. Perhaps the window has not yet been assigned to a screen in WillMove. > And how can it happen that [newWindow screen] is NULL, as Jack has cited from > the docs, when my screensaver is running in System Preference's Preview > window? Nullable simply means that a window can *not* be assigned to a screen, like when it’s first being initialized and hasn’t been made visible onscreen. It doesn’t mean that a particular screensaver window might be offscreen. That should never happen. >> If a screensaver window is not onscreen, there?s no screen to save, so it >> wouldn?t matter. > > How can a screensaver get launched by macOS and *not* be on screen? > Note that viewWillMoveToWindow gets called inly once during the lifetime of a > screensaver. It can’t. I was simply stating that it would never happen. > (Unless, maybe, it is running in System Preference's preview window, and the > user moves the System Preferences window to a different screen. but that is > of no concern right now.) When running in the System Prefs, it’s in a totally different parent view and window. If you need to use a screen number for some special purpose in that case, define a constant that will never be a valid screen index, like 1. I do that so I can keep track of a cached value and have it be different than any real screen. But you know this from your implementation of initWithFrame:isPreview:. Although that might not work, as I see from these comments in my code: // They broke screensavers in 10.15. They run in process legacyScreenSaver, and that never passes NO for isPreview. So we'll figure it out by checking the frame for something bigger than the preview view in System Prefs, which is 296x184. // Don't go off the actual size it happens to be in 10.15's System Prefs. Just assume that anything wider than this is a real screen: isPreview = frame.size.width < 500; Steve via iPad ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Proper way to retrieve the NSScreenNumber in a screen saver ?
Thanks a lot for your quick responses! I would like to understand what you are saying and what is going on, so please bear with me. So, Steve, if I understand correctly, you suggest to write: - (void) viewWillMoveToWindow: (NSWindow *) newWindow { unsigned long my_screen = [NSScreen.screens indexOfObject: [newWindow screen]]; displayID_ = [[ [NSScreen.screens[my_screen] deviceDescription] objectForKey: @"NSScreenNumber"]; ... } How is this better than using [newWindow screen] directly? And how can it happen that [newWindow screen] is NULL, as Jack has cited from the docs, when my screensaver is running in System Preference's Preview window? Only when I click on a different screensaver, then switch back to mine, does [newWindow screen] get a proper value, most of the time. What about [NSScreen mainScreen] ? > If a screensaver window is not onscreen, there?s no screen to save, so it > wouldn?t matter. How can a screensaver get launched by macOS and *not* be on screen? Note that viewWillMoveToWindow gets called inly once during the lifetime of a screensaver. (Unless, maybe, it is running in System Preference's preview window, and the user moves the System Preferences window to a different screen. but that is of no concern right now.) Best regards, Gabriel smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
test
Testing, please disregard. Dave -- David Young dyo...@pobox.comUrbana, IL(217) 721-9981 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Proper way to retrieve the NSScreenNumber in a screen saver ?
> On Nov 17, 2022, at 11:59, Jack Brindle via Cocoa-dev > wrote: > > The NSScreen screen property is nullable. From the docs for NSWindow screen: > > "The value of this property is the screen where most of the window is on; it > is nil when the window is offscreen." If a screensaver window is not onscreen, there’s no screen to save, so it wouldn’t matter. Steve via iPad ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Proper way to retrieve the NSScreenNumber in a screen saver ?
The NSScreen screen property is nullable. From the docs for NSWindow screen: "The value of this property is the screen where most of the window is on; it is nil when the window is offscreen." I would go with Steve’s suggestion as much as possible, The NSScreen class has the info you need. Jack > On Nov 17, 2022, at 10:44 AM, Gabriel Zachmann via Cocoa-dev > wrote: > > 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 * 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 > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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/jackbrindle%40me.com > > This email sent to jackbrin...@me.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Proper way to retrieve the NSScreenNumber in a screen saver ?
> On Nov 17, 2022, at 10:44, Gabriel Zachmann via Cocoa-dev > wrote: > > In my screensaver (macOS), > I am trying to retrieve the 'screen number' (NSScreenNumber) for the screen > on which I am running. [NSScreen.screens indexOfObject:window.screen] gives you the zero-based screen index. 0 is always the main screen. Steve via iPad ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Proper way to retrieve the NSScreenNumber in a screen saver ?
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 * 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 (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com