portalsettings

package
v0.3.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 10 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 portalsettings follows the desktop settings xdg-desktop-portal publishes (color scheme, accent color, contrast, icon theme, the interface font and its text scaling) over the session bus. Listeners run on the monitor's own goroutine; the application bridges them onto its loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

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

Monitor tracks the desktop's appearance preferences: the dark/light color scheme, the icon-theme name (#64), the accent color (#88), and the high-contrast preference (#88) - all portal settings, all with the same contract. Create one with New (session bus) or NewOn (an existing connection), call OnChange, and Close it when the application exits. All methods are safe from any goroutine; see the package comment for the threading and failure contracts.

func New

func New() *Monitor

New starts a monitor on the session bus. It performs the startup read synchronously (bounded by probeTimeout + readTimeout), so Appearance is valid as soon as New returns. Without a session bus the monitor is inert — Unknown, no events, no goroutines (see the package comment).

func NewOn

func NewOn(conn *dbus.Conn) *Monitor

NewOn starts a monitor on a caller-provided connection — for apps that already hold one shared session bus connection. The monitor does NOT own conn: Close leaves it open, and when it dies the monitor fails silent (keeps the last known value; no re-dial, since only the owner knows how the connection was made). Otherwise the behavior matches New.

func (*Monitor) Accent

func (m *Monitor) Accent() appearance.Accent

Accent returns the desktop's accent-color preference: RGB in [0,1] with Known set, or the zero Accent when the desktop published none (no portal, no key, unreadable value). Safe from any goroutine.

func (*Monitor) Close

func (m *Monitor) Close()

Close stops the monitor: the loop goroutine exits, the subscription and its match rules are removed, and a monitor-owned connection is closed (NewOn callers keep theirs, as it was). Idempotent, safe from any goroutine. A callback already running finishes first; Close does not wait for it. Appearance stays readable with the last known value.

func (*Monitor) ColorScheme

func (m *Monitor) ColorScheme() appearance.ColorScheme

ColorScheme returns the current color-scheme preference, Unknown when the monitor never connected. Safe from any goroutine.

func (*Monitor) Contrast

func (m *Monitor) Contrast() appearance.Contrast

Contrast returns the desktop's contrast preference: ContrastHigh or ContrastUnknown (no portal, no preference, unreadable value). Safe from any goroutine.

func (*Monitor) FontName

func (m *Monitor) FontName() string

FontName returns the desktop's interface font description (the portal's org.gnome.desktop.interface font-name, "Adwaita Sans 11"): empty means no portal, no setting, or a value that is not a string. Safe from any goroutine.

func (*Monitor) IconTheme

func (m *Monitor) IconTheme() string

IconTheme returns the current icon-theme name (the portal's org.gnome.desktop.interface icon-theme setting): empty means no portal, no setting, or a value that is not a string. Safe from any goroutine.

func (*Monitor) Motion

func (m *Monitor) Motion() appearance.Motion

Motion returns the desktop's reduced-motion preference: MotionReduced or MotionUnknown (no portal, no preference, unreadable value). Safe from any goroutine.

func (*Monitor) OnAccentChange

func (m *Monitor) OnAccentChange(fn func(appearance.Accent)) (off func())

OnAccentChange registers fn for every accent-color change; the returned function unregisters it. The same threading contract as OnChange: callbacks run serialized on the monitor's goroutine - bridge with Application.Invoke.

func (*Monitor) OnColorSchemeChange

func (m *Monitor) OnColorSchemeChange(fn func(appearance.ColorScheme)) (off func())

OnColorSchemeChange registers fn for every color-scheme change, on the monitor's goroutine; the returned function unregisters it. The startup read is the baseline and never fires.

func (*Monitor) OnContrastChange

func (m *Monitor) OnContrastChange(fn func(appearance.Contrast)) (off func())

OnContrastChange registers fn for every contrast change; the returned function unregisters it. Same threading contract as OnChange.

func (*Monitor) OnFontNameChange

func (m *Monitor) OnFontNameChange(fn func(string)) (off func())

OnFontNameChange registers fn for every font-name change; the returned function unregisters it. Same threading contract as OnChange.

func (*Monitor) OnIconThemeChange

func (m *Monitor) OnIconThemeChange(fn func(string)) (off func())

OnIconThemeChange registers fn to run with the new icon-theme name whenever the desktop setting changes (#64); the returned function unregisters it. The same threading contract as OnChange: callbacks run serialized on the monitor's goroutine, never on a Wayland loop goroutine — bridge with Application.Invoke. The startup read is a baseline and never fires; an explicitly emptied setting is reported as "" (the consumer owns the fallback policy).

func (*Monitor) OnMotionChange

func (m *Monitor) OnMotionChange(fn func(appearance.Motion)) (off func())

OnMotionChange registers fn for every reduced-motion change; the returned function unregisters it. Same threading contract as OnChange.

func (*Monitor) OnTextScaleChange

func (m *Monitor) OnTextScaleChange(fn func(float64)) (off func())

OnTextScaleChange registers fn for every text-scaling-factor change; the returned function unregisters it. Same threading contract as OnChange.

func (*Monitor) TextScale

func (m *Monitor) TextScale() float64

TextScale returns the desktop's text-scaling-factor (1 is unscaled), 0 when it published none or an unusable value. Safe from any goroutine.

Jump to

Keyboard shortcuts

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