window

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 9 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 window maps the xdg-shell role onto a wl_surface: real toplevel windows with titles, the configure handshake, the compositor-confirmed state set, ping/pong liveness, and the close signal.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("window: closed")

ErrClosed reports that the window was closed; the objects must not be used again.

View Source
var ErrNoImporter = errors.New("window: the compositor has no zxdg_importer_v2")

ErrNoImporter reports a foreign parent asked of a compositor that cannot import an xdg-foreign handle (no zxdg_importer_v2).

View Source
var ErrNotConfigured = errors.New("window: not configured yet")

ErrNotConfigured reports a draw attempt before the first configure event. The compositor rejects buffers committed before it.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	Known                                      bool
	WindowMenu, Maximize, Fullscreen, Minimize bool
}

Capabilities is what the compositor's window management offers a toplevel. Known is false until the compositor said (wm_capabilities, toplevel v5); until then every capability counts as available, the protocol's rule.

type Config

type Config struct {
	// Title and AppID identify the window to the compositor.
	Title, AppID string
	// Width and Height in surface (logical) pixels. Zeros let the
	// compositor pick.
	Width, Height uint32
	// MinWidth and MinHeight constrain how far the compositor may
	// resize the window down; zero axes are unconstrained. The app
	// clamps layout to the same limits (SizeLimits) in case a
	// compositor configures outside them.
	MinWidth, MinHeight uint32
	// MaxWidth and MaxHeight constrain how far the compositor may
	// resize the window up; zero axes are unconstrained.
	MaxWidth, MaxHeight uint32
}

Config describes the window before the first commit.

type State

type State struct {
	Activated  bool // keyboard focus
	Maximized  bool
	Fullscreen bool
	Resizing   bool // an interactive resize (Resize grab) is streaming
	Suspended  bool // the compositor stopped the window (not visible)
	// The tiled_* bits: the compositor snapped the window to an edge.
	TiledLeft, TiledRight, TiledTop, TiledBottom bool
}

State is the compositor-confirmed toplevel state: the state array of the most recent configure event, never the set of requests the client sent. A request (Maximize and friends) is a hint the compositor may refuse, delay, or undo in a later configure; only what arrives in the state array is true, so UI chrome reads this, not the requests.

There is no minimized bit: the protocol reports no state for a minimized (unmapped) window, and State keeps reporting what was last confirmed before it.

func (State) String

func (s State) String() string

String renders the confirmed state set ("activated+maximized"), "normal" when it is empty. The order is fixed so traces and dumps are comparable.

type Window

type Window struct {
	WLSurface  *wl.Surface
	XdgSurface *xdg.Surface
	Toplevel   *xdg.Toplevel

	OnCapabilities func(Capabilities)
	// contains filtered or unexported fields
}

Window is one toplevel window and its configure handshake.

func New

func New(wmBase *xdg.WmBase, surf *wl.Surface, cfg Config) (*Window, error)

New assigns the xdg_toplevel role and sends the initial state. The caller must still commit the wl_surface; the compositor answers with the first configure round.

func (*Window) Capabilities

func (w *Window) Capabilities() Capabilities

Capabilities reports the compositor's window-management offer.

func (*Window) Close

func (w *Window) Close()

Close closes the window, from the client side or on the compositor's close request: it destroys the toplevel role, which unmaps the surface, and marks the window closed for the next loop check. The wl_surface stays with its owner. Idempotent.

func (*Window) Closed

func (w *Window) Closed() bool

Closed reports whether the window was closed.

func (*Window) Decorate

func (w *Window) Decorate(mgr *xdeco.ZxdgDecorationManagerV1) error

Decorate requests server-side title bars and borders through the xdg-decoration manager. A nil manager (compositor without the global) is a silent no-op: the window simply stays undecorated.

func (*Window) DestroySurface

func (w *Window) DestroySurface()

DestroySurface destroys the role objects, if the window still holds them, and then the wl_surface. Idempotent.

func (*Window) EnsureUsable

