/** Connect to Wayland display on an already open fd * * \param fd The fd to use for the connection * \return A \ref wl_display object or \c NULL on failure * * The wl_display takes ownership of the fd and will close it when the * display is destroyed. The fd will also be closed in case of * failure. * * \memberof wl_display */ WL_EXPORT struct wl_display * wl_display_connect_to_fd(int fd) { struct wl_display *display; const char *debug; debug = getenv("WAYLAND_DEBUG"); if (debug && (strstr(debug, "client") || strstr(debug, "1"))) debug_client = 1; display = malloc(sizeof *display); if (display == NULL) { close(fd); return NULL; } memset(display, 0, sizeof *display); display->fd = fd; wl_map_init(&display->objects, WL_MAP_CLIENT_SIDE); wl_event_queue_init(&display->default_queue, display); wl_event_queue_init(&display->display_queue, display); wl_list_init(&display->event_queue_list); pthread_mutex_init(&display->mutex, NULL); pthread_cond_init(&display->reader_cond, NULL); display->reader_count = 0; wl_map_insert_new(&display->objects, 0, NULL); display->proxy.object.interface = &wl_display_interface; display->proxy.object.id = wl_map_insert_new(&display->objects, 0, display); display->proxy.display = display; display->proxy.object.implementation = (void(**)(void)) &display_listener; display->proxy.user_data = display; display->proxy.queue = &display->default_queue; display->proxy.flags = 0; display->proxy.refcount = 1; display->connection = wl_connection_create(display->fd); if (display->connection == NULL) goto err_connection; printf("<< %s:%u\n", __func__, __LINE__); return display; err_connection: pthread_mutex_destroy(&display->mutex); pthread_cond_destroy(&display->reader_cond); wl_map_release(&display->objects); close(display->fd); free(display); return NULL; }
/** Close a connection to a Wayland display * * \param display The display context object * * Close the connection to \c display and free all resources associated * with it. * * \memberof wl_display */ WL_EXPORT void wl_display_disconnect(struct wl_display *display) { wl_connection_destroy(display->connection); wl_map_release(&display->objects); wl_event_queue_release(&display->queue); pthread_mutex_destroy(&display->mutex); pthread_cond_destroy(&display->reader_cond); close(display->fd); free(display); }