MacOS specific but maybe iOS related responses could get me on the right track as well:
I need to determine wether there was any text input (swiftUI text field, NSTextField) active app wide when the app lost focus. This means the user either minimised the window of my app or clicked on the window of a different app. Is there a NSApplication (or AppKit in general) API i could use to achieve this? Under the hood something definitely exists because the field that was active when the app was last in focus becomes active again when the app regains focus. Unfortunately i think whatever api is used to achieve that was not made public.
Here is a code example of my needs:
struct FooView: View {
@Environment(\.controlActiveState) private var controlActiveState
var body: some View {
Text("Hello World")
.onChange(of: controlActiveState) { newState in
guard !(newState == .inactive) else { return }
let wasAnyTextInputActive: Bool = false // <- need to determine if any textfield was active app wide here
guard wasAnyTextInputActive else { return }
print("Should only be reached when the app was backgrounded with an active text input")
}
}
}
Thanks!