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 /st-0.8.5/x.c | |
| parent | 2016aeaa085bc37b4c5d01d6bcf12cdfd2235ca1 (diff) | |
Added graphics patch
Diffstat (limited to 'st-0.8.5/x.c')
| -rw-r--r-- | st-0.8.5/x.c | 38 |
1 files changed, 35 insertions, 3 deletions
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; } |