Mac Catalyst UIWindowScene requestGeometryUpdateWithPreferences: doesn't respect provided systemFrame origin.

On app launch I'm trying to specify a reasonable initial value for the window's frame.

Using the recommended API I create a UIWindowSceneGeometryPreferencesMac object and pass it to -requestGeometryUpdateWithPreferences:errorHandler: in -scene:willConnectToSession:options:

This method respects the value passed in as the size but does not seem to respect the requested origin. Initially I'm always placed at origin 0, 0 for the first window which doesn't look particularly good. I think I'd like to be inset on the x-axis a bit, or maybe even position the window in the center of the screen on app launch.

Is there anyway to get more control over the window frame on Mac Catalyst?

So the -requestGeometryUpdateWithPreferences:errorHandler: does actually respect the origin if I call the method after a bit of a delay in scene:willConnectToSession:options:

I know Catalyst automatically handles the window frame during stare restoration so I need to figure out if there's a way I can ensure my initial frame request won't be called after the system sets the frame on state restoration... because I don't want to break that.

Only thing I can think of off the top of my head is maybe saving and restoring the window frame myself in a user activity, though I'm not sure if -requestGeometryUpdateWithPreferences:errorHandler: will respect my requested origin in -scene:restoreInteractionStateWithUserActivity: or if the request is too early their too. I don't really feel like doing this since the user could be on a different display (could close a laptop and connect an external monitor) between save and restored state and I don't feel like implementing frame translation code.

So basically what I'm trying to do is this:

//Position the window in the center of the screen, initially.
 UIScreen *targetScreen = scene.screen;
 CGRect initialWindowRect = CGRectMake((targetScreen.bounds.size.width/2.0)-(DEFAULT_SIZE.width/2.0),
                                                                           targetScreen.bounds.size.height/2.0-(DEFAULT_SIZE.height/2.0),
                                                                           DEFAULT_SIZE.width,
                                                                           DEFAULT_SIZE.height);

Sometimes the origin is ignored (depending whether or not another window is opened, the system adds a default space between open windows. Typically this is how "New Document" windows open on Mac but you wouldn't always want this behavior (for example the "Welcome to Xcode" window always positions itself in the center of the screen when opening).

Also is there a way I can compute NSScreen's visibleFrame property from the Mac Catalyst environment so I can position the window relative to the visible frame (the area not including the menu bar and the dock)?

UIScreen.bounds property is  (origin = (x = 0, y = 0), size = (width = 1440, height = 900)) but really I'd like to compute the initial window frame relative to NSScreen's .visibleFrame property which would be {{0, 95}, {1440, 780}}

I filed FB11884759

Mac Catalyst UIWindowScene requestGeometryUpdateWithPreferences: doesn't respect provided systemFrame origin.
 
 
Q