1
0

ArkCompositor.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. import CSystem
  5. import CWayland
  6. /// ArkCompositor
  7. /// The core Wayland Server embedded directly into arkrt.
  8. /// Any UI app (like setup_app or ui_daemon) can connect to this Wayland server
  9. /// to render graphics using standard Wayland protocols.
  10. @_silgen_name("ark_compositor_init")
  11. func c_ark_compositor_init() -> Bool
  12. @_silgen_name("ark_compositor_dispatch")
  13. func c_ark_compositor_dispatch()
  14. @_silgen_name("ark_compositor_shutdown")
  15. func c_ark_compositor_shutdown()
  16. @_silgen_name("ark_compositor_set_render_buffer")
  17. func c_ark_compositor_set_render_buffer(_ buffer: UnsafeMutablePointer<UInt8>, _ width: Int32, _ height: Int32, _ bpp: Int32)
  18. public class ArkCompositor {
  19. public static let shared = ArkCompositor()
  20. public private(set) var isRunning = false
  21. private init() {}
  22. /// Starts the Wayland server in the arkrt core.
  23. public func start() {
  24. if isRunning { return }
  25. if c_ark_compositor_init() {
  26. isRunning = true
  27. print("ArkCompositor: Core Wayland Server Started.")
  28. } else {
  29. print("ArkCompositor: FATAL - Failed to start Wayland Server.")
  30. }
  31. }
  32. /// Hook this into the main runloop of arkrt to process Wayland events
  33. public func dispatch() {
  34. if isRunning {
  35. c_ark_compositor_dispatch()
  36. }
  37. }
  38. /// Connects the Wayland compositor to the actual physical screen buffer (e.g. from DRM/KMS or Splash rendering)
  39. public func setRenderBuffer(buffer: UnsafeMutablePointer<UInt8>, width: Int, height: Int, bpp: Int) {
  40. c_ark_compositor_set_render_buffer(buffer, Int32(width), Int32(height), Int32(bpp))
  41. }
  42. public func shutdown() {
  43. if isRunning {
  44. c_ark_compositor_shutdown()
  45. isRunning = false
  46. print("ArkCompositor: Core Wayland Server Shut Down.")
  47. }
  48. }
  49. }