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 ¶
const ( ServiceName = "dev.stubbe.lys.Brightness1" ServicePath = dbus.ObjectPath("/dev/stubbe/lys/Brightness") )
ServiceName and ServicePath are dev.stubbe.lys.Brightness1, which `lys-shell brightness` drives.
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 DRMDir = drmconn.Dir
DRMDir is the sysfs class directory of DRM cards and connectors; a var so tests can repoint it.
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.
var I2CAdapterDir = "/sys/bus/i2c/devices"
I2CAdapterDir lists every I²C adapter as a link into its device tree; a var so tests can repoint it.
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 Change ¶ added in v0.2.0
type Change struct {
// contains filtered or unexported fields
}
Change is a validated brightness request in whole percent: an absolute level in 0..=100 or a signed step from the current level.
func ParseChange ¶ added in v0.2.0
ParseChange reads "N", "+N" or "-N" with N in ASCII digits.
func (Change) IsRelative ¶ added in v0.2.0
IsRelative reports whether the change is a step.
type Daemon ¶ added in v0.2.0
type Daemon struct {
// contains filtered or unexported fields
}
Daemon is the dev.stubbe.lys.Brightness1 object: it changes the shell's own source, so the bar and the OSD follow every change.
func NewDaemon ¶ added in v0.2.0
NewDaemon serves src; focused names the focused output and floor is the lowest level a change may leave.
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 ForOutput ¶ added in v0.2.0
ForOutput picks the devices that drive output: the backlights and DDC/CI monitors wired to its connector, else, for an internal panel, the backlights wired to no connector. Of several backlights only the best kind is kept (firmware, then platform, then raw), as the kernel's backlight ABI advises.
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. logind is the system bus logind's writes go over, and stays the caller's; nil writes through sysfs. A missing uevent socket degrades to 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), each at the level a queued write is heading to.
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.
func (*System) SetExternal ¶ added in v0.2.0
SetExternal follows the enable-external key: on starts a detached DDC scan, off closes every i2c bus held and scans no more until it is on again.
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.