Documentation
¶
Overview ¶
Package linux holds what the Linux backends share: the event loop, the key tables, system settings and the choice between Wayland and X11.
Flutter: the Linux embedder (engine/src/flutter/shell/platform/linux).
Index ¶
- Constants
- func CursorNames(c platform.MouseCursor) []string
- func KeysymLogicalKey(keysym uint32) (uint64, bool)
- func PhysicalKey(xkbKeycode uint32) (uint64, bool)
- func ProcessStart() (time.Time, bool)
- func Select(s Selection) (Connection, Backend, error)
- type Backend
- type Connection
- type Events
- type LayoutGoal
- type Loop
- type Selection
- type Services
- type SettingsWatcher
- type Source
- type Timer
Constants ¶
const ( // UnicodePlane holds the keys that are a character: the id is the Unicode // code point of the lower-case character. // // Flutter: dev/tools/gen_keycodes kUnicodePlane UnicodePlane uint64 = 0 // GTKPlane holds the keys that Flutter has no id for: the id is the keysym // plus the plane. // // Flutter: dev/tools/gen_keycodes kGtkPlane GTKPlane uint64 = 0x15_0000_0000 )
Key id planes (Flutter's key ID scheme, dev/tools/gen_keycodes/README.md). A logical key id is the plane in the bits above the lowest 32, and a value in the plane below.
const AudioBackendEnv = "GLUTTER_AUDIO_BACKEND"
AudioBackendEnv names the environment variable that limits the audio backend: "pulse" (PulseAudio, and PipeWire's PulseAudio protocol) or "alsa". Unset, the backends are tried in that order, PulseAudio first (SPEC §28.3).
const BackendEnv = "GLUTTER_BACKEND"
BackendEnv names the environment variable that chooses the backend: "wayland" or "x11" (SPEC §6.3 rule 5).
Variables ¶
This section is empty.
Functions ¶
func CursorNames ¶
func CursorNames(c platform.MouseCursor) []string
CursorNames returns the names to look up in an XCursor theme for the cursor, best first, and nil for MouseCursorNone and for an invalid cursor. Wayland and X11 both use it.
Flutter: no counterpart (the Linux embedder passes the names to GTK)
func KeysymLogicalKey ¶
KeysymLogicalKey returns the id of Flutter's LogicalKeyboardKey for a keysym that is not a printable character (Return, Shift_L, F1, ...), and false for any other keysym.
Flutter: dev/tools/gen_keycodes gtk_keyval_to_logical_key_map
func PhysicalKey ¶
PhysicalKey returns the id of Flutter's PhysicalKeyboardKey for an XKB keycode (the evdev scancode plus 8), and false for a keycode Flutter does not know.
Flutter: dev/tools/gen_keycodes xkb_to_physical_key_map
func ProcessStart ¶
ProcessStart returns when this process started, to the tick of the kernel's clock (10 ms), from /proc: the start of a program is before its first Go code runs, and the cold start of SPEC §15 counts from it. It says false where /proc cannot be read.
Flutter: no counterpart
func Select ¶
func Select(s Selection) (Connection, Backend, error)
Select chooses and connects a backend (SPEC §6.3 rule 5):
- The backend named by Selection.Backend or $GLUTTER_BACKEND, if any. It is the only one tried, and its failure is returned unchanged.
- Wayland, when $WAYLAND_DISPLAY is set and the connection and its libraries work. A failure is logged and the next one is tried.
- X11, when $DISPLAY is set and the connection works.
- Otherwise NoDisplay, which carries what was tried and why it failed.
The log says which backend was chosen and why. A value that is not "wayland" or "x11" fails with BackendUnknown.
Flutter: no counterpart
Types ¶
type Connection ¶
type Connection interface {
platform.Platform
// Close releases the connection and everything that depends on it.
Close() error
}
Connection is a platform that is connected to its display server and can be closed.
Flutter: no counterpart
type Events ¶
type Events uint32
Events says what is ready on the file descriptor of a Source.
Flutter: no counterpart
const ( // Readable means the descriptor has data to read. It is also set when the // descriptor hung up or failed, so that reading reveals the error. // // Flutter: no counterpart Readable Events = 1 << iota // Writable means the descriptor accepts data. It is reported only to a // Source that WantsWrite. // // Flutter: no counterpart Writable // Hangup means the other end closed the descriptor or it failed. // // Flutter: no counterpart Hangup )
The bits of Events.
type LayoutGoal ¶
type LayoutGoal struct {
// Keycode is the XKB keycode of the key.
Keycode uint32
// Default is the logical key id on the US layout.
Default uint64
// Mandatory is whether Default applies when no layout has a Latin character on
// the key.
Mandatory bool
}
LayoutGoal describes one key whose logical key is chosen by looking across the layouts of the keymap (Flutter's layout goals).
Flutter: dev/tools/gen_keycodes/data/layout_goals.json
func LayoutGoals ¶
func LayoutGoals() []LayoutGoal
LayoutGoals returns the layout goals, ordered by keycode.
Flutter: dev/tools/gen_keycodes/data/layout_goals.json
type Loop ¶
type Loop struct {
// contains filtered or unexported fields
}
Loop is the event loop of the UI thread: it waits with epoll on its sources, an eventfd for Post and a timerfd for timers (docs/SPEC.md §8.4). An idle loop sleeps in epoll_wait with no timer armed.
Run, AddSource, RemoveSource, AfterFunc and Timer.Stop belong to the loop's thread, which is the goroutine that calls Run (call them before Run, or from functions the loop runs). Post, Stop and Close are safe from any goroutine.
Flutter: no counterpart
func NewLoop ¶
NewLoop creates the epoll instance, the eventfd and the timerfd. Close releases them.
Flutter: no counterpart
func (*Loop) AddSource ¶
AddSource starts waiting on the source's descriptor.
Flutter: no counterpart
func (*Loop) AfterFunc ¶
AfterFunc runs fn on the loop's thread after at least d. A timer that is due runs on the next pass of the loop.
Flutter: no counterpart
func (*Loop) Close ¶
Close releases the descriptors of the loop. Do not use the loop afterwards.
Flutter: no counterpart
func (*Loop) Post ¶
func (l *Loop) Post(fn func())
Post queues fn to run on the loop's thread. It is safe to call from any goroutine and wakes the loop. The functions of one goroutine run in the order that goroutine posted them.
Flutter: no counterpart
func (*Loop) RemoveSource ¶
RemoveSource stops waiting on the source's descriptor. Call it before closing the descriptor.
Flutter: no counterpart
func (*Loop) Run ¶
Run runs the loop on the calling goroutine until ctx is cancelled or Stop is called, and then returns nil, or until a source fails, and then returns its error unchanged. Each pass: BeforeWait of every source, epoll_wait, AfterWait of every source (display events), the due timers, and the posted functions.
Flutter: no counterpart
type Selection ¶
type Selection struct {
// Backend, when not empty, is the backend to use and overrides the
// environment variable (RunAppOpts.Backend, SPEC §13).
Backend string
// Getenv reads the environment; os.Getenv when nil.
Getenv func(string) string
// Wayland connects to the Wayland compositor. It must fail, not hang, when
// the compositor or a library is missing.
Wayland func() (Connection, error)
// X11 connects to the X server.
X11 func() (Connection, error)
// Logger gets the record of the choice; slog.Default() when nil.
Logger *slog.Logger
}
Selection says how to choose a backend. The two connect functions are the backends themselves (the engine passes wayland.New and x11.New; package linux cannot import them), so the choice can be tested with fakes.
Flutter: no counterpart
type Services ¶
type Services struct {
// contains filtered or unexported fields
}
Services are the optional capabilities that the Linux backends share: the accessibility bridge (AT-SPI2 over D-Bus, SPEC §8.10), the gamepads (evdev, SPEC §28.2) and the audio (PulseAudio and ALSA, SPEC §28.3).
Flutter: no counterpart
func NewServices ¶
func NewServices(post func(func())) *Services
NewServices makes the services of a backend. post runs a function on its UI thread. The bridge connects to the session bus only when it is started, and only if a bus is there: it never starts one.
GLUTTER_GAMEPAD_HID=0 turns the HID drivers of the gamepads off, so that every pad is read through its event device (SPEC §28.2).
Flutter: no counterpart
func (*Services) Accessibility ¶
func (s *Services) Accessibility() platform.Accessibility
Accessibility returns the AT-SPI2 bridge, or nil when there are no services.
func (*Services) Audio ¶
Audio returns the audio service: PulseAudio, then ALSA (SPEC §28.3). Nothing is loaded or connected until it is used.
type SettingsWatcher ¶
type SettingsWatcher struct {
// Post runs a function on the UI thread (Platform.Post).
Post func(func())
// Apply is called on the UI thread with the settings after each change.
Apply func(platform.Settings)
// Open connects to the session bus; nil means dbus.Connect when a session bus is
// there. Tests replace it.
Open func(ctx context.Context) (dbus.Bus, error)
// Getenv reads the environment; nil means os.Getenv.
Getenv func(string) string
// contains filtered or unexported fields
}
SettingsWatcher reads the system settings for a backend and follows their changes (SPEC §8.8): from the Settings portal over the session bus, else from the environment. Backends add their own source, such as XSETTINGS on X11, with Set. Every method belongs to the UI thread.
Flutter: no counterpart
func (*SettingsWatcher) Current ¶
func (w *SettingsWatcher) Current() platform.Settings
Current returns the settings now.
func (*SettingsWatcher) Replace ¶
func (w *SettingsWatcher) Replace(s platform.Settings)
Replace sets the settings without passing them on, for the first reading of a source other than the portal.
func (*SettingsWatcher) Set ¶
func (w *SettingsWatcher) Set(s platform.Settings)
Set replaces the settings, for a source other than the portal, and passes them on when they changed.
func (*SettingsWatcher) Start ¶
func (w *SettingsWatcher) Start() (settings platform.Settings, fromPortal bool)
Start connects to the portal and reads the settings once; later calls return the settings now. fromPortal says that the portal answered, so that the backend knows it need not look elsewhere.
func (*SettingsWatcher) Stop ¶
func (w *SettingsWatcher) Stop()
Stop stops following and closes the bus.
type Source ¶
type Source interface {
// FD is the descriptor to wait on.
FD() int
// WantsWrite reports whether the loop should also wait for the descriptor
// to become writable, because earlier output could not be sent in full.
WantsWrite() bool
// BeforeWait is called before every wait: flush output and prepare to read.
// An error ends the loop.
BeforeWait() error
// AfterWait is called after every wait, with what is ready (possibly
// nothing, when something else woke the loop): read and dispatch events. An
// error ends the loop.
AfterWait(ready Events) error
}
Source is a file descriptor that the Loop waits on, together with what to do before and after each wait. The Wayland connection is one; X11 and D-Bus connections are others.
Flutter: no counterpart
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package alsa is the ALSA backend of the audio service on Linux (SPEC §28.3, step 31.5), for the systems where no PulseAudio (or PipeWire) server answers: playback and capture of float32 frames through libasound's PCM interface, on a goroutine of its own for each device.
|
Package alsa is the ALSA backend of the audio service on Linux (SPEC §28.3, step 31.5), for the systems where no PulseAudio (or PipeWire) server answers: playback and capture of float32 frames through libasound's PCM interface, on a goroutine of its own for each device. |
|
Package dl is the one safe way to load C libraries and call into them without cgo: it wraps purego's Dlopen, Dlsym and callbacks, tags every failure, and offers the libc helpers (malloc, free, C strings) that the backends share.
|
Package dl is the one safe way to load C libraries and call into them without cgo: it wraps purego's Dlopen, Dlsym and callbacks, tags every failure, and offers the libc helpers (malloc, free, C strings) that the backends share. |
|
layouttest
Package layouttest is the helper for the layout test that every Go mirror of a C struct needs (SPEC §8.1 rule 3).
|
Package layouttest is the helper for the layout test that every Go mirror of a C struct needs (SPEC §8.1 rule 3). |
|
Package evdev is the gamepad backend of Linux: it finds the pads among the event devices of /dev/input, reads their buttons, axes and hats, and reports them to the pad manager (internal/pads) through platform.Gamepads.
|
Package evdev is the gamepad backend of Linux: it finds the pads among the event devices of /dev/input, reads their buttons, axes and hats, and reports them to the pad manager (internal/pads) through platform.Gamepads. |
|
Package fontconfig binds libfontconfig (through purego, SPEC §8.1) to match a font family, weight, slant and language to the font files of the system, in the fallback order the user's fontconfig settings give.
|
Package fontconfig binds libfontconfig (through purego, SPEC §8.1) to match a font family, weight, slant and language to the font files of the system, in the fallback order the user's fontconfig settings give. |
|
Package ime connects a window system backend to an input method framework over D-Bus (IBus or Fcitx5): the same way for X11, and for Wayland on a compositor without text-input-v3 (SPEC §8.3, §8.6).
|
Package ime connects a window system backend to an input method framework over D-Bus (IBus or Fcitx5): the same way for X11, and for Wayland on a compositor without text-input-v3 (SPEC §8.3, §8.6). |
|
imetest
Package imetest has test doubles for the input method of the Linux backends: an input method that records its calls, and a poster that lets the test run what the bridge hands to the UI thread.
|
Package imetest has test doubles for the input method of the Linux backends: an input method that records its calls, and a poster that lets the test run what the bridge hands to the UI thread. |
|
Package input turns what the Linux windowing systems report about pointers and touch screens into ui.PointerData, the same way for Wayland and X11.
|
Package input turns what the Linux windowing systems report about pointers and touch screens into ui.PointerData, the same way for Wayland and X11. |
|
Package pixelpool is the buffers of one window that a CPU renderer draws into: the part of the Wayland and X11 backends that hands a buffer out only when the display server no longer reads it, and says how old its content is (SPEC §9.6; steps 32.1 and 32.2).
|
Package pixelpool is the buffers of one window that a CPU renderer draws into: the part of the Wayland and X11 backends that hands a buffer out only when the display server no longer reads it, and says how old its content is (SPEC §9.6; steps 32.1 and 32.2). |
|
Package pulse is the PulseAudio backend of the audio service on Linux (SPEC §28.3, step 31.5): playback and capture streams of float32 frames on libpulse's threaded main loop, the devices and the default device of the server, and a notification when they change.
|
Package pulse is the PulseAudio backend of the audio service on Linux (SPEC §28.3, step 31.5): playback and capture streams of float32 frames on libpulse's threaded main loop, the devices and the default device of the server, and a notification when they change. |
|
Package wayland is the Wayland backend.
|
Package wayland is the Wayland backend. |
|
decor
Package decor binds libdecor, the library that draws native title bars for Wayland compositors without server-side decorations (GNOME).
|
Package decor binds libdecor, the library that draws native title bars for Wayland compositors without server-side decorations (GNOME). |
|
fakecomp
Package fakecomp is a tiny fake Wayland compositor for tests: it speaks the wire protocol over a socket pair, answers the requests that the tests send, and logs them.
|
Package fakecomp is a tiny fake Wayland compositor for tests: it speaks the wire protocol over a socket pair, answers the requests that the tests send, and logs them. |
|
wl
Package wl is the Wayland client: the runtime over libwayland-client, which is bound with purego, and the Go bindings of every protocol in ../protocols, generated by `glutter-gen wayland` into the *_gen.go files.
|
Package wl is the Wayland client: the runtime over libwayland-client, which is bound with purego, and the Go bindings of every protocol in ../protocols, generated by `glutter-gen wayland` into the *_gen.go files. |
|
Package x11 is the X11 backend.
|
Package x11 is the X11 backend. |
|
Package xkb binds libxkbcommon (through purego, SPEC §8.1) and turns key presses into Flutter key data: the physical key, the logical key and the text, for any keyboard layout, with dead keys and compose sequences.
|
Package xkb binds libxkbcommon (through purego, SPEC §8.1) and turns key presses into Flutter key data: the physical key, the logical key and the text, for any keyboard layout, with dead keys and compose sequences. |