summaryrefslogtreecommitdiffstats
path: root/x.c
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2022-12-31 17:21:08 -0500
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2022-12-31 17:21:08 -0500
commitb1df89ed947503c74a61f36a1b3a92f5f424352e (patch)
treed3a529698171143929554aca7f150da242f52130 /x.c
parent655ba6883b219befcc8aefdd6f50a4f678a7af98 (diff)
downloadst-b1df89ed947503c74a61f36a1b3a92f5f424352e.tar.gz
Applied plumber patch
Diffstat (limited to 'x.c')
-rw-r--r--x.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/x.c b/x.c
index 754f48c..fa2939f 100644
--- a/x.c
+++ b/x.c
@@ -5,6 +5,7 @@
#include <locale.h>
#include <signal.h>
#include <sys/select.h>
+#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <libgen.h>
@@ -232,6 +233,7 @@ static void (*handler[LASTEvent])(XEvent *) = {
};
/* Globals */
+static int plumbsel;
static DC dc;
static XWindow xw;
static XSelection xsel;
@@ -711,6 +713,37 @@ xsetsel(char *str)
}
void
+plumbinit()
+{
+ for(plumbsel = 0; plumb_cmd[plumbsel]; plumbsel++);
+}
+
+void
+plumb(char *sel) {
+ if (sel == NULL)
+ return;
+ char cwd[PATH_MAX];
+ pid_t child;
+ if (subprocwd(cwd) != 0)
+ return;
+
+ plumb_cmd[plumbsel] = sel;
+
+ switch(child = fork()) {
+ case -1:
+ return;
+ case 0:
+ if (chdir(cwd) != 0)
+ exit(1);
+ if (execvp(plumb_cmd[0], plumb_cmd) == -1)
+ exit(1);
+ exit(0);
+ default:
+ waitpid(child, NULL, 0);
+ }
+}
+
+void
brelease(XEvent *e)
{
int btn = e->xbutton.button;
@@ -727,6 +760,8 @@ brelease(XEvent *e)
return;
if (btn == Button1)
mousesel(e, 1);
+ else if (e->xbutton.button == Button3)
+ plumb(xsel.primary);
}
void
@@ -2196,6 +2231,7 @@ main(int argc, char *argv[])
} ARGEND;
run:
+ plumbinit();
if (argc > 0) /* eat all remaining arguments */
opt_cmd = argv;