wayland::display_t(3)
NAME π
okay so this is the manual page for wayland::display_t(3), and wayland::display_t Represents a connection to the compositor and acts as a proxy to the display singleton object. bestie, thatβs the whole vibe: itβs the display connection AND the display singleton proxy. iconic behavior π
SYNOPSIS π
#include <wayland-client.hpp>
Inherits wayland::proxy_t.
Public Types π
enum class wrapper_type { standard, display, foreign, proxy_wrapper }
Public Member Functions β¨
display_t (int fd)β Connect to Wayland display on an already open fd.display_t (const std::string &name={})β Connect to a Wayland display.display_t (wl_display *display)β Use an existing connection to a Wayland display to construct a waylandppdisplay_t.~display_t () noexcept=defaultβ Close a connection to a Wayland display.event_queue_t create_queue () constβ Create a new event queue for this display.int get_fd () constβ Get a display contextβs file descriptor.int roundtrip () constβ Block until all pending request are processed by the server.int roundtrip_queue (const event_queue_t &queue) constβ Block until all pending request are processed by the server.read_intent obtain_read_intent () constβ Announce calling threadβs intention to read events from the Wayland display file descriptor.read_intent obtain_queue_read_intent (const event_queue_t &queue) constβ Announce calling threadβs intention to read events from the Wayland display file descriptor.int dispatch_queue (const event_queue_t &queue) constβ Dispatch events in an event queue.int dispatch_queue_pending (const event_queue_t &queue) constβ Dispatch pending events in an event queue.int dispatch () constβ Process incoming events.int dispatch_pending () constβ Dispatch main queue events without reading from the display fd.int get_error () constβ Retrieve the last error that occurred on a display.std::tuple< int, bool > flush () constβ Send all buffered requests on the display to the server.callback_t sync ()β asynchronous roundtripregistry_t get_registry ()β get global registry objectdisplay_t proxy_create_wrapper ()β create proxy wrapper for this displayuint32_t get_id () constβ Get the id of a proxy object.std::string get_class () constβ Get the interface name (class) of a proxy object.uint32_t get_version () constβ Get the protocol object version of a proxy object.wrapper_type get_wrapper_type () constβ Get the type of a proxy object.void set_queue (event_queue_t queue)β Assign a proxy to an event queue.wl_proxy * c_ptr () constβ Get a pointer to the underlying C struct.bool proxy_has_object () constβ Check whether this wrapper actually wraps an object.operator bool () constβ Check whether this wrapper actually wraps an object.bool operator== (const proxy_t &right) constβ Check whether two wrappers refer to the same object.bool operator!= (const proxy_t &right) constβ Check whether two wrappers refer to different objects.void proxy_release ()β Release the wrapped object (if any), making this an empty wrapper.
Detailed Description π
Represents a connection to the compositor and acts as a proxy to the display singleton object.
A display_t object represents a client connection to a Wayland compositor. It is created with display_t::display_t(). A connection is terminated using display_t::~display_t().
A display_t is also used as the proxy for the display singleton object on the compositor side. A display_t object handles all the data sent from and to the compositor. When a proxy_t 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 display_t::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 proxy_t is called.
A display has at least one event queue, called the main queue. Clients can create additional event queues with display_t::create_queue() and assign proxy_tβ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 display_t::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 display_t::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 display_t::dispatch_pending() before flushing and blocking.
Examples π¦
dump.cppegl.cppforeign_display.cppproxy_wrapper.cpp
Definition at line 479 of file wayland-client.hpp.
Member Enumeration Documentation π§
enum class wayland::proxy_t::wrapper_type [strong], [inherited]
Underlying wl_proxy type and properties of a proxy_t that affect construction, destruction, and event handling.
Enumerator π
standardβ C pointer is a standard type compatible withwl_proxy*. Events are dispatched and it is destructed when theproxy_tis destructed. User data is set.displayβ C pointer is awl_display*. No events are dispatched,wl_display_disconnectis called when theproxy_tis destructed. User data is set.foreignβ C pointer is a standard type compatible withwl_proxy*, but another library owns it and it should not be touched in a way that could affect the operation of the other library. No events are dispatched,wl_proxy_destroyis not called when theproxy_tis destructed, user data is not touched. Consequently, there is no reference counting for theproxy_t. Lifetime of such wrappers should preferably be short to minimize the chance that the owning library decides to destroy thewl_proxy.proxy_wrapperβ C pointer is awl_proxy*that was constructed withwl_proxy_create_wrapper. No events are dispatched,wl_proxy_wrapper_destroyis called when theproxy_tis destroyed. Reference counting is active. A reference to theproxy_tcreating this proxy wrapper is held to extend its lifetime until after the proxy wrapper is destroyed.
Definition at line 117 of file wayland-client.hpp.
Constructor & Destructor Documentation π
wayland::display_t::display_t (int fd)
Connect to Wayland display on an already open fd.
Parameters: fd β The fd to use for the connection
The display_t takes ownership of the fd and will close it when the display is destroyed. The fd will also be closed in case of failure. no cap, itβs got custody of that fd now π
wayland::display_t::display_t (const std::string & name = {})
Connect to a Wayland display.
Parameters: name β Optional name of the Wayland display to connect to
Connect to the Wayland display named name. If name is empty, its value will be replaced with the WAYLAND_DISPLAY environment variable if it is set, otherwise display "wayland-0" will be used.
wayland::display_t::display_t (wl_display * display) [explicit]
Use an existing connection to a Wayland display to construct a waylandpp display_t.
Parameters: display β C wl_display pointer to use; must not be nullptr
A wl_display* that was already established using the C wayland-client API is wrapped in a waylandpp display_t instance so it can be used easily from C++. Ownership of the display is not taken, so this may be used for wrapping a wl_display connection established by another library.
On destruction of the display_t, wl_display_disconnect is not called and no resources are freed. It is the responsibility of the caller to make sure that the wl_display and the display_t are not used simultaneously in incompatible ways. It is especially problematic if the wl_display is destroyed while the display_t wrapper is still being used. this part is serious, bestie β incompatible simultaneous use is giving undefined chaos π
Whether the wl_display or the display_t is destructed first ultimately does not matter, but any waylandpp proxy_t instances must be destructed or have their owned objects released before the wl_display is destroyed. Otherwise, the proxy_t destructor will try to free the underlying wl_proxy that was already destroyed together with the wl_display.
wayland::display_t::~display_t () [default], [noexcept]
Close a connection to a Wayland display. Close the connection to display and free all resources associated with it. This does not apply to display_t instances that are wrappers for a pre-established C wl_display.
Member Function Documentation π
wl_proxy * wayland::proxy_t::c_ptr () const [inherited]
Get a pointer to the underlying C struct.
Returns: The underlying wl_proxy wrapped by this proxy_t if it exists, otherwise an exception is thrown
event_queue_t wayland::display_t::create_queue () const
Create a new event queue for this display.
Returns: A new event queue associated with this display or NULL on failure.
Examples: proxy_wrapper.cpp.
int wayland::display_t::dispatch () const
Process incoming events.
Returns: The number of dispatched events
Exceptions: std::system_error on failure
Dispatch the displayβs main event queue. main character queue energy, literally π
So if the main event queue is empty, this function blocks until there are events to read from the display fd. β¨ Events get read and queued on the appropriate event queues, and finally the events on the main event queue are dispatched. That's the whole little ritual, bestie.
Note: it is not possible to check if there are events on the main queue or not. For dispatching main queue events without blocking, seedisplay_t::dispatch_pending(). Calling this will release the display file descriptor if this thread acquired it usingdisplay_t::acquire_fd().
See also: display_t::dispatch_pending(), display_t::dispatch_queue().
int wayland::display_t::dispatch_pending () const
Dispatch main queue events without reading from the display fd. π«Ά
Returns β The number of dispatched events.
Exceptions β std::system_error 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. Iconic behavior, honestly.
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. π Not the vibe.
To properly integrate the wayland display fd into a main loop, the client should always call display_t::dispatch_pending() and then display_t::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 display_t::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: display_t::dispatch(), display_t::dispatch_queue(), display_t::flush().
int wayland::display_t::dispatch_queue (const event_queue_t & queue) const
Dispatch events in an event queue. πΈ
Parameters
queueβ The event queue to dispatch.
Returns β The number of dispatched events.
Exceptions β std::system_error 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. β
int wayland::display_t::dispatch_queue_pending (const event_queue_t & queue) const
Dispatch pending events in an event queue. π¦
Parameters
queueβ The event queue to dispatch.
Returns β The number of dispatched events.
Exceptions β std::system_error 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. No blocking, no drama. π
std::tuple< int, bool > wayland::display_t::flush () const
Send all buffered requests on the display to the server. β¨
Returns β Tuple of the number of bytes sent and whether all data was sent.
Exceptions β std::system_error 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.
display_t::flush() never blocks. It will write as much data as possible, but if all data could not be written, the second element in the returned tuple will be set to false. In that case, use poll on the display file descriptor to wait for it to become writable again. π₯
std::string wayland::proxy_t::get_class () const [inherited]
Get the interface name (class) of a proxy object.
Returns β The interface name of the object associated with the proxy.
int wayland::display_t::get_error () const
Retrieve the last error that occurred on a display.
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. π
int wayland::display_t::get_fd () const
Get a display context's file descriptor.
Returns β Display object file descriptor.
Return the file descriptor associated with a display so it can be integrated into the client's main loop. π«Ά
uint32_t wayland::proxy_t::get_id () const [inherited]
Get the id of a proxy object.
Returns β The id the object associated with the proxy.
registry_t wayland::display_t::get_registry ()
Get global registry object. This request creates a registry object that allows the client to list and bind the global objects available from the compositor. π
Examples β dump.cpp, and proxy_wrapper.cpp.
uint32_t wayland::proxy_t::get_version () const [inherited]
Get the protocol object version of a proxy object. Gets the protocol object version of a proxy object, or 0 if the proxy was created with unversioned API.
A returned value of 0 means that no version information is available, so the caller must make safe assumptions about the object's real version. π
display_t will always return version 0.
Returns β The protocol object version of the proxy or 0.
wrapper_type wayland::proxy_t::get_wrapper_type () const [inline], [inherited]
Get the type of a proxy object.
Definition at line 303 of file wayland-client.hpp.
read_intent wayland::display_t::obtain_queue_read_intent (const event_queue_t & queue) const
Announce calling thread's intention to read events from the Wayland display file descriptor. π§
Parameters
queueβ event queue for which the read event will be valid.
Returns β New read_intent for this display and the specified event queue.
Exceptions β std::system_error on failure.
See obtain_read_intent for details.
read_intent wayland::display_t::obtain_read_intent () const
Announce calling thread's intention to read events from the Wayland display file descriptor. This ensures that until the thread is ready to read and calls read_intent::read, no other thread will read from the file descriptor. During preparation, all undispatched events in the event queue are dispatched until the queue is empty. π
Use this function before polling on the display fd or to integrate the fd into a toolkit event loop in a race-free way.
Typical usage is:
auto read_intent = display.obtain_read_intent();
display.flush();
poll(fds, nfds, -1); // Custom poll() handling is possible here
if(fd.revents & POLLIN)
read_intent.read();
display.dispatch_pending();
The read_intent ensures that if the above code e.g. throws an exception before actually reading from the file descriptor or times out in poll(), the read intent is always cancelled so other threads can proceed. π
In one thread, do not hold more than one read intent for the same display at the same time, irrespective of the event queue.
Returns β New read_intent for this display and the default event queue.
Exceptions β std::system_error on failure.
wayland::proxy_t::operator bool () const [inherited]
Check whether this wrapper actually wraps an object.
Returns β true if there is an underlying object, false if this wrapper is empty.
bool wayland::proxy_t::operator!= (const proxy_t & right) const [inherited]
Check whether two wrappers refer to different objects.
bool wayland::proxy_t::operator== (const proxy_t & right) const [inherited]
Check whether two wrappers refer to the same object.
display_t wayland::display_t::proxy_create_wrapper ()
Create proxy wrapper for this display. π
Examples β proxy_wrapper.cpp.
bool wayland::proxy_t::proxy_has_object () const [inherited]
Check whether this wrapper actually wraps an object.
Returns β true if there is an underlying object, false if this wrapper is empty.
void wayland::proxy_t::proxy_release () [inherited]
Release the wrapped object (if any), making this an empty wrapper. Note that display_t instances cannot be released this way. Attempts to do so are ignored. π
Examples β foreign_display.cpp.
int wayland::display_t::roundtrip () const
Block until all pending request are processed by the server.
Returns β The number of dispatched events.
Exceptions β std::system_error on failure.
Blocks until the server process all currently issued requests and sends out pending events on all event queues. β
int wayland::display_t::roundtrip_queue (const event_queue_t & queue) const
Block until all pending request are processed by the server.
Returns β The number of dispatched events.
Exceptions β std::system_error on failure.
Blocks until the server processes all currently issued requests and sends out pending events on the event queue.
Note: This function usesdispatch_queue()internally. If you are usingread_events()from more threads, don't use this function (or make sure that callingroundtrip_queue()doesn't interfere with callingprepare_read()andread_events()).
Examples β proxy_wrapper.cpp.
void wayland::proxy_t::set_queue (event_queue_t queue) [inherited]
Assign a proxy to an event queue.
Parameters
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: display_t::dispatch_queue().
Examples β proxy_wrapper.cpp.
callback_t wayland::display_t::sync ()
Asynchronous roundtrip. The sync request asks the server to emit the 'done' event on the returned callback_t object. Since requests are handled in-order and events are delivered in-order, this can be used as a barrier to ensure all previous requests and the resulting events have been handled. π₯
The object returned by this request will be destroyed by the compositor after the callback is fired and as such the client must not attempt to use it after that point. π
π Author
Generated automatically by Doxygen for Wayland++ from the source code.
This little manual masterpiece was auto-cooked by Doxygen for Wayland++ straight from the source code, version 1.0.1, dated Fri Mar 27 2026 13:15:00, and it's the wayland::display_t(3) page. Go forth and slay your event loop, bestie! π
β¨πΈ
π¦ where this page comes from
- ubuntu stonking: waylandpp-dev 1.0.1-2 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms