feat: Write ocr result into clipboard

This commit is contained in:
wangjue 2026-06-02 14:57:37 +08:00 committed by wangjue
parent 5d4965f014
commit e73044d6f7

View File

@ -120,6 +120,20 @@ static std::vector<unsigned char> read_clipboard() {
return data;
}
static void write_clipboard(const std::string &text) {
const char *cmd;
if (getenv("WAYLAND_DISPLAY")) {
cmd = "wl-copy 2>/dev/null";
} else {
cmd = "xclip -selection clipboard 2>/dev/null";
}
FILE *pipe = popen(cmd, "we");
if (!pipe)
return;
fwrite(text.data(), 1, text.size(), pipe);
pclose(pipe);
}
static std::string capture_screenshot(bool quiet) {
const char *tmpdir = getenv("TMPDIR");
if (!tmpdir)
@ -507,6 +521,8 @@ int main(int argc, char **argv) {
printf("\n");
}
write_clipboard(ocr_text);
llama_batch_free(batch);
llama_sampler_free(smpl);
mtmd_free(ctx_vision);