@Mobiel I was able to use your example to create a UIKit → SwiftUI connection where those layout guide values are available to a SwiftUI view. It works okay. You can see here the red box is in SwiftUI, and it is detecting where the window control is.
There is one issue, which is that when the window is returned to full screen, the layout guide is not updating to "0" size for the window control. Not sure if that's an iPadOS beta bug or what.
Here is a screenshot:
Here is the code:
//
// ContentView.swift
// WindowControlsTest
//
// Created by MAK on 8/7/25.
//
import SwiftUI
import UIKit
struct ContentView: View {
@State var offsets = WindowControlDetection()
var body: some View {
ZStack(alignment: .topLeading) {
WindowControlsUIKitViewRepresentable()
Rectangle()
.foregroundStyle(.red)
.frame(width: offsets.leadingInset, height: offsets.topInset)
Rectangle()
.hidden()
.overlay {
Text("leading: \(Int(offsets.leadingInset)) top: \(Int(offsets.topInset))")
}
}
.ignoresSafeArea()
.environment(offsets)
}
}
@Observable class WindowControlDetection {
var leadingInset: CGFloat = 0
var topInset: CGFloat = 0
}
class WindowControlsUIKitView: UIView {
private let offsets: WindowControlDetection
init(offsets: WindowControlDetection) {
self.offsets = offsets
super.init(frame: .zero)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
let newLeading = layoutGuide(for: .margins(cornerAdaptation: .horizontal)).layoutFrame.minX
let newTop = layoutGuide(for: .margins(cornerAdaptation: .vertical)).layoutFrame.minY
DispatchQueue.main.async { [weak offsets] in
offsets?.leadingInset = newLeading
offsets?.topInset = newTop
}
}
}
struct WindowControlsUIKitViewRepresentable: UIViewRepresentable {
@Environment(WindowControlDetection.self) var layoutOffsets
func makeUIView(context: Context) -> WindowControlsUIKitView {
return WindowControlsUIKitView(offsets: layoutOffsets)
}
func updateUIView(_ uiView: WindowControlsUIKitView, context: Context) { }
}