Skip to content

Class SeatClipboard ​

A seat's clipboard, read from seat.clipboard. This is the normal copy and paste clipboard. The middle-click selection isn't available to Lua.

lua
seat.clipboard:set({
	["text/plain;charset=utf-8"] = "copied by the config",
	["text/plain"] = "copied by the config",
})

Methods ​

seat.clipboard:current() -> ClipboardOffer?current ​

What is on the clipboard now. Read the data with offer:read.

  • nil when the clipboard is empty.

seat.clipboard:set(contents: table) -> nilset ​

Puts data on this seat's clipboard. contents maps mime types to Lua strings: { [mime_type] = data }.

  • The data stays after the app that copied earlier has closed.
  • An empty table clears the clipboard.
  • Put text under both text/plain;charset=utf-8 and text/plain. Apps differ in which one they ask for.
  • changed fires afterwards, not during the call, with an offer whose origin is "lua".

Errors for an empty mime type.

Events ​

Listen with seat.clipboard:on(name, fn), which returns a function that stops listening.

Errors for any event name other than "changed".

"changed" (offer: ClipboardOffer?)changed ​

Something new is on this seat's clipboard.

  • offer is nil when the clipboard was cleared.
  • Its origin is "wayland" when an app copied, "lua" after set.
  • Calling set from the handler is fine.
lua
seat.clipboard:on("changed", function(offer)
	if offer == nil then return end
	print(offer.origin, #offer:mime_types())
end)