Configuration file for DWM on MacBook Air
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.9 KiB

18 years ago
18 years ago
18 years ago
  1. /*
  2. * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
  3. * See LICENSE file for license details.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <locale.h>
  9. unsigned int
  10. textwidth_l(BlitzFont *font, char *text, unsigned int len)
  11. {
  12. if(font->set) {
  13. XRectangle r;
  14. XmbTextExtents(font->set, text, len, nil, &r);
  15. return r.width;
  16. }
  17. return XTextWidth(font->xfont, text, len);
  18. }
  19. unsigned int
  20. textwidth(BlitzFont *font, char *text)
  21. {
  22. return blitz_textwidth_l(font, text, strlen(text));
  23. }
  24. void
  25. loadfont(Blitz *blitz, BlitzFont *font)
  26. {
  27. char *fontname = font->fontstr;
  28. char **missing = nil, *def = "?";
  29. int n;
  30. setlocale(LC_ALL, "");
  31. if(font->set)
  32. XFreeFontSet(blitz->dpy, font->set);
  33. font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
  34. if(missing) {
  35. while(n--)
  36. fprintf(stderr, "missing fontset: %s\n", missing[n]);
  37. XFreeStringList(missing);
  38. if(font->set) {
  39. XFreeFontSet(blitz->dpy, font->set);
  40. font->set = nil;
  41. }
  42. }
  43. if(font->set) {
  44. XFontSetExtents *font_extents;
  45. XFontStruct **xfonts;
  46. char **font_names;
  47. unsigned int i;
  48. font->ascent = font->descent = 0;
  49. font_extents = XExtentsOfFontSet(font->set);
  50. n = XFontsOfFontSet(font->set, &xfonts, &font_names);
  51. for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
  52. if(font->ascent < (*xfonts)->ascent)
  53. font->ascent = (*xfonts)->ascent;
  54. if(font->descent < (*xfonts)->descent)
  55. font->descent = (*xfonts)->descent;
  56. xfonts++;
  57. }
  58. }
  59. else {
  60. if(font->xfont)
  61. XFreeFont(blitz->dpy, font->xfont);
  62. font->xfont = nil;
  63. font->xfont = XLoadQueryFont(blitz->dpy, fontname);
  64. if (!font->xfont) {
  65. fontname = "fixed";
  66. font->xfont = XLoadQueryFont(blitz->dpy, fontname);
  67. }
  68. if (!font->xfont) {
  69. fprintf(stderr, "%s", "error, cannot load 'fixed' font\n");
  70. exit(1);
  71. }
  72. font->ascent = font->xfont->ascent;
  73. font->descent = font->xfont->descent;
  74. }
  75. }