brightness

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: 22 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 brightness is the shell's brightness control: the kernel's backlights from desktop/service/backlight, external monitors over DDC/CI (ddc.go) re-scanned on DRM hotplug, the outputs each drives (output.go), and the shell's brightness daemon.

Index

Constants

View Source
const (
	TypeRaw      = backlight.TypeRaw
	TypeFirmware = backlight.TypeFirmware
	TypePlatform = backlight.TypePlatform
	TypeDDC      = backlight.TypeDDC
)

Device types.

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 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 ErrAutoNotRunning = errors.New("automatic brightness is not running: nothing owns " + autobrightness.ServiceName + " on the session bus")

ErrAutoNotRunning is what ResumeAuto wraps when automatic brightness is off: nothing owns its name on the session bus.

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: what the bar label and the OSD show, since a brightness action drives every device at once. False when there is none.

func ResumeAuto

func ResumeAuto(ctx context.Context, conn *dbus.Conn) error

ResumeAuto hands the backlight back to automatic brightness on conn, which then follows the room's light again; ErrAutoNotRunning when it is off.

func SetOutput

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 Auto

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

Auto follows automatic brightness on a session bus: its State on each PropertiesChanged of whichever connection owns its name, read again each time the name gains an owner, and ControlManual while nobody owns it.

func FollowAuto

func FollowAuto(conn *dbus.Conn, failed func(error)) (*Auto, error)

FollowAuto starts following automatic brightness on conn. failed is told of each state that could not be read or understood, which leaves the control as it was.

func (*Auto) Close

func (a *Auto) Close() error

Close stops following, once the watch has taken its match rules off the bus.

func (*Auto) Control

func (a *Auto) Control() Control

Control is who sets the backlight now.

func (*Auto) Resume

func (a *Auto) Resume(ctx context.Context) error

Resume hands the backlight back to automatic brightness.

func (*Auto) Subscribe

func (a *Auto) Subscribe() (<-chan struct{}, func())

Subscribe ticks whenever the control changed.

type Change

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

func Absolute(percent int32) (Change, error)

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

func NewChange

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

NewChange is Relative or Absolute by relative.

func ParseChange

func ParseChange(raw string) (Change, error)

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

func Relative

func Relative(delta int32) Change

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

func (Change) IsRelative

func (c Change) IsRelative() bool

IsRelative reports whether the change is a step.

func (Change) Percent

func (c Change) Percent() int32

Percent is the level or the signed step.

func (Change) Target

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 Control

type Control uint8

Control is who sets the backlight: the user alone while automatic brightness is off, or automatic brightness, following the room's light or paused by a manual change.

const (
	ControlManual Control = iota
	ControlFollowing
	ControlPaused
)

Controls.

func (Control) String

func (c Control) String() string

type Daemon

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

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

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

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

Export serves the daemon on conn under ServiceName.

type Device

type Device = backlight.Device

Device is one backlight or DDC/CI monitor snapshot.

func ForOutput

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.

type Source

type Source = backlight.Source

Source enumerates, watches and sets devices.

type System

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

System is the real source: the kernel's backlights, 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 DDC 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(ctx 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.

func (*System) SetExternal

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, stop or Close.

type Type

type Type = backlight.Type

Type is the kind of a Device.

Jump to

Keyboard shortcuts

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