]> git.armaanb.net Git - st.git/blobdiff - st.c
Do not mark as invalid UTF8 control codes
[st.git] / st.c
diff --git a/st.c b/st.c
index c07cc3bbe50e020aa7b165d4e313669895935c71..35a840b66ef906c50e718ecd2176c98d3dfa8964 100644 (file)
--- a/st.c
+++ b/st.c
@@ -560,7 +560,8 @@ static int frclen = 0;
 ssize_t
 xwrite(int fd, const char *s, size_t len)
 {
-       size_t aux = len, r;
+       size_t aux = len;
+       ssize_t r;
 
        while (len > 0) {
                r = write(fd, s, len);
@@ -1329,9 +1330,8 @@ execsh(void)
                        die("who are you?\n");
        }
 
-       if (!(sh = getenv("SHELL"))) {
+       if ((sh = getenv("SHELL")) == NULL)
                sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
-       }
 
        if (opt_cmd)
                prog = opt_cmd[0];
@@ -2895,15 +2895,15 @@ tputc(Rune u)
        int width, len;
        Glyph *gp;
 
+       control = ISCONTROL(u);
        len = utf8encode(u, c);
-       if ((width = wcwidth(u)) == -1) {
+       if (!control && (width = wcwidth(u)) == -1) {
                memcpy(c, "\357\277\275", 4); /* UTF_INVALID */
                width = 1;
        }
 
        if (IS_SET(MODE_PRINT))
                tprinter(c, len);
-       control = ISCONTROL(u);
 
        /*
         * STR sequence must be checked before anything else
@@ -3411,6 +3411,7 @@ xinit(void)
        Cursor cursor;
        Window parent;
        pid_t thispid = getpid();
+       XColor xmousefg, xmousebg;
 
        if (!(xw.dpy = XOpenDisplay(NULL)))
                die("Can't open display\n");
@@ -3483,11 +3484,22 @@ xinit(void)
                die("XCreateIC failed. Could not obtain input method.\n");
 
        /* white cursor, black outline */
-       cursor = XCreateFontCursor(xw.dpy, XC_xterm);
+       cursor = XCreateFontCursor(xw.dpy, mouseshape);
        XDefineCursor(xw.dpy, xw.win, cursor);
-       XRecolorCursor(xw.dpy, cursor,
-               &(XColor){.red = 0xffff, .green = 0xffff, .blue = 0xffff},
-               &(XColor){.red = 0x0000, .green = 0x0000, .blue = 0x0000});
+
+       if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
+               xmousefg.red   = 0xffff;
+               xmousefg.green = 0xffff;
+               xmousefg.blue  = 0xffff;
+       }
+
+       if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) {
+               xmousebg.red   = 0x0000;
+               xmousebg.green = 0x0000;
+               xmousebg.blue  = 0x0000;
+       }
+
+       XRecolorCursor(xw.dpy, cursor, &xmousefg, &xmousebg);
 
        xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
        xw.wmdeletewin = XInternAtom(xw.dpy, "WM_DELETE_WINDOW", False);
@@ -4160,9 +4172,9 @@ run(void)
        do {
                XNextEvent(xw.dpy, &ev);
                /*
-                * XFilterEvent is required to be called after you using XOpenIM,
-                * this is not unnecessary.It does not only filter the key event,
-                * but some clientmessage for input method as well.
+                * This XFilterEvent call is required because of XOpenIM. It
+                * does filter out the key event and some client message for
+                * the input method too.
                 */
                if (XFilterEvent(&ev, None))
                        continue;
@@ -4259,9 +4271,11 @@ usage(void)
 {
        die("%s " VERSION " (c) 2010-2015 st engineers\n"
        "usage: st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n"
-       "          [-i] [-t title] [-w windowid] [-e command ...] [command ...]\n"
+       "          [-i] [-t title] [-T title] [-w windowid] [-e command ...]"
+       " [command ...]\n"
        "       st [-a] [-v] [-c class] [-f font] [-g geometry] [-o file]\n"
-       "          [-i] [-t title] [-w windowid] [-l line] [stty_args ...]\n",
+       "          [-i] [-t title] [-T title] [-w windowid] [-l line]"
+       " [stty_args ...]\n",
        argv0);
 }
 
@@ -4302,6 +4316,7 @@ main(int argc, char *argv[])
                opt_line = EARGF(usage());
                break;
        case 't':
+       case 'T':
                opt_title = EARGF(usage());
                break;
        case 'w':