From b201a6a391e56bebf38f268bb0541a5b807cdb74 Mon Sep 17 00:00:00 2001 From: cancel Date: Wed, 15 Jan 2020 19:21:12 +0900 Subject: [PATCH] Add Mac pbcopy/pbpaste support for clipboard --- sysmisc.c | 16 +++++++++++++--- tool | 2 ++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sysmisc.c b/sysmisc.c index 3eed84a..42ec74d 100644 --- a/sysmisc.c +++ b/sysmisc.c @@ -1,6 +1,6 @@ -#include "sysmisc.h" #include "gbuffer.h" #include "oso.h" +#include "sysmisc.h" #include #include #include @@ -10,7 +10,12 @@ Cboard_error cboard_copy(Glyph const *gbuffer, Usz field_height, Usz field_width, Usz rect_y, Usz rect_x, Usz rect_h, Usz rect_w) { (void)field_height; - FILE *fp = popen("xclip -i -selection clipboard 2>/dev/null", "w"); + FILE *fp = +#ifdef ORCA_OS_MAC + popen("pbcopy -pboard general 2>/dev/null", "w"); +#else + popen("xclip -i -selection clipboard 2>/dev/null", "w"); +#endif if (!fp) return Cboard_error_popen_failed; for (Usz iy = 0; iy < rect_h; iy++) { @@ -26,7 +31,12 @@ Cboard_error cboard_copy(Glyph const *gbuffer, Usz field_height, ORCA_FORCE_NO_INLINE Cboard_error cboard_paste(Glyph *gbuffer, Usz height, Usz width, Usz y, Usz x, Usz *out_h, Usz *out_w) { - FILE *fp = popen("xclip -o -selection clipboard 2>/dev/null", "r"); + FILE *fp = +#ifdef ORCA_OS_MAC + popen("pbpaste -pboard general -Prefer txt 2>/dev/null", "r"); +#else + popen("xclip -o -selection clipboard 2>/dev/null", "r"); +#endif Usz start_y = y, start_x = x, max_y = y, max_x = x; if (!fp) return Cboard_error_popen_failed; diff --git a/tool b/tool index 1b65b7d..60706a0 100755 --- a/tool +++ b/tool @@ -358,6 +358,8 @@ build_target() { add libraries "-L$portmidi_dir/lib" add cc_flags "-I$portmidi_dir/include" fi + # needed for using pbpaste instead of xclip + add cc_flags -DORCA_OS_MAC ;; *) # librt and high-res posix timers on Linux