Product SiteDocumentation Site

Chapter 5. Wayland Library

5.1. Client API
5.2. Server API
The open-source reference implementation of Wayland protocol is split in two C libraries, libwayland-server and libwayland-client. Their main responsibility is to handle the Inter-process communication (IPC) with each other, therefore guaranteeing the protocol objects marshaling and messages synchronization.
This Chapter describes in detail each library's methods and their helpers, aiming implementors who can use for building Wayland clients and servers; respectively at Section 5.1, “Client API” and Section 5.2, “Server API”.

5.1. Client API

Following is the Wayland library classes for the Client (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_list - doubly-linked list
The list head is of "struct wl_list" type, and must be initialized using wl_list_init(). All entries in the list must be of the same type. The item type must have a "struct wl_list" member. This member will be initialized by wl_list_insert(). There is no need to call wl_list_init() on the individual item. To query if the list is empty in O(1), use wl_list_empty().
Let's call the list reference "struct wl_list foo_list", the item type as "item_t", and the item member as "struct wl_list link".
The following code will initialize a list: struct wl_list foo_list; struct item_t { int foo; struct wl_list link; }; struct item_t item1, item2, item3; wl_list_init(&foo_list); wl_list_insert(&foo_list, &item1.link); Pushes item1 at the head wl_list_insert(&foo_list, &item2.link); Pushes item2 at the head wl_list_insert(&item2.link, &item3.link); Pushes item3 after item2
The list now looks like [item2, item3, item1]
Will iterate the list in ascending order: item_t *item; wl_list_for_each(item, foo_list, link) { Do_something_with_item(item); }
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.
Methods for the respective classes.
wl_display_create_queue - Create a new event queue for this display.
struct wl_event_queue * wl_display_create_queue(struct wl_display *display)
display
The display context object
Returns:
A new event queue associated with this display or NULL on failure.
wl_display_connect_to_fd - Connect to Wayland display on an already open fd.
struct wl_display * wl_display_connect_to_fd(int fd)
fd
The fd to use for the connection
Returns:
A wl_display object or 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.
wl_display_connect - Connect to a Wayland display.
struct wl_display * wl_display_connect(const char *name)
name
Name of the Wayland display to connect to
Returns:
A wl_display object or NULL on failure
Connect to the Wayland display named name. If name is NULL, its value will be replaced with the WAYLAND_DISPLAY environment variable if it is set, otherwise display "wayland-0" will be used.
wl_display_disconnect - Close a connection to a Wayland display.
void wl_display_disconnect(struct wl_display *display)
display
The display context object
Close the connection to display and free all resources associated with it.
wl_display_get_fd - Get a display context's file descriptor.
int wl_display_get_fd(struct wl_display *display)
display
The display context object
Returns:
Display object file descriptor
Return the file descriptor associated with a display so it can be integrated into the client's main loop.
wl_display_roundtrip_queue - Block until all pending request are processed by the server.
int wl_display_roundtrip_queue(struct wl_display *display, struct wl_event_queue *queue)
display
The display context object
queue
The queue on which to run the roundtrip
Returns:
The number of dispatched events on success or -1 on failure
Blocks until the server process all currently issued requests and sends out pending events on the event queue.
wl_display_roundtrip - Block until all pending request are processed by the server.
int wl_display_roundtrip(struct wl_display *display)
display
The display context object
Returns:
The number of dispatched events on success or -1 on failure
Blocks until the server process all currently issued requests and sends out pending events on the default event queue.
wl_display_read_events - Read events from display file descriptor.
int wl_display_read_events(struct wl_display *display)
display
The display context object
Returns:
0 on success or -1 on error. In case of error errno will be set accordingly
This will read events from the file descriptor for the display. This function does not dispatch events, it only reads and queues events into their corresponding event queues. If no data is avilable on the file descriptor, wl_display_read_events() returns immediately. To dispatch events that may have been queued, call wl_display_dispatch_pending() or wl_display_dispatch_queue_pending().
Before calling this function, wl_display_prepare_read() must be called first.
wl_display_prepare_read - Prepare to read events after polling file descriptor.
int wl_display_prepare_read(struct wl_display *display)
display
The display context object
Returns:
0 on success or -1 if event queue was not empty
This function must be called before reading from the file descriptor using wl_display_read_events(). Calling wl_display_prepare_read() announces the calling threads intention to read and ensures that until the thread is ready to read and calls wl_display_read_events(), no other thread will read from the file descriptor. This only succeeds if the event queue is empty though, and if there are undispatched events in the queue, -1 is returned and errno set to EAGAIN.
If a thread successfully calls wl_display_prepare_read(), it must either call wl_display_read_events() when it's ready or cancel the read intention by calling wl_display_cancel_read().
Use this function before polling on the display fd or to integrate the fd into a toolkit event loop in a race-free way. Typically, a toolkit will call wl_display_dispatch_pending() before sleeping, to make sure it doesn't block with unhandled events. Upon waking up, it will assume the file descriptor is readable and read events from the fd by calling wl_display_dispatch(). Simplified, we have:
wl_display_dispatch_pending(display); wl_display_flush(display); poll(fds, nfds, -1); wl_display_dispatch(display);
There are two races here: first, before blocking in poll(), the fd could become readable and another thread reads the events. Some of these events may be for the main queue and the other thread will queue them there and then the main thread will go to sleep in poll(). This will stall the application, which could be waiting for a event to kick of the next animation frame, for example.
The other race is immediately after poll(), where another thread could preempt and read events before the main thread calls wl_display_dispatch(). This call now blocks and starves the other fds in the event loop.
A correct sequence would be:
while (wl_display_prepare_read(display) != 0) wl_display_dispatch_pending(display); wl_display_flush(display); poll(fds, nfds, -1); wl_display_read_events(display); wl_display_dispatch_pending(display);
Here we call wl_display_prepare_read(), which ensures that between returning from that call and eventually calling wl_display_read_events(), no other thread will read from the fd and queue events in our queue. If the call to wl_display_prepare_read() fails, we dispatch the pending events and try again until we're successful.
wl_display_cancel_read - Release exclusive access to display file descriptor.
void wl_display_cancel_read(struct wl_display *display)
display
The display context object
This releases the exclusive access. Useful for canceling the lock when a timed out poll returns fd not readable and we're not going to read from the fd anytime soon.
wl_display_dispatch_queue - Dispatch events in an event queue.
int wl_display_dispatch_queue(struct wl_display *display, struct wl_event_queue *queue)
display
The display context object
queue
The event queue to dispatch
Returns:
The number of dispatched events on success or -1 on failure
Dispatch all incoming events for objects assigned to the given event queue. On failure -1 is returned and errno set appropriately.
This function blocks if there are no events to dispatch. If calling from the main thread, it will block reading data from the display fd. For other threads this will block until the main thread queues events on the queue passed as argument.
wl_display_dispatch_queue_pending - Dispatch pending events in an event queue.
int wl_display_dispatch_queue_pending(struct wl_display *display, struct wl_event_queue *queue)
display
The display context object
queue
The event queue to dispatch
Returns:
The number of dispatched events on success or -1 on failure
Dispatch all incoming events for objects assigned to the given event queue. On failure -1 is returned and errno set appropriately. If there are no events queued, this function returns immediately.
  • Since: 1.0.2
wl_display_dispatch - Process incoming events.
int wl_display_dispatch(struct wl_display *display)
display
The display context object
Returns:
The number of dispatched events on success or -1 on failure
Dispatch the display's main event queue.
If the main event queue is empty, this function blocks until there are events to be read from the display fd. Events are read and queued on the appropriate event queues. Finally, events on the main event queue are dispatched.
Note: It is not possible to check if there are events on the main queue or not. For dispatching main queue events without blocking, see wl_display_dispatch_pending().Note: Calling this will release the display file descriptor if this thread acquired it using wl_display_acquire_fd().
  • See also: wl_display_dispatch_pending() wl_display_dispatch_queue()
wl_display_dispatch_pending - Dispatch main queue events without reading from the display fd.
int wl_display_dispatch_pending(struct wl_display *display)
display
The display context object
Returns:
The number of dispatched events or -1 on failure
This function dispatches events on the main event queue. It does not attempt to read the display fd and simply returns zero if the main queue is empty, i.e., it doesn't block.
This is necessary when a client's main loop wakes up on some fd other than the display fd (network socket, timer fd, etc) and calls wl_display_dispatch_queue() from that callback. This may queue up events in the main queue while reading all data from the display fd. When the main thread returns to the main loop to block, the display fd no longer has data, causing a call to poll(2) (or similar functions) to block indefinitely, even though there are events ready to dispatch.
To proper integrate the wayland display fd into a main loop, the client should always call wl_display_dispatch_pending() and then wl_display_flush() prior to going back to sleep. At that point, the fd typically doesn't have data so attempting I/O could block, but events queued up on the main queue should be dispatched.
A real-world example is a main loop that wakes up on a timerfd (or a sound card fd becoming writable, for example in a video player), which then triggers GL rendering and eventually eglSwapBuffers(). eglSwapBuffers() may call wl_display_dispatch_queue() if it didn't receive the frame event for the previous frame, and as such queue events in the main queue.
Note: Calling this makes the current thread the main one.
  • See also: wl_display_dispatch() wl_display_dispatch_queue() wl_display_flush()
wl_display_get_error - Retrieve the last error that occurred on a display.
int wl_display_get_error(struct wl_display *display)
display
The display context object
Returns:
The last error that occurred on display or 0 if no error occurred
Return the last error that occurred on the display. This may be an error sent by the server or caused by the local client.
Note: Errors are fatal. If this function returns non-zero the display can no longer be used.
wl_display_flush - Send all buffered requests on the display to the server.
int wl_display_flush(struct wl_display *display)
display
The display context object
Returns:
The number of bytes sent on success or -1 on failure
Send all buffered data on the client side to the server. Clients should call this function before blocking. On success, the number of bytes sent to the server is returned. On failure, this function returns -1 and errno is set appropriately.
wl_display_flush() never blocks. It will write as much data as possible, but if all data could not be written, errno will be set to EAGAIN and -1 returned. In that case, use poll on the display file descriptor to wait for it to become writable again.
wl_event_queue_destroy - Destroy an event queue.
void wl_event_queue_destroy(struct wl_event_queue *queue)
queue
The event queue to be destroyed
Destroy the given event queue. Any pending event on that queue is discarded.
The wl_display object used to create the queue should not be destroyed until all event queues created with it are destroyed with this function.
wl_proxy_create - Create a proxy object with a given interface.
struct wl_proxy * wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
factory
Factory proxy object
interface
Interface the proxy object should use
Returns:
A newly allocated proxy object or NULL on failure
This function creates a new proxy object with the supplied interface. The proxy object will have an id assigned from the client id space. The id should be created on the compositor side by sending an appropriate request with wl_proxy_marshal().
The proxy will inherit the display and event queue of the factory object.
Note: This should not normally be used by non-generated code.
  • See also: wl_display wl_event_queue wl_proxy_marshal()
wl_proxy_destroy - Destroy a proxy object.
void wl_proxy_destroy(struct wl_proxy *proxy)
proxy
The proxy to be destroyed
wl_proxy_add_listener - Set a proxy's listener.
int wl_proxy_add_listener(struct wl_proxy *proxy, void(**implementation)(void), void *data)
proxy
The proxy object
implementation
The listener to be added to proxy
data
User data to be associated with the proxy
Returns:
0 on success or -1 on failure
Set proxy's listener to implementation and its user data to data. If a listener has already been set, this function fails and nothing is changed.
implementation is a vector of function pointers. For an opcode n, implementation[n] should point to the handler of n for the given object.
wl_proxy_get_listener - Get a proxy's listener.
const void * wl_proxy_get_listener(struct wl_proxy *proxy)
proxy
The proxy object
Returns:
The address of the proxy's listener or NULL if no listener is set
Gets the address to the proxy's listener; which is the listener set with wl_proxy_add_listener.
This function is useful in client with multiple listeners on the same interface to allow the identification of which code to eexecute.
wl_proxy_add_dispatcher - Set a proxy's listener (with dispatcher)
int wl_proxy_add_dispatcher(struct wl_proxy *proxy, wl_dispatcher_func_t dispatcher, const void *implementation, void *data)
proxy
The proxy object
dispatcher
The dispatcher to be used for this proxy
implementation
The dispatcher-specific listener implementation
data
User data to be associated with the proxy
Returns:
0 on success or -1 on failure
Set proxy's listener to use dispatcher_func as its dispatcher and dispatcher_data as its dispatcher-specific implementation and its user data to data. If a listener has already been set, this function fails and nothing is changed.
The exact details of dispatcher_data depend on the dispatcher used. This function is intended to be used by language bindings, not user code.
wl_proxy_marshal_array_constructor - Prepare a request to be sent to the compositor.
struct wl_proxy * wl_proxy_marshal_array_constructor(struct wl_proxy *proxy, uint32_t opcode, union wl_argument *args, const struct wl_interface *interface)
proxy
The proxy object
opcode
Opcode of the request to be sent
args
Extra arguments for the given request
interface
The interface to use for the new proxy
Translates the request given by opcode and the extra arguments into the wire format and write it to the connection buffer. This version takes an array of the union type wl_argument.
For new-id arguments, this function will allocate a new wl_proxy and send the ID to the server. The new wl_proxy will be returned on success or NULL on errror with errno set accordingly.
Note: This is intended to be used by language bindings and not in non-generated code.
  • See also: wl_proxy_marshal()
wl_proxy_marshal - Prepare a request to be sent to the compositor.
void wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode,...)
proxy
The proxy object
opcode
Opcode of the request to be sent
...
Extra arguments for the given request
This function is similar to wl_proxy_marshal_constructor(), except it doesn't create proxies for new-id arguments.
Note: This should not normally be used by non-generated code.
  • See also: wl_proxy_create()
