clip

dacapMIT活跃维护

跨平台 C++ 剪贴板库,统一封装 Windows、macOS 和 Linux 的剪贴板接口,让程序能方便地读写文本、图片等剪贴板内容。

Cross-platform C++ library to copy/paste clipboard content

暂无版本707star +1 / 7 天114fork同步于 2026-11-10 11:56 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/dacap/clip
cmake -S clip -B build -DCLIP_EXAMPLES=ON
cmake --build build
硬件要求按 README 说明

README 未说明;仅需 Windows、macOS 或 Linux(X11)环境,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

跨平台 C++ 剪贴板库,统一处理 Windows、macOS、Linux 的复制粘贴

跨平台 C++ 剪贴板库,统一封装 Windows、macOS 和 Linux 的剪贴板接口,让程序能方便地读写文本、图片等剪贴板内容。

核心能力

  • 复制粘贴 UTF-8 文本
  • 读写 RGB/RGBA 图像,使用非预乘 alpha
  • 注册自定义剪贴板格式存取任意数据
  • 用 clip::lock 批量清空并写入多格式
  • CMake 编译选项按需开启图像与示例

容易踩的坑

Linux 需先装 libx11-dev,复制图像还需 libpng-dev 并开启 CLIP_X11_WITH_PNG;图像支持默认关闭,需定义 CLIP_ENABLE_IMAGE;自定义格式别存 size_t 等随平台变化的类型,32/64 位程序可能同时运行

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Clip Library

    Copyright (c) 2015-2026 David Capello

    build MIT Licensed

    Library to copy/retrieve content to/from the clipboard/pasteboard.

    Features

    Available features on Windows, macOS, and Linux (X11):

    • Copy/paste UTF-8 text.
    • Copy/paste user-defined data.
    • Copy/paste RGB/RGBA images. This library use non-premultiplied alpha RGB values.

    Example

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

    User-defined clipboard formats

    #include "clip.h"
    
    int main() {
      clip::format my_format =
        clip::register_format("com.appname.FormatName");
    
      int value = 32;
      std::string str = "Alternative text for value 32";
    
      clip::lock l;
      l.clear();
      l.set_data(clip::text_format(), str.c_str(), str.size());
      l.set_data(my_format, (const char*)&value, sizeof(int));
    }
    

    Platform specific details

    • If two versions of your application (32-bit and 64-bit) can run at at the same time, remember to avoid storing data types that could change depending on the platform (e.g. size_t) in your custom format data.
    • Windows:
    • Linux:
      • To be able to copy/paste on Linux you need libx11-dev/libX11-devel package.
      • To copy/paste images you will need libpng-dev/libpng-devel package.

    Compilation Flags

    • CLIP_ENABLE_IMAGE: Enables the support to copy/paste images.
    • CLIP_ENABLE_LIST_FORMATS (only for Windows): Enables the clip::lock::list_formats() API function and the list_clip_formats example.
    • CLIP_EXAMPLES: Compile examples.
    • CLIP_TESTS: Compile tests.
    • CLIP_INSTALL: Generate installation rules for CMake.
    • CLIP_X11_WITH_PNG (only for Linux/X11): Enables support to copy/paste images using the libpng library on Linux.

    Who is using this library?

    Check the wiki to know what projects are using the clip library.

    License

    This library is distributed under the terms of the MIT License. Contributions using generative AI are not allowed.