NSScreen frame location with multiple monitors

I have a Mac Studio 2023 M2 Max

Running Sonoma 14.6.1

Developing in XCode 16.1

It seems that the NSScreen frame settings may be incorrect. The frame settings received from NSScreen.screens don't seem to match up with the Desktop arrangement settings in the Settings.

Apologies in advance for this long post!

for screen in NSScreen.screens {
            
            let name = screen.localizedName
            
            Globals.logger.debug("Globals initializeScreens - screen \(i) '\(name, privacy: .public)'")
            Globals.logger.debug("Globals initializeScreens - '\(screen.debugDescription, privacy: .public)'")
}
            

This is what I receive in the log:

Globals initializeScreens - '<NSScreen: 0x600000ef4240; 
name="PHL 346E2C"; 
backingScaleFactor=1.000000; 
frame={{0, 0}, {3440, 1440}}; 
visibleFrame={{0, 0}, {3440, 1415}}>'

Globals initializeScreens - screen 2 'Blackmagic (1)'
Globals initializeScreens - '<NSScreen: 0x600000ef42a0; 
name="Blackmagic (1)"; 
backingScaleFactor=1.000000; 
frame={{-3840, 0}, {1920, 1080}}; 
visibleFrame={{-3840, 0}, {1920, 1055}}>'

Globals initializeScreens - screen 3 'Blackmagic (4)'
Globals initializeScreens - '<NSScreen: 0x600000ef4360; 
name="Blackmagic (4)"; 
backingScaleFactor=1.000000; 
frame={{-1920, 0}, {1920, 1080}}; 
visibleFrame={{-1920, 0}, {1920, 1055}}>'

Globals initializeScreens - screen 4 'Blackmagic (2)'
Globals initializeScreens - '<NSScreen: 0x600000ef43c0; 
name="Blackmagic (2)"; 
backingScaleFactor=1.000000; 
frame={{5360, 0}, {1920, 1080}}; 
visibleFrame={{5360, 0}, {1920, 1055}}>'

Globals initializeScreens - screen 5 'Blackmagic (3)'
Globals initializeScreens - '<NSScreen: 0x600000ef4420; 
name="Blackmagic (3)"; 
backingScaleFactor=1.000000; 
frame={{3440, 0}, {1920, 1080}}; 
visibleFrame={{3440, 0}, {1920, 1055}}>'

It looks like the frame settings for Blackmagic (2) and Blackmagic (4) are switched.

The setup has five monitors. Four are using the USB-C Digital AV Multiport Adapters. The output for these are streamed into a rack of A/V equipment using BlackMagic Design mini converters and monitors.

My Swift application allows users to open four movies, one for each of the AV Adapters. The movies can then be played back in sync for later processing by the A/V equipment.

Here are some screen captures that show my display settings.

Blackmagic (1) and Blackmagic (2) are to the left of the main screen.

Blackmagic (3) and Blackmagic(4) are to the right of the main screen.

The desktop is hard to see but is correct.

The wallpaper settings are all correct.

The wallpaper is correctly ordered when displayed on the monitors.

After opening the movies and using the NSScreen frame settings, the displays are incorrectly ordered. Test B and Test D are switched, which is what I would expect given the NSScreen frame values.

Any ideas? I've tried re-arranging the desktops, rebooting, etc. but no luck.

The code that changes the screen location is similar to this post on Stack Overflow

public func setDisplay( screen: NSScreen ) {
         
        Globals.logger.log("MovieWindowController - setDisplay =  \(screen.localizedName, privacy: .public)")
        Globals.logger.debug("MovieWindowController - setDisplay - '\(screen.debugDescription, privacy: .public)'")
        
        let dx = CGFloat(Constants.midX)
        let dy = CGFloat(Constants.midY)
        
        var pos = NSPoint()
        pos.x = screen.visibleFrame.midX - dx
        pos.y = screen.visibleFrame.midY - dy
        
        Globals.logger.debug("MovieWindowController - setDisplay - x = '\(pos.x, privacy: .public)', y = '\(pos.y, privacy: .public)'")
        
        window?.setFrameOrigin(pos)
 
    }


The log show just what I would expect given the incorrect frame values.

MovieWindowController - setDisplay =  Blackmagic (1)
MovieWindowController - setDisplay - '<NSScreen: 0x6000018e8420; name="Blackmagic (1)"; backingScaleFactor=1.000000; frame={{-3840, 0}, {1920, 1080}}; visibleFrame={{-3840, 0}, {1920, 1055}}>'
MovieWindowController - setDisplay - x = '-3840.000000', y = '-12.500000'

MovieWindowController - setDisplay =  Blackmagic (2)
MovieWindowController - setDisplay - '<NSScreen: 0x6000018a10e0; name="Blackmagic (2)"; backingScaleFactor=1.000000; frame={{5360, 0}, {1920, 1080}}; visibleFrame={{5360, 0}, {1920, 1055}}>'
MovieWindowController - setDisplay - x = '5360.000000', y = '-12.500000'

MovieWindowController - setDisplay =  Blackmagic (3)
MovieWindowController - setDisplay - '<NSScreen: 0x6000018cc8a0; name="Blackmagic (3)"; backingScaleFactor=1.000000; frame={{3440, 0}, {1920, 1080}}; visibleFrame={{3440, 0}, {1920, 1055}}>'
MovieWindowController - setDisplay - x = '3440.000000', y = '-12.500000'

MovieWindowController - setDisplay =  Blackmagic (4)
MovieWindowController - setDisplay - '<NSScreen: 0x6000018c9ce0; name="Blackmagic (4)"; backingScaleFactor=1.000000; frame={{-1920, 0}, {1920, 1080}}; visibleFrame={{-1920, 0}, {1920, 1055}}>'
MovieWindowController - setDisplay - x = '-1920.000000', y = '-12.500000'

Am I correct? I think this is driving me crazy!

Thanks in advance!

Edit: The mouse behavior is correct in moving across the displays!

NSScreen frame location with multiple monitors
 
 
Q