backlight

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 20 Imported by: ? modules, 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 backlight is the kernel's backlights as the lys apps share them: sysfs enumeration and reads, logind's SetBrightness as the write path with a direct sysfs fallback, and a watch that ticks whenever a level may have changed.

Index

Constants

This section is empty.

Variables

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

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

View Source
var ErrClosed = errors.New("backlight: source closed")

ErrClosed is Subscribe on a closed Broadcast.

Functions

func AveragePercentage

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

AveragePercentage is the mean level across devices, false when there is none.

func RawLevel

func RawLevel(percent float64, top uint32) uint32

RawLevel maps a percentage, clamped to 0..100, onto 0..top.

Types

type Broadcast

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

Broadcast fans change ticks out to subscribers, coalescing the ticks a slow subscriber has not taken yet into one.

func NewBroadcast

func NewBroadcast() *Broadcast

NewBroadcast is a broadcast with no subscriber.

func (*Broadcast) Close

func (b *Broadcast) Close()

Close ends every subscription; later Subscribes fail with ErrClosed.

func (*Broadcast) Subscribe

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

Subscribe ticks until ctx ends, stop is called or the broadcast closes, and then closes the channel.

func (*Broadcast) Tick

func (b *Broadcast) Tick()

Tick wakes every subscriber.

type Device

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

Device is one backlight snapshot: its level against its maximum in raw units, and the DRM connector it is wired to, "" for none.

func Enumerate

func Enumerate() []Device

Enumerate lists every backlight device that reads; an unreadable class directory yields an empty list.

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 enumerates, watches and sets backlights.

type Sysfs

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

Sysfs is the backlights under Dir as a Source: read from sysfs, written through logind with a sysfs fallback, and watched through inotify, the kernel's backlight uevents and a drift probe.

func NewSysfs

func NewSysfs(system *dbus.Conn) *Sysfs

NewSysfs starts the watch. system is the system bus logind's writes go over, and stays the caller's; nil writes through sysfs alone. A missing inotify or uevent socket degrades to the drift probe instead of failing.

func (*Sysfs) Close

func (s *Sysfs) Close() error

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

func (*Sysfs) Devices

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

Devices reads every device under Dir.

func (*Sysfs) Set

func (s *Sysfs) Set(ctx context.Context, name string, percent float64) error

Set applies a clamped percentage through logind, and writes sysfs directly when logind refuses or there is no system bus.

func (*Sysfs) Subscribe

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

Subscribe ticks whenever a level may have changed or a device came or went, until ctx ends, stop or Close.

type Type

type Type uint8

Type distinguishes firmware, platform and raw backlights, and external monitors driven over DDC/CI.

const (
	TypeRaw Type = iota
	TypeFirmware
	TypePlatform
	TypeDDC
)

Backlight types.

func TypeFromSysfs

func TypeFromSysfs(value string) Type

TypeFromSysfs parses the sysfs type attribute; unknown values are Raw.

Directories

Path Synopsis
Package backlighttest fakes the sysfs backlight class directory for tests of code that reads or writes backlights.
Package backlighttest fakes the sysfs backlight class directory for tests of code that reads or writes backlights.

Jump to

Keyboard shortcuts

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