Documentation
¶
Overview ¶
Package transfer is the content shape every data transfer shares: clipboard claims, the primary selection, and drag and drop all offer a payload as mime types, best first, with a writer for each, and all read one back by mime preference. The builders cover the formats the desktop speaks - text, images (PNG and JPEG), uri lists (file copies), HTML (formatted text) - and encode up front, so a peer's transfer deadline never runs during encoding.
Index ¶
- Constants
- Variables
- func DecodeHTML(data []byte) string
- func FilePaths(uris []string) []string
- func FileURI(path string) string
- func ParseURIList(data []byte) []string
- func Pick(prefs []string, present func(string) bool) string
- func URIPath(uri string) (string, bool)
- type Action
- type Content
- func Bytes(mime string, data []byte) Content
- func Files(paths ...string) Content
- func HTML(html, plain string) Content
- func Image(img image.Image) (Content, error)
- func Merge(parts ...Content) Content
- func Payloads(mimes []string, data map[string][]byte) Content
- func Text(s string) Content
- func URIs(uris ...string) Content
- type Drag
- type Feedback
Constants ¶
const ( MimeText = "text/plain;charset=utf-8" MimeURIList = "text/uri-list" MimeHTML = "text/html" MimePNG = "image/png" MimeJPEG = "image/jpeg" MimeWebP = "image/webp" MimeGIF = "image/gif" )
Well-known mime types.
Variables ¶
ImageMimes are the image types accepted, best first: PNG round-trips exactly, the rest decode lossy or flattened.
var TextMimes = []string{ MimeText, "UTF8_STRING", "text/plain", "COMPOUND_TEXT", "TEXT", "STRING", }
TextMimes are the text types offered and accepted, best first: the X11 atoms after the mime types, for clients bridged through Xwayland.
Functions ¶
func DecodeHTML ¶
DecodeHTML returns an HTML payload as a string: UTF-8 as sent, or UTF-16 when it opens with a byte-order mark (some browsers write their HTML that way).
func FileURI ¶
FileURI encodes an absolute local path as a file:// uri, percent escapes included; anything else returns unchanged, for the consumer to reject.
func ParseURIList ¶
ParseURIList reads a uri list: one uri per line, comment lines (starting with #) and blank lines skipped, CR tolerated.
Types ¶
type Action ¶
type Action uint8
Action is a drag-and-drop action, a set when offered: what becomes of the payload at the source once dropped.
const ( ActionNone Action = 0 // ActionCopy leaves the source's data as it was. ActionCopy Action = 1 // ActionMove means the source deletes its data once the drop // finished. ActionMove Action = 2 // ActionAsk lets the destination ask the user (a drop menu). ActionAsk Action = 4 )
Actions, the wl_data_device_manager dnd_action bits.
type Content ¶
Content is one transfer's payload: the mimes it is offered as, best first, and Write, which writes the bytes for one of them.
func Files ¶
Files is local paths as a uri list of file URIs - what a file manager copies and takes; relative paths resolve against the working directory.
func Image ¶
Image is img offered as PNG (exact) and JPEG (flattened onto white: JPEG has no alpha), both encoded now.
func Merge ¶
Merge offers every part's mimes in order; a mime two parts share is served by the first. Formatted text merges HTML before plain text, files their uri list before the paths as text.
func Payloads ¶
Payloads is content from finished bytes per mime, offered in the order given; the writers copy, so the content may be served any number of times.
func URIs ¶
URIs is a uri list (RFC 2483: CRLF-terminated lines), with the uris one per line as plain text for targets that only take text.
type Drag ¶
type Drag struct {
Content
// Actions are the actions offered; zero offers copy.
Actions Action
// OnFeedback, optional, hears every change of acceptance and
// negotiated action.
OnFeedback func(Feedback)
// OnDone, optional, fires once the drag concluded: the action the
// destination finished with (ActionMove: delete the source data),
// or ActionNone for a cancelled or rejected drag.
OnDone func(done Action)
}
Drag is a drag's payload and its source-side hooks.