del test. add wayland
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
// 1. Обработчик глобальных объектов (Global Registry)
|
||||
static void global_registry_handler(void *data, struct wl_registry *registry,
|
||||
uint32_t id, const char *interface, uint32_t version) {
|
||||
|
||||
// Выводим имя интерфейса, чтобы показать, какие сервисы доступны
|
||||
printf("Обнаружен глобальный объект: id: %u, интерфейс: %s, версия: %u\n",
|
||||
id, interface, version);
|
||||
|
||||
// В реальном приложении здесь происходит привязка к нужным интерфейсам
|
||||
// (например, wl_compositor, xdg_wm_base) для создания окон.
|
||||
}
|
||||
|
||||
// 2. Обработчик удаления глобальных объектов
|
||||
static void global_registry_remover(void *data, struct wl_registry *registry, uint32_t id) {
|
||||
printf("Объект удален: id: %u\n", id);
|
||||
}
|
||||
|
||||
// 3. Структура для слушателей реестра
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
.global = global_registry_handler,
|
||||
.global_remove = global_registry_remover,
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
// 4. Установка соединения с Wayland-дисплеем
|
||||
struct wl_display *display = wl_display_connect(NULL);
|
||||
if (display == NULL) {
|
||||
fprintf(stderr, "Не удалось подключиться к Wayland-дисплею.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Успешное подключение к Wayland-дисплею.\n");
|
||||
|
||||
// 5. Получение реестра глобальных объектов
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
if (registry == NULL) {
|
||||
fprintf(stderr, "Не удалось получить реестр.\n");
|
||||
wl_display_disconnect(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 6. Добавление слушателя к реестру
|
||||
wl_registry_add_listener(registry, ®istry_listener, NULL);
|
||||
|
||||
// 7. Ожидание ответа от композитора (обработка всех глобальных объектов)
|
||||
// Wayland работает асинхронно, wl_display_dispatch_pending() обрабатывает
|
||||
// все сообщения, включая список глобальных объектов, который присылает композитор.
|
||||
wl_display_dispatch(display);
|
||||
wl_display_roundtrip(display); // Убеждаемся, что все сообщения обработаны
|
||||
|
||||
// 8. Очистка ресурсов
|
||||
wl_registry_destroy(registry);
|
||||
wl_display_disconnect(display);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user