wl_proxy_marshal_constructor - Prepare a request to be sent to the compositor.
struct wl_proxy * wl_proxy_marshal_constructor(struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface,...)
proxy
The proxy object
opcode
Opcode of the request to be sent
interface
The interface to use for the new proxy
...
Extra arguments for the given request
Returns:
A new wl_proxy for the new_id argument or NULL on error
Translates the request given by opcode and the extra arguments into the wire format and write it to the connection buffer.
For new-id arguments, this function will allocate a new wl_proxy and send the ID to the server. The new wl_proxy will be returned on success or NULL on errror with errno set accordingly.
Note: This should not normally be used by non-generated code.
wl_proxy_marshal_array - Prepare a request to be sent to the compositor.
void wl_proxy_marshal_array(struct wl_proxy *proxy, uint32_t opcode, union wl_argument *args)
proxy
The proxy object
opcode
Opcode of the request to be sent
args
Extra arguments for the given request
This function is similar to wl_proxy_marshal_array_constructor(), except it doesn't create proxies for new-id arguments.
Note: This is intended to be used by language bindings and not in non-generated code.
  • See also: wl_proxy_marshal()
wl_proxy_set_user_data - Set the user data associated with a proxy.
void wl_proxy_set_user_data(struct wl_proxy *proxy, void *user_data)
proxy
The proxy object
user_data
The data to be associated with proxy
Set the user data associated with proxy. When events for this proxy are received, user_data will be supplied to its listener.
wl_proxy_get_user_data - Get the user data associated with a proxy.
void * wl_proxy_get_user_data(struct wl_proxy *proxy)
proxy
The proxy object
Returns:
The user data associated with proxy
wl_proxy_get_id - Get the id of a proxy object.
uint32_t wl_proxy_get_id(struct wl_proxy *proxy)
proxy
The proxy object
Returns:
The id the object associated with the proxy
wl_proxy_get_class - Get the interface name (class) of a proxy object.
const char * wl_proxy_get_class(struct wl_proxy *proxy)
proxy
The proxy object
Returns:
The interface name of the object associated with the proxy
wl_proxy_set_queue - Assign a proxy to an event queue.
void wl_proxy_set_queue(struct wl_proxy *proxy, struct wl_event_queue *queue)
proxy
The proxy object
queue
The event queue that will handle this proxy
Assign proxy to event queue. Events coming from proxy will be queued in queue instead of the display's main queue.
  • See also: wl_display_dispatch_queue()
