datacontrol

package
v0.2.22 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 10 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 datacontrol is the clipboard-manager side of the seat's selections, over ext_data_control_v1 or, on compositors that predate it, zwlr_data_control_unstable_v1. A data-control device needs no surface and no keyboard focus: it sees every selection change on the seat, can read any offer under any advertised mime type, and can claim either selection with its own data source.

Everything here runs on the loop goroutine, like every Wayland event handler. The two slow parts are moved off it: reading an offer drains its pipe on a goroutine and delivers the bytes back through the application's Invoke, and serving a claim writes each payload on a goroutine. Both ends of every transfer are foreign clients, so both are bounded through internal/xfer: a read in size and time, a write in time.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable reports that the compositor advertises neither
	// data-control protocol, or the seat is missing.
	ErrUnavailable = errors.New("datacontrol: compositor offers no data-control protocol")
	// ErrPrimaryUnavailable reports a primary-selection request on a
	// wlr-data-control manager older than version 2.
	ErrPrimaryUnavailable = errors.New("datacontrol: the bound protocol has no primary selection")
	// ErrFinished reports that the compositor retired the device (its
	// seat went away); nothing more can be read or claimed through it.
	ErrFinished = errors.New("datacontrol: device finished")
	// ErrStaleOffer reports a read on an offer that is no longer the
	// selection: the compositor has already replaced it.
	ErrStaleOffer = errors.New("datacontrol: offer is no longer the selection")
	// ErrMimeNotOffered reports a read under a mime type the offer did
	// not advertise.
	ErrMimeNotOffered = errors.New("datacontrol: mime type not offered")
)

Functions

This section is empty.

Types

type Claim

type Claim struct {
	// contains filtered or unexported fields
}

Claim is our ownership of one selection, live until another client claims it, we replace or release it, or the device finishes.

func (*Claim) Live

func (c *Claim) Live() bool

Live reports whether the claim still holds its selection. Nil-safe.

func (*Claim) OnCancelled

func (c *Claim) OnCancelled(fn func())

OnCancelled registers fn to run once the claim ends for any reason other than Release; it runs at once when the claim already ended.

func (*Claim) Release

func (c *Claim) Release()

Release gives the selection up: the source is destroyed, which empties the selection unless another client claimed it since. The OnCancelled callbacks do not run. Idempotent.

func (*Claim) Selection

func (c *Claim) Selection() Selection

Selection reports which selection the claim holds.

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device is the seat's data-control device. Create it with Bind; it is not safe for concurrent use — call it from the loop goroutine.

func Bind

func Bind(sess *wlsession.Session, invoke func(func())) (*Device, error)

Bind creates the seat's data-control device, preferring ext-data-control-v1 over wlr-data-control-unstable-v1. invoke must run a function on the loop goroutine (the application's Invoke): finished reads deliver through it. Fails with ErrUnavailable when the compositor offers neither protocol or has no seat.

func (*Device) ClearSelection

func (d *Device) ClearSelection(sel Selection) error

ClearSelection empties sel, cancelling our claim on it if we hold one.

func (*Device) Finished

func (d *Device) Finished() bool

Finished reports whether the compositor retired the device.

func (*Device) Offer

func (d *Device) Offer(sel Selection) *Offer

Offer returns sel's current offer, nil when the selection is empty (or sel is the primary selection and the device has none).

func (*Device) OnSelection

func (d *Device) OnSelection(fn func(sel Selection, offer *Offer)) (remove func())

OnSelection registers fn for every selection change: sel is the selection that changed and offer its new content, nil when the selection was cleared. The compositor announces both selections as soon as the device exists, so the first calls report what the seat already holds. The returned function unregisters fn.

func (*Device) PrimaryAvailable

func (d *Device) PrimaryAvailable() bool

PrimaryAvailable reports whether the device can watch and claim the primary selection: always with ext-data-control, from version 2 of wlr-data-control.

func (*Device) Protocol

func (d *Device) Protocol() Protocol

Protocol reports which data-control protocol the device speaks.

func (*Device) SetSelection

func (d *Device) SetSelection(sel Selection, src Source) (*Claim, error)

