Reduce visibility wherever possible
[st.git] / x.c
diff --git a/x.c b/x.c
index 873ff08..f7b0528 100644 (file)
--- a/x.c
+++ b/x.c
@@ -75,6 +75,15 @@ typedef XftColor Color;
 typedef XftGlyphFontSpec GlyphFontSpec;
 
 /* Purely graphic info */
+typedef struct {
+       int tw, th; /* tty width and height */
+       int w, h; /* window width and height */
+       int ch; /* char height */
+       int cw; /* char width  */
+       int mode; /* window state/mode flags */
+       int cursor; /* cursor style */
+} TermWindow;
+
 typedef struct {
        Display *dpy;
        Colormap cmap;
@@ -133,6 +142,8 @@ static int xgeommasktogravity(int);
 static void xinit(int, int);
 static void cresize(int, int);
 static void xresize(int, int);
+static void xhints(void);
+static int xloadcolor(int, const char *, Color *);
 static int xloadfont(Font *, FcPattern *);
 static void xloadfonts(char *, double);
 static void xunloadfont(Font *);
@@ -227,6 +238,8 @@ static char *opt_line  = NULL;
 static char *opt_name  = NULL;
 static char *opt_title = NULL;
 
+static int oldbutton = 3; /* button event on startup: 3 = release */
+
 void
 clipcopy(const Arg *dummy)
 {
@@ -1428,8 +1441,8 @@ xdrawcursor(int cx, int cy, Glyph g, int ox, int oy, Glyph og)
        /* draw the new one */
        if (IS_SET(MODE_FOCUSED)) {
                switch (win.cursor) {
-               case 7: /* st extension: snowman */
-                       utf8decode("☃", &g.u, UTF_SIZ);
+               case 7: /* st extension: snowman (U+2603) */
+                       g.u = 0x2603;
                case 0: /* Blinking Block */
                case 1: /* Blinking Block (Default) */
                case 2: /* Steady Block */
@@ -1733,8 +1746,7 @@ cmessage(XEvent *e)
                        win.mode &= ~MODE_FOCUSED;
                }
        } else if (e->xclient.data.l[0] == xw.wmdeletewin) {
-               /* Send SIGHUP to shell */
-               kill(pid, SIGHUP);
+               ttyhangup();
                exit(0);
        }
 }
@@ -1755,6 +1767,7 @@ run(void)
        int w = win.w, h = win.h;
        fd_set rfd;
        int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
+       int ttyfd;
        struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
        long deltatime;
 
@@ -1774,7 +1787,7 @@ run(void)
                }
        } while (ev.type != MapNotify);
 
-       ttynew(opt_line, opt_io, opt_cmd);
+       ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
        cresize(w, h);
 
        clock_gettime(CLOCK_MONOTONIC, &last);
@@ -1782,15 +1795,15 @@ run(void)
 
        for (xev = actionfps;;) {
                FD_ZERO(&rfd);
-               FD_SET(cmdfd, &rfd);
+               FD_SET(ttyfd, &rfd);
                FD_SET(xfd, &rfd);
 
-               if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
+               if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
                        if (errno == EINTR)
                                continue;
                        die("select failed: %s\n", strerror(errno));
                }
-               if (FD_ISSET(cmdfd, &rfd)) {
+               if (FD_ISSET(ttyfd, &rfd)) {
                        ttyread();
                        if (blinktimeout) {
                                blinkset = tattrset(ATTR_BLINK);
@@ -1834,7 +1847,7 @@ run(void)
 
                        if (xev && !FD_ISSET(xfd, &rfd))
                                xev--;
-                       if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+                       if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
                                if (blinkset) {
                                        if (TIMEDIFF(now, lastblink) \
                                                        > blinktimeout) {