enum GLibPump
Swift
enum GLibPump
Runs GLib's work on the frame loop when there is some, and not otherwise.
D-Bus — the global menu, the tray, notifications — is GLib, and GLib only gets anything done when its main context is iterated. The frame loop owns everything that work touches, so it is the one that iterates; the question is how it learns there is something to iterate for. It used to guess: an app exporting a global menu capped its idle wait at 20 ms, and the panel iterated from a 50 ms timer, so an idle desktop woke seventy times a second to find nothing nearly every time.
Instead one thread per process sleeps on GLib's own file descriptors
(canvas::waitForGLibEvents), and when they say something arrived it hops
to the frame loop, which runs every registered pump, and waits for that to
finish before sleeping again. The hand-off is strict on purpose: the waiter
holds the GLib context while it sleeps, so the pumps are the only place the
context can be iterated, and they run while the waiter has let go of it.
A pump returns how long until it next needs a turn on its own account — a toast's expiry is a clock GLib knows nothing about — or nil.
Sources/LavaUI/GLibPump.swift:23
Methods
static func add(_ pump: @escaping Pump)
Registers a pump and starts the waiter if it is not running. Frame-loop thread only, and only once whatever needed to iterate GLib by hand at start-up has finished: from here on the waiter holds the context.
Sources/LavaUI/GLibPump.swift:37
Type aliases
typealias Pump = () -> Int64?
Work for the frame loop. Returns milliseconds until it next has to run even if nothing arrives, or nil.
Sources/LavaUI/GLibPump.swift:26