Update XIM cursor position only if changed
[st.git] / st.c
diff --git a/st.c b/st.c
index 2ecf8f3..0ce6ac2 100644 (file)
--- a/st.c
+++ b/st.c
@@ -682,9 +682,12 @@ execsh(char *cmd, char **args)
        if (args) {
                prog = args[0];
                arg = NULL;
-       } else if (scroll || utmp) {
-               prog = scroll ? scroll : utmp;
-               arg = scroll ? utmp : NULL;
+       } else if (scroll) {
+               prog = scroll;
+               arg = utmp ? utmp : sh;
+       } else if (utmp) {
+               prog = utmp;
+               arg = NULL;
        } else {
                prog = sh;
                arg = NULL;
@@ -820,15 +823,13 @@ ttyread(void)
 {
        static char buf[BUFSIZ];
        static int buflen = 0;
-       int written;
-       int ret;
+       int ret, written;
 
        /* append read bytes to unprocessed bytes */
        ret = read(cmdfd, buf+buflen, LEN(buf)-buflen);
 
        switch (ret) {
        case 0:
-               fputs("Found EOF in input\n", stderr);
                exit(0);
        case -1:
                die("couldn't read from shell: %s\n", strerror(errno));
@@ -836,7 +837,7 @@ ttyread(void)
                buflen += ret;
                written = twrite(buf, buflen, 0);
                buflen -= written;
-               /* keep any uncomplete utf8 char for the next call */
+               /* keep any incomplete UTF-8 byte sequence for the next call */
                if (buflen > 0)
                        memmove(buf, buf + written, buflen);
                return ret;
@@ -2570,6 +2571,7 @@ void
 drawregion(int x1, int y1, int x2, int y2)
 {
        int y;
+
        for (y = y1; y < y2; y++) {
                if (!term.dirty[y])
                        continue;
@@ -2582,7 +2584,7 @@ drawregion(int x1, int y1, int x2, int y2)
 void
 draw(void)
 {
-       int cx = term.c.x;
+       int cx = term.c.x, ocx = term.ocx, ocy = term.ocy;
 
        if (!xstartdraw())
                return;
@@ -2598,9 +2600,11 @@ draw(void)
        drawregion(0, 0, term.col, term.row);
        xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
                        term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
-       term.ocx = cx, term.ocy = term.c.y;
+       term.ocx = cx;
+       term.ocy = term.c.y;
        xfinishdraw();
-       xximspot(term.ocx, term.ocy);
+       if (ocx != term.ocx || ocy != term.ocy)
+               xximspot(term.ocx, term.ocy);
 }
 
 void