Table of Contents
The open-source reference implementation of Wayland protocol is split in two C libraries, libwayland-client and libwayland-server. Their main responsibility is to handle the Inter-process communication (IPC) with each other, therefore guaranteeing the protocol objects marshaling and messages synchronization.
The server library is designed to work much like libwayland-client, although it is considerably complicated due to the server needing to support multiple versions of the protocol. It is best to learn libwayland-client first.
Each open socket to a client is represented by a wl_client. The equivalent of the wl_proxy that libwayland-client uses to represent an object is wl_resource for client-created objects, and wl_global for objects created by the server.
Often a server is also a client for another Wayland server, and thus must link with both libwayland-client and libwayland-server. This produces some type name conflicts (such as the client wl_display and server wl_display, but the duplicate-but-not-the-same types are opaque, and accessed only inside the correct library where it came from. Naturally that means that the program writer needs to always know if a pointer to a wl_display is for the server or client side and use the corresponding functions.
This union represents all of the argument types in the Wayland protocol wire format. The protocol implementation uses wl_argument within its marshalling machinery for dispatching messages between a client and a compositor.
See also: wl_message See also: wl_interface See also: Wire Format
A wl_array is a dynamic array that can only grow until released. It is intended for relatively small allocations whose size is variable or not known in advance. While construction of a wl_array does not require all elements to be of the same size, wl_array_for_each() does require all elements to have the same type and size.
size_t wl_array::size
size_t wl_array::alloc
void* wl_array::data
void wl_array_init(struct wl_array *array)
void wl_array_release(struct wl_array *array)
Note: Leaves the array in an invalid state.
void * wl_array_add(struct wl_array *array, size_t size)
int wl_array_copy(struct wl_array *array, struct wl_array *source)
This macro expresses a for-each iterator for wl_array. It assigns each element in the array to pos, which can then be referenced in a trailing code block. pos must be a pointer to the array element type, and all array elements must be of the same type and size.
See also: wl_list_for_each()
void wl_client_flush(struct wl_client *client)
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.
struct wl_display * wl_client_get_display(struct wl_client *client)
void wl_client_get_credentials(struct wl_client *client, pid_t *pid, uid_t *uid, gid_t *gid)
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.
Note, process IDs are subject to race conditions and are not a reliable way to identify a client.
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.
int wl_client_get_fd(struct wl_client *client)
This function returns the file descriptor for the given client.
Be sure to use the file descriptor from the client for inspection only. If the caller does anything to the file descriptor that changes its state, it will likely cause problems.
See also wl_client_get_credentials(). It is recommended that you evaluate whether wl_client_get_credentials() can be applied to your use case instead of this function.
If you would like to distinguish just between the client and the compositor itself from the client's request, it can be done by getting the client credentials and by checking the PID of the client and the compositor's PID. Regarding the case in which the socketpair() is being used, you need to be careful. Please note the documentation for wl_client_get_credentials().
This function can be used for a compositor to validate a request from a client if there are additional information provided from the client's file descriptor. For instance, suppose you can get the security contexts from the client's file descriptor. The compositor can validate the client's request with the contexts and make a decision whether it permits or deny it.
struct wl_resource * wl_client_get_object(struct wl_client *client, uint32_t id)
This looks up an object in the client object name space by its object ID.
void wl_client_post_implementation_error(struct wl_client *client, char const *msg,...)
Report an unspecified internal implementation error and disconnect the client.
void wl_client_add_destroy_listener(struct wl_client *client, struct wl_listener *listener)
The listener provided will be called when wl_client destroy has begun, before any of that client's resources have been destroyed.
There is no requirement to remove the link of the wl_listener when the signal is emitted.
void wl_client_add_destroy_late_listener(struct wl_client *client, struct wl_listener *listener)
The listener provided will be called when wl_client destroy is nearly complete, after all of that client's resources have been destroyed.
There is no requirement to remove the link of the wl_listener when the signal is emitted.
Since: 1.22.0
struct wl_list * wl_client_get_link(struct wl_client *client)
See also: wl_client_for_each() See also: wl_display_get_client_list() See also: wl_client_from_link()
struct wl_client * wl_client_from_link(struct wl_list *link)
See also: wl_client_for_each() See also: wl_display_get_client_list() See also: wl_client_get_link()
void wl_client_add_resource_created_listener(struct wl_client *client, struct wl_listener *listener)
When a new resource is created for this client the listener will be notified, carrying the new resource as the data argument.
void wl_client_for_each_resource(struct wl_client *client, wl_client_for_each_resource_iterator_func_t iterator, void *user_data)
The function pointed by iterator will be called for each resource owned by the client. The user_data will be passed as the second argument of the iterator function. If the iterator function returns WL_ITERATOR_CONTINUE the iteration will continue, if it returns WL_ITERATOR_STOP it will stop.
Creating and destroying resources while iterating is safe, but new resources may or may not be picked up by the iterator.
See also: wl_iterator_result
void wl_client_set_max_buffer_size(struct wl_client *client, size_t max_buffer_size)
The actual size of the connection buffers is a power of two, the requested max_buffer_size is therefore rounded up to the nearest power of two value.
Lowering the maximum size may not take effect immediately if the current content of the buffer does not fit within the new size limit.
The minimum buffer size is 4096. The default buffers size can be set using wl_display_set_default_max_buffer_size().
See also: wl_display_set_default_max_buffer_size() Since: 1.22.90
struct wl_client * wl_client_create(struct wl_display *display, int fd)
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.
Listeners added with wl_display_add_client_created_listener() will be notified by this function after the client is fully constructed.
On failure this function sets errno accordingly and returns NULL.
On success, the new client object takes the ownership of the file descriptor. On failure, the ownership of the socket endpoint file descriptor is unchanged, it is the responsibility of the caller to perform cleanup, e.g. call close().
struct wl_display * wl_display_create(void)
This creates the wl_display object.
void wl_display_destroy(struct wl_display *display)
This function emits the wl_display destroy signal, releases all the sockets added to this display, free's all the globals associated with this display, free's memory of additional shared memory formats and destroy the display object.
See also: wl_display_add_destroy_listener
void wl_display_set_global_filter(struct wl_display *display, wl_display_global_filter_func_t filter, void *data)
Set a filter for the wl_display to advertise or hide global objects to clients. The set filter will be used during wl_global advertisement to determine whether a global object should be advertised to a given client, and during wl_global binding to determine whether a given client should be allowed to bind to a global.
Clients that try to bind to a global that was filtered out will have an error raised.
Setting the filter NULL will result in all globals being advertised to all clients. The default is no filter.
The filter should be installed before any client connects and should always take the same decision given a client and a global. Not doing so will result in inconsistent filtering and broken wl_registry event sequences.
uint32_t wl_display_get_serial(struct wl_display *display)
This function returns the most recent serial number, but does not increment it.
uint32_t wl_display_next_serial(struct wl_display *display)
This function increments the display serial number and returns the new value.
void wl_display_destroy_clients(struct wl_display *display)
This function should be called right before wl_display_destroy() to ensure all client resources are closed properly. Destroying a client from within wl_display_destroy_clients() is safe, but creating one will leak resources and raise a warning.
void wl_display_set_default_max_buffer_size(struct wl_display *display, size_t max_buffer_size)
This function sets the default size of the internal connection buffers for new clients. It doesn't change the buffer size for existing wl_client.
The connection buffer size of an existing wl_client can be adjusted using wl_client_set_max_buffer_size().
The actual size of the connection buffers is a power of two, the requested max_buffer_size is therefore rounded up to the nearest power of two value.
The minimum buffer size is 4096.
See also: wl_client_set_max_buffer_size Since: 1.22.90
int wl_display_add_socket_fd(struct wl_display *display, int sock_fd)
The existing socket fd must already be created, opened, and locked. The fd must be properly set to CLOEXEC and bound to a socket file with both bind() and listen() already called.
On success, the socket fd ownership is transferred to libwayland: libwayland will close the socket when the display is destroyed.
int wl_display_add_socket(struct wl_display *display, const char *name)
This adds a Unix socket to Wayland display which can be used by clients to connect to Wayland display.
If NULL is passed as name, then it would look for WAYLAND_DISPLAY env variable for the socket name. If WAYLAND_DISPLAY is not set, then default wayland-0 is used.
If the socket name is a relative path, the Unix socket will be created in the directory pointed to by environment variable XDG_RUNTIME_DIR. If XDG_RUNTIME_DIR is invalid or not set, then this function fails and returns -1.
If the socket name is an absolute path, then it is used as-is for the the Unix socket.
The length of the computed socket path must not exceed the maximum length of a Unix socket path. The function also fails if the user does not have write permission in the directory or if the path is already in use.
struct wl_protocol_logger * wl_display_add_protocol_logger(struct wl_display *display, wl_protocol_logger_func_t func, void *user_data)
When a new protocol message arrives or is sent from the server all the protocol logger functions will be called, carrying the user_data pointer, the type of the message (request or event) and the actual message. The lifetime of the messages passed to the logger function ends when they return so the messages cannot be stored and accessed later.
errno is set on error.
See also: wl_protocol_logger_destroy
uint32_t * wl_display_add_shm_format(struct wl_display *display, uint32_t format)
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.
struct wl_list * wl_display_get_client_list(struct wl_display *display)
This function returns a pointer to the list of clients currently connected to the display. You can iterate on the list by using the wl_client_for_each macro. The returned value is valid for the lifetime of the display. You must not modify the returned list, but only access it.
See also: wl_client_for_each() See also: wl_client_get_link() See also: wl_client_from_link()
Usually you create an event loop context, add sources to it, and call wl_event_loop_dispatch() in a loop to process events.
See also: wl_event_source
struct wl_event_loop * wl_event_loop_create(void)
This creates a new event loop context. Initially this context is empty. Event sources need to be explicitly added to it.
Normally the event loop is run by calling wl_event_loop_dispatch() in a loop until the program terminates. Alternatively, an event loop can be embedded in another event loop by its file descriptor, see wl_event_loop_get_fd().
void wl_event_loop_destroy(struct wl_event_loop *loop)
This emits the event loop destroy signal, closes the event loop file descriptor, and frees loop.
If the event loop has existing sources, those cannot be safely removed afterwards. Therefore one must call wl_event_source_remove() on all event sources before destroying the event loop context.
void wl_event_loop_dispatch_idle(struct wl_event_loop *loop)
See also: wl_event_loop_add_idle()
int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
All the associated event sources are polled. This function blocks until any event source delivers an event (idle sources excluded), or the timeout expires. A timeout of -1 disables the timeout, causing the function to block indefinitely. A timeout of zero causes the poll to always return immediately.
All idle sources are dispatched before blocking. An idle source is destroyed when it is dispatched. After blocking, all other ready sources are dispatched. Then, idle sources are dispatched again, in case the dispatched events created idle sources. Finally, all sources marked with wl_event_source_check() are dispatched in a loop until their dispatch functions all return zero.
int wl_event_loop_get_fd(struct wl_event_loop *loop)
This function returns the aggregate file descriptor, that represents all the event sources (idle sources excluded) associated with the given event loop context. When any event source makes an event available, it will be reflected in the aggregate file descriptor.
When the aggregate file descriptor delivers an event, one can call wl_event_loop_dispatch() on the event loop context to dispatch all the available events.
void wl_event_loop_add_destroy_listener(struct wl_event_loop *loop, struct wl_listener *listener)
See also: wl_listener
struct wl_listener * wl_event_loop_get_destroy_listener(struct wl_event_loop *loop, wl_notify_func_t notify)
This is the generic type for fd, timer, signal, and idle sources. Functions that operate on specific source types must not be used with a different type, even if the function signature allows it.
typedef int(* wl_event_loop_fd_func_t) (int fd, uint32_t mask, void *data))(int fd, uint32_t mask, void *data)
Functions of this type are used as callbacks for file descriptor events.
See also: wl_event_loop_add_fd()
typedef int(* wl_event_loop_timer_func_t) (void *data))(void *data)
Functions of this type are used as callbacks for timer expiry.
See also: wl_event_loop_add_timer()
typedef int(* wl_event_loop_signal_func_t) (int signal_number, void *data))(int signal_number, void *data)
Functions of this type are used as callbacks for (POSIX) signals.
See also: wl_event_loop_add_signal()
typedef void(* wl_event_loop_idle_func_t) (void *data))(void *data)
Functions of this type are used as callbacks before blocking in wl_event_loop_dispatch().
struct wl_event_source * wl_event_loop_add_fd(struct wl_event_loop *loop, int fd, uint32_t mask, wl_event_loop_fd_func_t func, void *data)
The given file descriptor is initially watched for the events given in mask. This can be changed as needed with wl_event_source_fd_update().
If it is possible that program execution causes the file descriptor to be read while leaving the data in a buffer without actually processing it, it may be necessary to register the file descriptor source to be re-checked, see wl_event_source_check(). This will ensure that the dispatch function gets called even if the file descriptor is not readable or writable anymore. This is especially useful with IPC libraries that automatically buffer incoming data, possibly as a side-effect of other operations.
See also: wl_event_loop_fd_func_t
int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask)
This changes which events, readable and/or writable, cause the dispatch callback to be called on.
File descriptors are usually writable to begin with, so they do not need to be polled for writable until a write actually fails. When a write fails, the event mask can be changed to poll for readable and writable, delivering a dispatch callback when it is possible to write more. Once all data has been written, the mask can be changed to poll only for readable to avoid busy-looping on dispatch.
See also: wl_event_loop_add_fd()
struct wl_event_source * wl_event_loop_add_timer(struct wl_event_loop *loop, wl_event_loop_timer_func_t func, void *data)
The timer is initially disarmed. It needs to be armed with a call to wl_event_source_timer_update() before it can trigger a dispatch call.
See also: wl_event_loop_timer_func_t
int wl_event_source_timer_update(struct wl_event_source *source, int ms_delay)
If the timeout is zero, the timer is disarmed.
If the timeout is non-zero, the timer is set to expire after the given timeout in milliseconds. When the timer expires, the dispatch function set with wl_event_loop_add_timer() is called once from wl_event_loop_dispatch(). If another dispatch is desired after another expiry, wl_event_source_timer_update() needs to be called again.
struct wl_event_source * wl_event_loop_add_signal(struct wl_event_loop *loop, int signal_number, wl_event_loop_signal_func_t func, void *data)
This function blocks the normal delivery of the given signal in the calling thread, and creates a "watch" for it. Signal delivery no longer happens asynchronously, but by wl_event_loop_dispatch() calling the dispatch callback function func.
It is the caller's responsibility to ensure that all other threads have also blocked the signal.
See also: wl_event_loop_signal_func_t
struct wl_event_source * wl_event_loop_add_idle(struct wl_event_loop *loop, wl_event_loop_idle_func_t func, void *data)
Idle tasks are dispatched before wl_event_loop_dispatch() goes to sleep. See wl_event_loop_dispatch() for more details.
Idle tasks fire once, and are automatically destroyed right after the callback function has been called.
An idle task can be cancelled before the callback has been called by wl_event_source_remove(). Calling wl_event_source_remove() after or from within the callback results in undefined behaviour.
See also: wl_event_loop_idle_func_t
void wl_event_source_check(struct wl_event_source *source)
This function permanently marks the event source to be re-checked after the normal dispatch of sources in wl_event_loop_dispatch(). Re-checking will keep iterating over all such event sources until the dispatch function for them all returns zero.
Re-checking is used on sources that may become ready to dispatch as a side-effect of dispatching themselves or other event sources, including idle sources. Re-checking ensures all the incoming events have been fully drained before wl_event_loop_dispatch() returns.
int wl_event_source_remove(struct wl_event_source *source)
The event source is removed from the event loop it was created for, and is effectively destroyed. This invalidates source . The dispatch function of the source will no longer be called through this source.
uint32_t wl_global_get_name(const struct wl_global *global, const struct wl_client *client)
Since: 1.22
uint32_t wl_global_get_version(const struct wl_global *global)
Since: 1.21
struct wl_display * wl_global_get_display(const struct wl_global *global)
Since: 1.20
A wl_interface describes the API of a protocol object defined in the Wayland protocol specification. The protocol implementation uses a wl_interface within its marshalling machinery for encoding client requests.
The name of a wl_interface is the name of the corresponding protocol interface, and version represents the version of the interface. The members method_count and event_count represent the number of methods (requests) and events in the respective wl_message members.
For example, consider a protocol interface foo, marked as version 1, with two requests and one event.
<interface name="foo" version="1"> <request name="a"></request> <request name="b"></request> <event name="c"></event> </interface>
Given two wl_message arrays foo_requests and foo_events, a wl_interface for foo might be:
struct wl_interface foo_interface = { "foo", 1, 2, foo_requests, 1, foo_events };
Note: The server side of the protocol may define interface implementation types that incorporate the term interface in their name. Take care to not confuse these server-side structs with a wl_interface variable whose name also ends in interface. For example, while the server may define a type struct wl_foo_interface, the client may define a struct wl_interface wl_foo_interface. See also: wl_message See also: wl_proxy See also: Interfaces See also: Versioning
On its own, an instance of struct wl_list represents the sentinel head of a doubly-linked list, and must be initialized using wl_list_init(). When empty, the list head's next and prev members point to the list head itself, otherwise next references the first element in the list, and prev refers to the last element in the list.
Use the struct wl_list type to represent both the list head and the links between elements within the list. Use wl_list_empty() to determine if the list is empty in O(1).
All elements in the list must be of the same type. The element type must have a struct wl_list member, often named link by convention. Prior to insertion, there is no need to initialize an element's link - invoking wl_list_init() on an individual list element's struct wl_list member is unnecessary if the very next operation is wl_list_insert(). However, a common idiom is to initialize an element's link prior to removal - ensure safety by invoking wl_list_init() before wl_list_remove().
Consider a list reference struct wl_list foo_list, an element type as struct element, and an element's link member as struct wl_list link.
The following code initializes a list and adds three elements to it.
struct wl_list foo_list; struct element { int foo; struct wl_list link; }; struct element e1, e2, e3; wl_list_init(&foo_list); wl_list_insert(&foo_list, &e1.link); // e1 is the first element wl_list_insert(&foo_list, &e2.link); // e2 is now the first element wl_list_insert(&e2.link, &e3.link); // insert e3 after e2
The list now looks like [e2, e3, e1].
The wl_list API provides some iterator macros. For example, to iterate a list in ascending order:
struct element *e; wl_list_for_each(e, foo_list, link) { do_something_with_element(e); }
See the documentation of each iterator for details. See also: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/list.h
struct wl_list* wl_list::prev
struct wl_list* wl_list::next
void wl_list_init(struct wl_list *list)
void wl_list_insert(struct wl_list *list, struct wl_list *elm)
When list is a reference to the list itself (the head), set the containing struct of elm as the first element in the list.
Note: If elm is already part of a list, inserting it again will lead to list corruption.
void wl_list_remove(struct wl_list *elm)
Note: This operation leaves elm in an invalid state.
int wl_list_length(const struct wl_list *list)
Note: This is an O(n) operation.
int wl_list_empty(const struct wl_list *list)
void wl_list_insert_list(struct wl_list *list, struct wl_list *other)
Note: This leaves other in an invalid state.
This macro expresses a for-each iterator for wl_list. Given a list and wl_list link member name (often named link by convention), this macro assigns each element in the list to pos, which can then be referenced in a trailing code block. For example, given a wl_list of struct message elements:
struct message { char *contents; wl_list link; }; struct wl_list *message_list; // Assume message_list now "contains" many messages struct message *m; wl_list_for_each(m, message_list, link) { do_something_with_message(m); }
Note: Only removal of the current element, pos, is safe. Removing any other element during traversal may lead to a loop malfunction. See also: wl_list_for_each()
See also: wl_list_for_each()
Note: Only removal of the current element, pos, is safe. Removing any other element during traversal may lead to a loop malfunction. See also: wl_list_for_each()
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.
struct wl_listener your_listener; your_listener.notify = your_callback_method; // Direct access wl_signal_add(&some_object->destroy_signal, &your_listener); // Accessor access 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:
void your_listener(struct wl_listener *listener, void *data) { struct your_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);
See also: wl_signal
A wl_message describes the signature of an actual protocol message, such as a request or event, that adheres to the Wayland protocol wire format. The protocol implementation uses a wl_message within its demarshal machinery for decoding messages between a compositor and its clients. In a sense, a wl_message is to a protocol message like a class is to an object.
The name of a wl_message is the name of the corresponding protocol message.
The signature is an ordered list of symbols representing the data types of message arguments and, optionally, a protocol version and indicators for nullability. A leading integer in the signature indicates the since version of the protocol message. A ? preceding a data type symbol indicates that the following argument type is nullable. While it is a protocol violation to send messages with non-nullable arguments set to NULL, event handlers in clients might still get called with non-nullable object arguments set to NULL. This can happen when the client destroyed the object being used as argument on its side and an event referencing that object was sent before the server knew about its destruction. As this race cannot be prevented, clients should - as a general rule - program their event handlers such that they can handle object arguments declared non-nullable being NULL gracefully.
When no arguments accompany a message, signature is an empty string.
Symbols:
While demarshaling primitive arguments is straightforward, when demarshaling messages containing object or new_id arguments, the protocol implementation often must determine the type of the object. The types of a wl_message is an array of wl_interface references that correspond to o and n arguments in signature, with NULL placeholders for arguments with non-object types.
Consider the protocol event wl_display delete_id that has a single uint argument. The wl_message is:
{ "delete_id", "u", [NULL] }
Here, the message name is "delete_id", the signature is "u", and the argument types is [NULL], indicating that the uint argument has no corresponding wl_interface since it is a primitive argument.
In contrast, consider a wl_foo interface supporting protocol request bar that has existed since version 2, and has two arguments: a uint and an object of type wl_baz_interface that may be NULL. Such a wl_message might be:
{ "bar", "2u?o", [NULL, &wl_baz_interface] }
Here, the message name is "bar", and the signature is "2u?o". Notice how the 2 indicates the protocol version, the u indicates the first argument type is uint, and the ?o indicates that the second argument is an object that may be NULL. Lastly, the argument types array indicates that no wl_interface corresponds to the first argument, while the type wl_baz_interface corresponds to the second argument.
See also: wl_argument See also: wl_interface See also: Wire Format
A wl_object is an opaque struct identifying the protocol object underlying a wl_proxy or wl_resource.
Note: Functions accessing a wl_object are not normally used by client code. Clients should normally use the higher level interface generated by the scanner to interact with compositor objects.
void wl_protocol_logger_destroy(struct wl_protocol_logger *logger)
This function destroys a protocol logger and removes it from the display it was added to with wl_display_add_protocol_logger. The logger object becomes invalid after calling this function.
See also: wl_display_add_protocol_logger
const char * wl_resource_get_class(struct wl_resource *resource)
struct wl_resource * wl_resource_create(struct wl_client *client, const struct wl_interface *interface, int version, uint32_t id)
Listeners added with wl_client_add_resource_created_listener will be notified at the end of this function.
wl_shm_buffer provides a helper for accessing the contents of a wl_buffer resource created via the wl_shm interface.
A wl_shm_buffer becomes invalid as soon as its wl_resource is destroyed.
void * wl_shm_buffer_get_data(struct wl_shm_buffer *buffer)
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.
struct wl_shm_pool * wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer)
Returns a pointer to a buffer's shm_pool and increases the shm_pool refcount.
The compositor must remember to call wl_shm_pool_unref when it no longer needs the reference to ensure proper destruction of the pool.
See also: wl_shm_pool_unref
void wl_shm_buffer_begin_access(struct wl_shm_buffer *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.
void wl_shm_buffer_end_access(struct wl_shm_buffer *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.
void wl_shm_pool_unref(struct wl_shm_pool *pool)
Drops a reference to a wl_shm_pool object.
This is only necessary if the compositor has explicitly taken a reference with wl_shm_buffer_ref_pool(), otherwise the pool will be automatically destroyed when appropriate.
See also: wl_shm_buffer_ref_pool
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).
See also: wl_listener for more information on using wl_signal
void wl_signal_emit_mutable(struct wl_signal *signal, void *data)
A safer version of wl_signal_emit() which can gracefully handle additions and deletions of any signal listener from within listener notification callbacks.
Listeners deleted during a signal emission and which have not already been notified at the time of deletion are not notified by that emission.
Listeners added (or readded) during signal emission are ignored by that emission.
Note that repurposing a listener without explicitly removing it and readding it is not supported and can lead to unexpected behavior.
Since: 1.20.90
typedef bool(* wl_display_global_filter_func_t) (const struct wl_client *client, const struct wl_global *global, void *data))(const struct wl_client *client, const struct wl_global *global, void *data)
A filter function enables the server to decide which globals to advertise to each client.
When a wl_global filter is set, the given callback function will be called during wl_global advertisement and binding.
This function should return true if the global object should be made visible to the client or false otherwise.
struct wl_event_loop * wl_event_loop_create(void)
void wl_event_loop_destroy(struct wl_event_loop *loop)
struct wl_event_source * wl_event_loop_add_fd(struct wl_event_loop *loop, int fd, uint32_t mask, wl_event_loop_fd_func_t func, void *data)
int wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask)
struct wl_event_source * wl_event_loop_add_timer(struct wl_event_loop *loop, wl_event_loop_timer_func_t func, void *data)
struct wl_event_source * wl_event_loop_add_signal(struct wl_event_loop *loop, int signal_number, wl_event_loop_signal_func_t func, void *data)
int wl_event_source_timer_update(struct wl_event_source *source, int ms_delay)
int wl_event_source_remove(struct wl_event_source *source)
void wl_event_source_check(struct wl_event_source *source)
int wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
void wl_event_loop_dispatch_idle(struct wl_event_loop *loop)
struct wl_event_source * wl_event_loop_add_idle(struct wl_event_loop *loop, wl_event_loop_idle_func_t func, void *data)
int wl_event_loop_get_fd(struct wl_event_loop *loop)
void wl_event_loop_add_destroy_listener(struct wl_event_loop *loop, struct wl_listener *listener)
struct wl_listener * wl_event_loop_get_destroy_listener(struct wl_event_loop *loop, wl_notify_func_t notify)
struct wl_display * wl_display_create(void)
void wl_display_destroy(struct wl_display *display)
struct wl_event_loop * wl_display_get_event_loop(struct wl_display *display)
int wl_display_add_socket(struct wl_display *display, const char *name)
const char * wl_display_add_socket_auto(struct wl_display *display)
int wl_display_add_socket_fd(struct wl_display *display, int sock_fd)
void wl_display_terminate(struct wl_display *display)
void wl_display_run(struct wl_display *display)
void wl_display_flush_clients(struct wl_display *display)
void wl_display_destroy_clients(struct wl_display *display)
void wl_display_set_default_max_buffer_size(struct wl_display *display, size_t max_buffer_size)
uint32_t wl_display_get_serial(struct wl_display *display)
uint32_t wl_display_next_serial(struct wl_display *display)
void wl_display_add_destroy_listener(struct wl_display *display, struct wl_listener *listener)
void wl_display_add_client_created_listener(struct wl_display *display, struct wl_listener *listener)
When a new client object is created, listener will be notified, carrying a pointer to the new wl_client object.
wl_client_create wl_display wl_listener
struct wl_listener * wl_display_get_destroy_listener(struct wl_display *display, wl_notify_func_t notify)
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)
void wl_global_remove(struct wl_global *global)
Broadcast a global remove event to all clients without destroying the global. This function can only be called once per global.
wl_global_destroy() removes the global and immediately destroys it. On the other end, this function only removes the global, allowing clients that have not yet received the global remove event to continue to bind to it.
This can be used by compositors to mitigate clients being disconnected because a global has been added and removed too quickly. Compositors can call wl_global_remove(), then wait an implementation-defined amount of time, then call wl_global_destroy(). Note that the destruction of a global is still racy, since clients have no way to acknowledge that they received the remove event.
Since: 1.17.90
void wl_global_destroy(struct wl_global *global)
void wl_display_set_global_filter(struct wl_display *display, wl_display_global_filter_func_t filter, void *data)
const struct wl_interface * wl_global_get_interface(const struct wl_global *global)
uint32_t wl_global_get_name(const struct wl_global *global, const struct wl_client *client)
uint32_t wl_global_get_version(const struct wl_global *global)
struct wl_display * wl_global_get_display(const struct wl_global *global)
void * wl_global_get_user_data(const struct wl_global *global)
void wl_global_set_user_data(struct wl_global *global, void *data)
Since: 1.17.90
struct wl_client * wl_client_create(struct wl_display *display, int fd)
struct wl_list * wl_display_get_client_list(struct wl_display *display)
struct wl_list * wl_client_get_link(struct wl_client *client)
struct wl_client * wl_client_from_link(struct wl_list *link)
void wl_client_destroy(struct wl_client *client)
void wl_client_flush(struct wl_client *client)
void wl_client_get_credentials(struct wl_client *client, pid_t *pid, uid_t *uid, gid_t *gid)
int wl_client_get_fd(struct wl_client *client)
void wl_client_add_destroy_listener(struct wl_client *client, struct wl_listener *listener)
struct wl_listener * wl_client_get_destroy_listener(struct wl_client *client, wl_notify_func_t notify)
void wl_client_add_destroy_late_listener(struct wl_client *client, struct wl_listener *listener)
struct wl_listener * wl_client_get_destroy_late_listener(struct wl_client *client, wl_notify_func_t notify)
struct wl_resource * wl_client_get_object(struct wl_client *client, uint32_t id)
void wl_client_post_no_memory(struct wl_client *client)
void wl_client_post_implementation_error(struct wl_client *client, const char *msg,...)
void wl_client_add_resource_created_listener(struct wl_client *client, struct wl_listener *listener)
void wl_client_for_each_resource(struct wl_client *client, wl_client_for_each_resource_iterator_func_t iterator, void *user_data)
void wl_client_set_user_data(struct wl_client *client, void *data, wl_user_data_destroy_func_t dtor)
void * wl_client_get_user_data(struct wl_client *client)
void wl_client_set_max_buffer_size(struct wl_client *client, size_t max_buffer_size)
void wl_signal_emit_mutable(struct wl_signal *signal, void *data)
void wl_resource_post_event(struct wl_resource *resource, uint32_t opcode,...)
void wl_resource_post_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
void wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode,...)
void wl_resource_queue_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
void wl_resource_post_error(struct wl_resource *resource, uint32_t code, const char *msg,...)
void wl_resource_post_no_memory(struct wl_resource *resource)
struct wl_display * wl_client_get_display(struct wl_client *client)
struct wl_resource * wl_resource_create(struct wl_client *client, const struct wl_interface *interface, int version, uint32_t id)
void wl_resource_set_implementation(struct wl_resource *resource, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
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)
void wl_resource_destroy(struct wl_resource *resource)
uint32_t wl_resource_get_id(struct wl_resource *resource)
struct wl_list * wl_resource_get_link(struct wl_resource *resource)
struct wl_resource * wl_resource_from_link(struct wl_list *resource)
struct wl_resource * wl_resource_find_for_client(struct wl_list *list, struct wl_client *client)
struct wl_client * wl_resource_get_client(struct wl_resource *resource)
void wl_resource_set_user_data(struct wl_resource *resource, void *data)
void * wl_resource_get_user_data(struct wl_resource *resource)
int wl_resource_get_version(struct wl_resource *resource)
void wl_resource_set_destructor(struct wl_resource *resource, wl_resource_destroy_func_t destroy)
int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, const void *implementation)
const char * wl_resource_get_class(struct wl_resource *resource)
void wl_resource_add_destroy_listener(struct wl_resource *resource, struct wl_listener *listener)
struct wl_listener * wl_resource_get_destroy_listener(struct wl_resource *resource, wl_notify_func_t notify)
struct wl_shm_buffer * wl_shm_buffer_get(struct wl_resource *resource)
void wl_shm_buffer_begin_access(struct wl_shm_buffer *buffer)
void wl_shm_buffer_end_access(struct wl_shm_buffer *buffer)
void * wl_shm_buffer_get_data(struct wl_shm_buffer *buffer)
int32_t wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer)
uint32_t wl_shm_buffer_get_format(struct wl_shm_buffer *buffer)
int32_t wl_shm_buffer_get_width(struct wl_shm_buffer *buffer)
int32_t wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
struct wl_shm_pool * wl_shm_buffer_ref_pool(struct wl_shm_buffer *buffer)
void wl_shm_pool_unref(struct wl_shm_pool *pool)
int wl_display_init_shm(struct wl_display *display)
uint32_t * wl_display_add_shm_format(struct wl_display *display, uint32_t format)
WL_DEPRECATED 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)
void wl_log_set_handler_server(wl_log_func_t handler)
struct wl_protocol_logger * wl_display_add_protocol_logger(struct wl_display *display, wl_protocol_logger_func_t, void *user_data)
void wl_protocol_logger_destroy(struct wl_protocol_logger *logger)
void wl_resource_post_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
void wl_resource_post_event(struct wl_resource *resource, uint32_t opcode,...)
void wl_resource_queue_event_array(struct wl_resource *resource, uint32_t opcode, union wl_argument *args)
void wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode,...)
void wl_resource_post_error(struct wl_resource *resource, uint32_t code, const char *msg,...)
void wl_client_post_no_memory(struct wl_client *client)
void wl_resource_post_no_memory(struct wl_resource *resource)
void wl_resource_destroy(struct wl_resource *resource)
uint32_t wl_resource_get_id(struct wl_resource *resource)
struct wl_list * wl_resource_get_link(struct wl_resource *resource)
struct wl_resource * wl_resource_from_link(struct wl_list *link)
struct wl_resource * wl_resource_find_for_client(struct wl_list *list, struct wl_client *client)
struct wl_client * wl_resource_get_client(struct wl_resource *resource)
void wl_resource_set_user_data(struct wl_resource *resource, void *data)
void * wl_resource_get_user_data(struct wl_resource *resource)
int wl_resource_get_version(struct wl_resource *resource)
void wl_resource_set_destructor(struct wl_resource *resource, wl_resource_destroy_func_t destroy)
int wl_resource_instance_of(struct wl_resource *resource, const struct wl_interface *interface, const void *implementation)
void wl_resource_add_destroy_listener(struct wl_resource *resource, struct wl_listener *listener)
struct wl_listener * wl_resource_get_destroy_listener(struct wl_resource *resource, wl_notify_func_t notify)
struct wl_listener * wl_client_get_destroy_listener(struct wl_client *client, wl_notify_func_t notify)
struct wl_listener * wl_client_get_destroy_late_listener(struct wl_client *client, wl_notify_func_t notify)
void wl_client_destroy(struct wl_client *client)
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)
void wl_global_remove(struct wl_global *global)
Broadcast a global remove event to all clients without destroying the global. This function can only be called once per global.
wl_global_destroy() removes the global and immediately destroys it. On the other end, this function only removes the global, allowing clients that have not yet received the global remove event to continue to bind to it.
This can be used by compositors to mitigate clients being disconnected because a global has been added and removed too quickly. Compositors can call wl_global_remove(), then wait an implementation-defined amount of time, then call wl_global_destroy(). Note that the destruction of a global is still racy, since clients have no way to acknowledge that they received the remove event.
Since: 1.17.90
void wl_global_destroy(struct wl_global *global)
const struct wl_interface * wl_global_get_interface(const struct wl_global *global)
void * wl_global_get_user_data(const struct wl_global *global)
void wl_global_set_user_data(struct wl_global *global, void *data)
Since: 1.17.90
struct wl_event_loop * wl_display_get_event_loop(struct wl_display *display)
void wl_display_terminate(struct wl_display *display)
void wl_display_run(struct wl_display *display)
void wl_display_flush_clients(struct wl_display *display)
const char * wl_display_add_socket_auto(struct wl_display *display)
void wl_display_add_destroy_listener(struct wl_display *display, struct wl_listener *listener)
void wl_display_add_client_created_listener(struct wl_display *display, struct wl_listener *listener)
When a new client object is created, listener will be notified, carrying a pointer to the new wl_client object.
wl_client_create wl_display wl_listener
struct wl_listener * wl_display_get_destroy_listener(struct wl_display *display, wl_notify_func_t notify)
void wl_resource_set_implementation(struct wl_resource *resource, const void *implementation, void *data, wl_resource_destroy_func_t destroy)
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)
void wl_log_set_handler_server(wl_log_func_t handler)
WL_DEPRECATED uint32_t wl_client_add_resource(struct wl_client *client, struct wl_resource *resource)
WL_DEPRECATED 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 struct wl_resource * wl_client_new_object(struct wl_client *client, const struct wl_interface *interface, const void *implementation, void *data)
WL_DEPRECATED 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 void wl_display_remove_global(struct wl_display *display, struct wl_global *global)
int wl_display_init_shm(struct wl_display *display)
struct wl_shm_buffer * wl_shm_buffer_get(struct wl_resource *resource)
int32_t wl_shm_buffer_get_stride(struct wl_shm_buffer *buffer)
uint32_t wl_shm_buffer_get_format(struct wl_shm_buffer *buffer)
int32_t wl_shm_buffer_get_width(struct wl_shm_buffer *buffer)
int32_t wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
See also: https://gcc.gnu.org/onlinedocs/gcc-3.2.1/gcc/Function-Attributes.html
This macro allows "conversion" from a pointer to a member to its containing struct. This is useful if you have a contained item like a wl_list, wl_listener, or wl_signal, provided via a callback or other means, and would like to retrieve the struct that contains it.
To demonstrate, the following example retrieves a pointer to example_container given only its destroy_listener member:
struct example_container { struct wl_listener destroy_listener; // other members... }; void example_container_destroy(struct wl_listener *listener, void *data) { struct example_container *ctr; ctr = wl_container_of(listener, ctr, destroy_listener); // destroy ctr... }
Note: sample need not be a valid pointer. A null or uninitialised pointer is sufficient.
See also: wl_client_for_each_resource_iterator_func_t See also: wl_client_for_each_resource
typedef int32_t wl_fixed_t
A wl_fixed_t is a 24.8 signed fixed-point number with a sign bit, 23 bits of integer precision and 8 bits of decimal precision. Consider wl_fixed_t as an opaque struct with methods that facilitate conversion to and from double and int types.
typedef int(* wl_dispatcher_func_t) (const void *user_data, void *target, uint32_t opcode, const struct wl_message *msg, union wl_argument *args))(const void *user_data, void *target, uint32_t opcode, const struct wl_message *msg, union wl_argument *args)
A dispatcher is a function that handles the emitting of callbacks in client code. For programs directly using the C library, this is done by using libffi to call function pointers. When binding to languages other than C, dispatchers provide a way to abstract the function calling process to be friendlier to other function calling systems.
A dispatcher takes five arguments: The first is the dispatcher-specific implementation associated with the target object. The second is the object upon which the callback is being invoked (either wl_proxy or wl_resource). The third and fourth arguments are the opcode and the wl_message corresponding to the callback. The final argument is an array of arguments received from the other process via the wire protocol.
typedef void(* wl_log_func_t) (const char *fmt, va_list args))(const char *fmt, va_list args)
The C implementation of the Wayland protocol abstracts the details of logging. Users may customize the logging behavior, with a function conforming to the wl_log_func_t type, via wl_log_set_handler_client and wl_log_set_handler_server.
A wl_log_func_t must conform to the expectations of vprintf, and expects two arguments: a string to write and a corresponding variable argument list. While the string to write may contain format specifiers and use values in the variable argument list, the behavior of any wl_log_func_t depends on the implementation.
Note: Take care to not confuse this with wl_protocol_logger_func_t, which is a specific server-side logger for requests and events.
See also: wl_log_set_handler_client See also: wl_log_set_handler_server