> On Nov 17, 2022, at 16:11, Gabriel Zachmann via Cocoa-dev
> <[email protected]> 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 10000. 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 ([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]