JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Merge remote-tracking branch 'origin/master'
[st.git] / st.c
diff --git a/st.c b/st.c
index 4fb3311..37bec70 100644 (file)
--- a/st.c
+++ b/st.c
@@ -398,7 +398,7 @@ static void xinit(void);
 static void xloadcols(void);
 static int xsetcolorname(int, const char *);
 static int xloadfont(Font *, FcPattern *);
-static void xloadfonts(char *, int);
+static void xloadfonts(char *, double);
 static int xloadfontset(Font *);
 static void xsettitle(char *);
 static void xresettitle(void);
@@ -478,7 +478,7 @@ static char *opt_font = NULL;
 static int oldbutton = 3; /* button event on startup: 3 = release */
 
 static char *usedfont = NULL;
-static int usedfontsize = 0;
+static double usedfontsize = 0;
 
 /* Font Ring Cache */
 enum {
@@ -953,11 +953,12 @@ selcopy(void) {
                /* append every set & selected glyph to the selection */
                for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
                        gp = &term.line[y][0];
-                       last = gp + term.col;
+                       last = &gp[term.col-1];
 
-                       while(--last >= gp && !(selected(last - gp, y) && \
-                                               strcmp(last->c, " ") != 0))
-                               /* nothing */;
+                       while(last >= gp && !(selected(last - gp, y) &&
+                                             strcmp(last->c, " ") != 0)) {
+                               --last;
+                       }
 
                        for(x = 0; gp <= last; x++, ++gp) {
                                if(!selected(x, y) || (gp->mode & ATTR_WDUMMY))
@@ -2152,20 +2153,21 @@ csireset(void) {
 void
 strhandle(void) {
        char *p = NULL;
-       int i, j, narg;
+       int j, narg, par;
 
        strparse();
        narg = strescseq.narg;
+       par = atoi(strescseq.args[0]);
 
        switch(strescseq.type) {
        case ']': /* OSC -- Operating System Command */
-               switch(i = atoi(strescseq.args[0])) {
+               switch(par) {
                case 0:
                case 1:
                case 2:
                        if(narg > 1)
                                xsettitle(strescseq.args[1]);
-                       break;
+                       return;
                case 4: /* color set */
                        if(narg < 3)
                                break;
@@ -2182,25 +2184,20 @@ strhandle(void) {
                                 */
                                redraw(0);
                        }
-                       break;
-               default:
-                       fprintf(stderr, "erresc: unknown str ");
-                       strdump();
-                       break;
+                       return;
                }
                break;
        case 'k': /* old title set compatibility */
                xsettitle(strescseq.args[0]);
-               break;
+               return;
        case 'P': /* DSC -- Device Control String */
        case '_': /* APC -- Application Program Command */
        case '^': /* PM -- Privacy Message */
-       default:
-               fprintf(stderr, "erresc: unknown str ");
-               strdump();
-               /* die(""); */
-               break;
+               return;
        }
+
+       fprintf(stderr, "erresc: unknown str ");
+       strdump();
 }
 
 void
@@ -2826,9 +2823,9 @@ xloadfont(Font *f, FcPattern *pattern) {
 }
 
 void
-xloadfonts(char *fontstr, int fontsize) {
+xloadfonts(char *fontstr, double fontsize) {
        FcPattern *pattern;
-       FcResult result;
+       FcResult r_sz, r_psz;
        double fontval;
 
        if(fontstr[0] == '-') {
@@ -2842,12 +2839,16 @@ xloadfonts(char *fontstr, int fontsize) {
 
        if(fontsize > 0) {
                FcPatternDel(pattern, FC_PIXEL_SIZE);
+               FcPatternDel(pattern, FC_SIZE);
                FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)fontsize);
                usedfontsize = fontsize;
        } else {
-               result = FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval);
-               if(result == FcResultMatch) {
-                       usedfontsize = (int)fontval;
+               r_psz = FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval);
+               r_sz = FcPatternGetDouble(pattern, FC_SIZE, 0, &fontval);
+               if(r_psz == FcResultMatch) {
+                       usedfontsize = fontval;
+               } else if(r_sz == FcResultMatch) {
+                       usedfontsize = -1;
                } else {
                        /*
                         * Default font size is 12, if none given. This is to
@@ -2864,6 +2865,12 @@ xloadfonts(char *fontstr, int fontsize) {
        if(xloadfont(&dc.font, pattern))
                die("st: can't open font %s\n", fontstr);
 
+       if(usedfontsize < 0) {
+               FcPatternGetDouble(dc.font.match->pattern,
+                                  FC_PIXEL_SIZE, 0, &fontval);
+               usedfontsize = fontval;
+       }
+
        /* Setting character width and height. */
        xw.cw = CEIL(dc.font.width * cwscale);
        xw.ch = CEIL(dc.font.height * chscale);
@@ -3073,6 +3080,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
                        base.fg = defaultunderline;
        }
        if(IS_TRUECOL(base.fg)) {
+               colfg.alpha = 0xffff;
                colfg.red = TRUERED(base.fg);
                colfg.green = TRUEGREEN(base.fg);
                colfg.blue = TRUEBLUE(base.fg);
@@ -3083,6 +3091,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
        }
 
        if(IS_TRUECOL(base.bg)) {
+               colbg.alpha = 0xffff;
                colbg.green = TRUEGREEN(base.bg);
                colbg.red = TRUERED(base.bg);
                colbg.blue = TRUEBLUE(base.bg);