X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=fbcd9e02154fe586066648bdd3bafdff06820693;hb=c63a87cd936c1eeef14c4c21572e5b782d3df4bc;hp=6c1638651fe372e829ec57dd47e3e4a0fbb9f920;hpb=f7398434b8fa949af7bf43472caaefdd97eed0f3;p=st.git diff --git a/st.c b/st.c index 6c16386..fbcd9e0 100644 --- a/st.c +++ b/st.c @@ -66,6 +66,7 @@ char *argv0; #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LEN(a) (sizeof(a) / sizeof(a)[0]) +#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) #define DEFAULT(a, b) (a) = (a) ? (a) : (b) #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) @@ -87,6 +88,8 @@ char *argv0; #define TRUEGREEN(x) (((x) & 0xff00)) #define TRUEBLUE(x) (((x) & 0xff) << 8) +/* constants */ +#define ISO14755CMD "dmenu -w %lu -p codepoint: 7) + return; + if ((utf32 = strtoul(us, &e, 16)) == ULONG_MAX || + (*e != '\n' && *e != '\0')) + return; + + ttysend(uc, utf8encode(utf32, uc)); +} + void toggleprinter(const Arg *arg) { @@ -3342,25 +3373,64 @@ xgeommasktogravity(int mask) int xloadfont(Font *f, FcPattern *pattern) { + FcPattern *configured; FcPattern *match; FcResult result; XGlyphInfo extents; + int wantattr, haveattr; + + /* + * Manually configure instead of calling XftMatchFont + * so that we can use the configured pattern for + * "missing glyph" lookups. + */ + configured = FcPatternDuplicate(pattern); + if (!configured) + return 1; - match = XftFontMatch(xw.dpy, xw.scr, pattern, &result); - if (!match) + FcConfigSubstitute(NULL, configured, FcMatchPattern); + XftDefaultSubstitute(xw.dpy, xw.scr, configured); + + match = FcFontMatch(NULL, configured, &result); + if (!match) { + FcPatternDestroy(configured); return 1; + } if (!(f->match = XftFontOpenPattern(xw.dpy, match))) { + FcPatternDestroy(configured); FcPatternDestroy(match); return 1; } + if ((XftPatternGetInteger(pattern, "slant", 0, &wantattr) == + XftResultMatch)) { + /* + * Check if xft was unable to find a font with the appropriate + * slant but gave us one anyway. Try to mitigate. + */ + if ((XftPatternGetInteger(f->match->pattern, "slant", 0, + &haveattr) != XftResultMatch) || haveattr < wantattr) { + f->badslant = 1; + fputs("st: font slant does not match\n", stderr); + } + } + + if ((XftPatternGetInteger(pattern, "weight", 0, &wantattr) == + XftResultMatch)) { + if ((XftPatternGetInteger(f->match->pattern, "weight", 0, + &haveattr) != XftResultMatch) || haveattr != wantattr) { + f->badweight = 1; + fputs("st: font weight does not match\n", stderr); + } + } + XftTextExtentsUtf8(xw.dpy, f->match, (const FcChar8 *) ascii_printable, strlen(ascii_printable), &extents); f->set = NULL; - f->pattern = FcPatternDuplicate(pattern); + f->pattern = configured; f->ascent = f->match->ascent; f->descent = f->match->descent; @@ -3752,14 +3822,13 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i XRenderColor colfg, colbg; XRectangle r; - /* Determine foreground and background colors based on mode. */ - if (base.fg == defaultfg) { - if (base.mode & ATTR_ITALIC) - base.fg = defaultitalic; - else if ((base.mode & ATTR_ITALIC) && (base.mode & ATTR_BOLD)) - base.fg = defaultitalic; - else if (base.mode & ATTR_UNDERLINE) - base.fg = defaultunderline; + /* Fallback on color display for attributes not supported by the font */ + if (base.mode & ATTR_ITALIC && base.mode & ATTR_BOLD) { + if (dc.ibfont.badslant || dc.ibfont.badweight) + base.fg = defaultattr; + } else if ((base.mode & ATTR_ITALIC && dc.ifont.badslant) || + (base.mode & ATTR_BOLD && dc.bfont.badweight)) { + base.fg = defaultattr; } if (IS_TRUECOL(base.fg)) { @@ -4402,8 +4471,6 @@ usage(void) int main(int argc, char *argv[]) { - uint cols = 80, rows = 24; - xw.l = xw.t = 0; xw.isfixed = False; xw.cursor = cursorshape;