TIL - X11 Clipboard System
Key Points
Unix/X11 maintains 3 separate clipboards:
- CLIPBOARD (Ctrl+C/V)
- PRIMARY (highlight + middle click)
- SECONDARY (rarely used)
Clipboard doesn't store data directly - just references to source apps. Data transfer happens only on paste.
Clipboard Formats
Apps advertise available formats using MIME types. Common formats:
- text/plain
- text/html
- application/octet-stream (raw bytes)
- UTF8_STRING
- image/png
- text/uri-list
Debugging Commands
# See available formats
xclip -selection clipboard -o -t TARGETS
# Get specific format
xclip -selection clipboard -o -t text/plain
xclip -selection clipboard -o -t text/html
xclip -selection clipboard -o -t application/octet-stream
# Format HTML/XML output
xclip -selection clipboard -o -t text/html | tidy -qi --wrap 0
xclip -selection clipboard -o | xmllint --format -