Product SiteDocumentation Site

Chapter 4. Wayland Library

4.1. Client API

4.1. Client API

Following is the Wayland library classes for clients (libwayland-client). Note that most of the procedures are related with IPC, which is the main responsibility of the library.
wl_display - Represents a connection to the compositor and acts as a proxy to the wl_display singleton object.
A wl_display object represents a client connection to a Wayland compositor. It is created with either wl_display_connect() or wl_display_connect_to_fd(). A connection is terminated using wl_display_disconnect().A wl_display is also used as the wl_proxy for the wl_display singleton object on the compositor side.A wl_display object handles all the data sent from and to the compositor. When a wl_proxy marshals a request, it will write its wire representation to the display's write buffer. The data is sent to the compositor when the client calls wl_display_flush().Incoming data is handled in two steps: queueing and dispatching. In the queue step, the data coming from the display fd is interpreted and added to a queue. On the dispatch step, the handler for the incoming event set by the client on the corresponding wl_proxy is called.A wl_display has at least one event queue, called the main queue. Clients can create additional event queues with wl_display_create_queue() and assign wl_proxy's to it. Events occurring in a particular proxy are always queued in its assigned queue. A client can ensure that a certain assumption, such as holding a lock or running from a given thread, is true when a proxy event handler is called by assigning that proxy to an event queue and making sure that this queue is only dispatched when the assumption holds.The main queue is dispatched by calling wl_display_dispatch(). This will dispatch any events queued on the main queue and attempt to read from the display fd if its empty. Events read are then queued on the appropriate queues according to the proxy assignment. Calling that function makes the calling thread the main thread.A user created queue is dispatched with wl_display_dispatch_queue(). If there are no events to dispatch this function will block. If this is called by the main thread, this will attempt to read data from the display fd and queue any events on the appropriate queues. If calling from any other thread, the function will block until the main thread queues an event on the queue being dispatched.A real world example of event queue usage is Mesa's implementation of eglSwapBuffers() for the Wayland platform. This function might need to block until a frame callback is received, but dispatching the main queue could cause an event handler on the client to start drawing again. This problem is solved using another event queue, so that only the events handled by the EGL code are dispatched during the block.This creates a problem where the main thread dispatches a non-main queue, reading all the data from the display fd. If the application would call poll(2) after that it would block, even though there might be events queued on the main queue. Those events should be dispatched with wl_display_dispatch_pending() before flushing and blocking.
wl_event_queue - A queue for wl_proxy object events.
Event queues allows the events on a display to be handled in a thread-safe manner. See wl_display for details.
wl_proxy - Represents a protocol object on the client side.
A wl_proxy acts as a client side proxy to an object existing in the compositor. The proxy is responsible for converting requests made by the clients with wl_proxy_marshal() into Wayland's wire format. Events coming from the compositor are also handled by the proxy, which will in turn call the handler set with wl_proxy_add_listener().With the exception of function wl_proxy_set_queue(), functions accessing a wl_proxy are not normally used by client code. Clients should normally use the higher level interface generated by the scanner to interact with compositor objects.
And methods for the respective classes.
wl_display_create_queue - Create a new event queue for this display.
wl_display_connect_to_fd - Connect to Wayland display on an already open fd.
wl_display_connect - Connect to a Wayland display.
wl_display_disconnect - Close a connection to a Wayland display.
wl_display_get_fd - Get a display context's file descriptor.
wl_display_roundtrip - Block until all pending request are processed by the server.
wl_display_dispatch_queue - Dispatch events in an event queue.
wl_display_dispatch_queue_pending - Dispatch pending events in an event queue.
wl_display_dispatch - Process incoming events.
wl_display_dispatch_pending - Dispatch main queue events without reading from the display fd.
wl_display_get_error - Retrieve the last error occurred on a display.
wl_display_flush - Send all buffered request on the display to the server.
wl_event_queue_destroy - Destroy an event queue.
wl_proxy_create - Create a proxy object with a given interface.
wl_proxy_destroy - Destroy a proxy object.
wl_proxy_add_listener - Set a proxy's listener.
wl_proxy_marshal - Prepare a request to be sent to the compositor.
wl_proxy_set_user_data - Set the user data associated with a proxy.
wl_proxy_get_user_data - Get the user data associated with a proxy.
wl_proxy_get_id - Get the id of a proxy object.
wl_proxy_set_queue - Assign a proxy to an event queue.
wl_log_set_handler_client -