Thanks again for the responses. And sorry for following up so much later.
(a bit of context is recapped below)

First of all, thanks for the hint to viewDidMoveToWindow.

So, currently , I do this in my viewDidMoveToWindow:


- (void) viewDidMoveToWindow
{
    window_ = [self window];
    NSUInteger idx_of_screen = [NSScreen.screens indexOfObject: window_.screen];
    displayID_ = [NSNumber numberWithUnsignedLong: idx_of_screen ];


On my Mac this runs fine, and I get a proper idx_of_screen/displayID_;

However, one of my users sent me a log file, which shows that on his Mac, [self 
window] is non-null, but indexOfObject: returns NSNotFound, in the case where 
my screensaver is running in the preview of System Preferences.
(One difference between the systems is that I am still using macOS 12, while he 
is using macOS 13.)

I guess, there is not much I can do about it, except find some kind of 
work-around for those cases, where this happens. Right?


Best regards, Gabriel



>
>> On Nov 17, 2022, at 16:11, Gabriel Zachmann via Cocoa-dev 
>> <cocoa-dev@lists.apple.com> 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.
>

Attachment: 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

Reply via email to