func (w *Window) EnsureUsable() error

EnsureUsable gates drawing: the window must have completed the first configure round and must not be closed.

func (*Window) Export

func (w *Window) Export(exp *wlr.ZxdgExporterV2) error

Export publishes the toplevel through xdg-foreign so other clients, xdg-desktop-portal above all, can name it. The compositor answers with the handle asynchronously; ExportHandle reports it once it has arrived. A nil exporter (no xdg-foreign v2) is a no-op, and a second call keeps the first export.

func (*Window) ExportHandle

func (w *Window) ExportHandle() string

ExportHandle returns the toplevel's xdg-foreign handle, or "" before the compositor sent it or without an export.

func (*Window) ForeignParented added in v0.2.15

func (w *Window) ForeignParented() bool

ForeignParented reports whether the window holds a live import of a foreign parent.

func (*Window) Fullscreen

func (w *Window) Fullscreen(output *wl.Output) error

Fullscreen asks the compositor to show the window fullscreen; a nil output lets the compositor pick (the usual choice). The confirmed fullscreen state arrives with the output-sized configure. See Maximize.

func (*Window) HandleSurfaceConfigure

func (w *Window) HandleSurfaceConfigure(ev xdg.SurfaceConfigureEvent)

HandleSurfaceConfigure completes the configure round: it marks the window configured and acknowledges the serial. Without a wire surface (tests) only the state changes.

func (*Window) HandleToplevelClose

func (w *Window) HandleToplevelClose(ev xdg.ToplevelCloseEvent)

HandleToplevelClose marks the window closed unless a close-request veto rejects it.

func (*Window) HandleToplevelConfigure

func (w *Window) HandleToplevelConfigure(ev xdg.ToplevelConfigureEvent)

HandleToplevelConfigure records the new size. A zero axis leaves the size to the client, per the protocol: the window keeps its size, or returns to its unconstrained size when the configure ends a fullscreen, maximize, or tiling that dictated it. The state array is authoritative: it replaces the confirmed set wholesale, so a configure without a state the client asked for reports the request as refused (or withdrawn).

func (*Window) HandleToplevelWmCapabilities

func (w *Window) HandleToplevelWmCapabilities(ev xdg.ToplevelWmCapabilitiesEvent)

HandleToplevelWmCapabilities records the compositor's offer.

func (*Window) HostSurface

func (w *Window) HostSurface() *wl.Surface

HostSurface returns the underlying wl_surface.

func (*Window) Maximize

func (w *Window) Maximize() error

Maximize asks the compositor to maximize the window. Like every state request it is a hint: it becomes visible only through a configure carrying the maximized state, which the compositor is free to refuse - judge the outcome through State. A wireless window (tests) sends nothing.

func (*Window) Minimize

func (w *Window) Minimize() error

Minimize asks the compositor to minimize the window; a hint compositors without a minimized concept ignore.

func (*Window) ModalHinted

func (w *Window) ModalHinted() bool

ModalHinted reports whether the xdg-dialog modality hint is set on this window (SetModal succeeded with modal true). The compositor's own presentation of the hint is not observable.

func (*Window) Move

func (w *Window) Move(seat *wl.Seat, serial uint32) error

Move starts the compositor's xdg_toplevel.move grab: the pointer drags the window from the point of the press with the given serial. Like resize, the grab replaces the widget press.

func (*Window) Parent

func (w *Window) Parent() *Window

Parent is the toplevel last set as this one's parent, nil for none.

func (*Window) Resize

func (w *Window) Resize(seat *wl.Seat, serial uint32, edges uint32) error

Resize hands the pointer grab to the compositor for an interactive resize: it streams configure events as the user drags, and this window repaints at every configured size. seat and serial come from the button press that started the gesture; edges is a combination of the xdg_toplevel.resize_edge bits. A none (zero) edges value or a missing seat is a no-op: there is nothing to resize with.

func (*Window) ServerDecorated

func (w *Window) ServerDecorated() bool

ServerDecorated reports whether server-side decorations were requested: the compositor then owns the window's borders and resize handles, and the client keeps its own edge handles passive. The answer reflects the request; the compositor may still decide otherwise (mode events are not tracked).

func (*Window) SetCloseRequest

func (w *Window) SetCloseRequest(veto func() bool)

SetCloseRequest installs a veto callback: returning false keeps the window open when the compositor asks it to close (an unsaved-changes prompt decides itself when to call Window.Close). Nil accepts every close request.

func (*Window) SetForeignParent added in v0.2.15

func (w *Window) SetForeignParent(imp *wlr.ZxdgImporterV2, handle string, lost func()) error

SetForeignParent parents this toplevel to another client's, named by the xdg-foreign handle that client exported it as: the compositor keeps this one above it, on its workspace. It replaces the previous parent, foreign or not, and an empty handle leaves none. lost runs once if the import ends, the parent having gone away or the handle naming no toplevel; the window then has no parent.

func (*Window) SetMaxSize

func (w *Window) SetMaxSize(width, height uint32) error

SetMaxSize publishes the largest size the compositor may resize the window to; zero axes are unconstrained. See SetMinSize.

func (*Window) SetMinSize

func (w *Window) SetMinSize(width, height uint32) error

SetMinSize publishes the smallest size the compositor may resize the window to; zero axes are unconstrained. The limits are also tracked client-side (SizeLimits) so layout clamps to them when a compositor configures outside them anyway. A wireless window (tests) records the limits without sending anything.

func (*Window) SetMinimized

func (w *Window) SetMinimized() error

SetMinimized asks the compositor to minimize the window. The protocol defines no minimized state event, so State keeps reporting whatever was confirmed before; treat the window as invisible from here on. See Maximize.

func (*Window) SetModal

func (w *Window) SetModal(mgr *wlr.WmDialogV1, modal bool) error

SetModal hints, through the optional xdg-dialog-v1 protocol, that this parented toplevel is a modal dialog of its parent: the compositor then blocks input to the parent itself, where the toolkit's application-level block only covers this client's windows. The hint rides the surface's next commit, so it should be sent before the first one for the compositor to map the dialog modal from the start.

A nil manager (compositor without the global) or a wireless window (tests) is a silent no-op — modality degrades to the application-level block, which callers keep as the floor. The dialog object is created lazily on the first call and reused after; closing the window unsets and destroys it.

func (*Window) SetParent

func (w *Window) SetParent(parent *Window)

SetParent parents this toplevel to another - a dialog, a toolbox that stays above its owner; the compositor keeps it above the parent and may group them. A nil parent clears the association.

func (*Window) SetTitle

func (w *Window) SetTitle(title string) error

SetTitle updates the compositor-visible title at runtime; the xdg_toplevel title is a hint surfaces show in their own chrome (taskbars, alt-tab) - CSD apps paint HeaderBar themselves.

func (*Window) Size

func (w *Window) Size() (int, int)

Size returns the last configured size in surface (logical) pixels. An unconfigured window reports zeros.

func (*Window) SizeLimits

func (w *Window) SizeLimits() (minW, minH, maxW, maxH int)

SizeLimits returns the current min/max size in surface (logical) pixels; a zero axis is unconstrained.

func (*Window) State

func (w *Window) State() State

State returns the compositor-confirmed state: what the last configure's state array said, not what the client asked for.

func (*Window) Title

func (w *Window) Title() string

Title is the title last set (at creation or by SetTitle).

func (*Window) TooltipSurface

func (w *Window) TooltipSurface() *xdg.Surface

TooltipSurface returns the xdg_surface hover tooltips anchor to.

func (*Window) Unfullscreen

func (w *Window) Unfullscreen() error

Unfullscreen asks the compositor to leave fullscreen. See Maximize.

func (*Window) Unmaximize

func (w *Window) Unmaximize() error

Unmaximize asks the compositor to restore the window. See Maximize.

Jump to

Keyboard shortcuts

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