Documentation
¶
Overview ¶
Package surfx is the surface-animation coordinator: one state machine every transient surface (menus, tooltips, toasts, dropdown lists, dialogs, layer overlays) drives its enter and exit tweens through, instead of one ad-hoc implementation per surface kind.
The core idea is that dismissal is a state, not a syscall. A surface's teardown splits in two:
- Dismiss flips the logical state: the surface's input region goes empty (clicks "through" the dying surface land beneath, the GTK/fuzzel behavior), the app's OnClosed callback fires exactly once, and — for a compositor-dismissed popup — the seat grab has already dropped with popup_done. The surface stays mapped.
- The exit tween paints the way out; only when it lands does the driver's Destroy run, which is the real wayland teardown.
Double dismissal is a no-op: Dismiss returns false on every call after the first, so another outside click mid-exit cannot re-enter the machine, re-seal input, or re-fire callbacks.
wlroots popup lifetime rules shaped the ordering: a grabbed popup whose grab dropped while mapped is legal (that is exactly the outside-click case — the compositor ends the grab before sending popup_done, and the surface stays mapped for the exit tween), while the client cannot drop the grab itself without destroying the popup role object, which unmaps the surface. Destroying mid-grab is therefore the one thing Dismiss defers: the grab lives until Destroy at tween end — or dies on the first outside press, which the empty input region turns into a popup_done that Dismiss absorbs as a no-op. That ordering is what makes an exit tween on a grabbed popup wire-legal.
Index ¶
- Variables
- func Enabled() bool
- func Rise(o anim.Owner, spec Spec, start float64, fn func(reveal float64)) anim.Cancel
- func SetEnabled(on bool) (restore func())
- func SetStyle(k Kind, s Style)
- type Coordinator
- func (c *Coordinator) Destroyed() bool
- func (c *Coordinator) Dismiss() bool
- func (c *Coordinator) Dismissed() bool
- func (c *Coordinator) Enter()
- func (c *Coordinator) Reveal() float64
- func (c *Coordinator) SetOnDismissed(f func())
- func (c *Coordinator) Teardown()
- func (c *Coordinator) Visual() (reveal float64, morph bool)
- type Driver
- type Kind
- type Spec
- type Style
Constants ¶
This section is empty.
Variables ¶
var Defaults = map[Kind]Style{ KindMenu: { Enter: Spec{Spring: &anim.SpringSnappy}, Exit: Spec{Duration: anim.DurationShort, Easing: anim.EmphasizedAccelerate}, Morph: true, }, KindTooltip: { Enter: Spec{Duration: anim.DurationShort * 3 / 4, Easing: anim.EmphasizedDecelerate}, Exit: Spec{Duration: anim.DurationShort / 2, Easing: anim.EmphasizedAccelerate}, }, KindToast: { Enter: Spec{Spring: &anim.SpringBouncy}, Exit: Spec{Duration: anim.DurationMedium, Easing: anim.EmphasizedAccelerate}, Morph: true, }, KindDialog: { Enter: Spec{Spring: &anim.SpringSmooth}, Exit: Spec{Duration: anim.DurationShort, Easing: anim.EmphasizedAccelerate}, Morph: true, }, KindOverlay: { Enter: Spec{Spring: &anim.SpringSmooth}, Exit: Spec{Duration: anim.DurationMedium, Easing: anim.EmphasizedAccelerate}, Morph: true, }, }
Defaults are the per-kind profiles. Menus and popovers morph out of their anchor on a snappy spring, toasts on a bouncy one, dialogs and overlays (launchers, panel reveals) on a smooth one; tooltips stay a quick, quiet fade. Every exit is a short emphasized-accelerate tween back into the anchor.
Functions ¶
func Rise ¶
Rise runs a rising motion owned by o from start to rest (1), calling fn with every frame's reveal: the spec's spring when it has one - from wherever start is, overshoot included, until it settles - else its tween over the rest of the way. A spec that does not move lands 1 at once.
func SetEnabled ¶
func SetEnabled(on bool) (restore func())
SetEnabled turns surface animations on or off — the API toggle beside LYS_UI_NO_ANIM. It returns the restore function. Disabled animations collapse the durations to zero; the state machine still runs, so dismissal, sealing, callbacks, and destroy all behave identically.
Types ¶
type Coordinator ¶
type Coordinator struct {
// contains filtered or unexported fields
}
Coordinator is the dismissal state machine for one surface. Embed or hold it; the surface keeps its own wire objects behind the Driver. All methods are safe from any goroutine: tween callbacks land on whichever loop ticked the animation clock, while Dismiss usually comes from an input path.
func NewCoordinator ¶
NewCoordinator builds the machine for one surface of kind k, whose tweens o owns. motion, when non-nil, is consulted at every launch so a live theme change applies to the next tween; callers typically pass their theme's animation flag there.
func (*Coordinator) Destroyed ¶
func (c *Coordinator) Destroyed() bool
Destroyed reports whether the wire teardown happened.
func (*Coordinator) Dismiss ¶
func (c *Coordinator) Dismiss() bool
Dismiss flips the logical state and starts the exit tween from the current reveal. Returns false when the surface is already dismissed or gone — the double-dismiss no-op the outside-click path relies on. Like Enter, the launch runs outside the lock (see there).
func (*Coordinator) Dismissed ¶
func (c *Coordinator) Dismissed() bool
Dismissed reports whether the logical close happened.
func (*Coordinator) Enter ¶
func (c *Coordinator) Enter()
Enter starts the enter tween: the first frame sits at progress 0 (applied synchronously, so a surface's very first paint is hidden or offset — never a flash of the final frame), the tween then raises the reveal to rest. Idempotent; a surface that skips Enter opens at rest.
Locking note: the launch happens OUTSIDE c.mp. A zero-duration tween (reduced motion) fires its callback synchronously inside Play, and that callback takes the lock — launching under the lock would self-deadlock. The phase flip stays inside so concurrent Enters stay single-shot.
func (*Coordinator) Reveal ¶
func (c *Coordinator) Reveal() float64
Reveal returns the current visual fraction for a paint pass.
func (*Coordinator) SetOnDismissed ¶
func (c *Coordinator) SetOnDismissed(f func())
SetOnDismissed registers the exactly-once dismissal callback. It fires inside the first Dismiss (the logical close), and from Teardown when teardown beats any dismissal — a surface interrupted mid-flight still tells its app it went away, once.
func (*Coordinator) Teardown ¶
func (c *Coordinator) Teardown()
Teardown cancels any tween, fires the dismissal callback if it never fired, and destroys the surface if it is not destroyed. This is the error-path and surface-teardown entry (the old Close): no leak, no zombie, exactly-once everywhere — and idempotent.
func (*Coordinator) Visual ¶
func (c *Coordinator) Visual() (reveal float64, morph bool)
Visual returns the current frame: the reveal fraction and whether the motion morphs, for a driver building its view after frames ran.
type Driver ¶
type Driver interface {
// ApplyVisual applies the reveal fraction, 0 hidden through 1 at
// rest - a spring enter may overshoot past 1 before it settles.
// morph says whether the surface grows out of its anchor (scale and
// clip with the fade) or only fades.
ApplyVisual(reveal float64, morph bool)
// MarkFrame schedules a repaint of the current visual and wakes the
// surface's loop if it is parked. Called once per tween frame.
MarkFrame()
// SealInput kills the surface's input: an empty input region,
// committed, so clicks during the exit land beneath. Called once,
// at Dismiss, before the first exit frame.
SealInput()
// Destroy is the real wayland teardown. Called exactly once, when
// the exit tween lands — or immediately by Teardown.
Destroy()
}
Driver is the surface-side half the coordinator drives. The surface wrapper (popup.Popup, a hostWindow) implements it; the coordinator never touches wire objects itself.
type Kind ¶
type Kind uint8
Kind selects a surface's animation profile. The zero value is the menu/popover profile, the default for xdg popups.
type Spec ¶
Spec is one motion's shape: a tween's duration and curve, or a physics spring (Spring set), which runs until it settles and may overshoot the rest state - the surface swells past its size and settles back.
type Style ¶
Style is a kind's enter and exit motion. Morph surfaces grow out of the side facing their anchor - scaling up and unrolling a rounded clip as they fade in - and shrink back into it on the way out; without it they only fade.
func Lookup ¶
Lookup returns the effective profile for k: the override when one is set, else the default.
func Plan ¶
Plan resolves a kind's effective profile. The package toggle and LYS_UI_NO_ANIM collapse it to zero-duration tweens, which deliver their end state once at launch, so the state machine's shape is identical either way. A caller's reduced-motion source such as the theme (motion false) or the desktop's preference (anim.Reduced) degrades it to a short fade with no movement - which is why callers pass their theme state here instead of consulting it twice.