SetSelection claims sel with src. The previous claim on sel, if any, is cancelled first-hand: its OnCancelled callbacks fire and it stops serving. The compositor then announces the new selection like any other — the offer that arrives is marked Own.

type Offer

type Offer struct {
	// contains filtered or unexported fields
}

Offer is one selection's content as its owner advertised it. It stays readable until the compositor replaces the selection.

func (*Offer) Has

func (o *Offer) Has(mime string) bool

Has reports whether the owner advertised mime.

func (*Offer) Live

func (o *Offer) Live() bool

Live reports whether the offer is still the selection.

func (*Offer) Mimes

func (o *Offer) Mimes() []string

Mimes returns the advertised mime types, in the order the owner offered them.

func (*Offer) Own

func (o *Offer) Own() bool

Own reports whether the offer is our own claim announced back to us. Reading it would put this process on both ends of the pipe, and a clipboard history would record its own restore as a new copy.

func (*Offer) Read

func (o *Offer) Read(mime string, limit int64, done func([]byte, error)) error

Read fetches the content under mime and calls done on the loop goroutine with it. The pipe drains on a goroutine, bounded by limit bytes and the transfer deadline: an oversized payload is refused whole with an error wrapping xfer.ErrTooLarge, a stalled owner with one wrapping xfer.ErrTimeout, and done then gets no bytes. The error return covers only what fails before the transfer starts.

func (*Offer) ReadTo

func (o *Offer) ReadTo(mime string, limit int64, w io.Writer, done func(int64, error)) error

ReadTo is Read streaming into w, memory the caller owns (reused, or off the Go heap), rather than a fresh slice: w is written on the transfer goroutine until done runs on the loop goroutine with the bytes written. A payload past limit leaves the first limit bytes in w and an error wrapping xfer.ErrTooLarge; a stalled owner one wrapping xfer.ErrTimeout; a write w refuses ends the transfer with its error. The error return covers only what fails before the transfer starts.

func (*Offer) Receive

func (o *Offer) Receive(mime string) (*os.File, error)

Receive asks the owner for the content under mime and returns the read end of the pipe it streams into; the caller closes it. The owner writes at its own pace, so drain the pipe off the loop goroutine — or use Read, which does. Only advertised mimes are accepted.

func (*Offer) Selection

func (o *Offer) Selection() Selection

Selection reports which selection the offer is.

type Protocol

type Protocol uint8

Protocol names the data-control protocol a device speaks.

const (
	// ProtocolExt is the staging ext-data-control-v1.
	ProtocolExt Protocol = iota + 1
	// ProtocolWlr is wlr-data-control-unstable-v1.
	ProtocolWlr
)

func (Protocol) String

func (p Protocol) String() string

String names the protocol as its XML does.

type Selection

type Selection uint8

Selection names one of the seat's two selections.

const (
	// Clipboard is the regular selection: ctrl+c, ctrl+v.
	Clipboard Selection = iota
	// Primary is the X11-style primary selection a middle click
	// pastes.
	Primary
)

func (Selection) String

func (s Selection) String() string

String names the selection.

type Source

type Source struct {
	Mimes []string
	// Data returns the payload for mime. It runs on the loop goroutine
	// once per request, and the bytes are written off the loop under
	// the transfer deadline; nil serves an empty payload.
	Data func(mime string) []byte
	// Send hands the receiver's pipe over instead, for payloads that
	// are produced later or elsewhere (a remote-desktop bridge that
	// asks its peer first). It runs on the loop goroutine; w carries
	// the transfer deadline, may be written from any goroutine, and
	// must be closed — closing is what ends the receiver's read.
	Send func(mime string, w io.WriteCloser)
	// Pass hands the receiver's pipe over untouched (blocking, no
	// deadline), for a bridge that passes the descriptor itself to
	// another process (a portal handing it to the app that owns the
	// selection). It runs on the loop goroutine and owns pipe: it must
	// close it, after passing it on or not.
	Pass func(mime string, pipe *os.File)
}

Source is what a claim offers: the mime types, in the order receivers should prefer them, and how each request is answered — exactly one of Data, Send and Pass.

Jump to

Keyboard shortcuts

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