Advertisement
Guest User

dwm 6.0 pango

a guest
Jan 9th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.24 KB | None | 0 0
  1. diff -u dwm_original/config.def.h dwm_xft/config.def.h
  2. --- dwm_original/config.def.h   2012-01-09 19:07:41.065029408 +0400
  3. +++ dwm_xft/config.def.h    2012-01-09 19:02:02.313506614 +0400
  4. @@ -1,7 +1,7 @@
  5.  /* See LICENSE file for copyright and license details. */
  6.  
  7.  /* appearance */
  8. -static const char font[]            = "-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*";
  9. +static const char font[]            = "Sans 8";
  10.  static const char normbordercolor[] = "#444444";
  11.  static const char normbgcolor[]     = "#222222";
  12.  static const char normfgcolor[]     = "#bbbbbb";
  13. diff -u dwm_original/config.mk dwm_xft/config.mk
  14. --- dwm_original/config.mk  2012-01-09 19:07:41.065029408 +0400
  15. +++ dwm_xft/config.mk   2012-01-09 19:03:39.721464085 +0400
  16. @@ -15,8 +15,8 @@
  17.  XINERAMAFLAGS = -DXINERAMA
  18.  
  19.  # includes and libs
  20. -INCS = -I${X11INC}
  21. -LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS}
  22. +INCS = -I${X11INC} `pkg-config --cflags xft pango pangoxft`
  23. +LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} `pkg-config --libs xft pango pangoxft`
  24.  
  25.  # flags
  26.  CPPFLAGS = -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
  27. diff -u dwm_original/dwm.c dwm_xft/dwm.c
  28. --- dwm_original/dwm.c  2012-01-09 19:07:41.065029408 +0400
  29. +++ dwm_xft/dwm.c   2012-01-09 19:07:17.705012468 +0400
  30. @@ -36,6 +36,10 @@
  31.  #include <X11/Xlib.h>
  32.  #include <X11/Xproto.h>
  33.  #include <X11/Xutil.h>
  34. +#include <X11/Xft/Xft.h>
  35. +#include <pango/pango.h>
  36. +#include <pango/pangoxft.h>
  37. +#include <pango/pango-font.h>
  38.  #ifdef XINERAMA
  39.  #include <X11/extensions/Xinerama.h>
  40.  #endif /* XINERAMA */
  41. @@ -47,8 +51,12 @@
  42.                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
  43.  #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
  44.  #define LENGTH(X)               (sizeof X / sizeof X[0])
  45. -#define MAX(A, B)               ((A) > (B) ? (A) : (B))
  46. +#ifndef MAX
  47. +#define MAX(A, B)      ((A) > (B) ? (A) : (B))
  48. +#endif
  49. +#ifndef MIN
  50.  #define MIN(A, B)               ((A) < (B) ? (A) : (B))
  51. +#endif
  52.  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
  53.  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
  54.  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
  55. @@ -103,12 +111,19 @@
  56.     unsigned long sel[ColLast];
  57.     Drawable drawable;
  58.     GC gc;
  59. +
  60. +   XftColor  xftnorm[ColLast];
  61. +   XftColor  xftsel[ColLast];
  62. +   XftDraw  *xftdrawable;
  63. +
  64. +   PangoContext *pgc;
  65. +   PangoLayout  *plo;
  66. +   PangoFontDescription *pfd;
  67. +
  68.     struct {
  69.         int ascent;
  70.         int descent;
  71.         int height;
  72. -       XFontSet set;
  73. -       XFontStruct *xfont;
  74.     } font;
  75.  } DC; /* draw context */
  76.  
  77. @@ -186,7 +201,7 @@
  78.  static void focusin(XEvent *e);
  79.  static void focusmon(const Arg *arg);
  80.  static void focusstack(const Arg *arg);
  81. -static unsigned long getcolor(const char *colstr);
  82. +//static unsigned long getcolor(const char *colstr);
  83.  static Bool getrootptr(int *x, int *y);
  84.  static long getstate(Window w);
  85.  static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
  86. @@ -485,10 +500,6 @@
  87.     for(m = mons; m; m = m->next)
  88.         while(m->stack)
  89.             unmanage(m->stack, False);
  90. -   if(dc.font.set)
  91. -       XFreeFontSet(dpy, dc.font.set);
  92. -   else
  93. -       XFreeFont(dpy, dc.font.xfont);
  94.     XUngrabKey(dpy, AnyKey, AnyModifier, root);
  95.     XFreePixmap(dpy, dc.drawable);
  96.     XFreeGC(dpy, dc.gc);
  97. @@ -581,6 +592,7 @@
  98.             if(dc.drawable != 0)
  99.                 XFreePixmap(dpy, dc.drawable);
  100.             dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
  101. +           XftDrawChange(dc.xftdrawable, dc.drawable);
  102.             updatebars();
  103.             for(m = mons; m; m = m->next)
  104.                 XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
  105. @@ -796,7 +808,7 @@
  106.         return;
  107.     olen = strlen(text);
  108.     h = dc.font.ascent + dc.font.descent;
  109. -   y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
  110. +   y = dc.y;
  111.     x = dc.x + (h / 2);
  112.     /* shorten text if necessary */
  113.     for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
  114. @@ -805,11 +817,8 @@
  115.     memcpy(buf, text, len);
  116.     if(len < olen)
  117.         for(i = len; i && i > len - 3; buf[--i] = '.');
  118. -   XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
  119. -   if(dc.font.set)
  120. -       XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  121. -   else
  122. -       XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  123. +   pango_layout_set_text(dc.plo, text, len);
  124. +   pango_xft_render_layout(dc.xftdrawable, (col==dc.norm?dc.xftnorm:dc.xftsel)+(invert?ColBG:ColFG), dc.plo, x * PANGO_SCALE, y * PANGO_SCALE);
  125.  }
  126.  
  127.  void
  128. @@ -927,13 +936,13 @@
  129.  }
  130.  
  131.  unsigned long
  132. -getcolor(const char *colstr) {
  133. +getcolor(const char *colstr, XftColor *color) {
  134.     Colormap cmap = DefaultColormap(dpy, screen);
  135. -   XColor color;
  136. +   Visual *vis = DefaultVisual(dpy, screen);
  137.  
  138. -   if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
  139. +   if(!XftColorAllocName(dpy,vis,cmap,colstr, color))
  140.         die("error, cannot allocate color '%s'\n", colstr);
  141. -   return color.pixel;
  142. +   return color->pixel;
  143.  }
  144.  
  145.  Bool
  146. @@ -1034,35 +1043,19 @@
  147.  
  148.  void
  149.  initfont(const char *fontstr) {
  150. -   char *def, **missing;
  151. -   int n;
  152. +   PangoFontMetrics *metrics;
  153.  
  154. -   dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
  155. -   if(missing) {
  156. -       while(n--)
  157. -           fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]);
  158. -       XFreeStringList(missing);
  159. -   }
  160. -   if(dc.font.set) {
  161. -       XFontStruct **xfonts;
  162. -       char **font_names;
  163. -
  164. -       dc.font.ascent = dc.font.descent = 0;
  165. -       XExtentsOfFontSet(dc.font.set);
  166. -       n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
  167. -       while(n--) {
  168. -           dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
  169. -           dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
  170. -           xfonts++;
  171. -       }
  172. -   }
  173. -   else {
  174. -       if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
  175. -       && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
  176. -           die("error, cannot load font: '%s'\n", fontstr);
  177. -       dc.font.ascent = dc.font.xfont->ascent;
  178. -       dc.font.descent = dc.font.xfont->descent;
  179. -   }
  180. +   dc.pgc = pango_xft_get_context(dpy, screen);
  181. +   dc.pfd = pango_font_description_from_string(fontstr);
  182. +
  183. +   metrics = pango_context_get_metrics(dc.pgc, dc.pfd, pango_language_from_string(setlocale(LC_CTYPE, "")));
  184. +   dc.font.ascent = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE;
  185. +   dc.font.descent = pango_font_metrics_get_descent(metrics) / PANGO_SCALE;
  186. +
  187. +   pango_font_metrics_unref(metrics);
  188. +
  189. +   dc.plo = pango_layout_new(dc.pgc);
  190. +   pango_layout_set_font_description(dc.plo, dc.pfd);
  191.     dc.font.height = dc.font.ascent + dc.font.descent;
  192.  }
  193.  
  194. @@ -1611,19 +1604,24 @@
  195.     cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
  196.     cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
  197.     cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
  198. +
  199.     /* init appearance */
  200. -   dc.norm[ColBorder] = getcolor(normbordercolor);
  201. -   dc.norm[ColBG] = getcolor(normbgcolor);
  202. -   dc.norm[ColFG] = getcolor(normfgcolor);
  203. -   dc.sel[ColBorder] = getcolor(selbordercolor);
  204. -   dc.sel[ColBG] = getcolor(selbgcolor);
  205. -   dc.sel[ColFG] = getcolor(selfgcolor);
  206. +        dc.norm[ColBorder] = getcolor(normbordercolor, dc.xftnorm+ColBorder);
  207. +        dc.norm[ColBG] = getcolor(normbgcolor, dc.xftnorm+ColBG);
  208. +        dc.norm[ColFG] = getcolor(normfgcolor, dc.xftnorm+ColFG);
  209. +        dc.sel[ColBorder] = getcolor(selbordercolor, dc.xftsel+ColBorder);
  210. +        dc.sel[ColBG] = getcolor(selbgcolor, dc.xftsel+ColBG);
  211. +        dc.sel[ColFG] = getcolor(selfgcolor, dc.xftsel+ColFG);
  212. +
  213.     dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
  214.     dc.gc = XCreateGC(dpy, root, 0, NULL);
  215.     XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  216. -   if(!dc.font.set)
  217. -       XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  218. -   /* init bars */
  219. +
  220. +        dc.xftdrawable = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy,screen), DefaultColormap(dpy,screen));
  221. +        if(!dc.xftdrawable)
  222. +           printf("error, cannot create drawable\n");
  223. +
  224. +   /* init bar */
  225.     updatebars();
  226.     updatestatus();
  227.     /* EWMH support per view */
  228. @@ -1692,13 +1690,10 @@
  229.  
  230.  int
  231.  textnw(const char *text, unsigned int len) {
  232. -   XRectangle r;
  233. -
  234. -   if(dc.font.set) {
  235. -       XmbTextExtents(dc.font.set, text, len, NULL, &r);
  236. -       return r.width;
  237. -   }
  238. -   return XTextWidth(dc.font.xfont, text, len);
  239. +   PangoRectangle r;
  240. +   pango_layout_set_text(dc.plo, text, len);
  241. +   pango_layout_get_extents(dc.plo, &r, 0);
  242. +   return r.width / PANGO_SCALE;
  243.  }
  244.  
  245.  void
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement