dbus

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0 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 dbus holds the D-Bus services, in pure Go on godbus: tray, notifications, portals, settings and AT-SPI2.

Flutter: no counterpart (Flutter leaves these to plugins).

Index

Constants

View Source
const (
	// PortalDest is the name of the xdg-desktop-portal service.
	//
	// Flutter: no counterpart
	PortalDest = "org.freedesktop.portal.Desktop"
	// PortalPath is the object path of the portal frontend.
	//
	// Flutter: no counterpart
	PortalPath godbus.ObjectPath = "/org/freedesktop/portal/desktop"
)
View Source
const PropertiesIface = "org.freedesktop.DBus.Properties"

PropertiesIface is the interface of the standard properties of an object.

Variables

This section is empty.

Functions

func FallbackSettings

func FallbackSettings(getenv func(string) string) platform.Settings

FallbackSettings returns the settings to use when the Settings portal is missing: the environment variables XCURSOR_SIZE and XCURSOR_THEME, then the defaults (a light theme, no text scaling, animations on).

getenv looks up an environment variable; pass os.Getenv.

The locale is always read from the environment (LC_ALL, LC_MESSAGES, LANG): the portal has no locale. X11 adds XSETTINGS to the fallback in its own package.

Flutter: no counterpart

func IBusAddress

func IBusAddress(getenv func(string) string, readFile func(string) ([]byte, error), display string) (string, error)

IBusAddress finds the address of the private bus of the IBus daemon: the variable IBUS_ADDRESS, or the line IBUS_ADDRESS of the file the daemon writes to <config>/ibus/bus/<machine-id>-<host>-<display>. display is "wayland" (the file is named after WAYLAND_DISPLAY, "unix-wayland-0") or "x11" (named after DISPLAY, "unix-0"). It fails with IBusAddressNotFound when there is none.

getenv looks up an environment variable; readFile reads a file; pass os.Getenv and os.ReadFile.

Flutter: no counterpart

func IBusBusFromEnvironment

func IBusBusFromEnvironment(display string) func(ctx context.Context) (Bus, error)

IBusBusFromEnvironment returns a function that opens the private bus of the IBus daemon found by IBusAddress for the display system ("x11" or "wayland"). Use it as IMEOptions.IBusBus.

Flutter: no counterpart

func IMEHintFromEnv

func IMEHintFromEnv(getenv func(string) string) string

IMEHintFromEnv reads which input method the environment names, from XMODIFIERS ("@im=fcitx"), then GTK_IM_MODULE and QT_IM_MODULE. It returns "fcitx", "ibus" or "".

getenv looks up an environment variable; pass os.Getenv.

Flutter: no counterpart

func LocalesFromEnv

func LocalesFromEnv(getenv func(string) string) []ui.Locale

LocalesFromEnv returns the locale that the environment names: the first of LC_ALL, LC_MESSAGES and LANG that is set and is not empty, "C" or "POSIX", as a language and a country ("de_DE.UTF-8@euro" is de DE). It returns nil when none names one, and the app then has the default locale.

Flutter: no counterpart

func PortalRequestPath

func PortalRequestPath(unique, token string) godbus.ObjectPath

PortalRequestPath is the object path of the request that the portal makes for the connection named unique and the handle token token.

Flutter: no counterpart

func ReadSettings

func ReadSettings(ctx context.Context, bus Bus, base platform.Settings) (platform.Settings, error)

ReadSettings reads the keys of SPEC §8.8 from the Settings portal and applies them over base. A key that the portal does not have keeps its value in base, and a value of the wrong type is ignored.

Flutter: no counterpart

func SessionBusPresent

func SessionBusPresent(getenv func(string) string) bool

SessionBusPresent says whether a session bus can be reached without starting one: DBUS_SESSION_BUS_ADDRESS names it, or the socket of systemd's user bus is there. A connection without either would start a bus with dbus-launch, which an app must not do.

Flutter: no counterpart

func WatchPortalSettings

func WatchPortalSettings(ctx context.Context, bus Bus, getenv func(string) string, post func(func()), onSettings func(platform.Settings)) (settings platform.Settings, fromPortal bool)

WatchPortalSettings is WatchSettings that also says whether the settings came from the portal. When they did not, the caller can look for other sources, such as XSETTINGS on X11.

