clipboard

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 11 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 clipboard is the session's clipboard history (crates/wayle-clipboard): what gets remembered, how it is labelled, what is refused, and the service that keeps it current from the Wayland selection over lys-ui's data-control device.

An entry is bytes plus the mime type they arrived under, not a string. A file manager puts text/uri-list on the clipboard, an image editor image/png, a terminal text/plain;charset=utf-8 — remembering only the last of those would make the history useless for exactly the things that are most annoying to copy twice.

Index

Constants

View Source
const DefaultCapacity = 200

DefaultCapacity is how many entries are kept before the oldest is dropped (history.rs DEFAULT_CAPACITY).

View Source
const MaxEntryBytes = 8 * 1024 * 1024

MaxEntryBytes is the largest selection worth remembering. The history lives in memory for the session, and a copied image or a large file list is unbounded. Past this the entry is refused rather than truncated: half a payload pasted back is worse than not offering it.

View Source
const URIListMime = "text/uri-list"

URIListMime is the mime type a file manager copies files under.

Variables

View Source
var ErrNoDataControl = errors.New("clipboard: compositor lacks ext-data-control-v1 and zwlr_data_control_manager_v1")

ErrNoDataControl is the Start failure on a compositor without either data-control protocol: the session simply has no clipboard history, and nothing else depends on it.

View Source
var SensitiveMimes = []string{
	"x-kde-passwordManagerHint",
	"org.kde.passwordManagerHint",
	"password",
	"x-lys-shell-no-history",
}

SensitiveMimes are the mime types lys-shell will not remember, however they are offered. Password managers mark a selection with one of these to ask clipboard managers not to keep it, and honouring that is the difference between a convenience and a credential leak. x-kde-passwordManagerHint carries the value "secret"; the others are presence-only conventions.

View Source
var TextMimes = []string{
	"text/plain;charset=utf-8",
	"text/plain",
	"UTF8_STRING",
	"STRING",
	"TEXT",
}

TextMimes are the mime types a plain-text selection arrives under, best first.

Functions

func BestMime

func BestMime(mimes []string) (string, bool)

BestMime picks the mime worth remembering out of everything the owner offered. Files beat images beat text: a file manager also offers the file's name as text/plain, and remembering that instead would put a bare filename on the clipboard where a file was copied. Within text, the order of TextMimes wins so the entry is UTF-8 wherever the owner can provide it. Anything else is still worth being able to paste back, byte for byte, so the first offered mime is the last resort; false only when nothing was offered.

func IsSensitive

func IsSensitive(mimes []string) bool

IsSensitive reports whether a selection offering these mimes must not be remembered.

func IsTextMime

func IsTextMime(mime string) bool

IsTextMime reports whether a mime type names plain text.

func SecretContent

func SecretContent(text string) transfer.Content

SecretContent is text offered as a password manager offers it: the text under every text mime, marked with x-kde-passwordManagerHint so a clipboard history (this one included) does not keep it.

Types

type Clipboard

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

Clipboard is the session's clipboard history, kept current: it watches the regular selection, remembers what lands on it, and puts an entry back when asked (service.rs). The primary selection is not remembered, as in the Rust service.

Entries, Get, Forget, and Clear are safe from any goroutine. Copy hops onto the loop goroutine itself, since claiming the selection is Wayland work.

func Start

func Start(a *app.Application, history *History) (*Clipboard, error)

Start begins watching the session's selection into history. Call it once at shell startup rather than when the launcher first opens, so the history covers the session instead of starting empty at the moment somebody goes looking for it. Fails with ErrNoDataControl when the compositor offers no data-control protocol.

func (*Clipboard) Clear

func (c *Clipboard) Clear()

Clear forgets everything.

func (*Clipboard) Copy

func (c *Clipboard) Copy(id uint64) bool

Copy puts a remembered entry back on the clipboard, under the mime it arrived with (and every text alias, for text), and reports whether the entry was still in the history. The entry keeps its place: a restore is not a new copy.

func (*Clipboard) Entries

func (c *Clipboard) Entries() []Entry

Entries returns a snapshot of the history, most recent first.

func (*Clipboard) Forget

func (c *Clipboard) Forget(id uint64) bool

Forget drops one entry, reporting whether it was there.

func (*Clipboard) Get

func (c *Clipboard) Get(id uint64) (Entry, bool)

Get returns the entry with this id, false once it aged out.

type Entry

type Entry struct {
	// ID is stable for the life of the entry, so a row the launcher
	// drew still names the same selection once something new arrives
	// at the front.
	ID uint64
	// Mime is the type the bytes are in, and the one they are offered
	// back under.
	Mime string
	// Bytes is the selection, exactly as it was copied.
	Bytes []byte
}

Entry is one remembered selection.

func (Entry) Kind

func (e Entry) Kind() Kind

Kind reports what the entry is, from its mime type.

func (Entry) Paths

func (e Entry) Paths() []string

Paths returns the decoded paths in a text/uri-list entry. Comment lines are part of the format (RFC 2483) and are not paths, and a URI that is not file:// has no path to give.

func (Entry) Preview

func (e Entry) Preview(maxChars int) string

Preview is a single line for a list row, at most maxChars characters.

func (Entry) Text

func (e Entry) Text() (string, bool)

Text returns the entry as text, when it is text (or a file list) and valid UTF-8.

type History

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

History is the most-recent-first clipboard history, bounded in both directions. It is plain bookkeeping and not safe for concurrent use; the Clipboard service guards it.

func DefaultHistory

func DefaultHistory() *History

DefaultHistory is the history the shell runs with: DefaultCapacity entries of up to MaxEntryBytes.

func NewHistory

func NewHistory(capacity, maxEntryBytes int) (*History, error)

NewHistory builds an empty history keeping at most capacity entries of at most maxEntryBytes each. A zero capacity remembers nothing; a negative bound is an error.

func (*History) Clear

func (h *History) Clear()

Clear forgets everything.

func (*History) Entries

func (h *History) Entries() []Entry

Entries returns every entry, most recent first. The slice is a copy; the byte slices are shared and must not be modified.

func (*History) Get

func (h *History) Get(id uint64) (Entry, bool)

Get returns the entry with this id, false once it aged out or was removed.

func (*History) Len

func (h *History) Len() int

Len reports how many entries are held.

func (*History) Push

func (h *History) Push(mime string, data []byte) (uint64, bool)

Push records a selection and returns the id it is stored under. Re-copying something already remembered moves it to the front and keeps its id rather than adding a second copy: the clipboard is a stack of what you have, and the same bytes twice is one thing. The same bytes under another mime are another entry — pasting a PNG back as text/plain would hand the receiver bytes it cannot use.

False when the selection is not worth remembering: empty, oversized, whitespace-only text, or a zero-capacity history.

func (*History) Remove

func (h *History) Remove(id uint64) bool

Remove forgets one entry, reporting whether it was there.

type Kind

type Kind uint8

Kind is what a remembered selection is, for labelling and for choosing an icon.

const (
	// KindText is plain text.
	KindText Kind = iota
	// KindFiles is one or more file:// URIs — what copying in a file
	// manager puts down.
	KindFiles
	// KindImage is an image, in whatever encoding the mime names.
	KindImage
	// KindOther is anything else, kept verbatim and offered back
	// under its own mime.
	KindOther
)

func (Kind) String

func (k Kind) String() string

String names the kind.

Jump to

Keyboard shortcuts

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