WaylandCS 1.0.0

dotnet add package WaylandCS --version 1.0.0
                    
NuGet\Install-Package WaylandCS -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WaylandCS" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WaylandCS" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WaylandCS" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WaylandCS --version 1.0.0
                    
#r "nuget: WaylandCS, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WaylandCS@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WaylandCS&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WaylandCS&version=1.0.0
                    
Install as a Cake Tool

WaylandCS

C# binding for Wayland using Net6.0 or above. Inspired by wayland-scanner in C language.

Goals

  • support wayland extension protocols as many as possible
  • easy to use, stable in production

Compatibility

.NET Version Compatibility
.NET (6.0 and above) ✔️
.NET Standard
.NET Framework

Getting started

Install WaylandCS nuget package.

dotnet add package WaylandCS

Grab wayland.xml from freedesktop.org. Drop the file into your project.

Add the following to your .csproj:

<ItemGroup>
    <CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="WaylandProtocol" />
    <AdditionalFiles Include="wayland.xml" WaylandProtocol="client" />
    
</ItemGroup>

Quick Guide

using WaylandCS namespace

using WaylandCS;

Connection to a wayland display server can be established by calling:

WlDisplay.Connect(string);

Global objects can be retrieved by creating a registry object and listening for Global event

using wlDisplay = WlDisplay.Connect();
using wlRegistry = wlDisplay.GetRegistry();

wlRegistry.Global += (_, e) =>
{
    Console.WriteLine($"{e.Name}:{e.Interface}:{e.Version}");
};

wlDisplay.Roundtrip();

Either a WlDisplay.Roundtrip() or WlDisplay.Dispatch() is required to generate event invocations. In this case, Global event will occur upon calling Roundtrip().

As described in Wayland's official docs, WlDisplay.Roundtrip() dispatches all currently pending events. If no events are pending, the function returns 0, otherwise it returns the number of pending events that were processed. This internally calls Sync and waits for the server's callback before returning.

On the other hand, Dispatch will block until there are events to process, as such, it will never return 0. It is useful for setting up an event loop, like in this example below.

while (someWlDisplayInstance.Dispatch() != -1)
{
    // intentionally empty
}

Binding to global objects are done by using the data received from GlobalEventArgs, specifically Name (a unique uint given by the server for this instance of global object), Interface (the contract used), and Version and passing it as the arguments of WlRegistry.Bind().

As an example, assuming that the user wants to bind to a wl_output

wlRegistry.Global += (_, e) =>
{
    if (e.Interface == WlInterface.WlOutput.Name)
    {
        // Passing a version is optional, it'll use the version specified in
        // the protocol xml by default.
        using var wlOutput = wlRegistry.Bind<WlOutput>(e.Name, e.Interface);

        // do something about wlOutput here.
    }
};
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 86 7/29/2025