SkyLightWindow

repository·main·Indexed 41 days ago

https://github.com/lakr233/skylightwindow

A macOS framework that utilizes private SkyLight APIs to display views above all other windows, including fullscreen applications. It provides a `.moveToSky()` modifier for SwiftUI and OpenSwiftUI, as well as programmatic window creation via `SkyLightOperator.shared.delegateView(_:toScreen:)` for AppKit. Compatible with macOS 11.0+ and Swift 5.9+ for standard integration, and macOS 15.0+ and Swift 6.1+ when using the OpenSwiftUI trait.

Tokens
943
Snippets
4
Records
7
Agent score
3%

What's inside SkyLightWindow

  1. How SkyLightWindow works

    main

    SkyLightWindow leverages macOS's private SkyLight framework to achieve system-level window positioning. It follows these steps:

    1. Creates a special space at the highest system level.
    2. Moves the target window to this space.
    3. Ensures the window remains visible above all other content (including fullscreen apps).

    The framework manages the connection to the SkyLight service, space management, window delegation, and positioning.

  2. Install SkyLightWindow via SwiftPM

    main

    Add SkyLightWindow as a dependency in your Package.swift file. You can use the default configuration or enable the OpenSwiftUI package trait if you are using the OpenSwiftUI framework.

    Default Configuration (macOS 11.0+, Swift 5.9+): Use this for standard SwiftUI integration.

    OpenSwiftUI Trait (macOS 15.0+, Swift 6.1+): Use this if you are importing OpenSwiftUI instead of SwiftUI. This requires the OpenSwiftUI-spm binary package.

    // Default installation
    dependencies: [
        .package(url: "https://github.com/Lakr233/SkyLightWindow", from: "1.0.0"),
    ]
    
    // Installation with OpenSwiftUI trait
    dependencies: [
        .package(
            url: "https://github.com/Lakr233/SkyLightWindow",
            from: "1.0.0",
            traits: ["OpenSwiftUI"]
        ),
    ]
  3. Install SkyLightWindow in Xcode

    main
    To install via Xcode, add the package dependency through the Xcode interface. If you need the OpenSwiftUI trait, you must enable it in the package settings. Note that enabling traits in Xcode requires Xcode 26.4+.
  4. Use the .moveToSky() modifier in SwiftUI

    main

    To display a SwiftUI view above all other windows (including fullscreen apps), import SwiftUI and SkyLightWindow, then apply the .moveToSky() modifier to any view.

    import SwiftUI
    import SkyLightWindow
    
    struct ContentView: View {
        var body: some View {
            Text("This view is always on top!")
                .moveToSky()
        }
    }
  5. Use SkyLightWindow with OpenSwiftUI

    main

    If your project uses OpenSwiftUI instead of standard SwiftUI, the usage is identical to the standard SwiftUI integration, but you must import OpenSwiftUI.

    import OpenSwiftUI
    import SkyLightWindow
    
    struct ContentView: View {
        var body: some View {
            Text("This view is always on top!")
                .moveToSky()
        }
    }
  6. Create topmost windows programmatically with AppKit

    main

    For AppKit-based applications, use SkyLightOperator.shared.delegateView(_:toScreen:) to programmatically create a topmost window for a specific view and screen.

    import SkyLightWindow
    
    let screen = NSScreen.main!
    let view = AnyView(Text("Overlay Content"))
    let controller = SkyLightOperator.shared.delegateView(view, toScreen: screen)
  7. Platform Compatibility and Important Notes

    main

    Compatibility

    • Default SwiftUI Integration: macOS 11.0+ and Swift Compiler 5.9+.
    • OpenSwiftUI Trait: macOS 15.0+ and Swift Compiler 6.1+.

    Security & Stability

    • Privacy: The framework uses private APIs but does not require special entitlements and is compatible with the Mac App Store.
    • Risk: Because it relies on private APIs, behavior may change with macOS system updates.