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 ¶
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.
var DevDir = "/dev"
DevDir is where Linux exposes i2c bus nodes; a var so tests can repoint it.
ErrDDCUnavailable is a write to a name that is not (or no longer) a managed monitor.
Functions ¶
func AveragePercentage ¶
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 ¶
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 ¶
ReadDevice reads one device's snapshot from sysfs.
func (Device) Percentage ¶
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 ¶
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 ¶
Close stops the watchers and waits for the goroutines; later calls are no-ops.
func (*System) Devices ¶
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 ¶
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.
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 ¶
TypeFromSysfs parses the sysfs `type` file; unknown values are Raw, matching BacklightType::from_sysfs's None fallback.