summaryrefslogtreecommitdiff
path: root/suckless/tabbed/tabbed-0.9/xembed.c
diff options
context:
space:
mode:
authorThomas Ulmer <thomasmulmer02@gmail.com>2026-07-29 11:15:52 -0400
committerThomas Ulmer <thomasmulmer02@gmail.com>2026-07-29 11:15:52 -0400
commit40e8a57a858750320f458e6bcdc097a6a1a8e52f (patch)
treeadd7bcc227472dd0635a86cfc7e35be52b4bb5bf /suckless/tabbed/tabbed-0.9/xembed.c
parentcf696c9308ddf235e5bc1372bfbda79d43206319 (diff)
suckless: add tabbed
Diffstat (limited to 'suckless/tabbed/tabbed-0.9/xembed.c')
-rw-r--r--suckless/tabbed/tabbed-0.9/xembed.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/suckless/tabbed/tabbed-0.9/xembed.c b/suckless/tabbed/tabbed-0.9/xembed.c
new file mode 100644
index 0000000..cbb0e97
--- /dev/null
+++ b/suckless/tabbed/tabbed-0.9/xembed.c
@@ -0,0 +1,45 @@
+/*
+ * See LICENSE file for copyright and license details.
+ */
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+ char *xembed;
+ int tty;
+ pid_t pgrp, tcpgrp;
+
+ if (argc < 3) {
+ fprintf(stderr, "usage: %s flag cmd ...\n", argv[0]);
+ return 2;
+ }
+
+ if (!(xembed = getenv("XEMBED")))
+ goto noembed;
+
+ if ((tty = open("/dev/tty", O_RDONLY)) < 0)
+ goto noembed;
+
+ pgrp = getpgrp();
+ tcpgrp = tcgetpgrp(tty);
+
+ close(tty);
+
+ if (pgrp == tcpgrp) { /* in foreground of tty */
+ argv[0] = argv[2];
+ argv[2] = xembed;
+ } else {
+noembed:
+ argv += 2;
+ }
+
+ execvp(argv[0], argv);
+
+ perror(argv[0]); /* failed to execute */
+ return 1;
+}