brightness

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package brightness reads and sets backlight levels, the Go counterpart of crates/wayle-brightness: sysfs enumeration and reads, logind SetBrightness as the write path with a direct sysfs fallback, and external monitors over DDC/CI (ddc.go) with kernel-uevent hotplug (uevent.go).

Index

Constants

This section is empty.

Variables

View Source
var BacklightDir = "/sys/class/backlight"

BacklightDir is the sysfs class directory for backlight devices; a var so tests can repoint it at a fake tree.

View Source
var DevDir = "/dev"

DevDir is where Linux exposes i2c bus nodes; a var so tests can repoint it.

View Source
var ErrDDCUnavailable = errors.New("brightness: DDC monitor unavailable")

ErrDDCUnavailable is a write to a name that is not (or no longer) a managed monitor.

Functions

func AveragePercentage

func AveragePercentage(devices []Device) (float64, bool)

AveragePercentage is the mean level across devices (helpers.rs): what the bar label and the OSD show, since a brightness action drives every device at once. False when there is none.

Types

type Device

type Device struct {
	Name       string
	Type       Type
	Brightness uint32
	Max        uint32
}

Device is one backlight snapshot: brightness against max in raw units, plus the derived percentage.

func Enumerate

func Enumerate() []Device

Enumerate lists every backlight device; an unreadable class directory yields an empty list, the Rust shell's warn-and-continue.

func ReadDevice

func ReadDevice(name string) (Device, error)

ReadDevice reads one device's snapshot from sysfs.

func (Device) Percentage

func (d Device) Percentage() float64

Percentage maps the raw level onto 0..100.

type Source

type Source interface {
	// Devices returns the current snapshots.
	Devices(ctx context.Context) ([]Device, error)
	// Subscribe ticks whenever any device's level may have changed.
	// The channel closes when ctx completes; stop releases the watch.
	Subscribe(ctx context.Context) (<-chan struct{}, func(), error)
	// Set applies a percentage to one device, clamped to 0..100.
	Set(ctx context.Context, name string, percent float64) error
}

Source is the module's seam: enumerate, watch, and set.

type System

type System struct {
	// contains filtered or unexported fields
}

System is the real source (backend/mod.rs): sysfs devices written through logind with a sysfs fallback, plus, when external monitors are enabled, DDC/CI monitors found by a detached scan and re-scanned on DRM hotplug.

func NewSystem

func NewSystem(external bool) *System

NewSystem starts the source. external enables DDC/CI discovery (the enable-external key); the first scan runs detached so internal panels are usable at once. A missing logind or uevent socket degrades (sysfs writes, no hotplug) instead of failing.

func (*System) Close

func (s *System) Close() error

Close stops the watchers and waits for the goroutines; later calls are no-ops.

func (*System) Devices

func (s *System) Devices(context.Context) ([]Device, error)

Devices reads every sysfs device, then the DDC monitors from their cached levels (a DDC read is too slow to make per refresh).

func (*System) Set

func (s *System) Set(_ context.Context, name string, percent float64) error

Set applies a clamped percentage. A DDC monitor's write is handed to its writer goroutine and Set returns at once: DDC I/O takes tens of milliseconds a transaction, and a slider drag coalesces to the latest value instead of queueing every step. Write failures are logged, as the Rust caller does with the error it gets back.

func (*System) Subscribe

func (s *System) Subscribe(ctx context.Context) (<-chan struct{}, func(), error)

Subscribe registers for change ticks until ctx ends or stop.

type Type

type Type uint8

Type distinguishes firmware, platform, and raw backlights (types/backlight.rs's BacklightType).

const (
	TypeRaw Type = iota
	TypeFirmware
	TypePlatform
	// TypeDDC is an external monitor driven over DDC/CI.
	TypeDDC
)

Backlight types.

func TypeFromSysfs

func TypeFromSysfs(value string) Type

TypeFromSysfs parses the sysfs `type` file; unknown values are Raw, matching BacklightType::from_sysfs's None fallback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL