DDCSharp.Linux
0.2.0
See the version list below for details.
dotnet add package DDCSharp.Linux --version 0.2.0
NuGet\Install-Package DDCSharp.Linux -Version 0.2.0
<PackageReference Include="DDCSharp.Linux" Version="0.2.0" />
<PackageVersion Include="DDCSharp.Linux" Version="0.2.0" />
<PackageReference Include="DDCSharp.Linux" />
paket add DDCSharp.Linux --version 0.2.0
#r "nuget: DDCSharp.Linux, 0.2.0"
#:package DDCSharp.Linux@0.2.0
#addin nuget:?package=DDCSharp.Linux&version=0.2.0
#tool nuget:?package=DDCSharp.Linux&version=0.2.0
DDCSharp
A .NET library for controlling displays via DDC/CI, including brightness, contrast, input source, and other display settings through a simple API
Lightweight C# (.NET 10) library for enumerating physical monitors and performing DDC/CI (MCCS VCP) VCP feature reads / writes (e.g. brightness, input source) with an extensible provider model.
Projects
DDCSharp.Core– Provider & transport abstractions plus capability / VCP feature models.DDCSharp.Windows– Windows implementation usingdxva2.dll(Win32 APIs) to enumerate and control monitors.DDCSharp.Linux– Linux implementation that talks DDC/CI directly over/dev/i2c-*(noddcutilneeded).
NuGet Packages
| Package | NuGet | Description |
|---|---|---|
| DDCSharp.Core | Core abstractions + capability models | |
| DDCSharp.Windows | Windows provider implementation | |
| DDCSharp.Linux | Linux provider implementation |
Install via Package Manager:
PM> Install-Package DDCSharp.Core
PM> Install-Package DDCSharp.Windows
PM> Install-Package DDCSharp.Linux
Or with dotnet CLI:
dotnet add package DDCSharp.Core
dotnet add package DDCSharp.Windows
dotnet add package DDCSharp.Linux
Key Concepts
IDisplay– Abstraction of a physical monitor (read / write VCP features, refresh capabilities).Id– Identifier built from the EDID (e.g.DELF167-JF7R864). It stays the same across enumerations, so use it to find a monitor again withDisplayService.FindDisplay(id)after its handle stops working.LastError– Why the last operation failed (Win32 error, errno, or DDC/CI reply problem).
DDCDisplay– Base class with the shared logic (input sources, brightness, capabilities). Providers only implement VCP reads, VCP writes and the capabilities request.IDisplayProvider– ProducesIDisplayinstances (platform / virtual). Multiple providers can be registered.DisplayService– Thread‑safe static registry to add / clear providers and obtain all displays.- Capabilities Parsing –
CapabilityParserparses the MCCS capability string into sections (type,model,mccs_ver,vcp) and a list ofCapabilityentries (feature + supported values list if present). Capabilities are read from the display on first access because the request takes one to three seconds.
Supported (subset) Features
Brightness, Contrast, Input Source, Sharpness, Color Gains, Color Presets, Power Mode, Speaker Volume, Audio Mute, Orientation, Frequencies, Panel/Tech info, Usage Time, etc. (See VCPFeature enum for details.)
Quick Start
using DDCSharp.Core;
using DDCSharp.Core.Abstractions;
using DDCSharp.Core.Capabilities;
using DDCSharp.Linux;
using DDCSharp.Windows;
// Register the platform provider once at startup
if (OperatingSystem.IsWindows())
{
WindowsDisplayProvider.Register();
}
else if (OperatingSystem.IsLinux())
{
LinuxDisplayProvider.Register();
}
// Enumerate displays
foreach (var display in DisplayService.GetDisplays())
{
Console.WriteLine($"Id: {display.Id} Description: {display.Description} Model: {display.Model} MCCS: {display.MCCSVersion}");
// Read brightness
if (display.TryGetVCPFeature(VCPFeature.Brightness, out var type, out var current, out var max))
{
Console.WriteLine($"Brightness: {current}/{max}");
}
// Set brightness (0..max range – caller responsibility)
display.TrySetBrightness(50);
// List supported input sources
var sources = display.GetSupportedInputSources();
Console.WriteLine("Inputs: " + string.Join(", ", sources));
// Switch input and wait until the display reports it (handles go stale on a switch, so this re-enumerates)
if (sources.Contains(InputSource.HDMI1))
{
var confirmed = await DisplayService.SwitchInputSource(display, InputSource.HDMI1);
}
}
Input switching
SetInputSourceonly sends the command. When the display is showing this computer it drops the link as soon as it accepts the command, so the write reports an error although the switch happens; it is not retried.DisplayService.SwitchInputSourcesends the command and confirms it by finding the display again byId, which takes 2 to 3 seconds. On Linux, switching away from this computer over DisplayPort MST takes about 6 seconds to confirm because the kernel blocks for 4 seconds, although the display switches within a second.DisplayService.WaitForInputSourcedoes only the confirmation.GetLocalInputSource()returns the input this computer is connected to, for displays that report it (e.g. Dell), so a "show this computer" action needs no configuration.
Thread Safety
- Provider registration is synchronized (
DisplayService). - Windows displays synchronize native calls per display instance.
- Linux displays synchronize per I2C bus, across all display instances that use it.
Extending (Custom Provider)
Implement IDisplayProvider and produce objects implementing IDisplay.
public sealed class MyProvider : IDisplayProvider
{
public IEnumerable<IDisplay> GetDisplays()
{
// Open native handles, wrap them in your IDisplay implementation
yield break;
}
}
DisplayService.RegisterProvider(new MyProvider());
Derive from DDCDisplay to get input source, brightness and capability handling for free; only TryGetVCPFeature, TrySetVCPFeature and ReadCapabilitiesString need implementing.
Capability Refresh
Call display.RefreshCapabilities() to re-fetch the MCCS capability string (e.g., after OSD adjustments or hot‑plug events).
Error Handling
- Provider enumeration exceptions are swallowed so one provider cannot block others.
- VCP read/write methods return
boolindicating success;LastErrordescribes the failure. - A successful write only means the command was sent. DDC/CI has no acknowledgement, so read the value back to confirm it.
Platform Notes
- Windows: uses
dxva2.dll(GetVCPFeatureAndVCPFeatureReply,SetVCPFeature, capability string APIs) +EnumDisplayMonitors. The EDID forIdis read from the registry. - Linux: finds connected monitors in
/sys/class/drmand their I2C bus through the connector'sddclink. DisplayPort MST connectors (docks, USB-C monitors) have no link, so the bus is found by matching EDIDs. Laptop panels (eDP/LVDS/DSI) are reported without DDC/CI support. Timings can be tuned withDDCTimings. - Some displays (e.g. Dell) put extra data in the high byte of the input source value;
GetInputSource()only uses the low byte. - Other platforms: supply a custom provider (e.g., USB HID, network bridge, mock/testing provider).
Linux permissions
The i2c-dev kernel module must be loaded and the user needs read/write access to /dev/i2c-*. Distributions that package ddcutil usually set this up already. Otherwise:
# Load i2c-dev now and on every boot
sudo modprobe i2c-dev
echo i2c-dev | sudo tee /etc/modules-load.d/i2c-dev.conf
# Give the logged-in user access to I2C devices
echo 'KERNEL=="i2c-[0-9]*", SUBSYSTEM=="i2c-dev", TAG+="uaccess"' | sudo tee /etc/udev/rules.d/60-i2c-dev.rules
sudo udevadm control --reload && sudo udevadm trigger --subsystem-match=i2c-dev
Disclaimer
Writing values to unsupported VCP features may fail silently. Some monitors expose incomplete or vendor-specific capability strings. Use at your own risk.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DDCSharp.Core (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.