+ XSizeHints *sizeh = NULL;
+
+ sizeh = XAllocSizeHints();
+ if(xw.isfixed == False) {
+ sizeh->flags = PSize | PResizeInc | PBaseSize;
+ sizeh->height = xw.h;
+ sizeh->width = xw.w;
+ sizeh->height_inc = xw.ch;
+ sizeh->width_inc = xw.cw;
+ sizeh->base_height = 2 * borderpx;
+ sizeh->base_width = 2 * borderpx;
+ } else {
+ sizeh->flags = PMaxSize | PMinSize;
+ sizeh->min_width = sizeh->max_width = xw.fw;
+ sizeh->min_height = sizeh->max_height = xw.fh;
+ }
+
+ XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
+ &class);
+ XFree(sizeh);
+}
+
+int
+xloadfont(Font *f, FcPattern *pattern) {
+ FcPattern *match;
+ FcResult result;
+
+ match = FcFontMatch(NULL, pattern, &result);
+ if(!match)
+ return 1;
+
+ if(!(f->match = XftFontOpenPattern(xw.dpy, match))) {
+ FcPatternDestroy(match);
+ return 1;
+ }
+
+ f->set = NULL;
+ f->pattern = FcPatternDuplicate(pattern);
+
+ f->ascent = f->match->ascent;
+ f->descent = f->match->descent;
+ f->lbearing = 0;
+ f->rbearing = f->match->max_advance_width;
+
+ f->height = f->ascent + f->descent;
+ f->width = f->lbearing + f->rbearing;
+
+ return 0;
+}
+
+void
+xloadfonts(char *fontstr, double fontsize) {
+ FcPattern *pattern;
+ FcResult r_sz, r_psz;
+ double fontval;
+
+ if(fontstr[0] == '-') {
+ pattern = XftXlfdParse(fontstr, False, False);
+ } else {
+ pattern = FcNameParse((FcChar8 *)fontstr);
+ }
+
+ if(!pattern)
+ die("st: can't open font %s\n", fontstr);
+
+ if(fontsize > 0) {
+ FcPatternDel(pattern, FC_PIXEL_SIZE);
+ FcPatternDel(pattern, FC_SIZE);
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)fontsize);
+ usedfontsize = fontsize;
+ } else {
+ 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
+ * have a known usedfontsize value.
+ */
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, 12);
+ usedfontsize = 12;
+ }
+ }
+
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+
+ 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);
+
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
+ if(xloadfont(&dc.ifont, pattern))
+ die("st: can't open font %s\n", fontstr);
+
+ FcPatternDel(pattern, FC_WEIGHT);
+ FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
+ if(xloadfont(&dc.ibfont, pattern))
+ die("st: can't open font %s\n", fontstr);
+
+ FcPatternDel(pattern, FC_SLANT);
+ FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
+ if(xloadfont(&dc.bfont, pattern))
+ die("st: can't open font %s\n", fontstr);
+
+ FcPatternDestroy(pattern);
+}
+
+int
+xloadfontset(Font *f) {
+ FcResult result;
+
+ if(!(f->set = FcFontSort(0, f->pattern, FcTrue, 0, &result)))
+ return 1;
+ return 0;
+}
+
+void
+xunloadfont(Font *f) {
+ XftFontClose(xw.dpy, f->match);
+ FcPatternDestroy(f->pattern);
+ if(f->set)
+ FcFontSetDestroy(f->set);
+}
+
+void
+xunloadfonts(void) {
+ int i;
+
+ /* Free the loaded fonts in the font cache. */
+ for(i = 0; i < frclen; i++) {
+ XftFontClose(xw.dpy, frc[i].font);
+ }
+ frclen = 0;
+
+ xunloadfont(&dc.font);
+ xunloadfont(&dc.bfont);
+ xunloadfont(&dc.ifont);
+ xunloadfont(&dc.ibfont);
+}
+
+void
+xzoom(const Arg *arg) {
+ xunloadfonts();
+ xloadfonts(usedfont, usedfontsize + arg->i);
+ cresize(0, 0);
+ redraw(0);