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 ¶
- type Monitor
- func (m *Monitor) Accent() appearance.Accent
- func (m *Monitor) Close()
- func (m *Monitor) ColorScheme() appearance.ColorScheme
- func (m *Monitor) Contrast() appearance.Contrast
- func (m *Monitor) FontName() string
- func (m *Monitor) IconTheme() string
- func (m *Monitor) Motion() appearance.Motion
- func (m *Monitor) OnAccentChange(fn func(appearance.Accent)) (off func())
- func (m *Monitor) OnColorSchemeChange(fn func(appearance.ColorScheme)) (off func())
- func (m *Monitor) OnContrastChange(fn func(appearance.Contrast)) (off func())
- func (m *Monitor) OnFontNameChange(fn func(string)) (off func())
- func (m *Monitor) OnIconThemeChange(fn func(string)) (off func())
- func (m *Monitor) OnMotionChange(fn func(appearance.Motion)) (off func())
- func (m *Monitor) OnTextScaleChange(fn func(float64)) (off func())
- func (m *Monitor) TextScale() float64
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 ¶
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 ¶
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 ¶
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 ¶
OnFontNameChange registers fn for every font-name change; the returned function unregisters it. Same threading contract as OnChange.
func (*Monitor) OnIconThemeChange ¶
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 ¶
OnTextScaleChange registers fn for every text-scaling-factor change; the returned function unregisters it. Same threading contract as OnChange.