PYWAYLAND(1)
โจ NAME โจ
pywayland โ pywayland Documentation
okay so bestie, PyWayland is giving Python bindings to the Wayland library, and it does it in pure Python by making calls through the CFFI module. It supports Python >=3.6, including sufficiently new versions of PyPy 3. Heads up though: this is currently a highly experimental package, and the usage is likely to change between releases. Check back as development continues, contributions are always welcome! ๐
Check out the different sections below for info on installing and running PyWayland. There's also info on running and developing from source (feedback and contributions are always welcome on the issue tracker at https://github.com/flacjacket/pywayland/issues). And finally, the module documentation is included. ๐ซถ
๐ DOCUMENTATION ๐
๐ ๏ธ Installation ๐ ๏ธ
To install PyWayland, you'll need a base set of dependencies installed. That should be all the config required to run the packaged version on PyPI at https://pypi.python.org/pypi/pywayland. The extra steps to build and install from source are outlined below.
If you have any problems with anything outlined here, feedback is greatly appreciated at https://github.com/flacjacket/pywayland/issues. ๐
๐ฆ External Dependencies ๐ฆ
To run PyWayland, you need the Wayland libraries and headers installed so CFFI can find them. You can do this with the libwayland-dev apt package; however, note that it's probably best to use the most recent version of Wayland available from the Wayland releases site at https://wayland.freedesktop.org/releases.html, and the pip package will try to track the most recent version.
You'll also need the Python headers installed and a version of GCC to compile the cffi library. The headers are typically available through the python-dev package.
Optionally, you can have installed the wayland-protocols package, also available from the Wayland releases page at https://wayland.freedesktop.org/releases.html. The package uploaded to PyPI will already have these protocols included, so this is only needed if you plan on installing from source.
๐ Installing with pip ๐
Once the external dependencies are in place, you should just be able to run:
$ pip install pywayland
Any additional unfulfilled dependencies should be downloaded. โจ
๐ง Installing from Source ๐ง
You can download and run PyWayland from source, which will not only give you the latest improvements and fixes, but will let you build the protocol files against a different version than is available through pip (the version of Wayland the protocol is compiled against is listed on the top of the PyPI page at https://pypi.python.org/pypi/pywayland).
๐ธ Getting the Source ๐ธ
You can download the most recent version of PyWayland from the git repository at https://github.com/flacjacket/pywayland, or clone the repository as:
$ git clone https://github.com/flacjacket/pywayland.git
๐ Python Dependencies ๐
PyWayland depends on a minimal set of dependencies. All Python versions require cffi at https://cffi.readthedocs.org/en/latest/ (to perform Wayland library calls), which can be pip installed for non-PyPy installations. Note that PyPy platforms ship with cffi. ๐ฆ
๐งฌ Generating the Wayland Protocol ๐งฌ
At this point, you have the base PyWayland module, which contains some core objects and objects specific to client and server implementations. The client and server exchange messages defined in the Wayland protocol, which is an XML file that ships with Wayland. The scanner parses this XML file and generates the relevant objects.
If the Wayland protocol file is in the default location (/usr/share/wayland/wayland.xml) or can be found with pkg-config, you should be able to build the protocol files without any problems:
$ python -m pywayland.scanner
This will output the protocol files to the directory ./pywayland/protocol/. The input file and the output directory can be set from the command line options, see python -m pywayland.scanner -h for more information.
๐ Running PyWayland inplace ๐
Once the protocol files are created, you can generate the cffi module. Note: this is only required if you want to run from the source in place. If the libwayland header files are correctly installed, you'll just need to run:
$ python pywayland/ffi_build.py
At this point, you should be able to use the PyWayland library. You can check that you have everything installed correctly by running the associated test-suite (note that you'll also need pytest to run the tests). Simply run:
$ pytest
from the root directory. ๐
๐ฅ Installing PyWayland ๐ฅ
The package can be installed from source using typical setup.py mechanisms:
$ python setup.py install
Additional arguments can be used to automatically generate the Wayland protocols for the standard Wayland package (which will fail if it cannot run) and the wayland-protocols package (which will be attempted by default, but will not raise an error if it fails).
If you have any problems or have any feedback, please report back to the issue tracker at https://github.com/flacjacket/pywayland/issues, contribution is always welcome, see Contributing (#contributing). ๐
๐ Contributing ๐
[image: Build Status] [image] https://travis-ci.org/flacjacket/pywayland [image: Build Coverage] [image] https://coveralls.io/r/flacjacket/pywayland
Contributions of any form are always welcome, whether it's general feedback on the use of PyWayland, bug reports, or pull requests. All development is done through GitHub at https://github.com/flacjacket/pywayland/.
If you wish to develop PyWayland, it's recommended that you follow the outline given in Installing from Source (#install-source). A few things to be aware of when writing code:
- Continuous integration testing is done with Travis at https://travis-ci.org/flacjacket/pywayland, and tests are run against all supported Python versions (currently 3.6+ and PyPy 3). You can check that your changes pass locally by running
py.testfrom the root directory (this requires installing pytest at https://pytest.org). Currently, the tests also run with nose at https://nose.readthedocs.org, however, they may not always in the future. - Code coverage is assessed using Coveralls at https://coveralls.io/r/flacjacket/pywayland. Currently, coverage is fairly low, any work to help this would be greatly appreciated.
- Code quality is assessed in the tests with ruff at https://beta.ruff.rs/docs/, be sure any new code meets Python standards.
- Type annotations are included in much of the codebase and checked with mypy. Additional checks using other type checkers are appreciated.
๐ PyWayland Scanner ๐
The PyWayland scanner parses the wayland.xml protocol definition file and outputs interfaces with the events, requests, and enums defined by the protocol. See Scanner Modules (#scanner) for details on the scanner implementation. ๐
๐ป Command-line Invocation ๐ป
If you have installed PyWayland, the scanner is placed in your path as pywayland-scanner.py. By default, invoking the scanner reads in the XML file from /usr/share/wayland/wayland.xml and outputs the protocol definitions to ./protocol/.
If you are running PyWayland from source, you can use the scanner in ./bin/pywayland-scanner.py. This file sets the path to the current source directory and runs method used by the entry-point. Otherwise, this functions the same as above.
๐ Script Invocation ๐
In addition to the command-line use, you can use the scanner from within Python scripts. This is done, for example, when installing or building the docs to ensure the protocol modules are included in both. For details on invoking the scanner module, see Scanner. โญ
๐ Module Reference ๐
๐งธ Client Modules ๐งธ
The base set of objects used by Wayland clients. Users should only be directly creating Display and EventQueue objects. The Proxy objects to interfaces should be returned by making request calls.
๐ Display ๐
class pywayland.client.Display(name_or_fd: int | str | None = None)
Represents a connection to the compositor.
A Display object represents a client connection to a Wayland compositor. The connection and the corresponding Wayland object are created with Display.connect(). The display must be connected before it can be used. A connection is terminated using Display.disconnect().
A Display is also used as the Proxy for the pywayland.protocol.wayland.WlDisplay (#pywayland.protocol.wayland.WlDisplay) protocol object on the compositor side.
A Display object handles all the data sent from and to the compositor. When a Proxy marshals a request, it will write its wire representation to the display's write buffer. The data is sent to the compositor when the client calls 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 is called.
A Display has at least one event queue, called the default queue. Clients can create additional event queues with Display.create_queue() and assign Proxy's to it. Events occurring in a particular proxy are always queued in its assigned queue. A client can ensure that a certain assumption, such as holding a lock or running from a given thread, is true when a proxy event handler is called by assigning that proxy to an event queue and making sure that this queue is only dispatched when the assumption holds.
The default queue is dispatched by calling Display.dispatch(). This will dispatch any events queued on the default queue and attempt to read from the display fd if it's empty. Events read are then queued on the appropriate queues according to the proxy assignment.
A user created queue is dispatched with Display.dispatch_queue(). This function behaves exactly the same as Display.dispatch() but it dispatches given queue instead of the default queue.
A real world example of event queue usage is Mesa's implementation of glSwapBuffers() for the Wayland platform. This function might need to block until a frame callback is received, but dispatching the default queue could cause an event handler on the client to start drawing gain. This problem is solved using another event queue, so that only the events handled by the EGL code are dispatched during the block. ๐
Parameters ๐
name_or_fd(intorstr) โ either the name of the display you wanna create, or the file descriptor to connect the display to. If you don't say anything at all, it just uses the default name, which is generallywayland-0. easy peasy ๐
connect() -> None
Connect to a Wayland display โจ
Connects to the Wayland display by name or by fd, okurrr:
- If you hand it an
int, that's a file descriptor and it opens the connection using it. TheDisplaytakes ownership of the fd and will close it when the display gets destroyed โ and yes, it's also closed if the connect fails, so no leaks bestie ๐ซถ - If you hand it a
str, it opens the display with that given name. - If
nameisNone, then its value gets replaced with theWAYLAND_DISPLAYenvironment variable (if it's set), and otherwise the display"wayland-0"is used. defaults are giving main character energy ๐
disconnect() -> None
Close a connection to a Wayland display ๐
Closes the connection to the display and frees all the resources associated with it. bye bye, no crumbs left.
dispatch(*, block: bool = False, queue: EventQueue | None = None) -> int
Process incoming events ๐
- If
blockisFalse, it does not even attempt to read the display fd or the event queue โ it just returns zero if the queue is empty. no thoughts, head empty, zero returned ๐ - If the given
queueis empty andblockisTrue, this function blocks until there are events to be read from the display fd. Then events are read and queued on the appropriate event queues, and finally the events on the default event queue get dispatched.
Note: it is not possible to check if there are events on the queue or not. so don't even try to peek, bestie ๐ญ
flush() -> int
Send all buffered requests on the display to the server ๐
Sends all the buffered data on the client side over to the server. Clients should call this function before blocking. On success, it returns the number of bytes sent to the server. On failure, this function returns -1 and errno is set appropriately.
Display.flush() never blocks. It'll write as much data as it possibly can, but if not all the data could be written, errno will be set to EAGAIN and it returns -1. In that case, use poll on the display file descriptor to wait for it to become writable again. it's giving "can't talk right now, try again later" ๐
get_fd() -> int
Get a display context's file descriptor ๐ฆ
Returns the file descriptor associated with a display, so you can plug it straight into your client's main loop. integration, slay.
read(*, queue: EventQueue | None = None) -> None
Read events from display file descriptor ๐
Calling this function means data available on the display file descriptor gets read, and the read events get queued onto their corresponding event queues.
Parameters
queueโ if you specify it, the events get queued onto that given event queue; otherwise the default display queue is used.
roundtrip(*, queue: EventQueue | None = None) -> int
Block until all pending requests are processed by the server โณ
This one blocks until the server has processed all the requests issued so far, by sending a request to the display server and waiting for a reply before it returns.
It uses wl_display_dispatch_queue() internally. It is not allowed to call this function while the thread is being prepared for reading events โ and doing so will cause a deadlock. fr fr, do not do this, it's giving disaster ๐
Note: this function may dispatch other events being received on the default queue.
Parameters
queue(EventQueue) โ the queue on which to run the roundtrip. If it's not given, it uses the default queue.
Returns
- The number of dispatched events on success, or
-1on failure. periodt.
๐ธ EventQueue ๐ธ
class pywayland.client.EventQueue(display: Display)
A queue for wl_proxy object events. iconic behavior only.
Event queues allow the events on a display to be handled in a thread-safe manner. See Display for the details, bestie.
Parameters
display(Display) โ the display object that the event queue is connected to.
destroy() -> None
Destroy an event queue ๐ฅ
Destroys the given event queue. Any pending event on that queue is discarded โ gone, evaporating, no takebacks.
The wl_display object used to create the queue should not be destroyed until all event queues created with it are destroyed with this function. so likeโฆ clean up your queues first, please ๐
property destroyed: bool
Determine the state of the event queue. is it alive or is it giving ghost ๐ป
โจ Server Modules โจ
The base set of objects used by Wayland servers. we're on the other side of the socket now, and honestly? obsessed.
๐ Client ๐
class pywayland.server.Client(display: Display | None = None, fd: int | None = None, ptr=None)
class pywayland.server.Client(display: Display | None = None, fd: int | None = None, ptr: <MagicMock name = 'mock.ffi.ClientCData.__or__()' id='140737181137280'> = None)
Create a client for the given file descriptor ๐ซถ
Given a file descriptor corresponding to one end of a socket, this creates a client struct and adds the new client to the compositor's client list. At that point, the client is initialized and ready to run, as if the client had connected to the server's listening socket. Alternatively, you can pass a pointer to an existing client and use that instead of creating a new one. choose your own adventure, bestie โจ
The other end of the socket can be passed to connect() on the client side, or used with the WAYLAND_SOCKET environment variable on the client side.
Parameters
display(Display) โ the display objectfd(int) โ the file descriptor for the socket to the clientptr(ffi.ClientCData) โ a pointer to an existingwl_client
add_destroy_listener(listener: Listener) -> None
Add a listener for the destroy signal ๐ง
Parameters
listener(Listener) โ the listener object
destroy() -> None
Destroy the client. bye girl ๐
flush() -> None
Flush pending events to the client ๐
Events sent to clients get 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 the queued-up events for a client immediately. no waiting, we move fast ๐
classmethod from_resource(resource: <MagicMock name = 'mock.ffi.ResourceCData' id='140737181137280'>) -> Client
Look up the corresponding wl_client for a wl_resource ๐
Parameters
resource(pywayland.protocol_core.Resource) โ thewl_resource
Returns
- A
Clientinstance.
get_credentials() -> tuple[int, int, int]
Return Unix credentials for the client. ๐ชช
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. like a little ID check, but make it unix ๐
get_object(object_id: int) -> Any
Look up an object in the client name space ๐
This looks up an object in the client object name space by its object ID.
Parameters
object_id(int) โ the object id
Returns
- The object, or
Noneif there is no object for the given ID. (and yes, the original literally says "if there is not object for the given ID" โ we're keeping the vibe, but you get it ๐ญ)
๐ Display ๐
class pywayland.server.Display(ptr=None)
Create a Wayland Display object โจ
add_shm_format(shm_format) -> None
Add support for a Shm pixel format ๐จ
Adds the specified format to the list of formats the WlShm object advertises when a client binds to it. Adding a format to the list means clients will know that the compositor supports this format and may use it for creating WlShm buffers.
The compositor must be able to handle the pixel format when a client requests it. no advertising formats you can't actually serve, that's catfishing fr ๐
The compositor by default supports WL_SHM_FORMAT_ARGB8888 and WL_SHM_FORMAT_XRGB8888.
Parameters
shm_format(format) โ the shm pixel format to advertise
add_socket(name: str | None = None) -> str
Add a socket to Wayland display for the clients to connect. ๐
This adds a Unix socket to the Wayland display, which clients can use to connect to the Wayland display. it's giving "everyone's welcome" ๐ซถ
- If
Noneis passed asname, then it looks for theWAYLAND_DISPLAYenvironment variable for the socket name. IfWAYLAND_DISPLAYis not set, then the defaultwayland-0is used. - The Unix socket gets created in the directory pointed to by the environment variable
XDG_RUNTIME_DIR. IfXDG_RUNTIME_DIRis not set, then this function throws an exception. ๐ญ - The length of the socket path โ i.e., the path set in
XDG_RUNTIME_DIRplus the socket name โ must not exceed the maximum length of a Unix socket path. The function also fails if the user does not have write permission in theXDG_RUNTIME_DIRpath, or if the socket name is already in use. (yes, the original says "maxium" โ keeping it, it's iconic actually ๐)
Parameters
name(stringorNone) โ name of the Unix socket.destroy() -> Noneโ destroys the Wayland display object, and bestie it does a lot on the way out. It emits the Display destroy signal, releases all the sockets that were added to this display, frees all the globals associated with this display, frees the memory of additional shared memory formats, and then destroys the display object itself. Gone. Poof. ๐
See also: Display.add_destroy_listener()
- property
destroyed: boolโ returns whether the display has been destroyed. Simple as that, no notes. flush_clients() -> Noneโ flushes client connections. โจget_event_loop() -> EventLoop <#pywayland.server.EventLoop>โ hands you the event loop for the display.
Returns: the EventLoop for the Display
get_serial() -> intโ gives you the current serial number. Heads up though: this returns the most recent serial number, it does not increment it. No cap.init_shm() -> Noneโ initializes shm for this display.next_serial() -> intโ gives you the next serial. And yes, this one increments the display serial number and returns the new value. That's the whole difference between this andget_serial(), iykyk. ๐ฅrun() -> Noneโ runs the display.terminate() -> Noneโ stops the display from running. ๐
๐ฆ EventLoop ๐ฆ
class pywayland.server.EventLoop(display: Display <#pywayland.server.Display> | None = None)
An event loop to add events to. That's her whole job and she's iconic for it. ๐
Returns an event loop. Either it hands you back the event loop of a given display (which will trigger when the Display is run), or it creates a brand new event loop (which you can trigger by using EventLoop.dispatch()).
Parameters
- display (
Display) โ the display to create theEventLoopon (defaults toNone)
class FdMask(*values)
add_destroy_listener(listener)โ adds a listener for the destroy signal.
Parameters
- listener (
Listener) โ the listener object
add_fd(fd, callback, mask=<FdMask.WL_EVENT_READABLE: 1>, data=None)โ adds a file descriptor callback.
Triggers a function call when the file descriptor state matches the mask.
The callback should take three arguments:
fdโ file descriptor (int)maskโ file descriptor mask (uint)dataโ any object
Parameters
- fd (
int) โ file descriptor - callback โ callback function
- mask โ file descriptor mask
- data (
object) โ user data to send to callback
Returns: EventSource for the specified callback
See also: pywayland.server.eventloop.EventSource.check()
add_idle(callback, data=None)โ adds an idle callback.
Parameters
- callback (function with callback
void(void *data)) โ callback function - data โ user data to send to callback
Returns: EventSource for the specified callback
add_signal(signal_number, callback, data=None)โ adds a signal callback.
Triggers a function call when a signal is received.
The callback should take three arguments:
signal_numberโ signal (int)dataโ any object
Parameters
- signal_number (
int) โ signal number to trigger on - callback โ callback function
- data (
object) โ user data to send to callback
Returns: EventSource for the specified callback
add_timer(callback, data=None)โ adds a timer callback.
Triggers a function call after a specified time.
The callback should take one argument:
dataโ any object
Parameters
- callback (function with callback
int(void *data)) โ callback function - data (
object) โ user data to send to callback
Returns: EventSource for the specified callback
See also: pywayland.server.eventloop.EventSource.timer_update()
destroy()โ destroys the event loop.dispatch(timeout)โ dispatches callbacks on the event loop.dispatch_idle()โ dispatches the idle callback on the event loop.
๐ Listener ๐
class pywayland.server.Listener(function: Callable)
A single listener for Wayland signals. One (1) listener. She's monogamous to her signal, ok?
Provides the means to listen for wl_listener signal notifications. Tons of Wayland objects use wl_listener for notification of significant events like object destruction.
Clients should create Listener objects manually, and can register them as listeners to objects' destroy events using the object's .add_destroy_listener() method. And heads up bestie: a listener can only listen to one signal at a time. ๐ซถ
Parameters
- function (
callable) โ callback function for theListener remove() -> Noneโ removes the listener.
๐ธ Protocol Core Modules ๐ธ
๐ Interface ๐
Interface objects are only created as a subclass of Interface. The Interface class wraps the protocol objects, and serves to initialize a set of parameters for the Interface and provide decorators for defining Message objects on the interface.
class pywayland.protocol_core.Interface
Wrapper class for wl_wayland structs.
Base class for interfaces that are defined by the wayland.xml class and generated by the scanner. Sub-classes should use the InterfaceMeta metaclass, which will define subclass.events and subclass.requests, the lists of the methods on this interface. These class variables are populated by the Interface.event() and Interface.request() decorators.
classmethod event(*arguments: Argument <#pywayland.protocol_core.argument.Argument>, version: int | None = None) -> Callable
Decorator for interface events.
Adds the decorated method to the list of events of the interface (server-side method).
Parameters
- signature (
string) โ encodes the types of the arguments to the decorated function. - types (
list) โ list of the types of any objects included in the argument list,Noneif otherwise.
classmethod request(*arguments: Argument <#pywayland.protocol_core.argument.Argument>, version: int | None = None)
Decorator for interface requests.
Adds the decorated method to the list of requests of the interface (client-side method).
Parameters
- signature (
string) โ encodes the types of the arguments to the decorated function. - types (
list) โ list of the types of any objects included in the argument list,Noneif otherwise.
โญ Interface Metaclass โญ
This metaclass initializes lists for the requests and events on an interface, and initializes a cdata struct for the class. Very setup, very behind-the-scenes, very much doing the work so you don't have to. ๐
class pywayland.protocol_core.interface.InterfaceMeta(name, bases, dct)
Metaclass for Interfaces.
Initializes empty lists for events and requests for the given class.
๐ง Proxy ๐ง
Proxy objects are not created directly, and users should generally not create a proxy class on their own. Proxy classes give client side access to the interfaces defined by the Wayland protocol. Proxies are returned from the server after calling protocol methods which return new_id's.
class pywayland.protocol_core.Proxy(ptr, display=None)
destroy() -> Noneโ frees the pointer associated with theProxy.- property
destroyed: boolโ determines if the proxy has been destroyed.
Returns true if the proxy has been destroyed.
๐ Resource ๐
class pywayland.protocol_core.Resource(client, version: int | None = None, id: int = 0)
A server-side Interface object for the client.
Not created directly โ created from the Interface object.
Parameters
- client (
Client <#pywayland.server.Client>or cdata forwl_client *) โ the client that theResourceis for - version (
int) โ the version to use for theInterface, uses the current version if not specified - id (
int) โ the id for the item add_destroy_listener(listener) -> Noneโ adds a listener for the destroy signal.
Parameters
- listener (
Listener <#pywayland.server.Listener>) โ the listener object
destroy() -> Noneโ destroys theResource.
๐ Global ๐
class pywayland.protocol_core.Global(display, version=None)
A server-side Interface object for the server.
Not created directly โ created from the Interface object.
Parameters
- display (
Display <#pywayland.server.Display>) โ the display the object is created on - version (
int) โ the version to use for theInterface, uses the current version if not specified destroy()โ destroys the global object.
๐ Message ๐
Message objects are used to wrap the method calls on the protocol objects. The Message objects are added to the Interface's as either requests (client-side functions) or events (server-side functions).
class pywayland.protocol_core.message.Message(func: Callable, arguments: list[Argument <#pywayland.protocol_core.argument.Argument>], version: int | None)
Wrapper class for wl_message structs.
Base class that corresponds to the methods defined on an interface in the wayland.xml protocol, and are generated by the scanner. Subclasses specify the type of method โ whether it's a server-side or client-side method.
Parameters
- func (
function) โ the function that is represented by the message signature(string) โ bestie this is literally just the signature of the message's arguments, no biggie ๐types(list) โ a whole list of the types of any objects chillin' in the argument list. If there aren't any, it'sNone. That's it, that's the whole tea ๐
โจ arguments_to_c(*args) โจ
Okay so this one creates an array of wl_argument C structs (iconic).
Basically it generates the CFFI cdata array of wl_argument structs that correspond to the arguments of the method, exactly as the method signature specifies. no cap, it's just doing the translation work for you ๐ซถ
Parameters
args(list) โ your input arguments, hand 'em over
Returns
cdata union wl_argument []ofargsโ the glow-up from Python list to C array, slay โจ
โจ build_message_struct(wl_message_struct) -> tuple โจ
Bulid the wl_message struct for this message ๐ (yes bestie the docs really wrote "Bulid", not me, I'm just the messenger)
Parameters
wl_message_structโ thewl_messagecdata struct you're using to build the message struct
Returns
- A tuple of elements which must be kept alive for the message struct to remain valid ๐ฅ โ like, do NOT let these get garbage collected, the struct will simply perish, periodt
โจ c_to_arguments(args_ptr) โจ
The reverse glow-up: create a list of arguments ๐
It generates the arguments of the method from a CFFI cdata array of wl_argument structs that correspond to the arguments of the method as specified by the method signature.
Parameters
args_ptr(cdata union wl_argument []) โ the input arguments, coming at you from the C side
Returns
- a
listofargsโ back in Python land, we love to see it ๐ธ
๐ Argument ๐
class pywayland.protocol_core.argument.Argument(argument_type: 'ArgumentType', nullable: 'bool' = False, interface: 'type[Interface] | None' = None)
๐ ArgumentType ๐
class pywayland.protocol_core.argument.ArgumentType(*values)
๐ง Protocol Modules ๐ง
Wayland protocols built against Wayland 1.21.0 and Wayland Protocols 1.25. The receipts, the versions, everything ๐
๐ wayland Module ๐
๐ WlBuffer ๐
class pywayland.protocol.wayland.WlBuffer
Content for a WlSurface โ the whole vibe of this object ngl.
A buffer provides the content for a WlSurface. Buffers are created through factory interfaces such as WlShm, wp_linux_buffer_params (from the linux-dmabuf protocol extension) or similar. It has a width and a height and can be attached to a WlSurface, but the mechanism by which a client provides and updates the contents is defined by the buffer factory interface. So like, the buffer is the frame, but how it gets filled is somebody else's business ๐จ
Color channels are assumed to be electrical rather than optical (in other words, encoded with a transfer function) unless otherwise specified. And if the buffer uses a format that has an alpha channel, the alpha channel is assumed to be premultiplied into the electrical color channel values (after transfer function encoding) unless otherwise specified. That's the default, don't come for me ๐
Note, becauseWlBufferobjects are created from multiple independent factory interfaces, theWlBufferinterface is frozen at version 1.
โจ destroy() -> 'None' โจ
Request โ opcode 0 (attached to Resource instance)
Destroy a buffer
Destroy a buffer. If and how you need to release the backing storage is defined by the buffer factory interface. Not this interface's problem, lowkey ๐
For possible side-effects to a surface, go look at WlSurface.attach().
โจ release() -> 'None' โจ
Event โ opcode 0 (attached to Proxy instance)
Compositor releases buffer
Sent when this WlBuffer is no longer used by the compositor. It's the compositor saying "okay I'm done with this one bestie, take it back" ๐ซถ
For more information on when release events may or may not be sent, and what consequences it has, please see the description of WlSurface.attach().
If a client receives a release event before the frame callback requested in the same WlSurface.commit() that attaches this WlBuffer to a surface, then the client is immediately free to reuse the buffer and its backing storage, and does not need a second buffer for the next surface content update. Typically this is possible when the compositor maintains a copy of the WlSurface contents, e.g. as a GL texture. This is an important optimization for GL(ES) compositors with WlShm clients. Genuinely ate ๐ฅ
๐ฆ WlCallback ๐ฆ
class pywayland.protocol.wayland.WlCallback
Callback object
Clients can handle the 'done' event to get notified when the related request is done. That's the entire main character energy of this class โจ
Note, becauseWlCallbackobjects are created from multiple independent factory interfaces, theWlCallbackinterface is frozen at version 1.
โจ done(callback_data: 'int') -> 'None' โจ
Event โ opcode 0 (attached to Proxy instance)
Done event
Notify the client when the related request is done.
Parameters
callback_data(ArgumentType.Uint) โ request-specific data for the callback ๐
๐ WlCompositor ๐
class pywayland.protocol.wayland.WlCompositor
The compositor singleton
A compositor. This object is a singleton global. The compositor is in charge of combining the contents of multiple surfaces into one displayable output. It's the one, the only ๐
โจ create_surface() -> 'Proxy[WlSurface]' โจ
Request โ opcode 0 (attached to Resource instance)
Create new surface
Ask the compositor to create a new surface. Just ask, it'll hook you up ๐
Returns
WlSurfaceโ the new surface โญ
โจ create_region() -> 'Proxy[WlRegion]' โจ
Request โ opcode 1 (attached to Resource instance)
Create new region
Ask the compositor to create a new region.
Returns
WlRegionโ the new region ๐ธ
โจ release() -> 'None' โจ
Request โ opcode 2 (attached to Resource instance)
Destroy WlCompositor
This request destroys the WlCompositor. This has no effect on any other objects. Like, it's just killing this one thing, everything else lives on, no collateral damage ๐
๐ WlDataDevice ๐
class pywayland.protocol.wayland.WlDataDevice
Data transfer device
There is one WlDataDevice per seat which can be obtained from the global WlDataDeviceManager singleton. One per seat, no sharing, periodt.
A WlDataDevice provides access to inter-client data transfer mechanisms such as copy-and-paste and drag-and-drop. The chaos and the convenience, all in one object ๐
โจ start_drag(source: 'WlDataSource | None', origin: 'WlSurface', icon: 'WlSurface | None', serial: 'int') -> 'None' โจ
Request โ opcode 0 (attached to Resource instance)
Start drag-and-drop operation
This request asks the compositor to start a drag-and-drop operation on behalf of the client.
The source argument is the data source that provides the data for the eventual data transfer. If source is NULL, enter, leave and motion events are sent only to the client that initiated the drag and the client is expected to handle the data passing internally. If source is destroyed, the drag-and-drop session will be cancelled ๐
The origin surface is the surface where the drag originates and the client must have an active implicit grab that matches the serial.
The icon surface is an optional (can be NULL) surface that provides an icon to be moved around with the cursor. Initially, the top-left corner of the icon surface is placed at the cursor hotspot, but subsequent WlSurface.offset() requests can move the relative position. Attach requests must be confirmed with WlSurface.commit() as usual. The icon surface is given the role of a drag-and-drop icon. If the icon surface already has another role, it raises a protocol error โ do not do that bestie, it will not end well ๐จ
The input region is ignored for wl_surfaces with the role of a drag-and-drop icon.
The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error. One and done, no recycling โ
Parameters
source(WlDataSourceorNone) โ data source for the eventual transferorigin(WlSurface) โ surface where the drag originatesicon(WlSurfaceorNone) โ drag-and-drop icon surfaceserial(ArgumentType.Uint) โ serial number of the implicit grab on the origin ๐
โจ set_selection(source: 'WlDataSource | None', serial: 'int') -> 'None' โจ
Request โ opcode 1 (attached to Resource instance)
Copy data to the selection
This request asks the compositor to set the selection to the data from the source on behalf of the client.
To unset the selection, set the source to NULL. Easy peasy ๐ฆ
The given source may not be used in any further set_selection or start_drag requests. Attempting to reuse a previously-used source may send a used_source error.
Parameters
source(WlDataSourceorNone) โ data source for the selectionserial(ArgumentType.Uint) โ serial number of the event that triggered this request โญ
โจ release() -> 'None' โจ
Request โ opcode 2 (attached to Resource instance)
Destroy data device
This request destroys the data device. Poof, gone ๐จ
โจ data_offer(id: 'WlDataOffer') -> 'None' โจ
Event โ opcode 0 (attached to Proxy instance)
Introduce a new WlDataOffer
The data_offer event introduces a new WlDataOffer object, which will subsequently be used in either the data_device.enter event (for drag-and-drop) or the data_device.selection event (for selections). Immediately following the data_device.data_offer event, the new data_offer object will send out data_offer.offer events to describe the mime types it offers. It's giving โจ formal introduction โจ
Parameters
id(WlDataOffer) โ the newdata_offerobject ๐
๐ซถ enter(...) โ event, opcode 1
enter(serial: 'int', surface: 'WlSurface', x: 'float', y: 'float', id: 'WlDataOffer | None') -> 'None'
Event -- opcode 1 (attached to Proxy instance)
Initiate drag-and-drop session ๐
okay so bestie, this one fires when a drag-and-drop pointer that's actively dragging wanders into a surface that YOUR client owns. ๐
Where exactly the pointer was when it crossed in? That's what x and y are for โ and they're in surface-local coordinates, so they're relative to your surface, not the big wide world.
Parameters
serial(ArgumentType.Uint) โ the serial number of the enter event โจsurface(WlSurface) โ the client surface that got entered ๐ฆx(ArgumentType.Fixed) โ surface-local x coordinatey(ArgumentType.Fixed) โ surface-local y coordinateid(WlDataOfferorNone) โ the sourcedata_offerobject ๐
๐ leave() โ event, opcode 2
leave() -> 'None'
Event -- opcode 2 (attached to Proxy instance)
End drag-and-drop session ๐ธ
This is the "okay we're done here" event โ it shows up when the drag-and-drop pointer peaces out of the surface and the whole session wraps up. And girl, listen: at this exact point the client must destroy the WlDataOffer that got introduced back at enter time. No leaving it lying around. ๐ญ
๐ motion(time: 'int', x: 'float', y: 'float') -> 'None' โ event, opcode 3
motion(time: 'int', x: 'float', y: 'float') -> 'None'
Event -- opcode 3 (attached to Proxy instance)
Drag-and-drop session motion ๐ซ
So the drag-and-drop pointer is moving around inside the surface it's currently focused on โ that's this event. The new spot of the pointer comes through as x and y, again in surface-local coordinates.
Parameters
time(ArgumentType.Uint) โ timestamp, and it's got millisecond granularity โฑ๏ธx(ArgumentType.Fixed) โ surface-local x coordinatey(ArgumentType.Fixed) โ surface-local y coordinate
๐ฅ drop() โ event, opcode 4
drop() -> 'None'
Event -- opcode 4 (attached to Proxy instance)
End drag-and-drop session successfully โจ๐
This one lands when a drag-and-drop operation ends because the implicit grab got removed. The drop is happening, fr fr.
The drag-and-drop destination is expected to honor the last action it received through WlDataOffer.action(). If the resulting action is "copy" or "move", the destination can still fire off WlDataOffer.receive() requests, and it's expected to end all transfers with a WlDataOffer.finish() request. ๐ฏ
But if the resulting action is "ask", then bestie... it's not final. The destination is expected to do one last WlDataOffer.set_actions() request โ or WlDataOffer.destroy() โ if it wants to cancel the whole operation. ๐
๐ฆ selection(id: 'WlDataOffer | None') -> 'None' โ event, opcode 5
selection(id: 'WlDataOffer | None') -> 'None'
Event -- opcode 5 (attached to Proxy instance)
Advertise new selection ๐
This event goes out to tell the client there's a new WlDataOffer for the selection on this device. Here's the timeline, so you're not confused: data_device.data_offer and the data_offer.offer events get sent out immediately before this event, to introduce the data offer object first. ๐ซถ
The selection event is sent to a client right before it receives keyboard focus, and also whenever a new selection gets set while the client already has keyboard focus. The data_offer stays valid until a new data_offer (or NULL) shows up, or until the client loses keyboard focus. And switching surface with keyboard focus within the same client? Yeah, that doesn't mean a new selection will be sent. Nope.
The client must destroy the previous selection data_offer, if there is one, the moment it receives this event. Periodt. ๐
Parameters
id(WlDataOfferorNone) โ selectiondata_offerobject
๐ซ WlDataDeviceManager
class pywayland.protocol.wayland.WlDataDeviceManager
Data transfer interface
WlDataDeviceManager is a singleton global object that hooks you up with inter-client data transfer mechanisms โ think copy-and-paste and drag-and-drop. These mechanisms are tied to a WlSeat, and this interface is what lets a client get a WlDataDevice corresponding to a WlSeat. ๐
Depending on the version you bound, the objects created from the bound WlDataDeviceManager object will have different requirements for functioning properly. For the deets, go look at WlDataSource.set_actions(), WlDataOffer.accept() and WlDataOffer.finish(). iykyk โจ
โญ create_data_source(...) โ request, opcode 0
create_data_source() -> 'Proxy[WlDataSource]'
Request -- opcode 0 (attached to Resource instance)
Create a new data source ๐ธ
Create a new data source. That's it, that's the vibe.
Returns
WlDataSourceโ data source to create
๐ get_data_device(...) โ request, opcode 1
get_data_device(seat: 'WlSeat') -> 'Proxy[WlDataDevice]'
Request -- opcode 1 (attached to Resource instance)
Create a new data device ๐
Create a new data device for a given seat. ๐ช
Parameters
seat(WlSeat) โ seat associated with the data device
Returns
WlDataDeviceโ data device to create
๐ง release() โ request, opcode 2
release() -> 'None'
Request -- opcode 2 (attached to Resource instance)
Destroy WlDataDeviceManager ๐
This request destroys the WlDataDeviceManager. And no, it has no effect on any other objects โ they're all fine, they're living their best lives. ๐
๐ WlDataOffer
class pywayland.protocol.wayland.WlDataOffer
Offer to transfer data
A WlDataOffer represents a piece of data that another client (the source client) is offering up for transfer. It gets used by both the copy-and-paste and drag-and-drop mechanisms. The offer describes all the different mime types the data can be converted to, and it also provides the mechanism for transferring that data directly from the source client. ๐
๐ accept(...) โ request, opcode 0
accept(serial: 'int', mime_type: 'str | None') -> 'None'
Request -- opcode 0 (attached to Resource instance)
Accept one of the offered mime types โจ
Say the client can accept the given mime type โ or pass NULL to say it can't. ๐
Now here's where it gets version-dependent, so pay attention bestie:
- For objects of version 2 or older, this request is how the client gives feedback on whether it can receive the given mime type, or
NULLif none is accepted. Important part: that feedback does not determine whether the drag-and-drop operation succeeds or not. - For objects of version 3 or newer, this request determines the final result of the drag-and-drop operation. If the end result is that no mime types were accepted, the drag-and-drop operation gets cancelled, and the corresponding drag source will receive
WlDataSource.cancelled(). Clients can still use this event alongsideWlDataSource.action()for feedback though. ๐ซ
Parameters
serial(ArgumentType.Uint) โ serial number of the accept requestmime_type(ArgumentType.StringorNone) โ mime type accepted by the client
๐ฆ receive(...) โ request, opcode 1
receive(mime_type: 'str', fd: 'int') -> 'None'
Request -- opcode 1 (attached to Resource instance)
Request that the data is transferred ๐ฆ
To transfer the offered data, the client sends this request and says which mime type it wants to receive. The transfer happens through the file descriptor you pass in โ typically one you made with the pipe system call. The source client writes the data in the representation of the mime type that was requested, then closes the file descriptor. ๐ซก
On the other side, the receiving client reads from the read end of the pipe until EOF, then closes its own end โ and at that point the transfer is complete. โ
This request may happen multiple times for different mime types, both before and after WlDataDevice.drop(). Drag-and-drop destination clients may preemptively fetch data, or examine it more closely, to decide whether to accept. ๐
Parameters
mime_type(ArgumentType.String) โ mime type desired by receiverfd(ArgumentType.FileDescriptor) โ file descriptor for data transfer
๐ destroy() โ request, opcode 2
destroy() -> 'None'
Request -- opcode 2 (attached to Resource instance)
Destroy data offer ๐
Destroy the data offer. Bye bestie! ๐
๐ finish() โ request, opcode 3
finish() -> 'None'
Request -- opcode 3 (attached to Resource instance)
The offer will no longer be used โจ
This notifies the compositor that the drag destination successfully finished the drag-and-drop operation. ๐
Once the compositor receives this request, it will emit WlDataSource.dnd_finished() on the drag source client. ๐
โ ๏ธ Now the strict bit: it is a client error to perform any requests other thanWlDataOffer.destroy()after this one. It's also an error to perform this request after aNULLmime type has been set inWlDataOffer.accept(), or if no action was received throughWlDataOffer.action(). Don't do it. ๐
And if a WlDataOffer.finish() request is received for something that isn't a drag-and-drop operation? The invalid_finish protocol error gets raised. ๐ฅ
๐ง set_actions(...) โ request, opcode 4
set_actions(dnd_actions: 'int', preferred_action: 'int') -> 'None'
Request -- opcode 4 (attached to Resource instance)
Set the available/preferred drag-and-drop actions ๐
Sets the actions that the destination side client supports for this operation. Heads up: this request may trigger the emission of WlDataSource.action() and WlDataOffer.action() events if the compositor needs to change the selected action. ๐ฅ
This request can be called multiple times throughout the drag-and-drop operation, typically as your little reply to WlDataDevice.enter() or WlDataDevice.motion() events, iykyk. ๐ซ
This request is literally the moment that determines the final result of the whole drag-and-drop saga. And if the end result is that no action gets accepted? Then the drag source receives a WlDataSource.cancelled() and honestly? devastating. ๐ญ
Now for the rules, bestie, listen up: the dnd_actions argument must contain only values expressed in the WlDataDeviceManager.dnd_actions() enum, and the preferred_action argument must have only one of those values set. Otherwise? Protocol error, no cap. ๐จ
While managing an "ask" action, the destination drag-and-drop client may perform further WlDataOffer.receive() requests, and is expected to perform one last WlDataOffer.set_actions() request with a preferred action other than "ask" (and optionally WlDataOffer.accept()) before requesting WlDataOffer.finish() โ all so it can convey the action the user actually selected. And if the preferred action is not in the WlDataOffer.source_actions() mask? An error will be raised, sorry babe. ๐
If the "ask" action is dismissed (think: user cancellation), the client is expected to perform WlDataOffer.destroy() right away. Immediately. Don't linger. ๐ซถ
And this request can only be made on drag-and-drop offers โ otherwise a protocol error gets raised. Periodt. ๐
Parameters
dnd_actions(ArgumentType.Uint) โ actions supported by the destination clientpreferred_action(ArgumentType.Uint) โ action preferred by the destination client
offer(mime_type: 'str') -> 'None'
Event โ opcode 0 (attached to Proxy instance)
Advertise offered mime type
Sent immediately after creating the WlDataOffer object. One event per offered mime type. โจ
Parameters
mime_type(ArgumentType.String) โ offered mime type
source_actions(source_actions: 'int') -> 'None'
Event โ opcode 1 (attached to Proxy instance)
Notify the source-side available actions
This event indicates the actions offered by the data source. It gets sent immediately after creating the WlDataOffer object, or anytime the source side changes its offered actions through WlDataSource.set_actions(). ๐
Parameters
source_actions(ArgumentType.Uint) โ actions offered by the data source
action(dnd_action: 'int') -> 'None'
Event โ opcode 2 (attached to Proxy instance)
Notify the selected action
This event indicates the action selected by the compositor after matching the source/destination side actions. Only one action (or none at all!) will be offered here.
This event can be emitted multiple times during the drag-and-drop operation, in response to destination side action changes through WlDataOffer.set_actions(). ๐ฅ
This event will no longer be emitted after WlDataDevice.drop() happened on the drag-and-drop destination โ at that point the client must honor the last action received, or the last preferred one set through WlDataOffer.set_actions() when handling an "ask" action. No takebacksies.
Compositors may also change the selected action on the fly, mainly in response to keyboard modifier changes during the drag-and-drop operation. ๐
The most recent action received is always the valid one. Prior to receiving WlDataDevice.drop(), the chosen action may change (e.g. due to keyboard modifiers being pressed). At the time of receiving WlDataDevice.drop(), the drag-and-drop destination must honor the last action received.
Action changes may still happen after WlDataDevice.drop(), especially on "ask" actions, where the drag-and-drop destination may choose another action afterwards. Action changes happening at this stage are always the result of inter-client negotiation โ the compositor shall no longer be able to induce a different action. ๐ง
Upon "ask" actions, it is expected that the drag-and-drop destination may potentially choose a different action and/or mime type, based on WlDataOffer.source_actions() and finally chosen by the user (think: popping up a menu with the available options). The final WlDataOffer.set_actions() and WlDataOffer.accept() requests must happen before the call to WlDataOffer.finish().
Parameters
dnd_action(ArgumentType.Uint) โ action selected by the compositor
๐ WlDataSource ๐
class pywayland.protocol.wayland.WlDataSource โ Offer to transfer data
The WlDataSource object is the source side of a WlDataOffer. It's created by the source client in a data transfer, and it provides a way to describe the offered data and a way to respond to requests to transfer that data. It's giving main character energy, honestly. ๐
offer(mime_type: 'str') -> 'None'
Request โ opcode 0 (attached to Resource instance)
Add an offered mime type
This request adds a mime type to the set of mime types advertised to targets. Can be called several times to offer multiple types โ stack 'em up, bestie. ๐ธ
Parameters
mime_type(ArgumentType.String) โ mime type offered by the data source
destroy() -> 'None'
Request โ opcode 1 (attached to Resource instance)
Destroy the data source
Destroy the data source. That's it, that's the whole vibe. ๐
set_actions(dnd_actions: 'int') -> 'None'
Request โ opcode 2 (attached to Resource instance)
Set the available drag-and-drop actions
Sets the actions that the source side client supports for this operation. This request may trigger WlDataSource.action() and WlDataOffer.action() events if the compositor needs to change the selected action. ๐
The dnd_actions argument must contain only values expressed in the WlDataDeviceManager.dnd_actions() enum, otherwise it will result in a protocol error. Periodt.
โ ๏ธ This request must be made once only, and can only be made on sources used in drag-and-drop, so it must be performed before WlDataDevice.start_drag(). Attempting to use the source for anything other than drag-and-drop will raise a protocol error. Don't test it. ๐
Parameters
dnd_actions(ArgumentType.Uint) โ actions supported by the data source
target(mime_type: 'str | None') -> 'None'
Event โ opcode 0 (attached to Proxy instance)
A target accepts an offered mime type
Sent when a target accepts pointer_focus or motion events. If a target does not accept any of the offered types, type is NULL. ๐ญ
Used for feedback during drag-and-drop.
Parameters
mime_type(ArgumentType.StringorNone) โ mime type accepted by the target
send(mime_type: 'str', fd: 'int') -> 'None'
Event โ opcode 1 (attached to Proxy instance)
Send the data
Request for data from the client. Send the data as the specified mime type over the passed file descriptor, then close it. Slay, then shut the door. ๐ชโจ
Parameters
mime_type(ArgumentType.String) โ mime type for the datafd(ArgumentType.FileDescriptor) โ file descriptor for the data
cancelled() -> 'None'
Event โ opcode 2 (attached to Proxy instance)
Selection was cancelled
This data source is no longer valid. There are several reasons why this could happen, and honestly some of them are so petty:
- The data source has been replaced by another data source. ๐
- The drag-and-drop operation was performed, but the drop destination did not accept any of the mime types offered through
WlDataSource.target(). - The drag-and-drop operation was performed, but the drop destination did not select any of the actions present in the mask offered through
WlDataSource.action(). - The drag-and-drop operation was performed but didn't happen over a surface.
- The compositor cancelled the drag-and-drop operation (e.g. compositor dependent timeouts to avoid stale drag-and-drop transfers).
The client should clean up and destroy this data source.
For objects of version 2 or older, WlDataSource.cancelled() will only be emitted if the data source was replaced by another data source. iykyk ๐
dnd_drop_performed() -> 'None'
Event โ opcode 3 (attached to Proxy instance)
The drag-and-drop operation physically finished
The user performed the drop action. This event does not indicate acceptance, y'all โ WlDataSource.cancelled() may still be emitted afterwards if the drop destination does not accept any mime type. ๐ญ
However, this event might not be received if the compositor cancelled the drag-and-drop operation before this event could happen.
๐ Note that the data_source may still be used in the future and should not be destroyed here. Put it down, bestie.
dnd_finished() -> 'None'
Event โ opcode 4 (attached to Proxy instance)
The drag-and-drop operation concluded
The drop destination is done vibing with this data source, so the client can now yeet this data source and free all the associated data. ๐ If the action that did the operation was "move", the source can now delete the transferred data. ๐๏ธ
action(dnd_action: 'int') -> 'None'
Event -- opcode 5 (attached to Proxy instance)
Notify the selected action โจ
This event is like the compositor sliding into your DMs to tell you which action it picked after matching the source/destination side actions. Only one action (or none at all) will be offered here. ๐
This event can pop off multiple times during the drag-and-drop operation, mostly when the destination side changes stuff through WlDataOffer.set_actions(), or as the data device enters/leaves surfaces. ๐ฆ
You can only get this event after WlDataSource.dnd_drop_performed() if the drag-and-drop operation ended in an "ask" action. In that case, the final WlDataSource.action() event will happen right before WlDataSource.dnd_finished(). โณ
Compositors might also change the selected action on the fly, usually because of keyboard modifier changes during the drag-and-drop operation. ๐น
The most recent action you receive is always the valid one, no cap. The chosen action can change while negotiation is happening (like an "ask" action can turn into a "move" operation), so the effects of the final action must always be applied in WlDataSource.dnd_finished(). ๐
Clients can trigger cursor surface changes from this point, so they reflect the current action. ๐ฑ๏ธ
Parameters
dnd_action(ArgumentType.Uint) -- action selected by the compositor
WlDisplay ๐
class pywayland.protocol.wayland.WlDisplay
Core global object ๐
The core global object. This is a special singleton object. It's used for internal Wayland protocol features. ๐ง
sync() -> 'Proxy[WlCallback]'
Request -- opcode 0 (attached to Resource instance)
Asynchronous roundtrip ๐
The sync request asks the server to emit the 'done' event on the returned WlCallback object. Since requests are handled in-order and events are delivered in-order, this can be used as a barrier to make sure 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, so the client must not try to use it after that point. ๐
The callback_data passed in the callback is undefined and should be ignored. ๐
Returns
WlCallback-- callback object for thesyncrequest
get_registry() -> 'Proxy[WlRegistry]'
Request -- opcode 1 (attached to Resource instance)
Get global registry object ๐
This request creates a registry object that lets the client list and bind the global objects available from the compositor. ๐
It should be noted that the server side resources consumed in response to a get_registry request can only be released when the client disconnects, not when the client side proxy is destroyed. So clients should invoke get_registry as infrequently as possible to avoid wasting memory. ๐ง
Returns
WlRegistry-- global registry object
error(object_id: 'Any', code: 'int', message: 'str') -> 'None'
Event -- opcode 0 (attached to Proxy instance)
Fatal error event ๐ฅ
The error event is sent out when a fatal (non-recoverable) error has occurred. The object_id argument is the object where the error occurred, most often in response to a request to that object. The code identifies the error and is defined by the object interface. So each interface defines its own set of error codes. The message is a brief description of the error, for (debugging) convenience. ๐
Parameters
object_id(ArgumentType.Object) -- object where the error occurredcode(ArgumentType.Uint) -- error codemessage(ArgumentType.String) -- error description
delete_id(id: 'int') -> 'None'
Event -- opcode 1 (attached to Proxy instance)
Acknowledge object id deletion ๐๏ธ
This event is used internally by the object ID management logic. ๐ง
When the server stops using an object created by the client, the server sends this event. In particular, after sending this event, the server will no longer send any events that contain the object as the receiver or as an argument. ๐ญ
When the client receives this event, it knows that it can reuse the object ID. โป๏ธ
Parameters
id(ArgumentType.Uint) -- deleted object ID
WlFixes ๐ ๏ธ
class pywayland.protocol.wayland.WlFixes
Wayland protocol fixes โจ
This global fixes problems with other core-protocol interfaces that cannot be fixed in these interfaces themselves. ๐
destroy() -> 'None'
Request -- opcode 0 (attached to Resource instance)
Destroys this object. ๐ฃ
destroy_registry(registry: 'WlRegistry') -> 'None'
Request -- opcode 1 (attached to Resource instance)
Destroy a WlRegistry ๐๏ธ
This request destroys a WlRegistry object. ๐ฅ
The client should no longer use the WlRegistry after making this request. ๐ซ
The compositor will emit a WlDisplay.delete_id() event with the object ID of the registry and will no longer emit any events on the registry. The client should re-use the object ID once it receives the WlDisplay.delete_id() event. โป๏ธ
Parameters
registry(WlRegistry) -- the registry to destroy
ack_global_remove(registry: 'WlRegistry', name: 'int') -> 'None'
Request -- opcode 2 (attached to Resource instance)
Acknowledge global removal ๐
Acknowledge the removal of the specified global. โ
If no global with the specified name exists or the global is not removed, the WlFixes.invalid_ack_remove() protocol error will be posted. โ ๏ธ
Due to the Wayland protocol being asynchronous, the wl_global objects cannot be destroyed immediately. For example, if a wl_global is removed and a client attempts to bind that global around same time, it can result in a protocol error due to an unknown global name in the bind request. ๐ต
In order to avoid crashing clients, the compositor should remove the wl_global once it is guaranteed that no more bind requests will come. ๐ก๏ธ
The WlFixes.ack_global_remove()() request is used to signal to the compositor that the client will not bind the given global anymore. After all clients acknowledge the removal of the global, the compositor can safely destroy it. ๐งน
The client must call the WlFixes.ack_global_remove()() request in response to a WlRegistry.global_remove()() event even if it did not bind the corresponding global. ๐ข
Parameters
registry(WlRegistry) -- the registry objectname(ArgumentType.Uint) -- unique name of the global
WlKeyboard โจ๏ธ
class pywayland.protocol.wayland.WlKeyboard
Keyboard input device ๐น
The WlKeyboard interface represents one or more keyboards associated with a seat. ๐ช
Each WlKeyboard has the following logical state:
- an active surface (possibly null),
- the keys currently logically down,
- the active modifiers,
- the active group.
By default, the active surface is null, the keys currently logically down are empty, the active modifiers and the active group are 0. ๐
release() -> 'None'
Request -- opcode 0 (attached to Resource instance)
Release the keyboard object. ๐๏ธ
keymap(format: 'int', fd: 'int', size: 'int') -> 'None'
Event -- opcode 0 (attached to Proxy instance)
Keyboard mapping ๐บ๏ธ
This event provides a file descriptor to the client which can be memory-mapped in read-only mode to provide a keyboard mapping description. ๐
From version 7 onwards, the fd must be mapped with MAP_PRIVATE by the recipient, as MAP_SHARED may fail. โ ๏ธ
Parameters
format(ArgumentType.Uint) -- keymap formatfd(ArgumentType.FileDescriptor) -- keymap file descriptorsize(ArgumentType.Uint) -- keymap size, in bytes
enter(serial: 'int', surface: 'WlSurface', keys: 'list') -> 'None'
Event -- opcode 1 (attached to Proxy instance)
Enter event ๐ช
Notification that this seat's keyboard focus is on a certain surface. ๐
The compositor must send the WlKeyboard.modifiers() event after this event. ๐
In the WlKeyboard logical state, this event sets the active surface to the surface argument and the keys currently logically down to the keys in the keys argument. The compositor must not send this event if the WlKeyboard already had an active surface immediately before this event. ๐ซ
Parameters
Real talk real quick though: clients should not use the list of pressed keys to emulate key-press events. Nope. Not happening. And the order of keys in that list? unspecified. Like, completely unspecified. Do not @ me about it, do not depend on it, periodt. ๐
Parameters
serial(ArgumentType.Uint) โ serial number of the enter eventsurface(WlSurface) โ surface gaining keyboard focuskeys(ArgumentType.Array) โ the keys currently logically down
๐ฆ leave(serial: 'int', surface: 'WlSurface') -> 'None'
Event โ opcode 2 (attached to Proxy instance)
Bestie, this is the Leave event. It's the heads-up that this seat's keyboard focus has, like, left a certain surface. Bye keyboard focus, we hardly knew ye. ๐ญ
Important order-lore: the leave notification gets sent before the enter notification for the new focus. Don't get it twisted.
And here's the state stuff you can't skip: in the WlKeyboard logical state, this event resets all values back to their defaults. The compositor must not send this event if the active surface of the WlKeyboard was not equal to the surface argument immediately before this event. That's a hard rule, no exceptions, fr fr.
Parameters
serial(ArgumentType.Uint) โ serial number of the leave eventsurface(WlSurface) โ surface that lost keyboard focus
โญ key(serial: 'int', time: 'int', key: 'int', state: 'int') -> 'None'
Event โ opcode 3 (attached to Proxy instance)
It's the Key event, and it means exactly what it sounds like: a key was pressed or released. Iconic, honestly. โจ
The time argument is a timestamp with millisecond granularity, and โ plot twist โ it has an undefined base. So don't go reading meaning into it that isn't there.
The key itself is a platform-specific key code that you can interpret by feeding it to the keyboard mapping (peep the keymap event for that, iykyk).
Now, if this event produces a change in modifiers, then the resulting WlKeyboard.modifiers() event must be sent after this event. Order is everything, babes.
Let's talk logical state, because this part is doing the most:
- In the
WlKeyboardlogical state, this event adds the key to the keys currently logically down (if thestateargument is pressed), or removes the key from the keys currently logically down (if thestateargument is released). - The compositor must not send this event if the
WlKeyboarddid not have an active surface immediately before this event. - The compositor also must not send this event if
stateis pressed (resp. released) and the key was already logically down (resp. was not logically down) immediately before this event.
And since version 10, compositors may send key events with the "repeated" key state when a WlKeyboard.repeat_info() event with a rate argument of 0 has been received. This lets the compositor take over the responsibility of key repetition. Main character compositor behavior, tbh. ๐
Parameters
serial(ArgumentType.Uint) โ serial number of the key eventtime(ArgumentType.Uint) โ timestamp with millisecond granularitykey(ArgumentType.Uint) โ key that produced the eventstate(ArgumentType.Uint) โ physical state of the key
๐ธ modifiers(serial: 'int', mods_depressed: 'int', mods_latched: 'int', mods_locked: 'int', group: 'int') -> 'None'
Event โ opcode 4 (attached to Proxy instance)
This is the Modifier and group state event. It slides into the client's DMs to say: heads up, the modifier and/or group state changed, so you should update your local state. Simple as that. ๐
Now here's a fun one โ the compositor may send this event even without a surface of the client having keyboard focus. You know, for example, to tie modifier information to pointer focus instead. Sneaky but legal.
And if a modifier event with pressed modifiers gets sent without a prior enter event? The client can assume the modifier state is valid until it receives the next WlKeyboard.modifiers() event. To reset the modifier state again, the compositor can just send a WlKeyboard.modifiers() event with no pressed modifiers. Clean slate era. ๐ง
In the WlKeyboard logical state, this event updates the modifiers and the group.
Parameters
serial(ArgumentType.Uint) โ serial number of the modifiers eventmods_depressed(ArgumentType.Uint) โ depressed modifiersmods_latched(ArgumentType.Uint) โ latched modifiersmods_locked(ArgumentType.Uint) โ locked modifiersgroup(ArgumentType.Uint) โ keyboard layout
๐ repeat_info(rate: 'int', delay: 'int') -> 'None'
Event โ opcode 5 (attached to Proxy instance)
Repeat rate and delay! This is how the client learns about the keyboard's repeat rate and delay. Literally just a little gossip sesh about how fast the keys go. ๐
Timing tea: this event is sent as soon as the WlKeyboard object has been created, and it's guaranteed to be received by the client before any key press event. Guaranteed. Not "usually." Guaranteed. ๐
โ ๏ธ Negative values for eitherrateordelayare illegal. And arateof zero will disable any repeating, regardless of the value ofdelay. Zero means off, no debate.
Also! This event can totally be sent again later with a new value if necessary, so clients should keep listening for it even past the creation of WlKeyboard. Don't sing your swan song after the first one, bestie. ๐ฆ
Parameters
rate(ArgumentType.Int) โ the rate of repeating keys in characters per seconddelay(ArgumentType.Int) โ delay in milliseconds since key down until repeating starts
๐ WlOutput
class pywayland.protocol.wayland.WlOutput
Compositor output region
OK so picture this: an output describes part of the compositor geometry. The compositor works in the 'compositor coordinate system', and an output corresponds to a rectangular area in that space that is actually visible. In practice? That's usually a monitor showing off part of the compositor space. โจ
This object gets published as a global during start up, or whenever a monitor gets hotplugged. Surprise! New screen, who dis. ๐
๐ซ release() -> 'None'
Request โ opcode 0 (attached to Resource instance)
Release the output object.
Use this request to tell the server "hey bestie, I'm not gonna use the output object anymore." Peace out, output. ๐ซถ
๐ geometry(x: 'int', y: 'int', physical_width: 'int', physical_height: 'int', subpixel: 'int', make: 'str', model: 'str', transform: 'int') -> 'None'
Event โ opcode 0 (attached to Proxy instance)
Properties of the output.
The geometry event spills the geometric properties of the output. It gets sent when binding to the output object, and every single time any of those properties change. Like a constant glow-up notification. ๐ฅ
You can set the physical size to zero if it just doesn't make sense for this output โ think projectors or virtual outputs. Zero is valid there, don't stress.
The geometry event will be followed by a done event, starting from version 2.
Oh and โ clients should use WlSurface.preferred_buffer_transform() instead of the transform advertised by this event to find the preferred buffer transform to use for a surface. Yes really. Yes it's a little extra. Moving on. ๐
๐ Note:WlOutputonly advertises partial information about the output position and identification. Some compositors โ for instance those not implementing a desktop-style output layout, or those exposing virtual outputs โ might fake this information. Instead of usingxandy, clients should usexdg_output.logical_position. Instead of usingmakeandmodel, clients should usenameanddescription. Don't trust the vibes on this one, trust the alternatives.
Parameters
x(ArgumentType.Int) โ x position within the global compositor spacey(ArgumentType.Int) โ y position within the global compositor spacephysical_width(ArgumentType.Int) โ width in millimeters of the outputphysical_height(ArgumentType.Int) โ height in millimeters of the outputsubpixel(ArgumentType.Int) โ subpixel orientation of the outputmake(ArgumentType.String) โ textual description of the manufacturermodel(ArgumentType.String) โ textual description of the modeltransform(ArgumentType.Int) โ additional transformation applied to buffer contents during presentation
โญ mode(flags: 'int', width: 'int', height: 'int', refresh: 'int') -> 'None'
Event โ opcode 1 (attached to Proxy instance)
Advertise available modes for the output.
The mode event describes an available mode for the output, bestie. It's the output saying "here's a resolution and refresh rate I can do."
Here's the tea on timing: the event is sent when binding to the output object, and there will always be one mode โ the current mode. The event is sent again if an output changes mode, for the mode that is now current. In other words: the current mode is always the last mode that was received with the current flag set. Keep track of it, don't lose the plot. ๐
And now, a warning with real consequences:
โ ๏ธ Non-current modes are deprecated. A compositor can decide to only advertise the current mode and never send any other modes. Clients should not rely on non-current modes. Periodt. Don't build your whole personality around them, they might not show up. ๐
The size of a mode is handed to you in physical hardware units of the output device, bestie. That is not necessarily the same as the output size in the global compositor space though โ sneaky, right? Like, the output might be scaled (peep WlOutput.scale()) or transformed (peep WlOutput.transform()). So if you're a client and you want the output size in global compositor space, use xdg_output.logical_size instead. Slay.
The vertical refresh rate can be set to zero if it doesn't make sense for that output (think: virtual outputs, they're just built different).
The mode event will be followed by a done event (starting from version 2). ๐
Clients should not use the refresh rate to schedule frames!! Instead, use the WlSurface.frame() event or the presentation-time protocol. Periodt.
Note: this info is not always meaningful for all outputs. Some compositors, like the ones exposing virtual outputs, might just fake the refresh rate or the size. It's giving illusion of a display tbh. ๐
Parameters
flags(ArgumentType.Uint) -- bitfield of mode flagswidth(ArgumentType.Int) -- width of the mode in hardware unitsheight(ArgumentType.Int) -- height of the mode in hardware unitsrefresh(ArgumentType.Int) -- vertical refresh rate in mHz
โจ done() -> 'None' โจ
Event -- opcode 2 (attached to Proxy instance)
Sent all information about output. โจ
This event goes out after all other properties have been sent โ after binding to the output object, and after any other property changes done after that. The way that works means changes to the output properties can be seen as atomic, even if they happen across multiple events. Chef's kiss honestly. ๐
๐ scale(factor: 'int') -> 'None' ๐
Event -- opcode 3 (attached to Proxy instance)
Output scaling properties.
This event carries scaling geometry info that isn't in the geometry event. It may be sent after binding the output object, or if the output scale changes later. The compositor will emit a non-zero, positive value for scale, no cap. And if it's not sent? The client should assume a scale of 1. ๐ซถ
A scale larger than 1 means the compositor will automatically scale surface buffers by that amount when rendering. Bestie, this is for very high resolution displays where apps rendering at native resolution would be way too small to be legible โ micro-text core. ๐ญ
Clients should use WlSurface.preferred_buffer_scale() instead of this event to find the preferred buffer scale to use for a surface. iykyk.
The scale event will be followed by a done event.
Parameters
factor(ArgumentType.Int) -- scaling factor of output
๐ฆ name(name: 'str') -> 'None' ๐ฆ
Event -- opcode 4 (attached to Proxy instance)
Name of this output.
Many compositors will assign user-friendly names to their outputs, show them to the user, let the user refer to an output, etc. And the client may wish to know this name too so it can offer the user similar behaviors. Matching energy. โจ
The name is a UTF-8 string with no convention defined for its contents. Each name is unique among all WlOutput globals. And the name is only guaranteed to be unique for the compositor instance.
The same output name is used for all clients for a given WlOutput global. So yes โ the name can be shared across processes to refer to a specific WlOutput global. ๐
The name is not guaranteed to be persistent across sessions, so you cannot use it to reliably identify an output in e.g. configuration files. Do not do that, I'm begging. ๐
Examples of names include 'HDMI-A-1', 'WL-1', 'X11-1', etc. But do not assume the name is a reflection of an underlying DRM connector, X11 connection, etc. It's just a name, bestie, not a whole identity.
The name event is sent after binding the output object. It's only sent once per output object, and the name does not change over the lifetime of the WlOutput global. Iconic consistency. ๐
Compositors may re-use the same output name if the WlOutput global is destroyed and re-created later. Compositors should avoid re-using the same name if possible. (Original had a lil' line break in "re- using" there โ we don't ship typos in this house, but the meaning is the same.)
The name event will be followed by a done event.
Parameters
name(ArgumentType.String) -- output name
๐ธ description(description: 'str') -> 'None' ๐ธ
Event -- opcode 5 (attached to Proxy instance)
Human-readable description of this output.
Many compositors can produce human-readable descriptions of their outputs. And the client may wish to know this description too โ e.g. for output selection purposes. โจ
The description is a UTF-8 string with no convention defined for its contents. The description is not guaranteed to be unique among all WlOutput globals. Examples might include 'Foocorp 11" Display' or 'Virtual X11 output via :1'. Adorable, honestly.
The description event is sent after binding the output object and whenever the description changes. The description is optional, and may not be sent at all. ๐
The description event will be followed by a done event.
Parameters
description(ArgumentType.String) -- output description
๐ฑ๏ธ WlPointer ๐ฑ๏ธ
class pywayland.protocol.wayland.WlPointer
Pointer input device.
The WlPointer interface represents one or more input devices โ like mice โ which control the pointer location and pointer_focus of a seat. ๐ญ
The WlPointer interface generates motion, enter and leave events for the surfaces the pointer is located over, plus button and axis events for button presses, button releases and scrolling. Full coverage, no notes. โจ
๐ set_cursor(serial: 'int', surface: 'WlSurface | None', hotspot_x: 'int', hotspot_y: 'int') -> 'None' ๐
Request -- opcode 0 (attached to Resource instance)
Set the pointer surface.
Set the pointer surface โ i.e. the surface that contains the pointer image (the cursor) โ bestie. This request gives the surface the role of a cursor. And if the surface already has another role? It raises a protocol error. One role only, this is not a situationship. ๐
The cursor actually changes only if the pointer focus for this device is one of the requesting client's surfaces, or the surface parameter is the current pointer surface. If there was a previous surface set with this request, it gets replaced. And if surface is NULL, the pointer image is hidden. Poof. ๐ซถ
The parameters hotspot_x and hotspot_y define the position of the pointer surface relative to the pointer location. Its top-left corner is always at (x, y) - (hotspot_x, hotspot_y), where (x, y) are the coordinates of the pointer location, in surface-local coordinates.
On WlSurface.offset() requests to the pointer surface, hotspot_x and hotspot_y are decremented by the x and y parameters passed to the request. The offset must be applied by WlSurface.commit() as usual. Don't skip the commit, okay? ๐
The hotspot can also be updated by passing the currently set pointer surface to this request with new values for hotspot_x and hotspot_y. Glow-up via re-send. โจ
The input region is ignored for wl_surfaces with the role of a cursor. And when the use as a cursor ends, the WlSurface is unmapped.
Theserialparameter must match the latestWlPointer.enter()serial number sent to the client. Otherwise the request will be ignored. Fr fr, no match no cursor.
Parameters
serial(ArgumentType.Uint) -- serial number of the enter eventsurface(WlSurfaceorNone) -- pointer surfacehotspot_x(ArgumentType.Int) -- surface-local x coordinatehotspot_y(ArgumentType.Int) -- surface-local y coordinate
๐ release() -> 'None' ๐
Request -- opcode 1 (attached to Resource instance)
Release the pointer object.
Using this request, a client can tell the server that it is not going to use the pointer object anymore. Moving on, respectfully. ๐
This request destroys the pointer proxy object, so clients must not call wl_pointer_destroy() after using this request!! Do not double-destroy, I am warning you. ๐ญ
๐ง enter(serial: 'int', surface: 'WlSurface', surface_x: 'float', surface_y: 'float') -> 'None' ๐ง
Event -- opcode 0 (attached to Proxy instance)
Enter event.
Notification that this seat's pointer is focused on a certain surface. We've arrived, bestie. โจ
When a seat's focus enters a surface, the pointer image is undefined and a client should respond to this event by setting an appropriate pointer image with the set_cursor request. No blank cursors allowed. ๐
Parameters
serial(ArgumentType.Uint) -- serial number of the enter eventsurface(WlSurface) -- surface entered by the pointersurface_x(ArgumentType.Fixed) -- surface-local x coordinatesurface_y(ArgumentType.Fixed) -- surface-local y coordinate
๐ leave(serial: 'int', surface: 'WlSurface') -> 'None' ๐
Event -- opcode 1 (attached to Proxy instance)
Leave event.
serial(ArgumentType.Uint) โ the serial number of that leave event ๐surface(WlSurface) โ the surface the pointer just left behind ๐
And lowkey the tea here: the leave notification gets sent before the enter notification for the new focus. Order matters, bestie, don't forget it. โจ
motion(time: 'int', surface_x: 'float', surface_y: 'float') -> 'None'
Event โ opcode 2 (attached to Proxy instance)
Pointer motion event, aka "the mouse moved, and we're telling you about it" ๐ฆ
Notification of pointer location change. The arguments surface_x and surface_y are the location relative to the focused surface. (Not global coords, babes โ surface-local, iykyk.)
Parameters
time(ArgumentType.Uint) โ timestamp with millisecond granularity โฑ๏ธsurface_x(ArgumentType.Fixed) โ surface-local x coordinatesurface_y(ArgumentType.Fixed) โ surface-local y coordinate
button(serial: 'int', time: 'int', button: 'int', state: 'int') -> 'None'
Event โ opcode 3 (attached to Proxy instance)
Pointer button event ๐ฅ mouse button click-and-release notifications, the whole dramatic saga.
The location of the click is given by the last motion, warp or enter event. The time argument is a timestamp with millisecond granularity, with an undefined base โ so like, don't go assuming it starts anywhere in particular, bestie ๐ญ
The button is a button code as defined in the Linux kernel's linux/input-event-codes.h header file, e.g. BTN_LEFT. ๐
Any 16-bit button code value is reserved for future additions to the kernel's event code list. All other button codes above 0xFFFF are currently undefined but may be used in future versions of this protocol. (Translation: don't get comfy with them. ๐)
Parameters
serial(ArgumentType.Uint) โ serial number of the button eventtime(ArgumentType.Uint) โ timestamp with millisecond granularitybutton(ArgumentType.Uint) โ button that produced the eventstate(ArgumentType.Uint) โ physical state of the button
axis(time: 'int', axis: 'int', value: 'float') -> 'None'
Event โ opcode 4 (attached to Proxy instance)
Axis event โจ scroll and other axis notifications, the scrolling moment we've all been waiting for.
For scroll events (vertical and horizontal scroll axes), the value parameter is the length of a vector along the specified axis in a coordinate space identical to those of motion events, representing a relative movement along the specified axis. ๐
For devices that support movements non-parallel to axes, multiple axis events will be emitted.
When applicable, for example for touch pads, the server can choose to emit scroll events where the motion vector is equivalent to a motion event vector. ๐ซถ
When applicable, a client can transform its content relative to the scroll distance.
Parameters
time(ArgumentType.Uint) โ timestamp with millisecond granularityaxis(ArgumentType.Uint) โ axis typevalue(ArgumentType.Fixed) โ length of vector in surface-local coordinate space
frame() -> 'None'
Event โ opcode 5 (attached to Proxy instance)
End of a pointer event sequence โ the "okay that's the whole vibe, go ahead and process it" event ๐
Indicates the end of a set of events that logically belong together. A client is expected to accumulate the data in all events within the frame before proceeding. Like, wait for the group photo, don't post the blurry ones. ๐
All WlPointer events before a WlPointer.frame() event belong logically together. For example, in a diagonal scroll motion the compositor will send an optional WlPointer.axis_source() event, two WlPointer.axis() events (horizontal and vertical) and finally a WlPointer.frame() event. The client may use this information to calculate a diagonal vector for scrolling. โจ
When multiple WlPointer.axis() events occur within the same frame, the motion vector is the combined motion of all events. When a WlPointer.axis() and a WlPointer.axis_stop() event occur within the same frame, this indicates that axis movement in one axis has stopped but continues in the other axis. When multiple WlPointer.axis_stop() events occur within the same frame, this indicates that these axes stopped in the same instance. ๐
A WlPointer.frame() event is sent for every logical event group, even if the group only contains a single WlPointer event. Specifically, a client may get a sequence: motion, frame, button, frame, axis, frame, axis_stop, frame. (Frame for breakfast, frame for lunch, frame for dinner fr fr ๐)
The WlPointer.enter() and WlPointer.leave() events are logical events generated by the compositor and not the hardware. These events are also grouped by a WlPointer.frame(). When a pointer moves from one surface to another, a compositor should group the WlPointer.leave() event within the same WlPointer.frame(). However, a client must not rely on WlPointer.leave() and WlPointer.enter() being in the same WlPointer.frame(). Compositor-specific policies may require the WlPointer.leave() and WlPointer.enter() event being split across multiple WlPointer.frame() groups. ๐
axis_source(axis_source: 'int') -> 'None'
Event โ opcode 6 (attached to Proxy instance)
Axis source event ๐ source information for scroll and other axes. It's giving "where did this scroll even come from".
This event does not occur on its own. It is sent before a WlPointer.frame() event and carries the source information for all events within that frame.
The source specifies how this event was generated. If the source is WlPointer.axis_source().finger, a WlPointer.axis_stop() event will be sent when the user lifts the finger off the device. ๐
If the source is WlPointer.axis_source().wheel, WlPointer.axis_source().wheel_tilt or WlPointer.axis_source().continuous, a WlPointer.axis_stop() event may or may not be sent. Whether a compositor sends an axis_stop event for these sources is hardware-specific and implementation-dependent; clients must not rely on receiving an axis_stop event for these scroll sources and should treat scroll sequences from these scroll sources as unterminated by default. ๐ญ No cap, this one bites people.
This event is optional. If the source is unknown for a particular axis event sequence, no event is sent. Only one WlPointer.axis_source() event is permitted per frame.
The order of WlPointer.axis_discrete() and WlPointer.axis_source() is not guaranteed. ๐
Parameters
axis_source(ArgumentType.Uint) โ source of the axis event
axis_stop(time: 'int', axis: 'int') -> 'None'
Event โ opcode 7 (attached to Proxy instance)
Axis stop event ๐ stop notification for scroll and other axes.
For some WlPointer.axis_source() types, a WlPointer.axis_stop() event is sent to notify a client that the axis sequence has terminated. This enables the client to implement kinetic scrolling. See the WlPointer.axis_source() documentation for information on when this event may be generated. ๐
Any WlPointer.axis() events with the same axis_source after this event should be considered as the start of a new axis motion. Fresh start, new era, main character energy. โจ
The timestamp is to be interpreted identical to the timestamp in the WlPointer.axis() event. The timestamp value may be the same as a preceding WlPointer.axis() event. (Yes really, that's allowed, don't come for me.) ๐
Parameters
time(ArgumentType.Uint) โ timestamp with millisecond granularityaxis(ArgumentType.Uint) โ the axis stopped with this event
axis_discrete(axis: 'int', discrete: 'int') -> 'None'
Event โ opcode 8 (attached to Proxy instance)
Axis click event ๐ discrete step information for scroll and other axes.
This event carries the axis value of the WlPointer.axis() event in discrete steps (e.g. mouse wheel clicks).
โ ๏ธ Deprecated alert, bestie. This event is deprecated with WlPointer version 8 โ this event is not sent to clients supporting version 8 or later. So if you're on 8+, this is a historical artifact, like a flip phone. ๐
This event does not occur on its own, it is coupled with a WlPointer.axis() event that represents this axis value on a continuous scale. The protocol guarantees that each axis_discrete event is always followed by exactly one axis event with the same axis number within the same WlPointer.frame(). Note that the protocol allows for other events to occur between the axis_discrete and its coupled axis event, including other axis_discrete or axis events. A WlPointer.frame() must not contain more than one axis_discrete event per axis type. ๐
This event is optional; continuous scrolling devices like two-finger scrolling on touchpads do not have discrete steps and do not generate this event. ๐ธ
The discrete value carries the directional information. e.g. a value of -2 is two steps towards the negative direction of this axis. โญ
The axis number is identical to the axis number in the associated axis event.
And bestie, the order of WlPointer.axis_discrete() and WlPointer.axis_source()? Not guaranteed. Not even a little. ๐
Parameters
- axis (
ArgumentType.Uint) -- axis type - discrete (
ArgumentType.Int) -- number of steps
axis_value120(axis: 'int', value120: 'int') -> 'None'
Event -- opcode 9 (attached to Proxy instance)
Axis high-resolution scroll event ๐ฆโจ
Discrete high-resolution scroll information. Like, actual fine-grained scroll tea.
This event carries high-resolution wheel scroll information, where every multiple of 120 is one logical scroll step (a wheel detent, iykyk). So for example, an axis_value120 of 30 is one quarter of a logical scroll step in the positive direction, and a value120 of -240 is two logical scroll steps in the negative direction within the same hardware event. Clients that rely on discrete scrolling should accumulate the value120 to multiples of 120 before processing the event. Periodt.
The value120 must not be zero. Not negotiable, bestie. ๐
This event replaces the WlPointer.axis_discrete() event in clients supporting WlPointer version 8 or later.
Where a WlPointer.axis_source() event occurs in the same WlPointer.frame(), the axis source applies to this event.
And the order of WlPointer.axis_value120 and WlPointer.axis_source()? Not guaranteed. Again. The chaos is the vibe. ๐
Parameters
- axis (
ArgumentType.Uint) -- axis type - value120 (
ArgumentType.Int) -- scroll distance as fraction of 120
axis_relative_direction(axis: 'int', direction: 'int') -> 'None'
Event -- opcode 10 (attached to Proxy instance)
Axis relative physical direction event ๐
Relative directional information of the entity causing the axis motion. Basically who is moving and which way they really went.
For a WlPointer.axis() event, the WlPointer.axis_relative_direction() event specifies the movement direction of the entity causing the WlPointer.axis() event. For example:
- if a user's fingers on a touchpad move down and this causes a
WlPointer.axis()vertical_scroll down event, the physical direction is 'identical' - if a user's fingers on a touchpad move down and this causes a
WlPointer.axis()vertical_scroll up scroll up event ('natural scrolling'), the physical direction is 'inverted'.
A client may use this information to adjust scroll motion of components. Specifically, enabling natural scrolling causes the content to change direction compared to traditional scrolling. Some widgets like volume control sliders should usually match the physical direction regardless of whether natural scrolling is active. This event enables clients to match the scroll direction of a widget to the physical direction. Obsessed with the foresight tbh. ๐
This event does not occur on its own โ it is coupled with a WlPointer.axis() event that represents this axis value. The protocol guarantees that each axis_relative_direction event is always followed by exactly one axis event with the same axis number within the same WlPointer.frame(). Note that the protocol allows for other events to occur between the axis_relative_direction and its coupled axis event. (Yes, it can just be standing there in the middle. Iconic, honestly.)
The axis number is identical to the axis number in the associated axis event.
The order of WlPointer.axis_relative_direction(), WlPointer.axis_discrete() and WlPointer.axis_source() is not guaranteed. ๐ซ
Parameters
- axis (
ArgumentType.Uint) -- axis type - direction (
ArgumentType.Uint) -- physical direction relative to axis motion
warp(surface_x: 'float', surface_y: 'float') -> 'None'
Event -- opcode 11 (attached to Proxy instance)
Pointer warp event ๐
Notification of pointer location change within a surface. Glow-up teleportation, but for your cursor.
This location change is not due to events on the input device, but because either the surface under the pointer was moved and thus the relative position of the pointer changed, or because the compositor changed the pointer position in response to an event like pointer confinement being exited. Not the user's fault, not the mouse's fault. ๐ง
The arguments surface_x and surface_y are the location relative to the focused surface.
This event must not occur in the sameWlPointer.frame()as aWlPointer.enter()orWlPointer.motion()event. Do not try it. We are watching. ๐
Parameters
- surface_x (
ArgumentType.Fixed) -- surface-local x coordinate - surface_y (
ArgumentType.Fixed) -- surface-local y coordinate
๐ WlRegion ๐
class pywayland.protocol.wayland.WlRegion
Region interface
A region object describes an area. That's it, that's the whole job and it eats every time. โจ
Region objects are used to describe the opaque and input regions of a surface.
destroy() -> 'None'
Request -- opcode 0 (attached to Resource instance)
Destroy region
Destroy the region. This will invalidate the object ID. She's gone, bestie, and the ID goes with her. ๐ฆ
add(x: 'int', y: 'int', width: 'int', height: 'int') -> 'None'
Request -- opcode 1 (attached to Resource instance)
Add rectangle to region
Add the specified rectangle to the region.
Parameters
- x (
ArgumentType.Int) -- region-local x coordinate - y (
ArgumentType.Int) -- region-local y coordinate - width (
ArgumentType.Int) -- rectangle width - height (
ArgumentType.Int) -- rectangle height
subtract(x: 'int', y: 'int', width: 'int', height: 'int') -> 'None'
Request -- opcode 2 (attached to Resource instance)
Subtract rectangle from region
Subtract the specified rectangle from the region.
Parameters
- x (
ArgumentType.Int) -- region-local x coordinate - y (
ArgumentType.Int) -- region-local y coordinate - width (
ArgumentType.Int) -- rectangle width - height (
ArgumentType.Int) -- rectangle height
๐ WlRegistry ๐
class pywayland.protocol.wayland.WlRegistry
Global registry object
The singleton global registry object. The server has a number of global objects that are available to all clients. These objects typically represent an actual object in the server (for example, an input device) or they are singleton objects that provide extension functionality. One registry to rule them all, fr fr. ๐
When a client creates a registry object, the registry object will emit a global event for each global currently in the registry. Globals come and go as a result of device or monitor hotplugs, reconfiguration or other events, and the registry will send out global and global_remove events to keep the client up to date with the changes. To mark the end of the initial burst of events, the client can use the WlDisplay.sync() request immediately after calling WlDisplay.get_registry(). Yes, call it immediately after. Main character timing. โญ
A client can bind to a global object by using the bind request. This creates a client-side handle that lets the object emit events to the client and lets the client invoke requests on the object.
bind(name: 'int', interface: 'type[T]', version: 'int') -> 'Proxy[T]'
Request -- opcode 0 (attached to Resource instance)
Bind an object to the display
Binds a new, client-created object to the server using the specified name as the identifier.
Parameters
- name (
ArgumentType.Uint) -- unique numeric name of the object - interface (string) -- Interface name
- version (int) -- Interface version
Returns pywayland.client.proxy.Proxy of specified Interface -- bound object
global_(name: 'int', interface: 'str', version: 'int') -> 'None'
Event -- opcode 0 (attached to Proxy instance)
Announce global object
Notify the client of global objects.
The event notifies the client that a global object with the given name is now available, and it implements the given version of the given interface. New drop just landed. ๐
Parameters
- name (
ArgumentType.Uint) -- numeric name of the global object - interface (
ArgumentType.String) -- interface implemented by the object - version (
ArgumentType.Uint) -- interface version
global_remove(name: 'int') -> 'None'
Event -- opcode 1 (attached to Proxy instance)
Announce removal of global object
Notify the client of removed global objects.
This event notifies the client that the global identified by name is no longer available. If the client bound to the global using the bind request, the client should now destroy that object. She left the group chat, destroy the object. ๐ญ
The object remains valid and requests to the object will be ignored until the client destroys it, to avoid races between the global going away and a client sending a request to it. The ghost stays valid, the messages get left on read. No cap.
Parameters name (ArgumentType.Uint) -- numeric name of the global object
๐ WlSeat ๐
class pywayland.protocol.wayland.WlSeat
Group of input devices
A seat is basically a lil squad of input devices โ keyboards, pointers, and touch stuff all chilling together. It gets published as a global when you start up, or whenever one of those devices gets hot plugged in. Your average seat has a pointer and it keeps track of a keyboard focus and a pointer focus. ๐
get_pointer() -> 'Proxy[WlPointer]'
- Request โ opcode 0 (attached to Resource instance)
Return pointer object โ gimme the pointer bestie ๐
That ID you hand over gets initialized to the WlPointer interface for this seat.
Heads up though: this request only actually does anything if the seat has the pointer capability, or has had it at some point in the past. Issuing it on a seat that has never had the pointer capability is a protocol violation, and the missing_capability error will get sent in that case. ๐ซ
Returns
WlPointerโ seat pointer
get_keyboard() -> 'Proxy[WlKeyboard]'
- Request โ opcode 1 (attached to Resource instance)
Return keyboard object โจ
The ID you provide gets initialized to the WlKeyboard interface for this seat.
Same deal as the pointer: this only takes effect if the seat has the keyboard capability, or has had the keyboard capability in the past. Doing it on a seat that has never had the keyboard capability is a protocol violation and you'll get the missing_capability error. No cap.
Returns
WlKeyboard-- seat keyboard
get_touch() -> 'Proxy[WlTouch]'
- Request โ opcode 2 (attached to Resource instance)
Return touch object ๐ซถ
That ID gets initialized to the WlTouch interface for this seat.
You already know the vibe: only takes effect if the seat has the touch capability, or had it in the past. Requesting it on a seat that never had touch capability is a protocol violation, and boom, missing_capability error. ๐ญ
Returns
WlTouch-- seat touch interface
release() -> 'None'
- Request โ opcode 3 (attached to Resource instance)
Release the seat object
With this request a client can tell the server it's done with the seat object, no longer using it, bye bestie ๐
capabilities(capabilities: 'int') -> 'None'
- Event โ opcode 0 (attached to Proxy instance)
Seat capabilities changed ๐ฅ
This gets sent when you bind to the seat global, or whenever a seat gains or loses the pointer, keyboard, or touch capabilities. The argument is a capability enum containing the complete set of capabilities this seat has.
When the pointer capability gets added, a client may create a WlPointer object using the WlSeat.get_pointer() request. That object will receive pointer events until the capability gets removed later on.
When the pointer capability is removed, a client should destroy the WlPointer objects associated with the seat where the capability was removed, using the WlPointer.release() request. No further pointer events will be received on those objects. Periodt.
In some compositors, if a seat regains the pointer capability and a client has a previously obtainedWlPointerobject of version 4 or less, that object may start sending pointer events again. This behavior is considered a misinterpretation of the intended behavior and must not be relied upon by the client.WlPointerobjects of version 5 or later must not send events if created before the most recent event notifying the client of an added pointer capability.
The above behavior also applies to WlKeyboard and WlTouch with the keyboard and touch capabilities, respectively.
Parameters
capabilities(ArgumentType.Uint) โ capabilities of the seat
name(name: 'str') -> 'None'
- Event โ opcode 1 (attached to Proxy instance)
Unique identifier for this seat ๐ธ
In a multi-seat configuration the seat name can be used by clients to help figure out which physical devices the seat represents.
The seat name is a UTF-8 string and there's no convention defined for its contents. Each name is unique among all WlSeat globals. It's only guaranteed to be unique for the current compositor instance though.
The same seat names are used for all clients. So yeah โ the name can be shared across processes to refer to a specific WlSeat global. ๐
The name event is sent after binding to the seat global, and should be sent before announcing capabilities. It's only sent once per seat object, and the name doesn't change over the lifetime of the WlSeat global.
Compositors may re-use the same seat name if the WlSeat global is destroyed and re-created later.
Parameters
name(ArgumentType.String) โ seat identifier
WlShell
class pywayland.protocol.wayland.WlShell
Create desktop-style surfaces
This interface is implemented by servers that provide desktop-style user interfaces.
It lets clients associate a WlShellSurface with a basic surface.
Note! This protocol is deprecated and not intended for production use. For desktop-style user interfaces, use xdg_shell. Compositors and clients should not implement this interface.
get_shell_surface(surface: 'WlSurface') -> 'Proxy[WlShellSurface]'
- Request โ opcode 0 (attached to Resource instance)
Create a shell surface from a surface
Create a shell surface for an existing surface. This gives the WlSurface the role of a shell surface. If the WlSurface already has another role, it raises a protocol error. ๐จ
Only one shell surface can be associated with a given surface.
Parameters
surface(WlSurface) โ surface to be given the shell surface role
Returns
WlShellSurfaceโ shell surface to create
WlShellSurface
class pywayland.protocol.wayland.WlShellSurface
Desktop-style metadata interface
An interface that may be implemented by a WlSurface, for implementations that provide a desktop-style user interface.
It provides requests to treat surfaces like toplevel, fullscreen or popup windows โ move, resize or maximize them, associate metadata like title and class, etc. ๐ช
On the server side the object is automatically destroyed when the related WlSurface is destroyed. On the client side, wl_shell_surface_destroy() must be called before destroying the WlSurface object. Don't forget, bestie. ๐
pong(serial: 'int') -> 'None'
- Request โ opcode 0 (attached to Resource instance)
Respond to a ping event
A client must respond to a ping event with a pong request or the client may be deemed unresponsive. ๐ณ
Parameters
serial(ArgumentType.Uint) โ serial number of the ping event
move(seat: 'WlSeat', serial: 'int') -> 'None'
- Request โ opcode 1 (attached to Resource instance)
Start an interactive move
Start a pointer-driven move of the surface.
This request must be used in response to a button press event. The server may ignore move requests depending on the state of the surface (e.g. fullscreen or maximized).
Parameters
seat(WlSeat) โ seat whose pointer is usedserial(ArgumentType.Uint) โ serial number of the implicit grab on the pointer
resize(seat: 'WlSeat', serial: 'int', edges: 'int') -> 'None'
- Request โ opcode 2 (attached to Resource instance)
Start an interactive resize
Start a pointer-driven resizing of the surface.
This request must be used in response to a button press event. The server may ignore resize requests depending on the state of the surface (e.g. fullscreen or maximized).
Parameters
seat(WlSeat) โ seat whose pointer is usedserial(ArgumentType.Uint) โ serial number of the implicit grab on the pointeredges(ArgumentType.Uint) โ which edge or corner is being dragged
set_toplevel() -> 'None'
- Request โ opcode 3 (attached to Resource instance)
Make the surface a toplevel surface โญ
Map the surface as a toplevel surface.
A toplevel surface is not fullscreen, maximized or transient.
set_transient(parent: 'WlSurface', x: 'int', y: 'int', flags: 'int') -> 'None'
- Request โ opcode 4 (attached to Resource instance)
Make the surface a transient surface
Map the surface relative to an existing surface.
The x and y arguments specify the location of the upper left corner of the surface relative to the upper left corner of the parent surface, in surface-local coordinates.
The flags argument controls details of the transient behaviour.
Parameters
parent(WlSurface) โ parent surfacex(ArgumentType.Int) โ surface-local x coordinatey(ArgumentType.Int) โ surface-local y coordinateflags(ArgumentType.Uint) โ transient surface behavior
set_fullscreen(method: 'int', framerate: 'int', output: 'WlOutput | None') -> 'None'
Request โ opcode 5 (attached to Resource instance)
Make the surface a fullscreen surface ๐
Okay bestie, this one does exactly what it says on the tin โ maps the surface as a fullscreen surface. Full screen. No panels, no taskbar, no mercy. ๐
If an _output_ parameter is given, then the surface is made fullscreen on that output. If the client doesn't specify the output, the compositor just does its own thing (applies its policy) โ which usually means it picks the output where the surface has the biggest surface area. Very "I'll pick for you, don't worry about it" of it. โจ
The client can pass a _method_ to sort out a size conflict between the output size and the surface size โ that's literally what the _method_ parameter is for.
The _framerate_ parameter only matters when _method_ is set to "driver", and it tells the compositor the preferred framerate. A value of 0 means the client simply does not care about framerate. And heads up: the framerate is specified in mHz, so a framerate of 60000 is 60Hz. Do not get that wrong, I am begging you. ๐ญ
A method of "scale" or "driver" implies a scaling operation of the surface โ either via a direct scaling operation or by changing the output mode. This overrides any kind of output scaling, so mapping a surface with a buffer size equal to the mode can fill the screen independent of buffer_scale. Slay.
A method of "fill" means we don't scale the buffer up, but any output scale still gets applied. Which means you can run into an edge case where the app maps a buffer with the same size as the output mode but buffer_scale 1 โ making a surface larger than the output. In that case it is allowed to downscale the results to fit the screen. Awkward but legal. ๐
The compositor must reply to this request with a configure event, with the dimensions for the output on which the surface will be made fullscreen. No skipping that, it's mandatory, periodt.
Parameters
method(ArgumentType.Uint) โ method for resolving size conflictframerate(ArgumentType.Uint) โ framerate in mHzoutput(WlOutputorNone) โ output on which the surface is to be fullscreen
set_popup(seat: 'WlSeat', serial: 'int', parent: 'WlSurface', x: 'int', y: 'int', flags: 'int') -> 'None'
Request โ opcode 6 (attached to Resource instance)
Make the surface a popup surface ๐
This maps the surface as a popup. A popup surface is a transient surface with an added pointer grab. So it pops up, it grabs the pointer, it's the main character for a sec. ๐ธ
An existing implicit grab gets changed to owner-events mode, and the popup grab keeps going after the implicit grab ends โ meaning, and I need you to hear this, releasing the mouse button does not cause the popup to be unmapped. It just chills there. ๐
The popup grab continues until the window is destroyed, or until a mouse button is pressed in any other client's window. A click in any of the client's own surfaces is reported as normal โ but clicks in other clients' surfaces get discarded and trigger the callback. Sorry babe, that click ain't yours. ๐
The _x_ and _y_ arguments specify the location of the upper left corner of the surface, relative to the upper left corner of the parent surface, in surface-local coordinates. Upper-left to upper-left, that's the vibe.
Parameters
seat(WlSeat) โ seat whose pointer is usedserial(ArgumentType.Uint) โ serial number of the implicit grab on the pointerparent(WlSurface) โ parent surfacex(ArgumentType.Int) โ surface-local x coordinatey(ArgumentType.Int) โ surface-local y coordinateflags(ArgumentType.Uint) โ transient surface behavior
set_maximized(output: 'WlOutput | None') -> 'None'
Request โ opcode 7 (attached to Resource instance)
Make the surface a maximized surface ๐ฆ
Maps the surface as a maximized surface. Big, but polite about it.
If an _output_ parameter is given, the surface gets maximized on that output. If the client doesn't specify the output, the compositor applies its policy โ which, again, usually means picking the output where the surface has the biggest surface area. Same energy as fullscreen, honestly. โจ
The compositor replies with a configure event telling the expected new surface size. And the operation is completed on the next buffer attach to this surface โ so don't go thinking it's done before then. โญ
A maximized surface typically fills the entire output it's bound to, except for desktop elements like panels. And that is the main difference between a maximized shell surface and a fullscreen shell surface โ maximized respects the panels, fullscreen does not. ๐
The details depend on the compositor implementation. iykyk.
Parameters
output(WlOutputorNone) โ output on which the surface is to be maximized
set_title(title: 'str') -> 'None'
Request โ opcode 8 (attached to Resource instance)
Set surface title ๐
Sets a short title for the surface. Keep it cute, keep it brief.
This string may be used to identify the surface in a task bar, window list, or other user interface elements provided by the compositor. So yeah, it's the name on the door. ๐ชโจ
The string must be encoded in UTF-8. Non-negotiable. ๐
Parameters
title(ArgumentType.String) โ surface title
set_class(class_: 'str') -> 'None'
Request โ opcode 9 (attached to Resource instance)
Set surface class ๐ธ
Sets a class for the surface. Not a school class, a category class. ๐
The surface class identifies the general class of applications to which the surface belongs. A common convention is to use the file name โ or the full path if it's a non-standard location โ of the application's .desktop file as the class. So like, org.gnome.Terminal type beat. ๐ง
Parameters
class(ArgumentType.String) โ surface class
ping(serial: 'int') -> 'None'
Event โ opcode 0 (attached to Proxy instance)
Ping client ๐ซถ
Pings a client to check whether it's actually receiving events and sending requests. You know, the "u up?" of the Wayland protocol. ๐
A client is expected to reply with a pong request. If they ghost you... that says a lot tbh. ๐ญ
Parameters
serial(ArgumentType.Uint) โ serial number of the ping
configure(edges: 'int', width: 'int', height: 'int') -> 'None'
Event โ opcode 1 (attached to Proxy instance)
Suggest resize โจ
The configure event asks the client to resize its surface. It's giving "hey maybe try this size?"
The size is a hint โ the client is free to ignore it if it doesn't resize, or pick a smaller size (to satisfy aspect ratio, or to resize in steps of NxM pixels). So it's a suggestion, not a command. Very chill. ๐
The _edges_ parameter gives a hint about how the surface was resized. The client may use that info to decide how to adjust its content to the new size โ for example, a scrolling area might adjust its content position to leave the viewable content unmoved. Iconic behaviour honestly. ๐
The client is free to dismiss all but the last configure event it received. So if you got five of them, only the last one matters. Bye to the rest. ๐
The _width_ and _height_ arguments specify the size of the window in surface-local coordinates.
Parameters
edges(ArgumentType.Uint) โ how the surface was resizedwidth(ArgumentType.Int) โ new width of the surfaceheight(ArgumentType.Int) โ new height of the surface
popup_done() -> 'None'
Event โ opcode 2 (attached to Proxy instance)
Popup interaction is done ๐
The popup_done event gets sent out when a popup grab is broken. That is, when the user clicks a surface that doesn't belong to the client that owns the popup surface. Rip to the popup, it's over. ๐ซถ
WlShm ๐
class pywayland.protocol.wayland.WlShm
Shared memory support. ๐ง โจ
A singleton global object that provides support for shared memory.
Clients can create WlShmPool objects using the create_pool request.
On binding the WlShm object, one or more format events are emitted to inform clients about the valid pixel formats that can be used for buffers. So you get the whole list up front, no guessing. ๐
create_pool
create_pool(fd: 'int', size: 'int') -> 'Proxy[WlShmPool]'
Request โ opcode 0 (attached to Resource instance)
Create a shm pool. ๐
Creates a new WlShmPool object.
The pool can be used to create shared memory based buffer objects. The server will mmap _size_ bytes of the passed file descriptor, to use as backing memory for the pool. So that fd better be valid, bestie. โญ
Parameters
fd(ArgumentType.FileDescriptor) โ file descriptor for the poolsize(ArgumentType.Int) โ pool size, in bytes
Returns
WlShmPoolโ pool to create
release
release() -> 'None'
Request โ opcode 1 (attached to Resource instance)
Release the shm object. ๐ฆ
Using this request a client can tell the server that it is not going to use the shm object anymore. It's the polite "okay we're done here, thank u next" ๐
Objects created via this interface remain unaffected. So the pools you made live on, no cap. โจ
format
format(format: 'int') -> 'None'
Event โ opcode 0 (attached to Proxy instance)
Pixel format description. ๐
Informs the client about a valid pixel format that can be used for buffers. Known formats include argb8888 and xrgb8888. Those two are the classics, the OG iconics. ๐
Extensions to drm_fourcc.h (or the format enum, whichever you vibe with) do not require bumping the WlShm version, bestie. Which means โ plot twist โ clients can absolutely receive format codes that weren't even in the list back when the client got built. It's giving forward compatibility. ๐
Parameters
format(ArgumentType.Uint) โ buffer pixel format ๐จ
๐ธ WlShmPool ๐ธ
class pywayland.protocol.wayland.WlShmPool
A shared memory pool. ๐ซง
The WlShmPool object is literally a chunk of memory shared between the compositor and the client. Through it, the client can allocate shared-memory WlBuffer objects. Every object created through the same pool shares the same underlying mapped memory โ so reusing that mapped memory dodges all the setup/teardown overhead, which is lowkey perfect when you're interactively resizing a surface or just have a ton of tiny buffers. ๐
create_buffer
create_buffer(offset: 'int', width: 'int', height: 'int', stride: 'int', format: 'int') -> 'Proxy[WlBuffer]'
Request -- opcode 0 (attached to Resource instance)
Create a buffer from the pool ๐
Makes a WlBuffer object out of the pool.
The buffer gets created offset bytes into the pool, with width and height exactly as specified. The stride argument is the number of bytes from the start of one row to the start of the next one (iykyk, it's the row-hop count). And format is the buffer's pixel format, which must be one of the ones advertised through the WlShm.format() event โ no making up your own. ๐
A buffer keeps a reference to the pool it was born from, so it's totally valid to destroy the pool the instant after you create a buffer from it. Slay. โจ
Parameters
offset(ArgumentType.Int) โ buffer byte offset within the poolwidth(ArgumentType.Int) โ buffer width, in pixelsheight(ArgumentType.Int) โ buffer height, in pixelsstride(ArgumentType.Int) โ number of bytes from the beginning of one row to the beginning of the next rowformat(ArgumentType.Uint) โ buffer pixel format
Returns
WlBuffer โ buffer to create ๐ฆ
destroy
destroy() -> 'None'
Request -- opcode 1 (attached to Resource instance)
Destroy the pool ๐
Destroys the shared memory pool.
The mmapped memory gets released once all the buffers that were created from this pool are gone. So like, no rush, but also no leaks. ๐
resize
resize(size: 'int') -> 'None'
Request -- opcode 2 (attached to Resource instance)
Change the size of the pool mapping ๐
This request makes the server remap the pool's backing memory from the file descriptor that was passed when the pool got created โ but using the new size. Heads up: this request can only be used to make the pool bigger. No shrinking, bestie. ๐
This request only changes how many bytes the server mmaps. It does not touch the file behind the file descriptor you passed at creation time. So it is 100% the client's responsibility to make sure that file is at least as big as the new pool size. Periodt. โญ
Parameters
size(ArgumentType.Int) โ new size of the pool, in bytes
๐ง WlSubcompositor ๐ง
class pywayland.protocol.wayland.WlSubcompositor
Sub-surface compositing โจ
The global interface that exposes sub-surface compositing capabilities. A WlSurface that has sub-surfaces attached to it is called the parent surface. And sub-surfaces can be nested arbitrarily deep, which builds up a whole tree of sub-surfaces. ๐ณ
The root surface in that tree is the main surface. The main surface can't itself be a sub-surface, because sub-surfaces must always have a parent โ them's the rules. ๐
A main surface plus all its sub-surfaces together forms a (compound) window. For window-management purposes, that whole set of WlSurface objects counts as a single window, and it should behave like one too.
The whole point of sub-surfaces is to offload some of the compositing work inside a window from the clients onto the compositor. The prime example: a video player with decorations and the video living in separate WlSurface objects. That lets the compositor hand YUV video buffer processing off to dedicated overlay hardware whenever it can. Iconic. ๐ฅ
destroy
destroy() -> 'None'
Request -- opcode 0 (attached to Resource instance)
Unbind from the subcompositor interface ๐
Tells the server that the client is done with this protocol object. Don't worry โ this doesn't affect any other objects, WlSubsurface objects included.
get_subsurface
get_subsurface(surface: 'WlSurface', parent: 'WlSurface') -> 'Proxy[WlSubsurface]'
Request -- opcode 1 (attached to Resource instance)
Give a surface the role sub-surface ๐ญ
Creates a sub-surface interface for the given surface and associates it with the given parent surface. Basically turns a plain WlSurface into a sub-surface.
The to-be sub-surface must not already have another role, and it must not already have a WlSubsurface object. Otherwise โ boom โ the bad_surface protocol error gets raised. ๐
Adding sub-surfaces to a parent is a double-buffered operation on the parent (see WlSurface.commit()). The effect of adding a sub-surface becomes visible the next time the parent surface's state gets applied.
The parent surface must not be one of the child surface's descendants, and the parent has to be different from the child surface โ otherwise the bad_parent protocol error gets raised. No circular nonsense here. ๐
โโ๏ธ
This request changes how the WlSurface.commit() request behaves on the sub-surface, so go read the docs on the WlSubsurface interface.
Parameters
surface(WlSurface) โ the surface to be turned into a sub-surfaceparent(WlSurface) โ the parent surface
Returns
WlSubsurface โ the new sub-surface object ID ๐
๐ฆ WlSubsurface ๐ฆ
class pywayland.protocol.wayland.WlSubsurface
Sub-surface interface to a WlSurface ๐ซ
An extra interface bolted onto a WlSurface object that has been made into a sub-surface. A sub-surface has exactly one parent surface. Its size and position are not limited to the parent's โ in particular, a sub-surface is not automatically clipped to its parent's area. Live your truth, overflow your parent. ๐
A sub-surface becomes mapped when a non-NULL WlBuffer is applied and the parent surface is mapped. Which one of those happens first? Doesn't matter. A sub-surface is hidden if the parent becomes hidden, or if a NULL WlBuffer gets applied. And these rules apply recursively down the whole tree of surfaces. ๐ฒ
A sub-surface can be in one of two modes: synchronized or desynchronized. See the methods WlSubsurface.set_sync() and WlSubsurface.set_desync(). ๐๏ธ
The main surface can be thought of as always being in desynchronized mode, since it doesn't have a parent in the sub-surfaces sense.
And okay, here's the tea: even if a sub-surface is in desynchronized mode, it'll behave as if it were in synchronized mode whenever its parent surface behaves as synchronized. This rule applies recursively throughout the entire tree. So you can set one sub-surface into synchronized mode and then just assume all its children and grandchildren are synchronized too โ no need to set them explicitly. The way that inheritance just works. ๐
If a surface behaves as synchronized, it's effectively synchronized; otherwise it's effectively desynchronized.
A sub-surface starts out in the synchronized mode. That's the default, bestie.
The WlSubsurface interface has requests that modify the double-buffered state of the parent surface: WlSubsurface.set_position(), .place_above, and .place_below. ๐ฏ
Destroying a sub-surface takes effect immediately. So if you need to synchronize the removal of a sub-surface with the parent surface update, unmap the sub-surface first by attaching a NULL WlBuffer, update the parent, and then destroy the sub-surface. Order matters, fr fr. ๐ญ
If the parent WlSurface object gets destroyed, the sub-surface is unmapped.
A sub-surface never has keyboard focus of any seat. Sorry, it's just not that kind of surface. ๐
The WlSurface.offset() request is ignored โ clients must use set_position instead to move the sub-surface. Don't fight it. ๐
destroy
destroy() -> 'None'
Request -- opcode 0 (attached to Resource instance)
Remove sub-surface interface โ๏ธ
The sub-surface interface gets removed from the WlSurface object that was turned into a sub-surface with a WlSubcompositor.get_subsurface() request. The wl_surface's association to the parent is deleted, and the WlSurface is unmapped immediately.
set_position
set_position(x: 'int', y: 'int') -> 'None'
Request -- opcode 1 (attached to Resource instance)
Reposition the sub-surface ๐ฏ
This sets the position of the sub-surface, relative to the parent surface.
The sub-surface gets moved so its origin (the top left corner pixel) sits at the location x, y of the parent surface's coordinate system. Those coordinates are not restricted to the parent surface's area โ negative values are totally allowed. Go wild. ๐
The initial position is 0, 0.
Position is double-buffered state on the parent surface โ see WlSubsurface and WlSurface.commit() for more info.
Parameters
x(ArgumentType.Int) โ x coordinate in the parent surfacey(ArgumentType.Int) โ y coordinate in the parent surface
place_above
place_above(sibling: 'WlSurface') -> 'None'
Request โ opcode 2 (attached to Resource instance)
Restack the sub-surface
okay so picture this: your sub-surface gets yoinked out of the stack and set back down just above the reference surface, and that reshuffles the z-order of all the sub-surfaces. ๐ The reference surface has to be one of the sibling surfaces, or the parent surface โ that's the rule. Use literally any other surface, including this sub-surface itself, and boom, protocol error. not negotiable bestie.
Also FYI: a brand new sub-surface starts life as the top-most in the stack of its siblings and parent. main character debut, honestly. ๐
And z-order? It's double-buffered state on the parent surface, so if you want the whole lore, go read WlSubsurface and WlSurface.commit().
Parameters
sibling(WlSurface) โ the reference surface
place_below(sibling: 'WlSurface') -> 'None'
Request โ opcode 3 (attached to Resource instance)
Restack the sub-surface
Same vibe as above but inverted: the sub-surface gets placed just below the reference surface. that's it, that's the request. ๐ฆ
See WlSubsurface.place_above() for the rest of the story.
Parameters
sibling(WlSurface) โ the reference surface
set_sync() -> 'None'
Request โ opcode 4 (attached to Resource instance)
Set sub-surface to synchronized mode
This switches up the commit behaviour of the sub-surface so it's in synchronized mode. โจ
See WlSubsurface and WlSurface.commit() for more information.
set_desync() -> 'None'
Request โ opcode 5 (attached to Resource instance)
Set sub-surface to desynchronized mode
And this one flips the commit behaviour of the sub-surface into desynchronized mode. two sides of the same coin, we love a matched set ๐ช
See WlSubsurface and WlSurface.commit() for more information.
๐ฆ WlSurface ๐ฆ
class pywayland.protocol.wayland.WlSurface
An onscreen surface
A surface is a rectangular area that may be displayed on zero or more outputs, and shown any number of times at the compositor's discretion. Zero outputs, bestie โ yes, really, it can just vibe invisibly. It can present wl_buffers, receive user input, and define a local coordinate system. ๐ธ
The size of a surface (and relative positions on it) is described in surface-local coordinates, which may differ from the buffer coordinates of the pixel content, in case a buffer_transform or a buffer_scale is used. so like, the math is doing math. ๐ข
Now, a surface without a "role" is fairly useless โ a compositor genuinely does not know where, when or how to present it. The role is the purpose of a WlSurface. Some iconic role examples:
- a cursor for a pointer, as set by
WlPointer.set_cursor() - a drag icon, via
WlDataDevice.start_drag() - a sub-surface, via
WlSubcompositor.get_subsurface() - a window as defined by a shell protocol, e.g.
WlShell.get_shell_surface()
A surface can have only one role at a time. Initially a WlSurface does not have a role at all โ a blank slate, an unclaimed vibe. ๐ But once a WlSurface is given a role, it is set permanently for the whole lifetime of the WlSurface object. Giving the current role again is allowed, unless it's explicitly forbidden by the relevant interface specification. so you can re-declare who you are, you just can't reinvent yourself. periodt.
Surface roles are given by requests in other interfaces, like WlPointer.set_cursor(). The request should explicitly mention that this request gives a role to a WlSurface. Often, this request also creates a new protocol object that represents the role and adds additional functionality to WlSurface. And when a client wants to destroy a WlSurface, they must destroy this role object before the WlSurface โ otherwise a defunct_role_object error gets sent. do not skip that step, it's giving "forgot to cancel the subscription" energy. ๐ญ
Destroying the role object does not remove the role from the WlSurface, but it may stop the WlSurface from "playing the role". For instance, if a WlSubsurface object is destroyed, the WlSurface it was created for will be unmapped and forget its position and z-order. It is allowed to create a WlSubsurface for the same WlSurface again, but it is not allowed to use the WlSurface as a cursor โ cursor is a different role than sub-surface, and role switching is not allowed. no take-backs, no glow-ups into a different species. ๐ซ
destroy() -> 'None'
Request โ opcode 0 (attached to Resource instance)
Delete surface
Deletes the surface and invalidates its object ID. gone, gone, gone ๐
attach(buffer: 'WlBuffer | None', x: 'int', y: 'int') -> 'None'
Request โ opcode 1 (attached to Resource instance)
Set the surface contents
Set a buffer as the content of this surface. ๐
The new size of the surface is calculated based on the buffer size transformed by the inverse buffer_transform and the inverse buffer_scale. Which means: at commit time, the supplied buffer size must be an integer multiple of the buffer_scale. If that's not the case, an invalid_size error is sent. math must math. ๐งฎ
The x and y arguments specify the location of the new pending buffer's upper left corner, relative to the current buffer's upper left corner, in surface-local coordinates. In other words, the x and y, combined with the new surface size, define in which directions the surface's size changes. Setting anything other than 0 as x and y arguments is discouraged, and should instead be replaced with using the separate WlSurface.offset() request. ๐
When the bound WlSurface version is 5 or higher, passing any non-zero x or y is a protocol violation, and will result in an invalid_offset error being raised. In that case the x and y arguments are ignored and do not change the pending state. To achieve equivalent semantics, use WlSurface.offset().
โ ๏ธ non-zerox/yon version 5+ = protocol violation,invalid_offset, args ignored. you've been warned bestie.
Surface contents are double-buffered state, see WlSurface.commit().
The initial surface contents are void; there is no content. WlSurface.attach() assigns the given WlBuffer as the pending WlBuffer. WlSurface.commit() makes the pending WlBuffer the new surface contents, and the size of the surface becomes the size calculated from the WlBuffer, as described above. After commit, there is no pending buffer until the next attach. clean slate every time โจ
Committing a pending WlBuffer allows the compositor to read the pixels in the WlBuffer. The compositor may access the pixels at any time after the WlSurface.commit() request. When the compositor will not access the pixels anymore, it will send the WlBuffer.release() event. Only after receiving WlBuffer.release(), the client may reuse the WlBuffer. A WlBuffer that has been attached and then replaced by another attach instead of committed will not receive a release event, and is not used by the compositor. ๐
If a pending WlBuffer has been committed to more than one WlSurface, the delivery of WlBuffer.release() events becomes undefined. A well behaved client should not rely on WlBuffer.release() events in this case. Instead, clients hitting this case should use WlSurface.get_release() or use a protocol extension providing per-commit release notifications. And if none of these options are available, a fallback can be implemented by creating multiple WlBuffer objects from the same backing storage. iykyk ๐ซถ
Destroying the WlBuffer after WlBuffer.release() does not change the surface contents. Destroying the WlBuffer before WlBuffer.release() is allowed, as long as the underlying buffer storage isn't re-used โ this can happen e.g. on client process termination. However, if the client destroys the WlBuffer before receiving the WlBuffer.release() event and mutates the underlying buffer storage, the surface contents become undefined immediately. ๐ญ
If WlSurface.attach() is sent with a NULL WlBuffer, the following WlSurface.commit() will remove the surface content. bye-bye pixels ๐
If a pending WlBuffer has been destroyed, the result is not specified. Many compositors are known to remove the surface content on the following WlSurface.commit(), but this behaviour is not universal. Clients seeking to maximise compatibility should not destroy pending buffers, and should ensure that they explicitly remove content from surfaces, even after destroying buffers. ๐
Parameters
buffer(WlBufferorNone) โ buffer of surface contentsx(ArgumentType.Int) โ surface-local x coordinatey(ArgumentType.Int) โ surface-local y coordinate
damage(x: 'int', y: 'int', width: 'int', height: 'int') -> 'None'
Request โ opcode 2 (attached to Resource instance)
Mark part of the surface damaged
This request is used to describe the regions where the pending buffer is different from the current surface contents, and where the surface therefore needs to be repainted. The compositor ignores the parts of the damage that fall outside of the surface. out of bounds? not my problem, says the compositor. ๐
Damage is double-buffered state, see WlSurface.commit().
The damage rectangle is specified in surface-local coordinates, where x and y specify the upper left corner of the damage rectangle. ๐
The initial value for pending damage is empty: no damage. WlSurface.damage() adds pending damage โ the new pending damage is the union of old pending damage and the given rectangle. stacking rectangles like they're outfit layers fr fr ๐
WlSurface.commit() assigns pending damage as the current damage, and clears pending damage. The server will clear the current damage as it repaints the surface. slay, glow-up achieved โจ
Note! New clients should not use this request. Instead damage can be posted with WlSurface.damage_buffer() which uses buffer coordinates instead of surface coordinates. bestie the old way still exists but it's giving legacy energy ๐
Parameters
x(ArgumentType.Int) โ surface-local x coordinatey(ArgumentType.Int) โ surface-local y coordinatewidth(ArgumentType.Int) โ width of damage rectangleheight(ArgumentType.Int) โ height of damage rectangle
๐ฆ frame() -> 'Proxy[WlCallback]'
Request โ opcode 3 (attached to Resource instance)
Request a frame throttling hint โจ
Okay so basically: you ask the compositor to ping you back when it's a good time to start drawing a new frame, and it does that by creating a frame callback. This is the move for throttling redrawing and driving your animations. no more drawing into the void ๐
When a client is animating on a WlSurface, it can use the frame request to get notified when it is a good time to draw and commit the next frame of animation. If the client commits an update earlier than that, it is likely that some updates will not make it to the display, and the client is wasting resources by drawing too often. like girl why are you rendering 900 times, nobody saw it ๐ญ
The frame request takes effect on the next WlSurface.commit(). The notification will only be posted for one frame unless requested again. For a WlSurface, the notifications are posted in the order the frame requests were committed.
The server must send the notifications so that a client will not send excessive updates, while still allowing the highest possible update rate for clients that wait for the reply before drawing again. The server should give some time for the client to draw and commit after sending the frame callback events, to let it hit the next output refresh.
A server should avoid signaling the frame callbacks if the surface is not visible in any way โ e.g. the surface is off-screen, or completely obscured by other opaque surfaces. if nobody can see it, why are we yapping ๐ต
Important one, don't skip it: 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. fr fr, it's gone, let it go ๐
The callback_data passed in the callback is the current time, in milliseconds, with an undefined base. undefined base!! don't compare it to your wall clock, it's not that kind of number โญ
Returns WlCallback โ callback object for the frame request
๐ธ set_opaque_region(region: 'WlRegion | None') -> 'None'
Request โ opcode 4 (attached to Resource instance)
Set opaque region
This request sets the region of the surface that contains opaque content.
The opaque region is an optimization hint for the compositor that lets it optimize the redrawing of content behind opaque regions. Setting an opaque region is not required for correct behaviour, but marking transparent content as opaque will result in repaint artifacts. so likeโฆ don't lie to it ๐
The opaque region is specified in surface-local coordinates.
The compositor ignores the parts of the opaque region that fall outside of the surface.
Opaque region is double-buffered state, see WlSurface.commit().
WlSurface.set_opaque_region() changes the pending opaque region. WlSurface.commit() copies the pending region to the current region. Otherwise, the pending and current regions are never changed.
The initial value for an opaque region is empty. Setting the pending opaque region has copy semantics, and the WlRegion object can be destroyed immediately. A NULL WlRegion causes the pending opaque region to be set to empty. so you can yeet the region object right after, iconic โจ
Parameters region (WlRegion or None) โ opaque region of the surface
๐ set_input_region(region: 'WlRegion | None') -> 'None'
Request โ opcode 5 (attached to Resource instance)
Set input region
This request sets the region of the surface that can receive pointer and touch events.
Input events happening outside of this region will try the next surface in the server surface stack. The compositor ignores the parts of the input region that fall outside of the surface.
The input region is specified in surface-local coordinates.
Input region is double-buffered state, see WlSurface.commit().
WlSurface.set_input_region() changes the pending input region. WlSurface.commit() copies the pending region to the current region. Otherwise the pending and current regions are never changed โ except cursor and icon surfaces are special cases, see WlPointer.set_cursor() and WlDataDevice.start_drag(). iykyk ๐
The initial value for an input region is infinite. That means the whole surface will accept input. Setting the pending input region has copy semantics, and the WlRegion object can be destroyed immediately. A NULL WlRegion causes the input region to be set to infinite. default is: everything is clickable, chaos mode ๐
Parameters region (WlRegion or None) โ input region of the surface
๐ commit() -> 'None'
Request โ opcode 6 (attached to Resource instance)
Commit pending surface state
Surface state (input, opaque, and damage regions, attached buffers, etc.) is double-buffered. Protocol requests modify the pending state, as opposed to the active state in use by the compositor. so there's the you-are-editing version and the compositor-is-actually-using version, keep up bestie โจ
All requests that need a commit to become effective are documented to affect double-buffered state.
Other interfaces may add further double-buffered surface state.
A commit request atomically creates a Content Update (CU) from the pending state, even if the pending state has not been touched. The content update is placed at the end of a per-surface queue until it becomes active. After commit, the new pending state is as documented for each related request.
A CU is either a Desync Content Update (DCU) or a Sync Content Update (SCU). If the surface is effectively synchronized at the commit request, it is a SCU, otherwise a DCU.
When a surface transitions from effectively synchronized to effectively desynchronized, all SCUs in its queue which are not reachable by any DCU become DCUs and dependency edges from outside the queue to these CUs are removed.
See WlSubsurface for the definition of 'effectively synchronized' and 'effectively desynchronized'. yes those are the actual words, go read that one too ๐
When a CU is placed in the queue, the CU has a dependency on the CU in front of it and to the SCU at end of the queue of every direct child surface if that SCU exists and does not have another dependent. This can form a directed acyclic graph of CUs with dependencies as edges. art girl math ๐ฆ
In addition to surface state, the CU can have constraints that must be satisfied before it can be applied. Other interfaces may add CU constraints.
All DCUs which do not have a SCU in front of themselves in their queue are candidates. If the graph that's reachable by a candidate does not have any unsatisfied constraints, the entire graph must be applied atomically. all or nothing, the whole graph, periodt ๐ฅ
When a CU is applied, the WlBuffer is applied before all other state. This means that all coordinates in double-buffered state are relative to the newly attached wl_buffers, except for WlSurface.attach() itself. If there is no newly attached WlBuffer, the coordinates are relative to the previous content update. read that twice, it's the kind of detail that eats your whole afternoon ๐ญ
โญ set_buffer_transform(transform: 'int') -> 'None'
Request โ opcode 7 (attached to Resource instance)
Sets the buffer transformation
This request sets the transformation that the client has already applied to the content of the buffer. The accepted values for the transform parameter are the values for WlOutput.transform().
The compositor applies the inverse of this transformation whenever it uses the buffer contents. you transformed it, it un-transforms it, teamwork ๐ค
Buffer transform is double-buffered state, see WlSurface.commit().
A newly created surface has its buffer transformation set to normal.
WlSurface.set_buffer_transform() changes the pending buffer transformation. WlSurface.commit() copies the pending buffer transformation to the current one. Otherwise, the pending and current values are never changed.
The purpose of this request is to allow clients to render content according to the output transform, thus permitting the compositor to use certain optimizations even if the display is rotated. Using hardware overlays and scanning out a client buffer for fullscreen surfaces are examples of such optimizations. Those optimizations are highly dependent on the compositor implementation, so the use of this request should be considered on a case-by-case basis. aka don't just assume it'll be fast, check with your compositor ๐ซถ
Note that if the transform value includes 90 or 270 degree rotation, the width of the buffer will become the surface height and the height of the buffer will become the surface width. your x and y literally swap vibes, watch out ๐
So if transform isn't one of the values from the WlOutput.transform() enum, the invalid_transform protocol error gets raised. like, do not freestyle a transform value bestie, the compositor will notice ๐
Parameters
transform(ArgumentType.Int) โ transform for interpreting buffer contents
set_buffer_scale(scale: 'int') -> 'None'
Request โ opcode 8 (attached to a Resource instance)
Sets the buffer scaling factor โจ
okay so this request sets an optional scaling factor on how the compositor interprets the contents of the buffer attached to the window.
Buffer scale is double-buffered state, see WlSurface.commit().
A newly created surface has its buffer scale set to 1. periodt.
WlSurface.set_buffer_scale() changes the pending buffer scale. WlSurface.commit() copies the pending buffer scale over to the current one. Otherwise? The pending and current values are just never changed. that's it, that's the whole deal ๐ฆ
The purpose of this request is to let clients supply higher resolution buffer data for use on high resolution outputs. The intent is that you pick the same buffer scale as the scale of the output that the surface is displayed on โ that way the compositor can skip scaling entirely when it renders the surface on that output. efficiency icon behavior.
Note that if the scale is larger than 1, then you have to attach a buffer that is larger (by a factor of scale in each dimension) than the desired surface size. do the math, it's giving geometry homework ๐ญ
If scale is not greater than 0 the invalid_scale protocol error is raised.
Parameters
scale(ArgumentType.Int) โ scale for interpreting buffer contents
damage_buffer(x: 'int', y: 'int', width: 'int', height: 'int') -> 'None'
Request โ opcode 9 (attached to a Resource instance)
Mark part of the surface damaged using buffer coordinates ๐ฅ
This request describes the regions where the pending buffer is different from the current surface contents, and where the surface therefore needs to be repainted. The compositor ignores the parts of the damage that fall outside of the surface.
Damage is double-buffered state, see WlSurface.commit().
The damage rectangle is specified in buffer coordinates, where x and y specify the upper left corner of the damage rectangle.
The initial value for pending damage is empty: no damage. WlSurface.damage_buffer() adds pending damage: the new pending damage is the union of the old pending damage and the given rectangle.
WlSurface.commit() assigns pending damage as the current damage, and clears pending damage. The server will clear the current damage as it repaints the surface.
This request differs from WlSurface.damage() in only one way โ it takes damage in buffer coordinates instead of surface-local coordinates. While this is generally more intuitive than surface coordinates, it is especially desirable when using wp_viewport or when a drawing library (like EGL) is unaware of buffer scale and buffer transform. so true, king.
Note: because buffer transformation changes and damage requests may be interleaved in the protocol stream, it's impossible to determine the actual mapping between surface and buffer damage untilWlSurface.commit()time. Therefore, compositors wishing to take both kinds of damage into account will have to accumulate damage from the two requests separately and only transform from one to the other after receiving theWlSurface.commit(). no shortcuts, sorry ๐
Parameters
x(ArgumentType.Int) โ buffer-local x coordinatey(ArgumentType.Int) โ buffer-local y coordinatewidth(ArgumentType.Int) โ width of damage rectangleheight(ArgumentType.Int) โ height of damage rectangle
offset(x: 'int', y: 'int') -> 'None'
Request โ opcode 10 (attached to a Resource instance)
Set the surface contents offset โจ
The x and y arguments specify the location of the new pending buffer's upper left corner, relative to the current buffer's upper left corner, in surface-local coordinates. In other words, the x and y, combined with the new surface size, define in which directions the surface's size changes.
The exact semantics of WlSurface.offset() are role-specific. Refer to the documentation of specific roles for more information โ like, it depends on the vibe of the role, ok? ๐
Surface location offset is double-buffered state, see WlSurface.commit().
This request is semantically equivalent to โ and replaces โ the x and y arguments in the WlSurface.attach() request in WlSurface versions prior to 5. See WlSurface.attach() for details.
Parameters
x(ArgumentType.Int) โ surface-local x coordinatey(ArgumentType.Int) โ surface-local y coordinate
get_release() -> 'Proxy[WlCallback]'
Request โ opcode 11 (attached to a Resource instance)
Get a release callback ๐
Create a callback for the release of the buffer attached by the client with WlSurface.attach().
The compositor will release the buffer when it has finished its usage of the underlying storage for the relevant commit. Once the client receives this event โ and assuming the associated buffer isn't pending release from other WlSurface.commit() requests โ the client can safely re-use the buffer. green flag, you're free ๐ซถ
Release callbacks are double-buffered state, and will be associated with the pending buffer at WlSurface.commit() time.
The callback_data passed in the WlCallback.done() event is unused and is always zero. always zero. truly nothing else.
Sending this request without attaching a non-null buffer in the same content update is a protocol error. The compositor will send the no_buffer error in this case. don't do it ๐
Returns
WlCallbackโ callback object for the release
enter(output: 'WlOutput') -> 'None'
Event โ opcode 0 (attached to a Proxy instance)
Surface enters an output ๐
This is emitted whenever a surface's creation, movement, or resizing results in some part of it being within the scanout region of an output.
Note that a surface may be overlapping with zero or more outputs. yes, zero. it can be on nothing at all, it's fine, it's just living its life.
Parameters
output(WlOutput) โ output entered by the surface
leave(output: 'WlOutput') -> 'None'
Event โ opcode 1 (attached to a Proxy instance)
Surface leaves an output ๐ฆ
This is emitted whenever a surface's creation, movement, or resizing results in it no longer having any part of it within the scanout region of an output.
Clients should not use the number of outputs the surface is on for frame throttling purposes. The surface might be hidden even if noleaveevent has been sent, and the compositor might expect new surface content updates even if noenterevent has been sent. The frame event should be used instead. use the frame event instead, bestie, i'm begging
Parameters
output(WlOutput) โ output left by the surface
preferred_buffer_scale(factor: 'int') -> 'None'
Event โ opcode 2 (attached to a Proxy instance)
Preferred buffer scale for the surface โจ
This event indicates the preferred buffer scale for this surface. It is sent whenever the compositor's preference changes.
Before receiving this event the preferred buffer scale for this surface is 1.
It is intended that scaling aware clients use this event to scale their content and use WlSurface.set_buffer_scale() to indicate the scale they have rendered with. This allows clients to supply a higher detail buffer. crispy โจ
The compositor shall emit a scale value greater than 0.
Parameters
factor(ArgumentType.Int) โ preferred scaling factor
preferred_buffer_transform(transform: 'int') -> 'None'
Event โ opcode 3 (attached to a Proxy instance)
Preferred buffer transform for the surface ๐ธ
This event indicates the preferred buffer transform for this surface. It is sent whenever the compositor's preference changes.
Before receiving this event the preferred buffer transform for this surface is normal.
Applying this transformation to the surface buffer contents and using WlSurface.set_buffer_transform() might allow the compositor to use the surface buffer more efficiently. might! no promises!
Parameters
transform(ArgumentType.Uint) โ preferred transform
WlTouch ๐
class pywayland.protocol.wayland.WlTouch
Touchscreen input device ๐
The WlTouch interface represents a touchscreen associated with a seat.
Touch interactions can consist of one or more contacts. For each contact, a series of events is generated, starting with a down event, followed by zero or more motion events, and ending with an up event. Events relating to the same contact point can be identified by the ID of the sequence. it's giving "one finger? two fingers? the sequence ID knows" ๐
release() -> 'None'
pssstโฆ the rest of release() is coming in the next part, don't go anywhere ๐
aaaaand that's the requests all wrapped up on this interface, except for one lil closer:
- Request โ opcode 0 (attached to a
Resourceinstance) โ ๐ Release the touch object
๐ down(...)
down(serial: 'int', time: 'int', surface: 'WlSurface', id: 'int', x: 'float', y: 'float') -> 'None'
Event โ opcode 0 (attached to a Proxy instance)
Touch down event and beginning of a touch sequence โจ
So bestie, a brand new touch point just popped onto the surface. It gets its own unique ID, and every future event from that touch point references that same ID. Heads up tho: the ID stops being valid the moment a touch up event fires, and it can totally get reused later. ๐
Parameters
serial(ArgumentType.Uint) โ serial number of the touch down eventtime(ArgumentType.Uint) โ timestamp with millisecond granularitysurface(WlSurface) โ surface touchedid(ArgumentType.Int) โ the unique ID of this touch pointx(ArgumentType.Fixed) โ surface-local x coordinatey(ArgumentType.Fixed) โ surface-local y coordinate
๐ up(...)
up(serial: 'int', time: 'int', id: 'int') -> 'None'
Event โ opcode 1 (attached to a Proxy instance)
End of a touch event sequence ๐ฆ
The touch point dipped. No more events are coming for this one, and its ID gets released so it can be recycled in some future touch down event. it's giving closure, honestly ๐ญ
Parameters
serial(ArgumentType.Uint) โ serial number of the touch up eventtime(ArgumentType.Uint) โ timestamp with millisecond granularityid(ArgumentType.Int) โ the unique ID of this touch point
๐ motion(...)
motion(time: 'int', id: 'int', x: 'float', y: 'float') -> 'None'
Event โ opcode 2 (attached to a Proxy instance)
Update of touch point coordinates ๐ซ
Basically: the touch point moved, bestie. Coordinates changed, that's the whole tea.
Parameters
time(ArgumentType.Uint) โ timestamp with millisecond granularityid(ArgumentType.Int) โ the unique ID of this touch pointx(ArgumentType.Fixed) โ surface-local x coordinatey(ArgumentType.Fixed) โ surface-local y coordinate
๐ผ๏ธ frame()
frame() -> 'None'
Event โ opcode 3 (attached to a Proxy instance)
End of touch frame event ๐
This one says: hey, that's the end of a bunch of events that logically belong together. A client is supposed to accumulate the data in all the events inside the frame before it proceeds. No vibing ahead, okay?
So WlTouch.frame() terminates at least one event, but other than that there's no guarantee at all about which set of events lands inside a frame. A client must assume that any state that didn't get updated in a frame is unchanged from whatever it knew before. That's the rule, periodt. ๐ซถ
๐ซ cancel()
cancel() -> 'None'
Event โ opcode 4 (attached to a Proxy instance)
Touch session cancelled ๐
Sent when the compositor decides the touch stream is actually a global gesture. After that, no further events get sent to the clients from that particular gesture. Touch cancellation hits all touch points currently active on this client's surface, so the client is the one responsible for finalizing those touch points โ and future touch points on this surface may reuse the touch point ID. ๐
Important detail, don't skip it: no frame event is required after the cancel event.
๐ฅ shape(...)
shape(id: 'int', major: 'float', minor: 'float') -> 'None'
Event โ opcode 5 (attached to a Proxy instance)
Update shape of touch point ๐ธ
Sent when a touchpoint changed its shape.
Okay so this one never shows up by itself. It gets sent before a WlTouch.frame() event, and it carries the new shape info for any previously reported touch points, or new touch points, of that frame.
Other events describing that touch point โ like WlTouch.down(), WlTouch.motion() or WlTouch.orientation() โ may land within the same WlTouch.frame(). A client should treat all of those as one single logical touch point update. And the order of WlTouch.shape(), WlTouch.orientation() and WlTouch.motion()? Not guaranteed. What is guaranteed: a WlTouch.down() event happens before the first WlTouch.shape() event for that touch ID โ but both of them can still show up inside the same WlTouch.frame().
Now the fun geometry bit: a touchpoint shape is approximated by an ellipse through the major and minor axis length. The major axis length describes the longer diameter of the ellipse, the minor axis length describes the shorter one. Major and minor are orthogonal, and both are specified in surface-local coordinates. The center of the ellipse is always at the touchpoint location as reported by WlTouch.down() or WlTouch.motion(). ๐
btw: this event is only sent by the compositor if the touch device actually supports shape reports. If the client never got this event, it has to make reasonable assumptions about the shape itself. no cap.
Parameters
id(ArgumentType.Int) โ the unique ID of this touch pointmajor(ArgumentType.Fixed) โ length of the major axis in surface-local coordinatesminor(ArgumentType.Fixed) โ length of the minor axis in surface-local coordinates
๐งญ orientation(...)
orientation(id: 'int', orientation: 'float') -> 'None'
Event โ opcode 6 (attached to a Proxy instance)
Update orientation of touch point ๐
Sent when a touchpoint changed its orientation.
Same deal as the shape one โ it does not occur on its own. It's sent before a WlTouch.frame() event and carries the new shape information for any previously reported touch points, or new touch points, of that frame.
Other events describing the touch point such as WlTouch.down(), WlTouch.motion() or WlTouch.shape() may be sent within the same WlTouch.frame(). A client should treat these as a single logical touch point update. The order of WlTouch.shape(), WlTouch.orientation() and WlTouch.motion() is not guaranteed. A WlTouch.down() event is guaranteed to occur before the first WlTouch.orientation() event for this touch ID, but both events may occur within the same WlTouch.frame().
The orientation describes the clockwise angle of a touchpoint's major axis to the positive surface y-axis, normalized to the -180 to +180 degree range. How granular that orientation is depends on the touch device โ some devices only support binary rotation values between 0 and 90 degrees. lowkey wild, but that's the hardware's business. ๐
also: this event is only sent by the compositor if the touch device supports orientation reports.
Parameters
id(ArgumentType.Int) โ the unique ID of this touch pointorientation(ArgumentType.Fixed) โ angle between major axis and positive surface y-axis in degrees
๐ง Scanner Modules ๐ง
๐ Argumet
(yes bestie, that's literally how it's spelled up top and we are not touching it ๐ )
class pywayland.scanner.argument.Argument(name: str, type: ArgumentType, summary: str | None, interface: str | None, allow_null: bool, enum: str | None, description: Description | None)
Argument to a request or event method.
- Required attributes:
nameandtype - Optional attributes:
summary,interface, andallow-null - Child elements:
description
property argument: str
Output as an Argument.
property interface_class: str
Returns the Interface class name โ it hands you the class name for the Interface that corresponds to the type of the argument.
output_doc_param(printer: Printer) -> None
Document the argument as a parameter.
output_doc_ret(printer: Printer) -> None
Document the argument as a return.
property signature: str
Output as the argument appears in the signature.
class pywayland.scanner.argument.ArgumentType(*values)
๐ผ Entry
class pywayland.scanner.entry.Entry(name: str, value: str, summary: str | None, since: str | None, description: Description | None)
Scanner for enum entries.
- Required attributes:
nameandvalue - Optional attributes:
summaryandsince - Child elements:
description
output(enum_name: str, printer: Printer) -> None
Generate the output for the entry in the enum.
๐ฆ Enum
class pywayland.scanner.enum.Enum(name: str, since: str | None, is_bitfield: bool, description: Description | None, entry: list[Entry])
Scanner for enum objects.
- Required attributes:
nameandsince - Child elements:
descriptionandentry
output(printer: Printer) -> None
Generate the output for the enum to the printer.
โญ Event
class pywayland.scanner.event.Event(name: str, since: str | None, description: Description | None, arg: list[Argument])
Scanner for event objects (server-side method).
- Required attributes:
name - Optional attributes:
since - Child elements:
descriptionandarg
property method_args: Iterator[str]
Generator of the arguments to the method.
All arguments to be sent to ._post_event must be passed in.
output_body(printer: Printer, opcode: int) -> None
Output the body of the event to the printer.
output_doc_params(printer: Printer) -> Noneโ writes the arguments up as documented parameters. And bestie, every single argument here is an event parameter, that's the whole vibe.
๐ Interface ๐
The whole class signature, verbatim, no cap:
class pywayland.scanner.interface.Interface(name: 'str', version: 'str', description: 'Description | None', enum: 'list[Enum]', event: 'list[Event]', request: 'list[Request]')
property class_name: strโ hands you back the name of the class of the interface. It CamelCases the interface's name so it can serve as the class name. โจoutput(printer: Printer, module_imports: dict[str, str]) -> Noneโ generates the output for the interface and sends it to the printer. ๐จ๏ธclassmethod parse(element: Element) -> Interface <#pywayland.scanner.interface.Interface>โ the scanner for interface objects. Required attributes:nameandversion. Child elements it's looking for:description,request,event,enum. ๐ง
๐ฆ Method ๐ฆ
class pywayland.scanner.method.Method(name: str, since: str | None, description: Description | None, arg: list[Argument <#pywayland.scanner.argument.Argument>])
This is the scanner for methods, and it corresponds to the events and requests defined on an interface. So iconic of it.
imports(interface: str, module_imports: dict[str, str]) -> list[tuple[str, str]]โ grabs the imports required for each of the interfaces.- Parameters:
interfaceโ the name of the interface that the method is a part of.module_importsโ a mapping from the name of an interface in the associated module that the interface comes from.
- Returns: a list of 2-tuples, each one specifying the path to an imported module plus the imported class. ๐ฆ
- Parameters:
output(printer: Printer, opcode: int, in_class: str, module_imports: dict[str, str]) -> Noneโ generates the output for the given method to the printer.output_doc(printer: Printer) -> Noneโ outputs the documentation for the interface.
๐จ๏ธ Printer ๐จ๏ธ
Not a single line under this heading. It's giving mysterious, it's giving nothing else to document. Genuinely just the name and the silence. ๐ (Keeping it, because facts are facts and the manpage said so.)
๐ Request ๐
class pywayland.scanner.request.Request(name: str, since: str | None, description: Description | None, arg: list[Argument <#pywayland.scanner.argument.Argument>], type: str | None)
Scanner for request objects โ aka the client-side method. ๐ซถ
- Required attributes:
name - Optional attributes:
typeandsince - Child elements:
descriptionandarg
What's inside:
property marshal_args: Iterable[str]โ the arguments that get sent to._marshal.property method_args: Iterable[str]โ a generator of the arguments to the method. Heads up: thenew_idargs are generated while marshaling the args, so they do not show up in the args of the method.output_body(printer: Printer, opcode: int) -> Noneโ outputs the body of the request to the printer.output_doc_params(printer: Printer) -> Noneโ the arguments documented as parameters. Anything that is not anew_idcounts. ๐output_doc_ret(printer: Printer) -> Noneโ the arguments documented as return values. Arguments of typenew_idare what gets returned from requests. ๐property return_type: strโ the return type for the request.
๐ Scanner ๐
Another heading with literally nothing under it. It's a vibe. Moving on, bestie. ๐ธ
๐ Using the Scanner module ๐
Okay so the PyWayland scanner lets you generate the protocol scanner output right from inside Python scripts. The general procedure to invoke the scanner: make a Protocol object, scan the input file, and have the Protocol output to a directory. Those steps look exactly like this:
Protocol.parse_file(path_to_xml_file)
Protocol.output(path_to_output_dir, {})
Peep the definitions below for more info on using Protocol objects. ๐
๐ฆ Protocol Module ๐ฆ
class pywayland.scanner.Protocol(name: str, copyright: Copyright | None, description: Description | None, interface: list[Interface <#pywayland.scanner.interface.Interface>])
This is the Protocol scanner object โ the main scanner object that acts on the input xml files to generate protocol files. โจ
- Required attributes:
name - Child elements:
copyright?,description?, andinterface+ - Parameters:
input_fileโ name of input XML file
And its method:
output(output_dir: str, module_imports: dict[str, str]) -> Noneโ outputs the scanned files to the given directory.- Parameters:
output_dir(string) โ path of directory to output protocol files to.
- Parameters:
๐งฐ Utilities Module ๐งฐ
๐ AnonymousFile Class ๐
class pywayland.utils.AnonymousFile(size: int)
The anonymous file object. ๐ฆ
It provides access to anonymous file objects that Wayland clients can use to render to surfaces. It opens an anonymous file using a method similar to Weston, which means XDG_RUNTIME_DIR must be set for this to work properly.
This class gives you a content manager, so you can use it with Python with statements, where the value returned is the file descriptor. Main character energy fr fr.
close() -> Noneโ closes the anonymous file. It closes the file descriptor and sets thefdproperty toNone. Does nothing at all if the file is not open. ๐ซถopen() -> Noneโ opens an anonymous file. It opens it and sets thefdproperty to the file descriptor that has been opened. โญ
โ๏ธ Author โ๏ธ
Sean Vig. The icon, the legend. ๐
ยฉ๏ธ Copyright ยฉ๏ธ
2016, Sean Vig
And that's a wrap on the whole page, bestie!! ๐ This was PYWAYLAND(1) from the 0.4.18 source, dated Aug 04, 2026 โ go forth and scan those protocols, slay, periodt. ๐โจ๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: python3-pywayland 0.4.18-7 ยท Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms