JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Style cleanup.
[st.git] / st.c
diff --git a/st.c b/st.c
index 6e7077a..c16e45d 100644 (file)
--- a/st.c
+++ b/st.c
@@ -441,6 +441,7 @@ 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 char *xstrdup(char *s);
 
 static void (*handler[LASTEvent])(XEvent *) = {
        [KeyPress] = kpress,
@@ -529,6 +530,16 @@ xrealloc(void *p, size_t len) {
        return p;
 }
 
+char *
+xstrdup(char *s) {
+       char *p = strdup(s);
+
+       if (!p)
+               die("Out of memory\n");
+
+       return p;
+}
+
 int
 utf8decode(char *s, long *u) {
        uchar c;
@@ -2790,7 +2801,8 @@ xhints(void) {
                sizeh->min_height = sizeh->max_height = xw.fh;
        }
 
-       XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, &class);
+       XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
+                       &class);
        XFree(sizeh);
 }
 
@@ -3079,6 +3091,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                if(base.fg == defaultfg)
                        base.fg = defaultunderline;
        }
+
        if(IS_TRUECOL(base.fg)) {
                colfg.alpha = 0xffff;
                colfg.red = TRUERED(base.fg);
@@ -3101,8 +3114,6 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                bg = &dc.col[base.bg];
        }
 
-
-
        if(base.mode & ATTR_BOLD) {
                if(BETWEEN(base.fg, 0, 7)) {
                        /* basic system colors */
@@ -3132,7 +3143,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        colfg.green = ~fg->color.green;
                        colfg.blue = ~fg->color.blue;
                        colfg.alpha = fg->color.alpha;
-                       XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
+                       XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg,
+                                       &revfg);
                        fg = &revfg;
                }
 
@@ -3143,7 +3155,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        colbg.green = ~bg->color.green;
                        colbg.blue = ~bg->color.blue;
                        colbg.alpha = bg->color.alpha;
-                       XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &revbg);
+                       XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg,
+                                       &revbg);
                        bg = &revbg;
                }
        }
@@ -3223,7 +3236,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        u8fblen += u8cblen;
                }
                if(doesexist) {
-                       if (oneatatime)
+                       if(oneatatime)
                                continue;
                        break;
                }
@@ -3246,6 +3259,8 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                         * Nothing was found in the cache. Now use
                         * some dozen of Fontconfig calls to get the
                         * font for one single character.
+                        *
+                        * Xft and fontconfig are design failures.
                         */
                        fcpattern = FcPatternDuplicate(font->pattern);
                        fccharset = FcCharSetCreate();
@@ -3290,6 +3305,12 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        }
 
        /*
+        * This is how the loop above actually should be. Why does the
+        * application have to care about font details?
+        *
+        * I have to repeat: Xft and Fontconfig are design failures.
+        */
+       /*
        XftDrawStringUtf8(xw.draw, fg, font->set, winx,
                        winy + font->ascent, (FcChar8 *)s, bytelen);
        */
@@ -3298,8 +3319,6 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                XftDrawRect(xw.draw, fg, winx, winy + font->ascent + 1,
                                width, 1);
        }
-       XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, winx, winy, width,
-                       CEIL((font->ascent + font->descent) * chscale), winx, winy);
 
        /* Reset clip to none. */
        XftDrawSetClip(xw.draw, 0);
@@ -3398,6 +3417,8 @@ redraw(int timeout) {
 void
 draw(void) {
        drawregion(0, 0, term.col, term.row);
+       XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.w,
+                       xw.h, 0, 0);
        XSetForeground(xw.dpy, dc.gc,
                        dc.col[IS_SET(MODE_REVERSE)?
                                defaultfg : defaultbg].pixel);
@@ -3789,7 +3810,7 @@ main(int argc, char *argv[]) {
                if(argc > 1) {
                        opt_cmd = &argv[1];
                        if(argv[1] != NULL && opt_title == NULL) {
-                               titles = strdup(argv[1]);
+                               titles = xstrdup(argv[1]);
                                opt_title = basename(titles);
                        }
                }