shithub: orca

Download patch

ref: b201a6a391e56bebf38f268bb0541a5b807cdb74
parent: 116a08245af2ba33ddb84ece7f4e4f0b46262266
author: cancel <cancel@cancel.fm>
date: Wed Jan 15 14:21:12 EST 2020

Add Mac pbcopy/pbpaste support for clipboard

--- a/sysmisc.c
+++ b/sysmisc.c
@@ -1,6 +1,6 @@
-#include "sysmisc.h"
 #include "gbuffer.h"
 #include "oso.h"
+#include "sysmisc.h"
 #include <ctype.h>
 #include <errno.h>
 #include <sys/stat.h>
@@ -10,7 +10,12 @@
                          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 @@
 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;
--- a/tool
+++ b/tool
@@ -358,6 +358,8 @@
             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