Clip Library Documentation

repository·master·Indexed 21 days ago

https://github.com/rezonality/zep

A lightweight C++ utility for cross-platform clipboard management on Windows, macOS, and Linux (X11). It supports copying and retrieving UTF-8 text, RGB/RGBA images, and custom user-defined data formats.

Tokens
591
Snippets
2
Records
4
Agent score
27%

What's inside Clip Library

  1. Overview of the Clip Library

    master

    The Clip Library is a C++ library designed to copy and retrieve content to and from the system clipboard or pasteboard. It provides cross-platform support for Windows, macOS, and Linux (X11).

    Supported Data Types:

    • UTF-8 Text: Standard text copy/paste.
    • User-defined Data: Custom formats for application-specific data exchange.
    • Images: RGB/RGBA image support (uses non-premultiplied alpha RGB values).
  2. Use user-defined clipboard formats

    master

    To exchange custom data between applications, you can register a unique format name and use the clip::lock mechanism to manage the clipboard data.

    1. Register a format using clip::register_format("your.unique.format") to obtain a clip::format object.
    2. Instantiate a clip::lock object to gain exclusive access to the clipboard.
    3. Use l.clear() to empty the current clipboard content.
    4. Use l.set_data(format, pointer, size) to write your custom data to the clipboard.

    You can also provide fallback data (like text) using clip::text_format() so that other applications can still interpret the clipboard content.

    #include "clip.h"
    
    int main() {
      clip::format my_format =
        clip::register_format("com.appname.FormatName");
    
      int value = 32;
    
      clip::lock l;
      l.clear();
      l.set_data(clip::text_format(), "Alternative text for value 32");
      l.set_data(my_format, &value, sizeof(int));
    }
  3. Copy and retrieve UTF-8 text

    master

    Use clip::set_text to copy a string to the clipboard and clip::get_text to retrieve the current clipboard content into a std::string.

    #include "clip.h"
    #include <iostream>
    
    int main() {
      clip::set_text("Hello World");
    
      std::string value;
      clip::get_text(value);
      std::cout << value << "\n";
    }