wayland ~master
Wayland bindings for D
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
This package provides sub packages which can be used individually:
wayland:scanner - Wayland protocol scanner
wayland:client - D bindings to wayland-client
wayland:egl - D bindings to wayland-egl
wayland:server - D bindings to wayland-server
wayland:cursor - D bindings to wayland-cursor
wayland:connect - Wayland connect client example.
wayland:list_registry - Wayland list_registry client example.
wayland:simple_egl - Wayland simple egl client example.
wayland:hello - Wayland hello client example.
wayland:compositor - A wayland compositor example.
Wayland D bindings
D bindings to wayland.
There are several components:
- *Scanner*: XML protocol parser and code generator. It generates high level objects.
- support for client and server side code generation.
- support foreign protocols (such as
xdg-shell
. See the simple-egl example) - *Client*: client protocol and
libwayland-client
native API wrapped into higher level objects. - *EGL*: allow use of wayland-egl (see this example).
- *Server*: server side protocol and bindings to
libwayland-server
to allow the creation of a compositor.
Scanner usage
$ dub run wayland:scanner -- -h
wayland:scanner-v0.1.0
A Wayland protocol scanner and D code generator.
Options:
-c --code generated code: client|server [client]
-i --input input file [stdin]
-o --output output file [stdout]
-m --module D module name (required)
-h --help This help information.
Client usage
Add the wayland:client
dependency in your dub.json
:
"dependencies": {
"wayland:client": "~>0.1.0"
}
The main wayland protocol is automatically generated by the scanner
as a pre-build step of wayland:client
.
To use other protocols, the scanner must be used and XML protocol definition
provided by the application. See the simple-egl
example that uses the xdg-shell
protocol.
Requests
Requests are made by calling methods on the WlProxy
objects generated by the
protocol. For example:
WlSurface surf = makeSurf();
WlBuffer buf = makeBuf();
surf.attach(buf, 0, 0);
As described in the protocol, some requests are void, others return a new object.
Events
Events are listened to by registering a delegate in the WlProxy
objects.
See WlRegistry.onGlobal
in the example hereunder.
Example of client code
import wayland.client;
import std.exception;
import std.stdio;
void main()
{
auto display = enforce(WlDisplay.connect());
scope(exit) display.disconnect();
auto reg = enforce(display.getRegistry());
scope(exit) reg.destroy();
reg.onGlobal = (WlRegistry /+reg+/, uint /+name+/, string iface, uint /+ver+/) {
writeln("registering ", iface);
};
display.roundtrip();
}
Server usage
In the current implementation of the bindings, handling client requests is done
by subclassing the WlGlobal
and WlResource
subclasses generated by the protocol.
All protocol-generated classes that have requests are abstract
.
In the requests creating new resources, the application must therefore return
a subclass object that implement the protocol requests.
Events are sent to clients by calling the send[EventName]
methods of resource objects.
A part of the main protocol is implemented natively by libwayland-server
. This
is the case of wl_shm
and wl_shm_pool
. A consequence of this is that wl_buffer
objects
are not created under the application control. To create a WlBuffer
subclass
object that implement the requests, it is required to listen to native resource creation:
class Compositor : WlCompositor
{
...
void newClientConnection(WlClient cl)
{
cl.addNativeResourceCreatedListener((wl_resource* natRes) {
import core.stdc.string : strcmp;
if (strcmp(wl_resource_get_class(natRes), "wl_buffer") == 0) {
new Buffer(natRes);
}
});
}
}
class Buffer : WlBuffer
{
...
}
See the compositor example that implement a quick and dirty compositor. It is not a good design of compositor, it only illustrates the bindings mechanics.
Playground
You can run the examples if you are under a wayland compositor:
dub run wayland:list_registry
For some of the examples, this only works if you cd
first to the project root
directory:
git clone https://github.com/rtbo/wayland-d.git
cd wayland-d
dub run wayland:hello
- Registered by Remi Thebault
- ~master released 3 months ago
- rtbo/wayland-d
- MIT
- Copyright © 2017, Rémi Thebault
- Authors:
- Sub packages:
- wayland:scanner, wayland:client, wayland:egl, wayland:server, wayland:cursor, wayland:connect, wayland:list_registry, wayland:simple_egl, wayland:hello, wayland:compositor
- Dependencies:
- none
- Versions:
-
0.3.1 2021-Aug-16 0.3.0 2021-Jul-10 0.2.0 2019-Jan-06 0.1.4 2019-Jan-06 0.1.3 2018-Dec-28 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
1 downloads this month
-
1279 downloads total
-
- Score:
- 1.2
- Short URL:
- wayland.dub.pm