brightness

package
v0.3.28 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 24 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

View Source
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

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 DRMDir = drmconn.Dir

DRMDir is the sysfs class directory of DRM cards and connectors; a var so tests can repoint it.

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.

View Source
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

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.

func SetOutput added in v0.2.0

func SetOutput(ctx context.Context, src Source, output string, change Change, floor float64) (float64, error)

SetOutput moves every device driving output by change, held at floor, and returns their mean new level.

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 Absolute added in v0.2.0

func Absolute(percent int32) (Change, error)

Absolute is a level of percent, which must be in 0..=100.

func NewChange added in v0.2.0

func NewChange(relative bool, percent int32) (Change, error)

NewChange is Relative or Absolute by relative.

func ParseChange added in v0.2.0

func ParseChange(raw string) (Change, error)

ParseChange reads "N", "+N" or "-N" with N in ASCII digits.

func Relative added in v0.2.0

func Relative(delta int32) Change

Relative is a step of delta percent from the current level.

func (Change) IsRelative added in v0.2.0

func (c Change) IsRelative() bool

IsRelative reports whether the change is a step.

func (Change) Percent added in v0.2.0

func (c Change) Percent() int32

Percent is the level or the signed step.

func (Change) Target added in v0.2.0

func (c Change) Target(d Device, floor float64) float64

Target is the percentage d moves to: the level, or the step from d's rounded level, held between floor and 100. A positive floor never rounds to a dark panel: it is at least one raw step of d.

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

func NewDaemon(src Source, focused func() (string, bool), floor func() float64) *Daemon

NewDaemon serves src; focused names the focused output and floor is the lowest level a change may leave.

func (*Daemon) Apply added in v0.2.0

func (d *Daemon) Apply(output string, relative bool, percent int32) (string, float64, *dbus.Error)

Apply changes output, or the focused output when it is empty, and returns the output and its new level.

func (*Daemon) Export added in v0.2.0

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

Export serves the daemon on conn under ServiceName.

type Device

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

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

func ForOutput(devices []Device, output string) ([]Device, error)

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

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(system *dbus.Conn, 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. system 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

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), each at the level a queued write is heading to.

func (*System) Set

func (s *System) Set(ctx 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) SetExternal added in v0.2.0

func (s *System) SetExternal(on bool)

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.

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