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 ¶
- Variables
- type Claim
- type Device
- func (d *Device) ClearSelection(sel Selection) error
- func (d *Device) Finished() bool
- func (d *Device) Offer(sel Selection) *Offer
- func (d *Device) OnSelection(fn func(sel Selection, offer *Offer)) (remove func())
- func (d *Device) PrimaryAvailable() bool
- func (d *Device) Protocol() Protocol
- func (d *Device) SetSelection(sel Selection, src Source) (*Claim, error)
- type Offer
- func (o *Offer) Has(mime string) bool
- func (o *Offer) Live() bool
- func (o *Offer) Mimes() []string
- func (o *Offer) Own() bool
- func (o *Offer) Read(mime string, limit int64, done func([]byte, error)) error
- func (o *Offer) ReadTo(mime string, limit int64, w io.Writer, done func(int64, error)) error
- func (o *Offer) Receive(mime string) (*os.File, error)
- func (o *Offer) Selection() Selection
- type Protocol
- type Selection
- type Source
Constants ¶
This section is empty.
Variables ¶
var ( // data-control protocol, or the seat is missing. ErrUnavailable = errors.New("datacontrol: compositor offers no data-control protocol") // 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) 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.
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 ¶
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 ¶
ClearSelection empties sel, cancelling our claim on it if we hold one.
func (*Device) 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 ¶
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 ¶
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) SetSelection ¶
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) Own ¶
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 ¶
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 ¶
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.
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.