.TH "wayland::display_t" 3 "Wed May 3 2023" "Version 1.0.0" "Wayland++" \" -*- nroff -*- .ad l .nh .SH NAME wayland::display_t \- Represents a connection to the compositor and acts as a proxy to the display singleton object\&. .SH SYNOPSIS .br .PP .PP \fC#include \fP .PP Inherits \fBwayland::proxy_t\fP\&. .SS "Public Types" .in +1c .ti -1c .RI "enum class \fBwrapper_type\fP { \fBstandard\fP, \fBdisplay\fP, \fBforeign\fP, \fBproxy_wrapper\fP }" .br .in -1c .SS "Public Member Functions" .in +1c .ti -1c .RI "\fBdisplay_t\fP (int fd)" .br .RI "Connect to Wayland display on an already open fd\&. " .ti -1c .RI "\fBdisplay_t\fP (const std::string &name={})" .br .RI "Connect to a Wayland display\&. " .ti -1c .RI "\fBdisplay_t\fP (wl_display *display)" .br .RI "Use an existing connection to a Wayland display to construct a waylandpp \fBdisplay_t\fP\&. " .ti -1c .RI "\fB~display_t\fP () noexcept=default" .br .RI "Close a connection to a Wayland display\&. " .ti -1c .RI "\fBevent_queue_t\fP \fBcreate_queue\fP () const" .br .RI "Create a new event queue for this display\&. " .ti -1c .RI "int \fBget_fd\fP () const" .br .RI "Get a display context's file descriptor\&. " .ti -1c .RI "int \fBroundtrip\fP () const" .br .RI "Block until all pending request are processed by the server\&. " .ti -1c .RI "int \fBroundtrip_queue\fP (const \fBevent_queue_t\fP &queue) const" .br .RI "Block until all pending request are processed by the server\&. " .ti -1c .RI "\fBread_intent\fP \fBobtain_read_intent\fP () const" .br .RI "Announce calling thread's intention to read events from the Wayland display file descriptor\&. " .ti -1c .RI "\fBread_intent\fP \fBobtain_queue_read_intent\fP (const \fBevent_queue_t\fP &queue) const" .br .RI "Announce calling thread's intention to read events from the Wayland display file descriptor\&. " .ti -1c .RI "int \fBdispatch_queue\fP (const \fBevent_queue_t\fP &queue) const" .br .RI "Dispatch events in an event queue\&. " .ti -1c .RI "int \fBdispatch_queue_pending\fP (const \fBevent_queue_t\fP &queue) const" .br .RI "Dispatch pending events in an event queue\&. " .ti -1c .RI "int \fBdispatch\fP () const" .br .RI "Process incoming events\&. " .ti -1c .RI "int \fBdispatch_pending\fP () const" .br .RI "Dispatch main queue events without reading from the display fd\&. " .ti -1c .RI "int \fBget_error\fP () const" .br .RI "Retrieve the last error that occurred on a display\&. " .ti -1c .RI "std::tuple< int, bool > \fBflush\fP () const" .br .RI "Send all buffered requests on the display to the server\&. " .ti -1c .RI "\fBcallback_t\fP \fBsync\fP ()" .br .RI "asynchronous roundtrip " .ti -1c .RI "\fBregistry_t\fP \fBget_registry\fP ()" .br .RI "get global registry object " .ti -1c .RI "\fBdisplay_t\fP \fBproxy_create_wrapper\fP ()" .br .RI "create proxy wrapper for this display " .ti -1c .RI "uint32_t \fBget_id\fP () const" .br .RI "Get the id of a proxy object\&. " .ti -1c .RI "std::string \fBget_class\fP () const" .br .RI "Get the interface name (class) of a proxy object\&. " .ti -1c .RI "uint32_t \fBget_version\fP () const" .br .RI "Get the protocol object version of a proxy object\&. " .ti -1c .RI "\fBwrapper_type\fP \fBget_wrapper_type\fP () const" .br .RI "Get the type of a proxy object\&. " .ti -1c .RI "void \fBset_queue\fP (\fBevent_queue_t\fP queue)" .br .RI "Assign a proxy to an event queue\&. " .ti -1c .RI "wl_proxy * \fBc_ptr\fP () const" .br .RI "Get a pointer to the underlying C struct\&. " .ti -1c .RI "bool \fBproxy_has_object\fP () const" .br .RI "Check whether this wrapper actually wraps an object\&. " .ti -1c .RI "\fBoperator bool\fP () const" .br .RI "Check whether this wrapper actually wraps an object\&. " .ti -1c .RI "bool \fBoperator==\fP (const \fBproxy_t\fP &right) const" .br .RI "Check whether two wrappers refer to the same object\&. " .ti -1c .RI "bool \fBoperator!=\fP (const \fBproxy_t\fP &right) const" .br .RI "Check whether two wrappers refer to different objects\&. " .ti -1c .RI "void \fBproxy_release\fP ()" .br .RI "Release the wrapped object (if any), making this an empty wrapper\&. " .in -1c .SH "Detailed Description" .PP Represents a connection to the compositor and acts as a proxy to the display singleton object\&. A \fBdisplay_t\fP object represents a client connection to a Wayland compositor\&. It is created with display_t::display_t()\&. A connection is terminated using \fBdisplay_t::~display_t()\fP\&. .PP A \fBdisplay_t\fP is also used as the proxy for the display singleton object on the compositor side\&. A \fBdisplay_t\fP object handles all the data sent from and to the compositor\&. When a \fBproxy_t\fP 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 \fBdisplay_t::flush()\fP\&. .PP 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 \fBproxy_t\fP is called\&. .PP A display has at least one event queue, called the main queue\&. Clients can create additional event queues with \fBdisplay_t::create_queue()\fP and assign \fBproxy_t\fP'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\&. .PP The main queue is dispatched by calling \fBdisplay_t::dispatch()\fP\&. 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\&. .PP A user created queue is dispatched with \fBdisplay_t::dispatch_queue()\fP\&. 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\&. .PP 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\&. .PP 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 \fBdisplay_t::dispatch_pending()\fP before flushing and blocking\&. .PP \fBExamples\fP .in +1c \fBdump\&.cpp\fP, \fBegl\&.cpp\fP, \fBforeign_display\&.cpp\fP, \fBproxy_wrapper\&.cpp\fP, and \fBshm\&.cpp\fP\&. .PP Definition at line \fB477\fP of file \fBwayland\-client\&.hpp\fP\&. .SH "Member Enumeration Documentation" .PP .SS "enum class \fBwayland::proxy_t::wrapper_type\fP\fC [strong]\fP, \fC [inherited]\fP" Underlying wl_proxy type and properties of a \fBproxy_t\fP that affect construction, destruction, and event handling .PP \fBEnumerator\fP .in +1c .TP \fB\fIstandard \fP\fP C pointer is a standard type compatible with wl_proxy*\&. Events are dispatched and it is destructed when the \fBproxy_t\fP is destructed\&. User data is set\&. .TP \fB\fIdisplay \fP\fP C pointer is a wl_display*\&. No events are dispatched, wl_display_disconnect is called when the \fBproxy_t\fP is destructed\&. User data is set\&. .TP \fB\fIforeign \fP\fP C pointer is a standard type compatible with wl_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_destroy is not called when the \fBproxy_t\fP is destructed, user data is not touched\&. Consequently, there is no reference counting for the \fBproxy_t\fP\&. Lifetime of such wrappers should preferably be short to minimize the chance that the owning library decides to destroy the wl_proxy\&. .TP \fB\fIproxy_wrapper \fP\fP C pointer is a wl_proxy* that was constructed with wl_proxy_create_wrapper\&. No events are dispatched, wl_proxy_wrapper_destroy is called when the \fBproxy_t\fP is destroyed\&. Reference counting is active\&. A reference to the \fBproxy_t\fP creating this proxy wrapper is held to extend its lifetime until after the proxy wrapper is destroyed\&. .PP Definition at line \fB115\fP of file \fBwayland\-client\&.hpp\fP\&. .SH "Constructor & Destructor Documentation" .PP .SS "wayland::display_t::display_t (int fd)" .PP Connect to Wayland display on an already open fd\&. .PP \fBParameters\fP .RS 4 \fIfd\fP The fd to use for the connection .RE .PP The \fBdisplay_t\fP takes ownership of the fd and will close it when the display is destroyed\&. The fd will also be closed in case of failure\&. .SS "wayland::display_t::display_t (const std::string & name = \fC{}\fP)" .PP Connect to a Wayland display\&. .PP \fBParameters\fP .RS 4 \fIname\fP Optional name of the Wayland display to connect to .RE .PP 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\&. .SS "wayland::display_t::display_t (wl_display * display)\fC [explicit]\fP" .PP Use an existing connection to a Wayland display to construct a waylandpp \fBdisplay_t\fP\&. .PP \fBParameters\fP .RS 4 \fIdisplay\fP C wl_display pointer to use; must not be nullptr .RE .PP A wl_display* that was already established using the C wayland-client API is wrapped in an waylandpp \fBdisplay_t\fP 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\&. .PP On destruction of the \fBdisplay_t\fP, 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 \fBdisplay_t\fP are not used simultaneously in incompatible ways\&. It is especially problematic if the wl_display is destroyed while the \fBdisplay_t\fP wrapper is still being used\&. .PP Whether the wl_display or the \fBdisplay_t\fP is destructed first ultimately does not matter, but any waylandpp \fBproxy_t\fP instances must be destructed or have their owned objects released before the wl_display is destroyed\&. Otherwise, the \fBproxy_t\fP destructor will try to free the underlying wl_proxy that was already destroyed together with the wl_display\&. .SS "wayland::display_t::~display_t ()\fC [default]\fP, \fC [noexcept]\fP" .PP Close a connection to a Wayland display\&. Close the connection to display and free all resources associated with it\&. This does not apply to \fBdisplay_t\fP instances that are wrappers for a pre-established C wl_display\&. .SH "Member Function Documentation" .PP .SS "wl_proxy * wayland::proxy_t::c_ptr () const\fC [inherited]\fP" .PP Get a pointer to the underlying C struct\&. .PP \fBReturns\fP .RS 4 The underlying wl_proxy wrapped by this \fBproxy_t\fP if it exists, otherwise an exception is thrown .RE .PP .SS "\fBevent_queue_t\fP wayland::display_t::create_queue () const" .PP Create a new event queue for this display\&. .PP \fBReturns\fP .RS 4 A new event queue associated with this display or NULL on failure\&. .RE .PP .PP \fBExamples\fP .in +1c \fBproxy_wrapper\&.cpp\fP\&. .SS "int wayland::display_t::dispatch () const" .PP Process incoming events\&. .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP Dispatch the display's main event queue\&. .PP 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\&. .PP 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 \fBdisplay_t::dispatch_pending()\fP\&. Calling this will release the display file descriptor if this thread acquired it using display_t::acquire_fd()\&. .PP See also: \fBdisplay_t::dispatch_pending()\fP, \fBdisplay_t::dispatch_queue()\fP .PP \fBExamples\fP .in +1c \fBegl\&.cpp\fP, and \fBshm\&.cpp\fP\&. .SS "int wayland::display_t::dispatch_pending () const" .PP Dispatch main queue events without reading from the display fd\&. .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP 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\&. .PP 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\&. .PP To proper integrate the wayland display fd into a main loop, the client should always call \fBdisplay_t::dispatch_pending()\fP and then \fBdisplay_t::flush()\fP 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\&. .PP 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 \fBdisplay_t::dispatch_queue()\fP 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\&. .PP See also: \fBdisplay_t::dispatch()\fP, \fBdisplay_t::dispatch_queue()\fP, \fBdisplay_t::flush()\fP .SS "int wayland::display_t::dispatch_queue (const \fBevent_queue_t\fP & queue) const" .PP Dispatch events in an event queue\&. .PP \fBParameters\fP .RS 4 \fIqueue\fP The event queue to dispatch .RE .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP Dispatch all incoming events for objects assigned to the given event queue\&. On failure -1 is returned and errno set appropriately\&. .PP 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\&. .SS "int wayland::display_t::dispatch_queue_pending (const \fBevent_queue_t\fP & queue) const" .PP Dispatch pending events in an event queue\&. .PP \fBParameters\fP .RS 4 \fIqueue\fP The event queue to dispatch .RE .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP 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\&. .SS "std::tuple< int, bool > wayland::display_t::flush () const" .PP Send all buffered requests on the display to the server\&. .PP \fBReturns\fP .RS 4 Tuple of the number of bytes sent and whether all data was sent\&. .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP 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\&. .PP \fBdisplay_t::flush()\fP 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\&. .SS "std::string wayland::proxy_t::get_class () const\fC [inherited]\fP" .PP Get the interface name (class) of a proxy object\&. .PP \fBReturns\fP .RS 4 The interface name of the object associated with the proxy .RE .PP .SS "int wayland::display_t::get_error () const" .PP Retrieve the last error that occurred on a display\&. .PP \fBReturns\fP .RS 4 The last error that occurred on display or 0 if no error occurred .RE .PP Return the last error that occurred on the display\&. This may be an error sent by the server or caused by the local client\&. .PP Note: Errors are fatal\&. If this function returns non-zero the display can no longer be used\&. .SS "int wayland::display_t::get_fd () const" .PP Get a display context's file descriptor\&. .PP \fBReturns\fP .RS 4 Display object file descriptor .RE .PP Return the file descriptor associated with a display so it can be integrated into the client's main loop\&. .SS "uint32_t wayland::proxy_t::get_id () const\fC [inherited]\fP" .PP Get the id of a proxy object\&. .PP \fBReturns\fP .RS 4 The id the object associated with the proxy .RE .PP .SS "\fBregistry_t\fP wayland::display_t::get_registry ()" .PP 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\&. .PP \fBExamples\fP .in +1c \fBdump\&.cpp\fP, \fBegl\&.cpp\fP, \fBproxy_wrapper\&.cpp\fP, and \fBshm\&.cpp\fP\&. .SS "uint32_t wayland::proxy_t::get_version () const\fC [inherited]\fP" .PP 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\&. .PP 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\&. .PP \fBdisplay_t\fP will always return version 0\&. .PP \fBReturns\fP .RS 4 The protocol object version of the proxy or 0 .RE .PP .SS "\fBwrapper_type\fP wayland::proxy_t::get_wrapper_type () const\fC [inline]\fP, \fC [inherited]\fP" .PP Get the type of a proxy object\&. .PP Definition at line \fB301\fP of file \fBwayland\-client\&.hpp\fP\&. .SS "\fBread_intent\fP wayland::display_t::obtain_queue_read_intent (const \fBevent_queue_t\fP & queue) const" .PP Announce calling thread's intention to read events from the Wayland display file descriptor\&. .PP \fBParameters\fP .RS 4 \fIqueue\fP event queue for which the read event will be valid .RE .PP \fBReturns\fP .RS 4 New \fBread_intent\fP for this display and the specified event queue .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP See \fBobtain_read_intent\fP for details\&. .SS "\fBread_intent\fP wayland::display_t::obtain_read_intent () const" .PP 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 \fBread_intent::read\fP, 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\&. .PP Use this function before polling on the display fd or to integrate the fd into a toolkit event loop in a race-free way\&. .PP Typical usage is: .PP .PP .nf 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(); .fi .PP .PP The \fBread_intent\fP 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\&. .PP In one thread, do not hold more than one read intent for the same display at the same time, irrespective of the event queue\&. .PP \fBReturns\fP .RS 4 New \fBread_intent\fP for this display and the default event queue .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP .SS "wayland::proxy_t::operator bool () const\fC [inherited]\fP" .PP Check whether this wrapper actually wraps an object\&. .PP \fBReturns\fP .RS 4 true if there is an underlying object, false if this wrapper is empty .RE .PP .SS "bool wayland::proxy_t::operator!= (const \fBproxy_t\fP & right) const\fC [inherited]\fP" .PP Check whether two wrappers refer to different objects\&. .SS "bool wayland::proxy_t::operator== (const \fBproxy_t\fP & right) const\fC [inherited]\fP" .PP Check whether two wrappers refer to the same object\&. .SS "\fBdisplay_t\fP wayland::display_t::proxy_create_wrapper ()" .PP create proxy wrapper for this display .PP \fBExamples\fP .in +1c \fBproxy_wrapper\&.cpp\fP\&. .SS "bool wayland::proxy_t::proxy_has_object () const\fC [inherited]\fP" .PP Check whether this wrapper actually wraps an object\&. .PP \fBReturns\fP .RS 4 true if there is an underlying object, false if this wrapper is empty .RE .PP .SS "void wayland::proxy_t::proxy_release ()\fC [inherited]\fP" .PP Release the wrapped object (if any), making this an empty wrapper\&. Note that \fBdisplay_t\fP instances cannot be released this way\&. Attempts to do so are ignored\&. .PP \fBExamples\fP .in +1c \fBforeign_display\&.cpp\fP\&. .SS "int wayland::display_t::roundtrip () const" .PP Block until all pending request are processed by the server\&. .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP Blocks until the server process all currently issued requests and sends out pending events on all event queues\&. .PP \fBExamples\fP .in +1c \fBdump\&.cpp\fP, \fBegl\&.cpp\fP, and \fBshm\&.cpp\fP\&. .SS "int wayland::display_t::roundtrip_queue (const \fBevent_queue_t\fP & queue) const" .PP Block until all pending request are processed by the server\&. .PP \fBReturns\fP .RS 4 The number of dispatched events .RE .PP \fBExceptions\fP .RS 4 \fIstd::system_error\fP on failure .RE .PP Blocks until the server processes all currently issued requests and sends out pending events on the event queue\&. .PP Note: This function uses \fBdispatch_queue()\fP internally\&. If you are using read_events() from more threads, don't use this function (or make sure that calling \fBroundtrip_queue()\fP doesn't interfere with calling prepare_read() and read_events()) .PP \fBExamples\fP .in +1c \fBproxy_wrapper\&.cpp\fP\&. .SS "void wayland::proxy_t::set_queue (\fBevent_queue_t\fP queue)\fC [inherited]\fP" .PP Assign a proxy to an event queue\&. .PP \fBParameters\fP .RS 4 \fIqueue\fP The event queue that will handle this proxy .RE .PP Assign proxy to event queue\&. Events coming from proxy will be queued in queue instead of the display's main queue\&. .PP See also: \fBdisplay_t::dispatch_queue()\fP\&. .PP \fBExamples\fP .in +1c \fBproxy_wrapper\&.cpp\fP\&. .SS "\fBcallback_t\fP wayland::display_t::sync ()" .PP asynchronous roundtrip The sync request asks the server to emit the 'done' event on the returned \fBcallback_t\fP 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\&. .PP 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\&. .SH "Author" .PP Generated automatically by Doxygen for Wayland++ from the source code\&.