wl_display_prepare_read_queue -
int wl_display_prepare_read_queue(struct wl_display *display, struct wl_event_queue *queue)
wl_display_get_protocol_error - Retrieves the information about a protocol error:
uint32_t wl_display_get_protocol_error(struct wl_display *display, const struct wl_interface **interface, uint32_t *id)
display
The Wayland display
interface
if not NULL, stores the interface where the error occurred
id
if not NULL, stores the object id that generated the error. There's no guarantee the object is still valid; the client must know if it deleted the object.
Returns:
The error code as defined in the interface specification.
interr=wl_display_get_error(display);

if(err==EPROTO){
code=wl_display_get_protocol_error(display,&interface,&id);
handle_error(code,interface,id);
}

...
wl_log_set_handler_client -
void wl_log_set_handler_client(wl_log_func_t handler)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)
wl_map_init -
void wl_map_init(struct wl_map *map, uint32_t side)
wl_map_release -
void wl_map_release(struct wl_map *map)
wl_map_insert_new -
uint32_t wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
wl_map_insert_at -
int wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
wl_map_reserve_new -
int wl_map_reserve_new(struct wl_map *map, uint32_t i)
wl_map_remove -
void wl_map_remove(struct wl_map *map, uint32_t i)
wl_map_lookup -
void* wl_map_lookup(struct wl_map *map, uint32_t i)
wl_map_lookup_flags -
uint32_t wl_map_lookup_flags(struct wl_map *map, uint32_t i)
wl_map_for_each -
void wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
wl_log -
void wl_log(const char *fmt,...)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)

