@startuml
title Последовательность инициализации Wayland приложения

actor Main
participant "wayland-runtime" as Runtime
participant "registry" as Registry
participant "input" as Input
participant "window" as Window

Main -> Runtime: init_wayland()
activate Runtime

Runtime -> Runtime: wl_display_connect()
note right: Подключение к Wayland серверу

Runtime -> Registry: registry_global_bind(display)
activate Registry

Registry -> Registry: wl_display_get_registry()
Registry -> Registry: wl_registry_add_listener()
Registry -> Registry: wl_display_roundtrip()
note right: Получение глобальных объектов:\n- wl_compositor\n- wl_shm\n- xdg_wm_base\n- wl_seat

Registry -> Input: input_register_seat(seat)
activate Input
Input -> Input: wl_seat_add_listener()
Input -> Input: wl_seat_get_keyboard()
Input -> Input: xkb_context_new()
note right: Инициализация обработки клавиатуры
deactivate Input

Registry -> Registry: pthread_create(global_thread)
note right: Запуск потока обработки\nглобальных событий

deactivate Registry

Runtime -> Runtime: Инициализация слотов окон
Runtime -> Runtime: atomic_store(g_shutdown, 0)

deactivate Runtime

Main -> Runtime: run_window()
activate Runtime

Runtime -> Runtime: Найти свободный слот
Runtime -> Runtime: pthread_create(window_thread)
note right: Создание потока окна

Runtime --> Main: slot_index

== Поток окна ==

Runtime -> Runtime: wl_display_create_queue()
Runtime -> Window: window_init(display, queue)
activate Window

Window -> Registry: registry_get_compositor()
Window -> Registry: registry_get_shm()
Window -> Registry: registry_get_xdg_wm_base()

Window -> Window: wl_compositor_create_surface()
Window -> Window: xdg_wm_base_get_xdg_surface()
Window -> Window: xdg_surface_get_toplevel()
Window -> Window: Инициализация listeners
Window -> Window: Инициализация figure_animation_info
note right: Параметры анимации:\n- position, velocity\n- angle, angular_velocity\n- speed, radius

deactivate Window

Runtime -> Runtime: pthread_create(aux_thread)
note right: Вспомогательный поток\nдля анимации

Runtime -> Runtime: wl_display_dispatch_queue()
note right: Цикл обработки событий окна

deactivate Runtime

@enduml
