- XSizeHints size = {
- .flags = PSize | PResizeInc | PBaseSize,
- .height = xw.h,
- .width = xw.w,
- .height_inc = xw.ch,
- .width_inc = xw.cw,
- .base_height = 2*BORDER,
- .base_width = 2*BORDER,
- };
- XSetWMProperties(xw.dis, xw.win, NULL, NULL, NULL, 0, &size, &wm, &class);
+ 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*BORDER;
+ sizeh->base_width = 2*BORDER;
+ } 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);
+}
+
+XFontSet
+xinitfont(char *fontstr) {
+ XFontSet set;
+ char *def, **missing;
+ int n;
+
+ missing = NULL;
+ set = XCreateFontSet(xw.dpy, fontstr, &missing, &n, &def);
+ if(missing) {
+ while(n--)
+ fprintf(stderr, "st: missing fontset: %s\n", missing[n]);
+ XFreeStringList(missing);
+ }
+ return set;
+}
+
+void
+xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) {
+ XFontStruct **xfonts;
+ char **font_names;
+ int i, n;
+
+ *ascent = *descent = *lbearing = *rbearing = 0;
+ n = XFontsOfFontSet(set, &xfonts, &font_names);
+ for(i = 0; i < n; i++) {
+ *ascent = MAX(*ascent, (*xfonts)->ascent);
+ *descent = MAX(*descent, (*xfonts)->descent);
+ *lbearing = MAX(*lbearing, (*xfonts)->min_bounds.lbearing);
+ *rbearing = MAX(*rbearing, (*xfonts)->max_bounds.rbearing);
+ xfonts++;
+ }
+}
+
+void
+initfonts(char *fontstr, char *bfontstr) {
+ if((dc.font.set = xinitfont(fontstr)) == NULL ||
+ (dc.bfont.set = xinitfont(bfontstr)) == NULL)
+ die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT);
+ xgetfontinfo(dc.font.set, &dc.font.ascent, &dc.font.descent,
+ &dc.font.lbearing, &dc.font.rbearing);
+ xgetfontinfo(dc.bfont.set, &dc.bfont.ascent, &dc.bfont.descent,
+ &dc.bfont.lbearing, &dc.bfont.rbearing);