5.2. Server API

Following is the Wayland library classes for the Server (libwayland-server). Note that most of the procedures are related with IPC, which is the main responsibility of the library.
wl_list - doubly-linked list
The list head is of "struct wl_list" type, and must be initialized using wl_list_init(). All entries in the list must be of the same type. The item type must have a "struct wl_list" member. This member will be initialized by wl_list_insert(). There is no need to call wl_list_init() on the individual item. To query if the list is empty in O(1), use wl_list_empty().
Let's call the list reference "struct wl_list foo_list", the item type as "item_t", and the item member as "struct wl_list link".
The following code will initialize a list: struct wl_list foo_list; struct item_t { int foo; struct wl_list link; }; struct item_t item1, item2, item3; wl_list_init(&foo_list); wl_list_insert(&foo_list, &item1.link); Pushes item1 at the head wl_list_insert(&foo_list, &item2.link); Pushes item2 at the head wl_list_insert(&item2.link, &item3.link); Pushes item3 after item2
The list now looks like [item2, item3, item1]
Will iterate the list in ascending order: item_t *item; wl_list_for_each(item, foo_list, link) { Do_something_with_item(item); }
wl_listener - A single listener for Wayland signals.
wl_listener provides the means to listen for wl_signal notifications. Many Wayland objects use wl_listener for notification of significant events like object destruction.
Clients should create wl_listener objects manually and can register them as listeners to signals using wl_signal_add, assuming the signal is directly accessible. For opaque structs like wl_event_loop, adding a listener should be done through provided accessor methods. A listener can only listen to one signal at a time.
structwl_listeneryour_listener; your_listener.notify=your_callback_method; /*Directaccess*/ wl_signal_add(&some_object->destroy_signal,&your_listener); /*Accessoraccess*/ wl_event_loop*loop=...; wl_event_loop_add_destroy_listener(loop,&your_listener);
If the listener is part of a larger struct, wl_container_of can be used to retrieve a pointer to it:
voidyour_listener(structwl_listener*listener,void*data) { structyour_data*data; your_data=wl_container_of(listener,data,your_member_name); }
If you need to remove a listener from a signal, use wl_list_remove().
wl_list_remove(&your_listener.link);
wl_signal
wl_signal - A source of a type of observable event.
Signals are recognized points where significant events can be observed. Compositors as well as the server can provide signals. Observers are wl_listener's that are added through wl_signal_add. Signals are emitted using wl_signal_emit, which will invoke all listeners until that listener is removed by wl_list_remove() (or whenever the signal is destroyed).
wl_listener for more information on using wl_signal
Methods for the respective classes.
wl_client_flush - Flush pending events to the client.
void wl_client_flush(struct wl_client *client)
client
The client object
Events sent to clients are queued in a buffer and written to the socket later - typically when the compositor has handled all requests and goes back to block in the event loop. This function flushes all queued up events for a client immediately.
wl_client_get_display - Get the display object for the given client.
struct wl_display * wl_client_get_display(struct wl_client *client)
client
The client object
Returns:
The display object the client is associated with.
wl_client_get_credentials - Return Unix credentials for the client.
void wl_client_get_credentials(struct wl_client *client, pid_t *pid, uid_t *uid, gid_t *gid)
client
The display object
pid
Returns the process ID
uid
Returns the user ID
gid
Returns the group ID
This function returns the process ID, the user ID and the group ID for the given client. The credentials come from getsockopt() with SO_PEERCRED, on the client socket fd. All the pointers can be NULL, if the caller is not interested in a particular ID.
Be aware that for clients that a compositor forks and execs and then connects using socketpair(), this function will return the credentials for the compositor. The credentials for the socketpair are set at creation time in the compositor.
wl_client_get_object - Look up an object in the client name space.
struct wl_resource * wl_client_get_object(struct wl_client *client, uint32_t id)
client
The client object
id
The object id
Returns:
The object or NULL if there is not object for the given ID
This looks up an object in the client object name space by its object ID.
wl_client_create - Create a client for the given file descriptor.
struct wl_client * wl_client_create(struct wl_display *display, int fd)
display
The display object
fd
The file descriptor for the socket to the client
Returns:
The new client object or NULL on failure.
Given a file descriptor corresponding to one end of a socket, this function will create a wl_client struct and add the new client to the compositors client list. At that point, the client is initialized and ready to run, as if the client had connected to the servers listening socket. When the client eventually sends requests to the compositor, the wl_client argument to the request handler will be the wl_client returned from this function.
The other end of the socket can be passed to wl_display_connect_to_fd() on the client side or used with the WAYLAND_SOCKET environment variable on the client side.
On failure this function sets errno accordingly and returns NULL.
wl_display_create - Create Wayland display object.
struct wl_display * wl_display_create(void)
None
Returns:
The Wayland display object. Null if failed to create
This creates the wl_display object.
wl_display_get_serial - Get the current serial number.
uint32_t wl_display_get_serial(struct wl_display *display)
display
The display object
This function returns the most recent serial number, but does not increment it.
wl_display_next_serial - Get the next serial number.
uint32_t wl_display_next_serial(struct wl_display *display)
display
The display object
This function increments the display serial number and returns the new value.
wl_display_add_shm_format - Add support for a wl_shm pixel format.
uint32_t * wl_display_add_shm_format(struct wl_display *display, uint32_t format)
display
The display object
format
The wl_shm pixel format to advertise
Returns:
A pointer to the wl_shm format that was added to the list or NULL if adding it to the list failed.
Add the specified wl_shm format to the list of formats the wl_shm object advertises when a client binds to it. Adding a format to the list means that clients will know that the compositor supports this format and may use it for creating wl_shm buffers. The compositor must be able to handle the pixel format when a client requests it.
The compositor by default supports WL_SHM_FORMAT_ARGB8888 and WL_SHM_FORMAT_XRGB8888.
wl_display_get_additional_shm_formats - Get list of additional wl_shm pixel formats.
struct wl_array * wl_display_get_additional_shm_formats(struct wl_display *display)
display
The display object
This function returns the list of addition wl_shm pixel formats that the compositor supports. WL_SHM_FORMAT_ARGB8888 and WL_SHM_FORMAT_XRGB8888 are always supported and not included in the array, but all formats added through wl_display_add_shm_format() will be in the array.
  • See also: wl_display_add_shm_format()
wl_shm_buffer_get_data - Get a pointer to the memory for the SHM buffer.
void * wl_shm_buffer_get_data(struct wl_shm_buffer *buffer)
buffer
The buffer object
Returns a pointer which can be used to read the data contained in the given SHM buffer.
As this buffer is memory-mapped, reading from it may generate SIGBUS signals. This can happen if the client claims that the buffer is larger than it is or if something truncates the underlying file. To prevent this signal from causing the compositor to crash you should call wl_shm_buffer_begin_access and wl_shm_buffer_end_access around code that reads from the memory.
wl_shm_buffer_begin_access - Mark that the given SHM buffer is about to be accessed.
void wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer)
buffer
The SHM buffer
An SHM buffer is a memory-mapped file given by the client. According to POSIX, reading from a memory-mapped region that extends off the end of the file will cause a SIGBUS signal to be generated. Normally this would cause the compositor to terminate. In order to make the compositor robust against clients that change the size of the underlying file or lie about its size, you should protect access to the buffer by calling this function before reading from the memory and call wl_shm_buffer_end_access afterwards. This will install a signal handler for SIGBUS which will prevent the compositor from crashing.
After calling this function the signal handler will remain installed for the lifetime of the compositor process. Note that this function will not work properly if the compositor is also installing its own handler for SIGBUS.
If a SIGBUS signal is received for an address within the range of the SHM pool of the given buffer then the client will be sent an error event when wl_shm_buffer_end_access is called. If the signal is for an address outside that range then the signal handler will reraise the signal which would will likely cause the compositor to terminate.
It is safe to nest calls to these functions as long as the nested calls are all accessing the same buffer. The number of calls to wl_shm_buffer_end_access must match the number of calls to wl_shm_buffer_begin_access. These functions are thread-safe and it is allowed to simultaneously access different buffers or the same buffer from multiple threads.
wl_shm_buffer_end_access - Ends the access to a buffer started by wl_shm_buffer_begin_access.
void wl_shm_buffer_end_access(struct wl_shm_buffer *buffer)
buffer
The SHM buffer
This should be called after wl_shm_buffer_begin_access once the buffer is no longer being accessed. If a SIGBUS signal was generated in-between these two calls then the resource for the given buffer will be sent an error.
wl_signal_init - Initialize a new wl_signal for use.
static void wl_signal_init(struct wl_signal *signal)
signal
The signal that will be initialized
wl_signal_add - Add the specified listener to this signal.
static void wl_signal_add(struct wl_signal *signal, struct wl_listener *listener)
signal
The signal that will emit events to the listener
listener
The listener to add
wl_signal_get - Gets the listener struct for the specified callback.
static struct wl_listener * wl_signal_get(struct wl_signal *signal, wl_notify_func_t notify)
signal
The signal that contains the specified listener
notify
The listener that is the target of this search
Returns:
the list item that corresponds to the specified listener, or NULL if none was found
wl_signal_emit - Emits this signal, notifying all registered listeners.
static void wl_signal_emit(struct wl_signal *signal, void *data)
signal
The signal object that will emit the signal
data
The data that will be emitted with the signal
wl_resource_post_event_array -
void wl_resource_post_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
wl_resource_post_event -
void wl_resource_post_event(struct wl_resource *resource, uint32_t opcode,...)
wl_resource_queue_event_array -
void wl_resource_queue_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
wl_resource_queue_event -
void wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode,...)
wl_resource_post_error -
void wl_resource_post_error(struct wl_resource *resource, uint32_t code, const char *msg,...)
wl_client_post_no_memory -
void wl_client_post_no_memory(struct wl_client *client)
wl_resource_post_no_memory -
void wl_resource_post_no_memory(struct wl_resource *resource)
wl_resource_destroy -
void wl_resource_destroy(struct wl_resource *resource)
wl_resource_get_id -
uint32_t wl_resource_get_id(struct wl_resource *resource)
wl_resource_get_link -
struct wl_list* wl_resource_get_link(struct wl_resource *resource)
wl_resource_from_link -
struct wl_resource* wl_resource_from_link(struct wl_list *link)
wl_resource_find_for_client -
struct wl_resource* wl_resource_find_for_client(struct wl_list *list, struct wl_client *client)
wl_resource_get_client -
struct wl_client* wl_resource_get_client(struct wl_resource *resource)
wl_resource_set_user_data -
void wl_resource_set_user_data(struct wl_resource *resource, void *data)
wl_resource_get_user_data -
void* wl_resource_get_user_data(struct wl_resource *resource)
wl_resource_get_version -
int wl_resource_get_version(struct wl_resource *resource)
wl_resource_set_destructor -
void wl_resource_set_destructor(struct wl_resource *resource, wl_resource_destroy_func_t destroy)
wl_resource_instance_of -
int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, const void *implementation)
wl_resource_add_destroy_listener -
void wl_resource_add_destroy_listener(struct wl_resource *resource, struct wl_listener *listener)
wl_resource_get_destroy_listener -
struct wl_listener* wl_resource_get_destroy_listener(struct wl_resource *resource, wl_notify_func_t notify)
wl_client_add_destroy_listener -
void wl_client_add_destroy_listener(struct wl_client *client, struct wl_listener *listener)
wl_client_get_destroy_listener -
struct wl_listener* wl_client_get_destroy_listener(struct wl_client *client, wl_notify_func_t notify)
wl_client_destroy -
void wl_client_destroy(struct wl_client *client)
wl_display_destroy -
void wl_display_destroy(struct wl_display *display)
wl_global_create -
struct wl_global* wl_global_create(struct wl_display *display, const struct wl_interface *interface, int version, void *data, wl_global_bind_func_t bind)
wl_global_destroy -
void wl_global_destroy(struct wl_global *global)
wl_display_get_event_loop -
struct wl_event_loop* wl_display_get_event_loop(struct wl_display *display)
wl_display_terminate -
void wl_display_terminate(struct wl_display *display)
wl_display_run -
void wl_display_run(struct wl_display *display)
wl_display_flush_clients -
void wl_display_flush_clients(struct wl_display *display)
wl_display_add_socket_auto -
const char* wl_display_add_socket_auto(struct wl_display *display)
wl_display_add_socket -
int wl_display_add_socket(struct wl_display *display, const char *name)
wl_display_add_destroy_listener -
void wl_display_add_destroy_listener(struct wl_display *display, struct wl_listener *listener)
wl_display_get_destroy_listener -
struct wl_listener* wl_display_get_destroy_listener(struct wl_display *display, wl_notify_func_t notify)
wl_resource_set_implementation -
void wl_resource_set_implementation(struct wl_resource *resource, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
wl_resource_set_dispatcher -
void wl_resource_set_dispatcher(struct wl_resource *resource, wl_dispatcher_func_t dispatcher, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
wl_resource_create -
struct wl_resource* wl_resource_create(struct wl_client *client, const struct wl_interface *interface, int version, uint32_t id)
wl_log_set_handler_server -
void wl_log_set_handler_server(wl_log_func_t handler)
wl_client_add_resource -
uint32_t wl_client_add_resource(struct wl_client *client, struct wl_resource *resource) WL_DEPRECATED
wl_client_add_object -
struct wl_resource * wl_client_add_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, uint32_t id, void *data) WL_DEPRECATED
wl_client_new_object -
struct wl_resource * wl_client_new_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, void *data) WL_DEPRECATED
wl_display_add_global -
struct wl_global * wl_display_add_global(struct wl_display *display, const struct wl_interface *interface, void *data, wl_global_bind_func_t bind) WL_DEPRECATED
wl_display_remove_global -
void wl_display_remove_global(struct wl_display *display, struct wl_global *global) WL_DEPRECATED
wl_display_init_shm -
int wl_display_init_shm(struct wl_display *display)
wl_shm_buffer_create -
struct wl_shm_buffer* wl_shm_buffer_create(struct wl_client *client, uint32_t id, int32_t width, int32_t height, int32_t stride, uint32_t format)
wl_shm_buffer_get -
struct wl_shm_buffer* wl_shm_buffer_get(struct wl_resource *resource)
wl_shm_buffer_get_stride -
int32_t wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer)
wl_shm_buffer_get_format -
uint32_t wl_shm_buffer_get_format(struct wl_shm_buffer *buffer)
wl_shm_buffer_get_width -
int32_t wl_shm_buffer_get_width(struct wl_shm_buffer *buffer)
wl_shm_buffer_get_height -
int32_t wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)
wl_map_init -
void wl_map_init(struct wl_map *map, uint32_t side)
wl_map_release -
void wl_map_release(struct wl_map *map)
wl_map_insert_new -
uint32_t wl_map_insert_new(struct wl_map *map, uint32_t flags, void *data)
wl_map_insert_at -
int wl_map_insert_at(struct wl_map *map, uint32_t flags, uint32_t i, void *data)
wl_map_reserve_new -
int wl_map_reserve_new(struct wl_map *map, uint32_t i)
wl_map_remove -
void wl_map_remove(struct wl_map *map, uint32_t i)
wl_map_lookup -
void* wl_map_lookup(struct wl_map *map, uint32_t i)
wl_map_lookup_flags -
uint32_t wl_map_lookup_flags(struct wl_map *map, uint32_t i)
wl_map_for_each -
void wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)
wl_log -
void wl_log(const char *fmt,...)
wl_list_init -
void wl_list_init(struct wl_list *list)
wl_list_insert -
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
wl_list_remove -
void wl_list_remove(struct wl_list *elm)
wl_list_length -
int wl_list_length(const struct wl_list *list)
wl_list_empty -
int wl_list_empty(const struct wl_list *list)
wl_list_insert_list -
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
wl_array_init -
void wl_array_init(struct wl_array *array)
wl_array_release -
void wl_array_release(struct wl_array *array)
wl_array_add -
void* wl_array_add(struct wl_array *array, size_t size)
wl_array_copy -
int wl_array_copy(struct wl_array *array, struct wl_array *source)