diff options
| author | stkhan <personal@slickd.xyz> | 2022-05-26 20:55:41 +0000 |
|---|---|---|
| committer | stkhan <personal@slickd.xyz> | 2022-05-26 20:55:41 +0000 |
| commit | c9a6277b4c5a08d587396c7bf597286d7b6efdaa (patch) | |
| tree | f1f5fdfd9656f8f5e93bd7715e73fe51e0a05d93 | |
| parent | 2016aeaa085bc37b4c5d01d6bcf12cdfd2235ca1 (diff) | |
Added graphics patch
| -rw-r--r-- | Makefile | 13 | ||||
| -rw-r--r-- | st-0.8.5/patches/st-graphics.diff | 166 | ||||
| -rw-r--r-- | st-0.8.5/st.c | 10 | ||||
| -rw-r--r-- | st-0.8.5/st.h | 6 | ||||
| -rw-r--r-- | st-0.8.5/x.c | 38 |
5 files changed, 225 insertions, 8 deletions
@@ -65,4 +65,15 @@ part: ./scripts/cp.sh cleanp: clean rm -rf .config - +uninstall: + make uninstall -C $(DWM) + make uninstall -C $(ST) + make uninstall -C $(DMENU) + make uninstall -C surf + make uninstall -C nsxiv + make uninstall -C tabbed + make uninstall -C dwmblocks + make uninstall -C farbfeld + make uninstall -C sent + make uninstall -C wmname + make uninstall -C scroll-0.1 diff --git a/st-0.8.5/patches/st-graphics.diff b/st-0.8.5/patches/st-graphics.diff new file mode 100644 index 0000000..1bc4d48 --- /dev/null +++ b/st-0.8.5/patches/st-graphics.diff @@ -0,0 +1,166 @@ +# A patch taken from boards.4channel.org/g/thread/87102876 +# adds graphics to st +diff --git a/st.c b/st.c +index 6ba467d..efad5ec 100644 +--- a/st.c ++++ b/st.c +@@ -752,10 +752,11 @@ stty(char **args) + perror("Couldn't call stty"); + } + +-int ++TTYConn + ttynew(const char *line, char *cmd, const char *out, char **args) + { + int m, s; ++ int mypipe[2]; + + if (out) { + term.mode |= MODE_PRINT; +@@ -766,6 +767,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) + out, strerror(errno)); + } + } ++ pipe(mypipe); + + if (line) { + if ((cmdfd = open(line, O_RDWR)) < 0) +@@ -773,7 +775,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) + line, strerror(errno)); + dup2(cmdfd, 0); + stty(args); +- return cmdfd; ++ return (TTYConn){ cmdfd, cmdfd }; + } + + /* seems to work fine on linux, openbsd and freebsd */ +@@ -791,6 +793,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) + dup2(s, 0); + dup2(s, 1); + dup2(s, 2); ++ dup2(mypipe[1], 3); + if (ioctl(s, TIOCSCTTY, NULL) < 0) + die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); + if (s > 2) +@@ -807,11 +810,12 @@ ttynew(const char *line, char *cmd, const char *out, char **args) + die("pledge\n"); + #endif + close(s); ++ close(mypipe[1]); + cmdfd = m; + signal(SIGCHLD, sigchld); + break; + } +- return cmdfd; ++ return (TTYConn){ .cmdfd = cmdfd, .pipefd = mypipe[0] }; + } + + size_t +diff --git a/st.h b/st.h +index fd3b0d8..e5613ba 100644 +--- a/st.h ++++ b/st.h +@@ -59,6 +59,10 @@ typedef unsigned short ushort; + + typedef uint_least32_t Rune; + ++typedef struct TTYConn { ++ int cmdfd, pipefd; ++} TTYConn; ++ + #define Glyph Glyph_ + typedef struct { + Rune u; /* character code */ +@@ -91,7 +95,7 @@ void tnew(int, int); + void tresize(int, int); + void tsetdirtattr(int); + void ttyhangup(void); +-int ttynew(const char *, char *, const char *, char **); ++TTYConn ttynew(const char *, char *, const char *, char **); + size_t ttyread(void); + void ttyresize(int, int); + void ttywrite(const char *, size_t, int); +diff --git a/x.c b/x.c +index 2a3bd38..16caf2b 100644 +--- a/x.c ++++ b/x.c +@@ -5,6 +5,7 @@ + #include <locale.h> + #include <signal.h> + #include <sys/select.h> ++#include <fcntl.h> + #include <time.h> + #include <unistd.h> + #include <libgen.h> +@@ -1914,9 +1915,11 @@ run(void) + XEvent ev; + int w = win.w, h = win.h; + fd_set rfd; +- int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; ++ int xfd = XConnectionNumber(xw.dpy), ttyfd, pipefd, xev, drawing; + struct timespec seltv, *tv, now, lastblink, trigger; + double timeout; ++ TTYConn conn; ++ unsigned long color; + + /* Waiting for window mapping */ + do { +@@ -1934,12 +1937,17 @@ run(void) + } + } while (ev.type != MapNotify); + +- ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd); ++ conn = ttynew(opt_line, shell, opt_io, opt_cmd); ++ ttyfd = conn.cmdfd; ++ pipefd = conn.pipefd; + cresize(w, h); + ++ fcntl(pipefd, F_SETFL, O_NONBLOCK); ++ FILE *command = fdopen(pipefd, "r"); + for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) { + FD_ZERO(&rfd); + FD_SET(ttyfd, &rfd); ++ FD_SET(pipefd, &rfd); + FD_SET(xfd, &rfd); + + if (XPending(xw.dpy)) +@@ -1949,7 +1957,7 @@ run(void) + seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec); + tv = timeout >= 0 ? &seltv : NULL; + +- if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { ++ if (pselect(MAX(MAX(xfd, ttyfd), pipefd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { + if (errno == EINTR) + continue; + die("select failed: %s\n", strerror(errno)); +@@ -2006,6 +2014,30 @@ run(void) + } + + draw(); ++ if(FD_ISSET(pipefd, &rfd)) { ++ char header[128]; ++ int x, y; ++ int w, h; ++ int r, g, b; ++ ++ xstartdraw(); ++ while(fscanf(command, "%s", header) != EOF) { ++ printf("Command: %s\n", header); ++ if(strcmp(header, "set-color") == 0) { ++ fscanf(command, "%d %d %d", &r, &g, &b); ++ ++ color = b + (g << 8) + (r << 16); ++ } ++ ++ if(strcmp(header, "fill-rectangle") == 0) { ++ fscanf(command, "%d %d %d %d", &x, &y, &w, &h); ++ XSetForeground(xw.dpy, dc.gc, color); ++ XFillRectangle(xw.dpy, xw.buf, dc.gc, x, y, w, h); ++ } ++ } ++ xfinishdraw(); ++ } ++ + XFlush(xw.dpy); + drawing = 0; + } diff --git a/st-0.8.5/st.c b/st-0.8.5/st.c index f9e24ba..3c2646a 100644 --- a/st-0.8.5/st.c +++ b/st-0.8.5/st.c @@ -775,10 +775,11 @@ stty(char **args) perror("Couldn't call stty"); } -int +TTYConn ttynew(const char *line, char *cmd, const char *out, char **args) { int m, s; + int mypipe[2]; if (out) { term.mode |= MODE_PRINT; @@ -789,6 +790,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) out, strerror(errno)); } } + pipe(mypipe); if (line) { if ((cmdfd = open(line, O_RDWR)) < 0) @@ -796,7 +798,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) line, strerror(errno)); dup2(cmdfd, 0); stty(args); - return cmdfd; + return (TTYConn){ cmdfd, cmdfd }; } /* seems to work fine on linux, openbsd and freebsd */ @@ -814,6 +816,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) dup2(s, 0); dup2(s, 1); dup2(s, 2); + dup2(mypipe[1], 3); if (ioctl(s, TIOCSCTTY, NULL) < 0) die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); if (s > 2) @@ -830,11 +833,12 @@ ttynew(const char *line, char *cmd, const char *out, char **args) die("pledge\n"); #endif close(s); + close(mypipe[1]); cmdfd = m; signal(SIGCHLD, sigchld); break; } - return cmdfd; + return (TTYConn){ .cmdfd = cmdfd, .pipefd = mypipe[0] }; } size_t diff --git a/st-0.8.5/st.h b/st-0.8.5/st.h index f82bbdd..f425fb6 100644 --- a/st-0.8.5/st.h +++ b/st-0.8.5/st.h @@ -60,6 +60,10 @@ typedef unsigned short ushort; typedef uint_least32_t Rune; +typedef struct TTYConn { + int cmdfd, pipefd; +} TTYConn; + #define Glyph Glyph_ typedef struct { Rune u; /* character code */ @@ -92,7 +96,7 @@ void tnew(int, int); void tresize(int, int); void tsetdirtattr(int); void ttyhangup(void); -int ttynew(const char *, char *, const char *, char **); +TTYConn ttynew(const char *, char *, const char *, char **); size_t ttyread(void); void ttyresize(int, int); void ttywrite(const char *, size_t, int); diff --git a/st-0.8.5/x.c b/st-0.8.5/x.c index 05f441b..601fc0d 100644 --- a/st-0.8.5/x.c +++ b/st-0.8.5/x.c @@ -5,6 +5,7 @@ #include <locale.h> #include <signal.h> #include <sys/select.h> +#include <fcntl.h> #include <time.h> #include <unistd.h> #include <libgen.h> @@ -1936,9 +1937,11 @@ run(void) XEvent ev; int w = win.w, h = win.h; fd_set rfd; - int xfd = XConnectionNumber(xw.dpy), ttyfd, xev, drawing; + int xfd = XConnectionNumber(xw.dpy), ttyfd, pipefd, xev, drawing; struct timespec seltv, *tv, now, lastblink, trigger; double timeout; + TTYConn conn; + unsigned long color; /* Waiting for window mapping */ do { @@ -1956,12 +1959,17 @@ run(void) } } while (ev.type != MapNotify); - ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd); + conn = ttynew(opt_line, shell, opt_io, opt_cmd); + ttyfd = conn.cmdfd; + pipefd = conn.pipefd; cresize(w, h); + fcntl(pipefd, F_SETFL, O_NONBLOCK); + FILE *command = fdopen(pipefd, "r"); for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) { FD_ZERO(&rfd); FD_SET(ttyfd, &rfd); + FD_SET(pipefd, &rfd); FD_SET(xfd, &rfd); if (XPending(xw.dpy)) @@ -1971,7 +1979,7 @@ run(void) seltv.tv_nsec = 1E6 * (timeout - 1E3 * seltv.tv_sec); tv = timeout >= 0 ? &seltv : NULL; - if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { + if (pselect(MAX(MAX(xfd, ttyfd), pipefd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { if (errno == EINTR) continue; die("select failed: %s\n", strerror(errno)); @@ -2032,6 +2040,30 @@ run(void) } draw(); + if(FD_ISSET(pipefd, &rfd)) { + char header[128]; + int x, y; + int w, h; + int r, g, b; + + xstartdraw(); + while(fscanf(command, "%s", header) != EOF) { + printf("Command: %s\n", header); + if(strcmp(header, "set-color") == 0) { + fscanf(command, "%d %d %d", &r, &g, &b); + + color = b + (g << 8) + (r << 16); + } + + if(strcmp(header, "fill-rectangle") == 0) { + fscanf(command, "%d %d %d %d", &x, &y, &w, &h); + XSetForeground(xw.dpy, dc.gc, color); + XFillRectangle(xw.dpy, xw.buf, dc.gc, x, y, w, h); + } + } + xfinishdraw(); + } + XFlush(xw.dpy); drawing = 0; } |