WaylandSharp 0.1.0

.NET Standard 2.0
There is a newer version of this package available.
See the version list below for details.
dotnet add package WaylandSharp --version 0.1.0
NuGet\Install-Package WaylandSharp -Version 0.1.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="WaylandSharp" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WaylandSharp --version 0.1.0
#r "nuget: WaylandSharp, 0.1.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install WaylandSharp as a Cake Addin
#addin nuget:?package=WaylandSharp&version=0.1.0

// Install WaylandSharp as a Cake Tool
#tool nuget:?package=WaylandSharp&version=0.1.0

WaylandSharp

An incremental source generator to automatically create bindings to Wayland using given protocol xml files.

wayland.xml should always be included to the list.

Getting started

Install WaylandSharp nuget package.

dotnet add package WaylandSharp

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

Add this to your csproj

<PropertyGroup>
  
  <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

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

No support for generating server-side bindings yet.

Benefit! 🍞

Quick Guide

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.
    }
};

A helper function will be introduced in the future to help shorten this specific pattern.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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
0.2.1 341 6/22/2022
0.2.0 224 6/21/2022
0.1.0 232 6/21/2022