How to control the position of windows and volumes in immersive space

My app has a window and a volume. I am trying to display the volume on the right side of the window. I know .defaultWindowPlacement can achieve that, but I want more control over the exact position of my volume in relation to my window. I need the volume to move as I move the window so that it always stays in the same position relative to the window. I think I need a way to track the positions of both the window and the volume. If this can be achieved without immersive space, it would be great. If not, how do I do that in immersive space?

Current code:

import SwiftUI

@main
struct tiktokForSpacialModelingApp: App {
    @State private var appModel: AppModel = AppModel()
    
    
    var body: some Scene {
        WindowGroup(id: appModel.launchWindowID) {
            LaunchWindow()
                .environment(appModel)
        }
        .windowResizability(.contentSize)
        
        
        
        WindowGroup(id: appModel.mainViewWindowID) {
                MainView()
                .frame(minWidth: 500, maxWidth: 600, minHeight: 1200, maxHeight: 1440)
                .environment(appModel)
        }
        .windowResizability(.contentSize)
        
        
        WindowGroup(id: appModel.postVolumeID) {
            let initialSize =  Size3D(width: 900, height: 500, depth: 900)
            PostVolume()
                .frame(minWidth: initialSize.width, maxWidth: initialSize.width * 4, minHeight: initialSize.height, maxHeight: initialSize.height * 4)
                .frame(minDepth: initialSize.depth, maxDepth: initialSize.depth * 4)
        }
        .windowStyle(.volumetric)
        .windowResizability(.contentSize)
        .defaultWindowPlacement { content, context in
            // Get WindowProxy from context based on id
            if let mainViewWindow = context.windows.first(where: { $0.id == appModel.mainViewWindowID }) {
                return WindowPlacement(.trailing(mainViewWindow))
            } else {
                return WindowPlacement()
            }
        }
        
        ImmersiveSpace(id: appModel.immersiveSpaceID) {
            ImmersiveView()
                .onAppear {
                    appModel.immersiveSpaceState = .open
                }
                .onDisappear {
                    appModel.immersiveSpaceState = .closed
                }
        }
        .immersionStyle(selection: .constant(.progressive), in: .progressive)

        
    }
}

What you are trying to do isn't possible using windows. defaultWindowPlacement is only to define the initial placement of the window. After that, users can reposition the window using the interface but the app cannot reposition itself as it could be confusing for users.

Instead, I'd suggest using ornaments as they are always relative to the window they are presented from. However, note that there are restrictions on the max width, depth and height of an ornament.

If this option doesn't work for you, I'd recommend filing an enhancement request on Feedback Assistant.

How to control the position of windows and volumes in immersive space
 
 
Q