Documentation
¶
Overview ¶
The enter/exit visual half of a popup: a widget.Morph the coordinator drives. The popup grows out of the edge facing its anchor - scaling up while a rounded clip unrolls away from the anchor and the surface fades in - with its shadow and plate drawn for the unrolled shape, and shrinks back into the anchor on the way out. Everything stays inside the popup's own surface.
The per-frame paint pipeline for a popup surface, factored out of Run so two kinds of host loops can drive it without a second wayland dispatcher: Run (a nested loop on the caller's goroutine, for grabbed menus) and the application loop (for tooltips, which must never dispatch — see docs/threading.md: one event-loop goroutine owns the connection).
Package popup manages transient surfaces with the xdg_popup role: menus and tooltips. New positions a popup relative to its parent via an xdg_positioner, grabs it for dismissal, and Run drives a nested render/dispatch loop until the popup is destroyed. Dismissal is a state (see internal/surfx): Dismiss seals input, fires the close callback once, and the exit tween keeps the surface mapped and repainting until it lands — the wire teardown follows, whatever the dismissal path.
Index ¶
- Variables
- func Run(sess *wlsession.Session, p *Popup, frac120 uint32, root widget.Widget, ...) error
- type Config
- type Gravity
- type Painter
- type Popup
- func (p *Popup) ApplyVisual(reveal float64, morph bool)
- func (p *Popup) AttachInput(sess inputSession, router *widget.Router, onPress func()) (detach func())
- func (p *Popup) Close()
- func (p *Popup) Closed() bool
- func (p *Popup) Destroy()
- func (p *Popup) Destroyed() bool
- func (p *Popup) Dismiss()
- func (p *Popup) Dismissed() bool
- func (p *Popup) EnsureUsable() error
- func (p *Popup) Gutter() int
- func (p *Popup) HandlePopupConfigure(ev xdg.PopupConfigureEvent)
- func (p *Popup) HandlePopupPopupDone(xdg.PopupPopupDoneEvent)
- func (p *Popup) HandleSurfaceConfigure(ev xdg.SurfaceConfigureEvent)
- func (p *Popup) HostSurface() *wl.Surface
- func (p *Popup) MarkFrame()
- func (p *Popup) NewPainter(sess *wlsession.Session, gpu Renderer, frac120 uint32, root widget.Widget, ...) *Painter
- func (p *Popup) Position() (x, y int, ok bool)
- func (p *Popup) RequestedSize() (int, int)
- func (p *Popup) Resize(w, h int) bool
- func (p *Popup) Scale() *scale.Controller
- func (p *Popup) SealInput()
- func (p *Popup) SetOnClosed(f func())
- func (p *Popup) Size() (int, int)
- type Renderer
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("popup: dismissed")
ErrClosed reports that the popup was dismissed; Run returns it when the loop exits.
Functions ¶
func Run ¶
func Run(sess *wlsession.Session, p *Popup, frac120 uint32, root widget.Widget, bg render.Color, keys widget.KeyActionHandler) error
Run drives the popup's own render loop until it is destroyed: paint through the Painter each frame, dispatch input through the session, and advance the enter/exit tweens. This nested loop is for grabbed menus: it dispatches, so the caller must already own the loop goroutine. The popup surface registers its own pointer handler, so events land here only while the compositor routes focus (or the popup grab) to it - the host surface keeps receiving nothing and no hooks are swapped. A non-nil keys handler receives seat keyboard events translated to KeyActions, which menus need for arrow and Enter navigation. It is the handler itself, not a Router: a fresh menu has no focused widget, so a Router would swallow every action before the menu saw it. frac120 is the parent window's 120-based device scale; the popup's buffers are built at that device scale while its widget tree stays logical. Surfaces that must not run a second dispatcher (tooltips) use NewPainter from the application loop instead.
Types ¶
type Config ¶
type Config struct {
// Parent is the parent's xdg_surface; a popup always nests under a
// shell surface. Layer-parented popups leave this nil and set
// LayerParent instead.
Parent *xdg.Surface
// LayerParent parents the popup to a layer surface (bars, panels).
LayerParent *wlr.ZwlrLayerSurfaceV1
// X, Y is the anchor point in parent surface coordinates.
X, Y int
// AnchorRect, when non-empty, anchors the popup to a widget's rect
// (parent surface coordinates) instead of the X, Y point: it opens on
// the Gravity side, centered on the rect across it, and the
// compositor flips it to the opposite side or slides it along when
// it would leave the output.
// Popovers and tooltips anchor this way; menus use the point.
AnchorRect render.Rect
// Width, Height is the popup's size in surface pixels.
Width, Height int
// Gravity picks which side of the anchor the popup opens on; zero
// is below.
Gravity Gravity
// Gap is the distance between an AnchorRect and the content on the
// opening side; it follows the popup when the compositor flips it.
Gap int
// NoPlate skips the theme's plate (fill and shadow) behind the
// content: the content paints its own look, its stylesheet
// declaring the background, and the rest of the surface stays
// transparent.
NoPlate bool
// NoGrab skips the seat grab: the popup tracks hover without
// taking input, which tooltips need. A grabbing popup anchors its
// grab to the session's latest input event (Session.InputSerial).
NoGrab bool
// Gutter reserves that many logical pixels on every side for the
// theme's box shadow: Width and Height cover content plus two
// gutters, the content occupies the inner rect (arranged and
// hit-tested there), the gutter stays transparent so the falloff
// blends over whatever the popup floats above, and the input
// region excludes it — a shadow never extends a hit area. Zero
// paints the popup exactly as before the shadow work.
Gutter int
// Kind picks the animation profile; zero is the menu/popover one
// (pass surfx.KindTooltip for tooltips).
Kind surfx.Kind
// NoEnter opens the popup at rest, without its enter tween: a
// shared-element morph into its content carries the opening.
NoEnter bool
// BackgroundBlur asks the compositor to blur what is behind the
// content, following the enter and exit motion. Where no blur is in
// effect the painted root (BlurRoot) carries css.BlurUnavailable.
BackgroundBlur bool
// BlurRoot is the widget carrying the style a missing blur changes.
BlurRoot widget.Widget
}
Config describes where the popup goes and how big it is.
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter owns one popup surface's buffer pool and frame pacing. Pass drives at most one frame per call; the owning loop calls it once per pass and parks however it likes between passes.
func (*Painter) Close ¶
func (pc *Painter) Close()
Close releases the painter's pool storage back to the session arena.
func (*Painter) Collect ¶
Collect drains the visual's invalidations into what the next frame owes and reports whether it owed any: the owner refits the popup to its content then and marks the frame.
func (*Painter) Owes ¶
Owes reports whether the painter has a frame to paint: a tween callback or content change marked it. Owners skip the Pass call while it reads false, the popover-style gate.
func (*Painter) Pass ¶
Pass paints at most one frame: when a repaint is owed and the compositor has taken the previous one, measure, arrange, paint what the visual owes under the current reveal (plus what the reused buffer is stale in), commit, and arm the next frame callback. The whole wire sequence holds p.mu, serialized against the dismissal state machine's SealInput and Destroy. It returns false when the popup is destroyed and the painter is spent.
type Popup ¶
type Popup struct {
WLSurface *wl.Surface
XdgSurface *xdg.Surface
XdgPopup *xdg.Popup
// contains filtered or unexported fields
}
Popup is one open transient surface.
func New ¶
New positions and maps a popup, then grabs the seat so clicks outside dismiss it. The configure handshake completes inside New: callers can draw immediately.
func (*Popup) ApplyVisual ¶
ApplyVisual implements surfx.Driver: one tween frame.
func (*Popup) AttachInput ¶
func (p *Popup) AttachInput(sess inputSession, router *widget.Router, onPress func()) (detach func())
AttachInput routes the popup surface's pointer events into router (press, release, motion, leave), each one marking the popup for a repaint, until the returned detach. Run attaches its own; the application loop attaches one for the popovers it drives.
func (*Popup) Close ¶
func (p *Popup) Close()
Close tears the popup down on the spot: the teardown path through the same state machine, for error paths and callers that want no exit (lys-ui-hello's replace-on-open, buffer allocation failures). OnClosed still fires exactly once, and the wire objects are destroyed exactly once even if a tween was mid-flight.
func (*Popup) Closed ¶
Closed reports whether the popup was dismissed (logically gone; the surface may still be running its exit tween).
func (*Popup) Destroy ¶
func (p *Popup) Destroy()
Destroy implements surfx.Driver: the real wayland teardown - xdg_popup, xdg_surface, wl_surface - so the compositor can drop the popup's buffers and release them back to the session pool. Runs after the exit tween lands, or immediately from Teardown. Under p.mu, so a frame mid-paint on the popup's loop goroutine finishes its commit before the proxies go away. After it, HostSurface is no longer valid.
func (*Popup) Dismiss ¶
func (p *Popup) Dismiss()
Dismiss starts the two-phase close: the logical state flips (input region empties, OnClosed fires, the popup stops taking pointer events), the exit tween keeps the surface mapped and repainting until it lands, and only then does the wire teardown run. A second Dismiss mid-exit — another outside click, another Esc — is a no-op. A popup still holding the seat grab tears down at once instead: the grab outlives any exit tween, and a toplevel the dismissing pick or click maps meanwhile never gets the keyboard focus the grab held.
func (*Popup) EnsureUsable ¶
EnsureUsable gates drawing until the first configure completed and the popup is not dismissed.
func (*Popup) HandlePopupConfigure ¶
func (p *Popup) HandlePopupConfigure(ev xdg.PopupConfigureEvent)
HandlePopupConfigure records the placed geometry.
func (*Popup) HandlePopupPopupDone ¶
func (p *Popup) HandlePopupPopupDone(xdg.PopupPopupDoneEvent)
HandlePopupPopupDone implements xdg.PopupPopupDoneEvent: outside- click dismissal. It routes through Dismiss like every other path — no fast lane: the surface stays mapped for the exit tween and the compositor has already ended the grab by the time this fires (a grab dropped while the popup is mapped is exactly the wire state the exit needs).
func (*Popup) HandleSurfaceConfigure ¶
func (p *Popup) HandleSurfaceConfigure(ev xdg.SurfaceConfigureEvent)
HandleSurfaceConfigure completes the configure round.
func (*Popup) HostSurface ¶
HostSurface returns the underlying wl_surface.
func (*Popup) MarkFrame ¶
func (p *Popup) MarkFrame()
MarkFrame implements surfx.Driver: schedule a repaint of this surface. The owning loop's pacing does the waking — Run arms the animation clock's next frame deadline itself, and the application loop is already woken by the same deadlines through its kicker. (Deliberately no WakeAfter(0) here: pacing every tween callback as an immediate wake turns a tween into a busy spin.)
func (*Popup) NewPainter ¶
func (p *Popup) NewPainter(sess *wlsession.Session, gpu Renderer, frac120 uint32, root widget.Widget, bg render.Color) *Painter
NewPainter wraps root in the tween view (seeded from the coordinator, so the first frame is the hidden or offset one, never a flash of the finished surface) and returns the frame driver. A non-nil gpu draws the frames on the GPU.
func (*Popup) Position ¶
Position is where the compositor placed the popup's surface, relative to its parent's (neither sets a window geometry, so it is surface to surface); false before the first configure.
func (*Popup) RequestedSize ¶
RequestedSize is the size last asked for: at open, or by Resize.
func (*Popup) Resize ¶
Resize re-places the popup at a new size against its original anchor (xdg_popup.reposition, xdg_wm_base 3 and later): the compositor answers with a configure carrying the new geometry, which the next frame paints at. It reports false when the compositor cannot reposition popups; the popup then keeps its size.
func (*Popup) Scale ¶
func (p *Popup) Scale() *scale.Controller
Scale returns the popup's scale controller. A surface can hold only one wp_viewport (a second get_viewport is a fatal protocol error), so every caller that rescales the popup must go through this one - building another controller on HostSurface kills the client.
func (*Popup) SealInput ¶
func (p *Popup) SealInput()
SealInput implements surfx.Driver: an empty input region, committed, so clicks during the exit fall through to whatever is beneath — the tooltip input-region trick, applied at dismissal. The commit only refreshes the region (the current buffer stays attached), and later animation commits keep it: the input region is double-buffered state that persists until changed. Under p.mu, serialized against frames like Destroy.
func (*Popup) SetOnClosed ¶
func (p *Popup) SetOnClosed(f func())
SetOnClosed runs f when the popup is dismissed — exactly once, inside the first Dismiss (or a teardown that beats any dismissal).
type Renderer ¶
type Renderer interface {
buffer.Copier
NewBuffer(sess *wlsession.Session, bufW, bufH, scale int) (*buffer.Buffer, error)
Frame(b *buffer.Buffer, num int, paint func(cv *render.Canvas)) (bool, error)
Failed() bool
}
Renderer draws a popup's frames on the GPU, as its window's are: the buffers it renders into, the frame a paint becomes there, and the copy that brings a reused buffer forward. A frame that fails reports false, after which Failed holds and the popup draws on the CPU; an error ends the popup.