Flutter: no counterpart

func WatchSettings

func WatchSettings(ctx context.Context, bus Bus, getenv func(string) string, post func(func()), onSettings func(platform.Settings)) platform.Settings

WatchSettings returns the current settings and follows their changes until ctx is done. Each change is passed to onSettings, which stands for Handler.OnSettings: it runs on the UI thread, through post (Platform.Post).

The settings come from the Settings portal over bus. When there is no bus (bus is nil), or the portal is missing, they are FallbackSettings(getenv) and nothing is followed; an app on a desktop without the portal simply keeps the settings it started with.

Flutter: no counterpart

Types

type Bus

type Bus interface {
	// UniqueName is the unique name (":1.42") of this connection.
	UniqueName() string
	// Call calls a method and returns the values of the reply. The method is
	// the full name, such as "org.freedesktop.portal.Settings.ReadAll".
	Call(ctx context.Context, dest string, path godbus.ObjectPath, method string, args ...any) ([]any, error)
	// Subscribe delivers the signals that match until ctx is done, then closes
	// the channel. The subscription exists when Subscribe returns, so a signal
	// sent after that is not missed.
	Subscribe(ctx context.Context, match SignalMatch) (<-chan *godbus.Signal, error)
	// Export serves the exported methods of receiver as the methods of iface on
	// path, with the rules of godbus (a method may return a *godbus.Error as its
	// last value, and take a godbus.Sender as its first argument). Exporting the
	// same path and interface again replaces the receiver.
	Export(receiver any, path godbus.ObjectPath, iface string) error
	// Unexport stops serving iface on path.
	Unexport(path godbus.ObjectPath, iface string)
	// EmitSignal sends the signal name (the full name, such as
	// "org.kde.StatusNotifierItem.NewIcon") from path.
	EmitSignal(path godbus.ObjectPath, name string, values ...any) error
	// RequestName takes the well-known name for this connection, without waiting
	// in the queue for it. It fails with DBusNameTaken when another connection owns it.
	RequestName(name string) error
	// ReleaseName gives the well-known name up.
	ReleaseName(name string) error
	// Close closes the connection.
	Close() error
}

Bus is the part of a D-Bus connection that the services use. The real implementation is Connect; the in-process fake of the tests is fakebus.Bus.

Flutter: no counterpart

func Connect

func Connect(ctx context.Context) (Bus, error)

Connect opens the session bus. The connection is private to the caller; close it with Close. ctx bounds the wait for the connection, and nothing else: the connection does not end with it (godbus closes a connection when the context it was made with is done, which would end every connection as soon as the caller's timeout is cancelled).

Flutter: no counterpart

func ConnectAddress

func ConnectAddress(ctx context.Context, address string) (Bus, error)

ConnectAddress opens a bus at an address, such as the private bus of the IBus daemon ("unix:path=/run/user/1000/ibus/dbus-xyz,guid=..."). The connection is private to the caller; close it with Close. It fails with DBusAddressDialFailed, DBusAddressAuthFailed or DBusAddressHelloFailed.

Flutter: no counterpart

func NewBus

func NewBus(conn *godbus.Conn) Bus

NewBus wraps an open connection, for example one to a private test bus.

Flutter: no counterpart

type IMEContent

type IMEContent struct {
	// Purpose is a GtkInputPurpose value (0 free-form ... 8 password, 9 PIN),
	// which agrees with ui.TextInputPurpose for 0 to 9.
	Purpose uint32
	// Hidden is whether the text is hidden (a password), whatever the purpose.
	Hidden bool
}

IMEContent is what the focused text field is for.

Flutter: no counterpart

type IMEEvent

type IMEEvent struct {
	// Kind says which fields mean something.
	Kind IMEEventKind
	// Text is the text to commit, or the preedit text. An IMEEventPreedit with
	// no text ends the preedit.
	Text string
	// Cursor is the position of the cursor in the preedit, as a UTF-8 byte
	// offset into Text; -1 means the input method hides the cursor.
	Cursor int
	// Offset and Count are the text to delete, in characters (runes) from the
	// cursor: the range starts Offset characters from it (negative is
	// before) and is Count characters long.
	Offset, Count int
}

IMEEvent is one change that the input method asks for.

Flutter: no counterpart

type IMEEventKind

type IMEEventKind int

IMEEventKind says which change an IMEEvent is.

Flutter: no counterpart

const (
	// IMEEventCommit inserts final text.
	//
	// Flutter: no counterpart
	IMEEventCommit IMEEventKind = iota + 1
	// IMEEventPreedit shows (or, with no text, hides) the text being composed.
	//
	// Flutter: no counterpart
	IMEEventPreedit
	// IMEEventDelete deletes text around the cursor.
	//
	// Flutter: no counterpart
	IMEEventDelete
)

The kinds of IMEEvent. The zero value is not a kind.

type IMEKey

type IMEKey struct {
	// Keysym is the X11 keysym of the key with the modifiers that apply.
	Keysym uint32
	// Keycode is the evdev scancode of the key (the XKB keycode minus 8).
	Keycode uint32
	// State is the X11 core modifier mask: Shift 1, Lock 2, Control 4, Mod1 8,
	// and so on.
	State uint32
	// Release is whether the key went up.
	Release bool
	// Time is the time of the event in milliseconds, or 0.
	Time uint32
}

IMEKey is a key event for an input method. The input method sees the keys before the app, because it may consume them to compose text.

Flutter: no counterpart

type IMEOptions

type IMEOptions struct {
	// Hint is the framework the user chose, "ibus" or "fcitx" (see
	// IMEHintFromEnv); it is tried first. Empty tries Fcitx5, then IBus.
	Hint string
	// Program is the name the input method shows for the app, such as the
	// app id.
	Program string
	// Display is the display system, "x11" or "wayland", which Fcitx5 uses to
	// tell the contexts apart.
	Display string
	// IBusBus opens the private bus of the IBus daemon. Nil, or an error, makes
	// IBus go through its portal on the session bus.
	IBusBus func(ctx context.Context) (Bus, error)
}

IMEOptions tells OpenInputMethod where to look.

Flutter: no counterpart

type InputMethod

type InputMethod interface {
	// Name is "ibus" or "fcitx5".
	Name() string
	// FocusIn tells the input method that a text field has the focus.
	FocusIn(ctx context.Context) error
	// FocusOut tells it that the text field lost the focus.
	FocusOut(ctx context.Context) error
	// Reset drops the text being composed.
	Reset(ctx context.Context) error
	// SetCursorRect gives the rectangle of the caret in screen pixels, so the
	// candidate window can sit next to it.
	SetCursorRect(ctx context.Context, x, y, w, h int) error
	// SetContent gives the purpose of the text field.
	SetContent(ctx context.Context, content IMEContent) error
	// SetSurroundingText gives the text around the caret and the caret and
	// the selection anchor in it, in characters (runes).
	SetSurroundingText(ctx context.Context, text string, cursor, anchor int) error
	// ProcessKey asks the input method whether it consumes the key.
	ProcessKey(ctx context.Context, key IMEKey) (handled bool, err error)
	// Close destroys the input context and stops the events.
	Close() error
}

InputMethod is a connection to an input method framework (IBus or Fcitx5) with one input context, which stands for the focused text field. The methods may be called from one goroutine at a time. The events arrive on a goroutine of the implementation, through the function given to OpenInputMethod.

Flutter: no counterpart

func OpenInputMethod

func OpenInputMethod(ctx context.Context, session Bus, opts IMEOptions, events func(IMEEvent)) (InputMethod, error)

OpenInputMethod connects to the input method framework that is running and creates an input context in it. session is the session bus. The framework of opts.Hint is tried first. It fails with InputMethodUnavailable when none is running; events then never come and the app uses plain keys with the compose table.

events is called on a goroutine of the implementation for every change the input method asks for, in order. It must not block.

Flutter: no counterpart

func OpenSessionInputMethod

func OpenSessionInputMethod(ctx context.Context, opts IMEOptions, events func(IMEEvent)) (InputMethod, error)

OpenSessionInputMethod connects to the session bus and calls OpenInputMethod on it. Closing the input method closes the connection. It fails with DBusConnectFailed when there is no session bus, and with InputMethodUnavailable when no framework is running.

Flutter: no counterpart

type PortalResponse

type PortalResponse struct {
	// Code says how the interaction ended.
	Code PortalResponseCode
	// Results are the values of the answer; empty unless Code is
	// PortalResponseSuccess.
	Results map[string]godbus.Variant
}

PortalResponse is the answer to a portal request.

Flutter: no counterpart

func PortalRequest

func PortalRequest(ctx context.Context, bus Bus, method string, args func(handleToken string) []any) (PortalResponse, error)

PortalRequest calls a portal method that answers through a org.freedesktop.portal.Request object, and waits for the answer.

The method is the full name, such as "org.freedesktop.portal.FileChooser.OpenFile". args builds the arguments of the call from the handle token it must put in its options dictionary as "handle_token". The Response signal is subscribed to before the call, at the path the portal derives from the token, so an answer that comes at once is not lost. When ctx is done before the answer, the request is closed and the error is PortalRequestAborted.

Flutter: no counterpart

type PortalResponseCode

type PortalResponseCode uint32

PortalResponseCode is the first value of the Response signal of a portal request.

Flutter: no counterpart

const (
	// PortalResponseSuccess means the request finished and has results.
	//
	// Flutter: no counterpart
	PortalResponseSuccess PortalResponseCode = 0
	// PortalResponseCancelled means the user cancelled the interaction. It is a
	// result, not an error.
	//
	// Flutter: no counterpart
	PortalResponseCancelled PortalResponseCode = 1
	// PortalResponseEnded means the interaction ended in some other way.
	//
	// Flutter: no counterpart
	PortalResponseEnded PortalResponseCode = 2
)

The values of PortalResponseCode are the codes of the portal protocol.

type Properties

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

Properties serves the properties of one object path: the methods Get, GetAll and Set of org.freedesktop.DBus.Properties, and the signal PropertiesChanged when a value is updated. The values are set and read from any goroutine.

Flutter: no counterpart

func NewProperties

func NewProperties(bus Bus, path godbus.ObjectPath) *Properties

NewProperties creates the properties of path. Nothing is served until Export.

Flutter: no counterpart

func (*Properties) Export

func (p *Properties) Export() error

Export starts serving the properties on the bus.

Flutter: no counterpart

func (*Properties) Store

func (p *Properties) Store(iface, name string, value any) (changed bool)

Store sets the value of a property without telling anybody, for the values that exist before the object is exported. It reports whether the value changed.

Flutter: no counterpart

func (*Properties) Unexport

func (p *Properties) Unexport()

Unexport stops serving the properties.

Flutter: no counterpart

func (*Properties) Update

func (p *Properties) Update(iface, name string, value any) error

Update sets the value of a property and, when it changed and the object is exported, emits PropertiesChanged with the new value.

Flutter: no counterpart

func (*Properties) Value

func (p *Properties) Value(iface, name string) (any, bool)

Value is the current value of a property.

Flutter: no counterpart

type SignalMatch

type SignalMatch struct {
	// Sender is the well-known or unique name of the sender.
	Sender string
	// Path is the object path the signal comes from.
	Path godbus.ObjectPath
	// Interface is the interface of the signal.
	Interface string
	// Member is the name of the signal.
	Member string
}

SignalMatch selects the signals a Subscribe delivers. An empty field matches every value.

Flutter: no counterpart

func (SignalMatch) Matches

func (m SignalMatch) Matches(sig *godbus.Signal) bool

Matches reports whether sig is selected by the path, interface and member of the match. The sender is not compared: a real bus filters by sender (which may be a well-known name that the signal does not carry), and the fake bus has one sender.

Flutter: no counterpart

Directories

Path Synopsis
Package atspi is the accessibility bridge for Linux desktops (SPEC §8.10): it mirrors the framework's semantics tree as AT-SPI2 objects on the accessibility bus, so that screen readers such as Orca can read the app and act on it.
Package atspi is the accessibility bridge for Linux desktops (SPEC §8.10): it mirrors the framework's semantics tree as AT-SPI2 objects on the accessibility bus, so that screen readers such as Orca can read the app and act on it.
Package fakebus is an in-process D-Bus for tests (SPEC §17).
Package fakebus is an in-process D-Bus for tests (SPEC §17).

Jump to

Keyboard shortcuts

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