JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Correctly initialize altscreen when defaultbg is not 0.
[st.git] / st.c
diff --git a/st.c b/st.c
index 362de23..0fa0c86 100644 (file)
--- a/st.c
+++ b/st.c
@@ -76,6 +76,7 @@ char *argv0;
 #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
 #define IS_SET(flag) ((term.mode & (flag)) != 0)
 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
+#define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x))
 
 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
 #define IS_TRUECOL(x)    (1 << 24 & (x))
@@ -361,7 +362,7 @@ static void tsetdirtattr(int);
 static void tsetmode(bool, bool, int *, int);
 static void tfulldirt(void);
 static void techo(char *, int);
-static ulong tdefcolor(int *, int *, int);
+static long tdefcolor(int *, int *, int);
 static inline bool match(uint, uint);
 static void ttynew(void);
 static void ttyread(void);
@@ -419,7 +420,6 @@ static int isfullutf8(char *, int);
 static ssize_t xwrite(int, char *, size_t);
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
-static void *xcalloc(size_t, size_t);
 
 static void (*handler[LASTEvent])(XEvent *) = {
        [KeyPress] = kpress,
@@ -508,16 +508,6 @@ xrealloc(void *p, size_t len) {
        return p;
 }
 
-void *
-xcalloc(size_t nmemb, size_t size) {
-       void *p = calloc(nmemb, size);
-
-       if(!p)
-               die("Out of memory\n");
-
-       return p;
-}
-
 int
 utf8decode(char *s, long *u) {
        uchar c;
@@ -1369,7 +1359,7 @@ treset(void) {
 
 void
 tnew(int col, int row) {
-       memset(&term, 0, sizeof(Term));
+       term = (Term){ .c = { .attr = { .fg = defaultfg, .bg = defaultbg } } };
        tresize(col, row);
        term.numlock = 1;
 
@@ -1625,7 +1615,7 @@ tdeleteline(int n) {
        tscrollup(term.c.y, n);
 }
 
-ulong
+long
 tdefcolor(int *attr, int *npar, int l) {
        long idx = -1;
        uint r, g, b;
@@ -1676,7 +1666,7 @@ tdefcolor(int *attr, int *npar, int l) {
 void
 tsetattr(int *attr, int l) {
        int i;
-       ulong idx;
+       long idx;
 
        for(i = 0; i < l; i++) {
                switch(attr[i]) {
@@ -2535,8 +2525,8 @@ tresize(int col, int row) {
        /* allocate any new rows */
        for(/* i == minrow */; i < row; i++) {
                term.dirty[i] = 1;
-               term.line[i] = xcalloc(col, sizeof(Glyph));
-               term.alt [i] = xcalloc(col, sizeof(Glyph));
+               term.line[i] = xmalloc(col * sizeof(Glyph));
+               term.alt[i] = xmalloc(col * sizeof(Glyph));
        }
        if(col > term.col) {
                bp = term.tabs + term.col;
@@ -2777,8 +2767,8 @@ xloadfonts(char *fontstr, int fontsize) {
                die("st: can't open font %s\n", fontstr);
 
        /* Setting character width and height. */
-       xw.cw = dc.font.width;
-       xw.ch = dc.font.height;
+       xw.cw = CEIL(dc.font.width * cwscale);
+       xw.ch = CEIL(dc.font.height * chscale);
 
        FcPatternDel(pattern, FC_SLANT);
        FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
@@ -2960,6 +2950,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        Colour *fg, *bg, *temp, revfg, revbg, truefg, truebg;
        XRenderColor colfg, colbg;
        Rectangle r;
+       int oneatatime;
 
        frcflags = FRC_NORMAL;
 
@@ -3087,6 +3078,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                u8fs = s;
                u8fblen = 0;
                u8fl = 0;
+               oneatatime = font->width != xw.cw;
                for(;;) {
                        u8c = s;
                        u8cblen = utf8decode(s, &u8char);
@@ -3094,8 +3086,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        bytelen -= u8cblen;
 
                        doesexist = XftCharExists(xw.dpy, font->match, u8char);
-                       if(!doesexist || bytelen <= 0) {
-                               if(bytelen <= 0) {
+                       if(oneatatime || !doesexist || bytelen <= 0) {
+                               if(oneatatime || bytelen <= 0) {
                                        if(doesexist) {
                                                u8fl++;
                                                u8fblen += u8cblen;
@@ -3108,7 +3100,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                                                        winy + font->ascent,
                                                        (FcChar8 *)u8fs,
                                                        u8fblen);
-                                       xp += font->width * u8fl;
+                                       xp += xw.cw * u8fl;
 
                                }
                                break;
@@ -3117,8 +3109,11 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        u8fl++;
                        u8fblen += u8cblen;
                }
-               if(doesexist)
+               if(doesexist) {
+                       if (oneatatime)
+                               continue;
                        break;
+               }
 
                /* Search the font cache. */
                for(i = 0; i < frclen; i++) {
@@ -3178,7 +3173,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                                xp, winy + frc[i].font->ascent,
                                (FcChar8 *)u8c, u8cblen);
 
-               xp += font->width;
+               xp += xw.cw;
        }
 
        /*
@@ -3252,6 +3247,7 @@ xsettitle(char *p) {
        Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
                        &prop);
        XSetWMName(xw.dpy, xw.win, &prop);
+       XFree(prop.value);
 }
 
 void
@@ -3600,8 +3596,8 @@ run(void) {
                        ttyread();
                        if(blinktimeout) {
                                blinkset = tattrset(ATTR_BLINK);
-                               if(!blinkset && term.mode & ATTR_BLINK)
-                                       term.mode &= ~(MODE_BLINK);
+                               if(!blinkset)
+                                       MODBIT(term.mode, 0, MODE_BLINK);
                        }
                }
 
@@ -3707,7 +3703,7 @@ main(int argc, char *argv[]) {
                        xw.fh = (int)hr;
                if(bitm & XNegative && xw.fx == 0)
                        xw.fx = -1;
-               if(bitm & XNegative && xw.fy == 0)
+               if(bitm & YNegative && xw.fy == 0)
                        xw.fy = -1;
 
                if(xw.fh != 0 && xw.fw != 0)