Module socket

Source
Available on crate feature wayland_frontend only.
Expand description

Wayland listening socket.

This module provides an EventSource that invokes a callback when a new client has connected to the socket. This is one of the ways a Wayland compositor allows clients to discover the compositor.

The callback provides a UnixStream that represents the client connection. You need to create the client using this stream by calling DisplayHandle::insert_client.

§Example usage

use smithay::wayland::socket::ListeningSocketSource;

// data passed into calloop
struct Example {
    display: wayland_server::Display<()>,
}

let event_loop = calloop::EventLoop::<Example>::try_new().unwrap();
let mut display = wayland_server::Display::<()>::new().unwrap();

// Create a socket for clients to discover the compositor.
//
// This function will select the next open name for a listening socket.
let listening_socket = ListeningSocketSource::new_auto().unwrap();

event_loop.handle().insert_source(listening_socket, |client_stream, _, state| {
    // Inside the callback, you should insert the client into the display.
    //
    // You may also associate some data with the client when inserting the client.
    state.display.handle().insert_client(client_stream, Arc::new(ExampleClientData));
});

Structs§

ListeningSocketSource
A Wayland listening socket event source.