EndoMint

Opinions are my own.

Building XerahS on our own Avalonia fork

XerahS now builds against a patched ShareX/Avalonia fork (12.1.7-sharex.1) instead of waiting on upstream Avalonia releases for platform features a screenshot tool needs.

Upstream Avalonia is a general desktop toolkit. A region capture app sits in the corners that general toolkits leave unimplemented or treat as low priority: Wayland overlay surfaces above panels and docks, Windows per-monitor DPI resize locks, and keeping SkiaSharp current without managed/native version conflicts. Treating the UI toolkit as a read-only dependency meant living with workarounds in application code or waiting on upstream queues.

Vertical integration, applied to a UI toolkit

Elon Musk's playbook at Tesla and SpaceX relies on vertical integration: own the parts of the stack that determine whether the product actually works, rather than buying generic components from a supplier and working around their limits. When a bottleneck sits in a battery pack, a flight computer or a factory line, owning that layer lets you fix the real part at the root instead of wrapping it in glue code.

For a cross-platform desktop app, the UI framework is that layer. The ShareX organisation already keeps forks of Avalonia and its companion repositories. Until now, XerahS treated those forks as read-only references and shipped upstream NuGet packages. Moving XerahS onto packages built from ShareX/Avalonia turns the fork into an active part of the stack: when Avalonia blocks a platform feature, we add the exact hook inside Avalonia and consume it directly.

What changed inside ShareX/Avalonia

The work sits on branch xerahs/12.1.6 of ShareX/Avalonia, branched from upstream 12.1.6 (cf8e56467) and packed as 12.1.7-sharex.1. Using 12.1.7-sharex.1 keeps SemVer strictly above 12.1.6 (avoiding NU1605 package downgrade errors against ShareX.ImageEditor's 12.1.6 pin) and strictly below an eventual upstream 12.1.7.

Area Change in ShareX/Avalonia Where it lives
Wayland overlays Native zwlr_layer_shell_v1 protocol bindings, WLayerShellSurface, LayerShellSink and attached properties on WaylandProperties Avalonia.Controls, Avalonia.Wayland
Windows DPI Win32Properties.IgnoreDpiChangeResizeProperty to return early on WM_DPICHANGED for locked overlays Avalonia.Controls, Avalonia.Win32
SkiaSharp Upgraded Avalonia.Skia from SkiaSharp 3.119.4 to 4.155.0 and migrated SKPath mutators to SKPathBuilder Avalonia.Skia, Directory.Packages.props
Packaging Added --pack-desktop-only to NUKE and a manual GitHub Packages workflow (publish-sharex-packages.yml) nukebuild, .github/workflows

On Wayland, Avalonia.Wayland now exposes WaylandLayer, WaylandLayerAnchor, WaylandLayerKeyboardInteractivity, output targeting by connector name (LayerOutputName), namespace assignment (LayerNamespace), backend/support queries (IsWaylandBackend, IsLayerShellSupported), and a "WAYLAND" platform handle descriptor. Layer-shell surfaces also bypass Avalonia's client-side decoration fallback so borderless overlays never gain managed borders or shadows.

What changed in XerahS

XerahS's develop branch points at the locally packed ../Avalonia/artifacts/nuget feed through NuGet.config and updates its desktop Avalonia packages to 12.1.7-sharex.1 (leaving Avalonia.Controls.DataGrid on 12.1.2 and Avalonia.Android/Avalonia.iOS on 12.1.6).

  • XerahS.App references Avalonia.Wayland on Linux and calls .With(new WaylandPlatformOptions { AppId = "xerahs" }).UseWaylandWithFallback(), with XERAHS_DISABLE_WAYLAND=1 available to force X11/XWayland.
  • LinuxDisplayBootstrap accepts a live WAYLAND_DISPLAY socket instead of requiring an XWayland DISPLAY at startup.
  • MonitorEnumerationService keeps real compositor output names (such as eDP-1) instead of overwriting them with Display 1, and detects native Wayland through WaylandProperties.IsWaylandBackend.
  • OverlayWindow sets Win32Properties.SetIgnoreDpiChangeResize(this, true) on Windows, and on zwlr_layer_shell_v1 compositors maps onto WaylandLayer.Overlay with namespace xerahs-region-capture, all-edge anchoring, exclusive zone -1, exclusive keyboard interactivity and its target monitor output name.

What was verified and what is still pending

Everything below was tested on Linux (Hyprland on Omarchy) against the local 12.1.7-sharex.1 packages.

Check Result
Avalonia.Skia.UnitTests on SkiaSharp 4.155.0 596 passed, 0 failed, 9 skipped (Windows font and profiling skips)
Avalonia.Wayland.UnitTests (headless and AVALONIA_WAYLAND_LAYER_TEST=1) 45 of 45 passed in both modes, confirming layer-3 map and unmap on Hyprland
Avalonia.Win32 (net10.0 Release build) 0 warnings, 0 errors
XerahS desktop solution (src/desktop/XerahS.sln) 0 warnings, 0 errors
XerahS.Build.Tests 20 of 20 passed
Targeted XerahS.Tests (bootstrap, region capture, overlay, Linux) 494 of 494 passed
Live Hyprland test of XerahS.RegionCapture.UI.OverlayWindow Mapped on eDP-1 (3072x1728 at 1.25 scale), level 3, namespace xerahs-region-capture, unmapped on close

Two gaps remain open. First, the Windows WM_DPICHANGED fix compiled cleanly but has not yet been runtime-tested on a live Windows machine with mixed or >100% DPI scaling. Second, Wayland compositors that do not implement zwlr_layer_shell_v1 (such as GNOME Mutter) still fall back to standard toplevel surfaces, where XDG Desktop Portal capture or external Linux region selectors remain available.

ShareX can do the same

At this stage only XerahS consumes the custom Avalonia build, and nothing has been pushed to GitHub Packages yet. Because ShareX/Avalonia lives in the ShareX organisation, ShareX's own cross-platform branch can adopt the exact same packages once the Windows DPI behaviour is confirmed on Windows and the packages are published.

Even while the native apps and Rust work continue on separate tracks, ShareX's Avalonia builds do not have to maintain separate native overlay shims for wlroots Wayland or fight WM_DPICHANGED from outside the framework. One shared ShareX/Avalonia fork gives both XerahS and ShareX direct control over the layer underneath them.

~ Mike