1. diff -crB dmenu-4.1.1/config.def.h dmenu-patched/config.def.h
  2. *** dmenu-4.1.1/config.def.h    2010-07-23 01:32:31.000000000 +0400
  3. --- dmenu-patched/config.def.h  2010-07-23 02:32:30.000000000 +0400
  4. ***************
  5. *** 7,9 ****
  6. --- 7,10 ----
  7.   static const char *selbgcolor  = "#0066ff";
  8.   static const char *selfgcolor  = "#ffffff";
  9.   static unsigned int spaceitem  = 30; /* px between menu items */
  10. + static const char *fontxft     = "Monospace-10:normal"; /*if set xft is used */  
  11. Только в dmenu-patched: config.def.h.orig
  12. Только в dmenu-patched: config.h
  13. diff -crB dmenu-4.1.1/config.mk dmenu-patched/config.mk
  14. *** dmenu-4.1.1/config.mk   2010-07-23 01:32:32.000000000 +0400
  15. --- dmenu-patched/config.mk 2010-07-23 02:32:30.000000000 +0400
  16. ***************
  17. *** 15,22 ****
  18.   XINERAMAFLAGS = -DXINERAMA
  19.  
  20.   # includes and libs
  21. ! INCS = -I. -I/usr/include -I${X11INC}
  22. ! LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
  23.  
  24.   # flags
  25.   CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
  26. --- 15,22 ----
  27.   XINERAMAFLAGS = -DXINERAMA
  28.  
  29.   # includes and libs
  30. ! INCS = -I. -I/usr/include -I${X11INC} -I/usr/include -I/usr/include/freetype2
  31. ! LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} -lXft -lX11 -lXrender -lfreetype -lz -lfontconfig -lXrender -lX11
  32.  
  33.   # flags
  34.   CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
  35. Только в dmenu-patched: config.mk.orig
  36. diff -crB dmenu-4.1.1/dmenu.1 dmenu-patched/dmenu.1
  37. *** dmenu-4.1.1/dmenu.1 2010-07-23 01:32:32.000000000 +0400
  38. --- dmenu-patched/dmenu.1   2010-07-23 02:32:30.000000000 +0400
  39. ***************
  40. *** 7,12 ****
  41. --- 7,13 ----
  42.   .RB [ \-b ]
  43.   .RB [ \-l " <lines>"]
  44.   .RB [ \-fn " <font>"]
  45. + .RB [ \-fa " <xftfont>"]
  46.   .RB [ \-nb " <color>"]
  47.   .RB [ \-nf " <color>"]
  48.   .RB [ \-p " <prompt>"]
  49. ***************
  50. *** 34,39 ****
  51. --- 35,43 ----
  52.   .B \-fn <font>
  53.   defines the font.
  54.   .TP
  55. + .B \-fa <font>
  56. + defines the xft font.
  57. + .TP
  58.   .B \-nb <color>
  59.   defines the normal background color (#RGB, #RRGGBB, and color names are supported).
  60.   .TP
  61. Только в dmenu-patched: dmenu.1.orig
  62. Только в dmenu-patched: dmenu-4.1.1-xft.diff
  63. Только в dmenu-patched: dmenu-4.1.1-xft.diff.1
  64. diff -crB dmenu-4.1.1/dmenu.c dmenu-patched/dmenu.c
  65. *** dmenu-4.1.1/dmenu.c 2010-07-23 01:32:31.000000000 +0400
  66. --- dmenu-patched/dmenu.c   2010-07-23 16:03:17.000000000 +0400
  67. ***************
  68. *** 13,18 ****
  69. --- 13,19 ----
  70.   #ifdef XINERAMA
  71.   #include <X11/extensions/Xinerama.h>
  72.   #endif
  73. + #include <X11/Xft/Xft.h>
  74.  
  75.   /* macros */
  76.   #define CLEANMASK(mask)         (mask & ~(numlockmask | LockMask))
  77. ***************
  78. *** 29,34 ****
  79. --- 30,36 ----
  80.     int x, y, w, h;
  81.     unsigned long norm[ColLast];
  82.     unsigned long sel[ColLast];
  83. +   Bool selected;
  84.     Drawable drawable;
  85.     GC gc;
  86.     struct {
  87. ***************
  88. *** 38,43 ****
  89. --- 40,55 ----
  90.         int descent;
  91.         int height;
  92.     } font;
  93. +   XftDraw *xftdraw;
  94. +   XftColor xftselcolor;
  95. +   XftColor xftcolor;
  96. +   XGlyphInfo gi;
  97. +   struct {
  98. +       XftFont *xft_font;
  99. +       int ascent;
  100. +       int descent;
  101. +       int height;
  102. +   } xftfont;
  103.   } DC; /* draw context */
  104.  
  105.   typedef struct Item Item;
  106. ***************
  107. *** 135,152 ****
  108.   void
  109.   calcoffsetsv(void) {
  110.     static unsigned int h;
  111.  
  112.     if(!curr)
  113.         return;
  114. !   h = (dc.font.height + 2) * (lines + 1);
  115.     for(next = curr; next; next=next->right) {
  116. !       h -= dc.font.height + 2;
  117.         if(h <= 0)
  118.             break;
  119.     }
  120. !   h = (dc.font.height + 2) * (lines + 1);
  121.     for(prev = curr; prev && prev->left; prev=prev->left) {
  122. !       h -= dc.font.height + 2;
  123.         if(h <= 0)
  124.             break;
  125.     }
  126. --- 147,169 ----
  127.   void
  128.   calcoffsetsv(void) {
  129.     static unsigned int h;
  130. +   int h2;
  131.  
  132.     if(!curr)
  133.         return;
  134. !   if(fontxft)
  135. !     h2 = dc.xftfont.height;
  136. !   else
  137. !     h2 = dc.font.height;
  138. !   h = (h2 + 2) * (lines + 1);
  139.     for(next = curr; next; next=next->right) {
  140. !       h -= h2 + 2;
  141.         if(h <= 0)
  142.             break;
  143.     }
  144. !   h = (h2 + 2) * (lines + 1);
  145.     for(prev = curr; prev && prev->left; prev=prev->left) {
  146. !       h -= h2 + 2;
  147.         if(h <= 0)
  148.             break;
  149.     }
  150. ***************
  151. *** 185,193 ****
  152.         free(allitems);
  153.         allitems = itm;
  154.     }
  155.     if(dc.font.set)
  156.         XFreeFontSet(dpy, dc.font.set);
  157. !   else
  158.         XFreeFont(dpy, dc.font.xfont);
  159.     XFreePixmap(dpy, dc.drawable);
  160.     XFreeGC(dpy, dc.gc);
  161. --- 202,215 ----
  162.         free(allitems);
  163.         allitems = itm;
  164.     }
  165. +   if(fontxft) {
  166. +       XftColorFree (dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &dc.xftcolor);
  167. +       XftFontClose (dpy, dc.xftfont.xft_font);
  168. +       XftDrawDestroy(dc.xftdraw);
  169. +   }
  170.     if(dc.font.set)
  171.         XFreeFontSet(dpy, dc.font.set);
  172. !   else if(!fontxft)
  173.         XFreeFont(dpy, dc.font.xfont);
  174.     XFreePixmap(dpy, dc.drawable);
  175.     XFreeGC(dpy, dc.gc);
  176. ***************
  177. *** 198,205 ****
  178.   void
  179.   drawcursor(void) {
  180.     XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 };
  181.  
  182. !   r.x += textnw(text, cursor) + dc.font.height / 2;
  183.  
  184.     XSetForeground(dpy, dc.gc, dc.norm[ColFG]);
  185.     XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  186. --- 220,234 ----
  187.   void
  188.   drawcursor(void) {
  189.     XRectangle r = { dc.x, dc.y + 2, 1, dc.font.height - 2 };
  190. +   int h2;
  191.  
  192. !   if(fontxft)
  193. !     h2 = dc.xftfont.height;
  194. !   else
  195. !     h2 = dc.font.height;
  196. !
  197. !   r.height = h2 - 2;
  198. !   r.x += textnw(text, cursor) + h2 / 2;
  199.  
  200.     XSetForeground(dpy, dc.gc, dc.norm[ColFG]);
  201.     XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  202. ***************
  203. *** 213,221 ****
  204.     dc.h = mh;
  205.     drawtext(NULL, dc.norm);
  206.     /* print prompt? */
  207. !   if(prompt) {
  208.         dc.w = promptw;
  209.         drawtext(prompt, dc.sel);
  210.         dc.x += dc.w;
  211.     }
  212.     dc.w = mw - dc.x;
  213. --- 242,252 ----
  214.     dc.h = mh;
  215.     drawtext(NULL, dc.norm);
  216.     /* print prompt? */
  217. !   if(promptw) {
  218.         dc.w = promptw;
  219. +       dc.selected = True;
  220.         drawtext(prompt, dc.sel);
  221. +       dc.selected = False;
  222.         dc.x += dc.w;
  223.     }
  224.     dc.w = mw - dc.x;
  225. ***************
  226. *** 244,250 ****
  227.     dc.x += dc.w;
  228.     for(i = curr; i != next; i=i->right) {
  229.         dc.w = MIN(textw(i->text), mw / 3);
  230. !       drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
  231.         dc.x += dc.w;
  232.     }
  233.     dc.w = spaceitem;
  234. --- 275,287 ----
  235.     dc.x += dc.w;
  236.     for(i = curr; i != next; i=i->right) {
  237.         dc.w = MIN(textw(i->text), mw / 3);
  238. !       if(sel == i) {
  239. !         dc.selected = True;
  240. !         drawtext(i->text, dc.sel);
  241. !         dc.selected = False;
  242. !       } else {
  243. !         drawtext(i->text, dc.norm);
  244. !       }
  245.         dc.x += dc.w;
  246.     }
  247.     dc.w = spaceitem;
  248. ***************
  249. *** 255,266 ****
  250.   void
  251.   drawmenuv(void) {
  252.     Item *i;
  253.  
  254.     dc.w = mw - dc.x;
  255. !   dc.y += dc.font.height + 2;
  256.     for(i = curr; i != next; i=i->right) {
  257.         drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
  258. !       dc.y += dc.font.height + 2;
  259.     }
  260.     drawtext(NULL, dc.norm);
  261.   }
  262. --- 292,309 ----
  263.   void
  264.   drawmenuv(void) {
  265.     Item *i;
  266. +   int h2;
  267. +
  268. +   if(fontxft)
  269. +     h2 = dc.xftfont.height;
  270. +   else
  271. +     h2 = dc.font.height;
  272.  
  273.     dc.w = mw - dc.x;
  274. !   dc.y += h2 + 2;
  275.     for(i = curr; i != next; i=i->right) {
  276.         drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
  277. !       dc.y += h2 + 2;
  278.     }
  279.     drawtext(NULL, dc.norm);
  280.   }
  281. ***************
  282. *** 268,274 ****
  283.   void
  284.   drawtext(const char *text, unsigned long col[ColLast]) {
  285.     char buf[256];
  286. !   int i, x, y, h, len, olen;
  287.     XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  288.  
  289.     XSetForeground(dpy, dc.gc, col[ColBG]);
  290. --- 311,317 ----
  291.   void
  292.   drawtext(const char *text, unsigned long col[ColLast]) {
  293.     char buf[256];
  294. !   int i, x, y, h, a, len, olen;
  295.     XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  296.  
  297.     XSetForeground(dpy, dc.gc, col[ColBG]);
  298. ***************
  299. *** 276,283 ****
  300.     if(!text)
  301.         return;
  302.     olen = strlen(text);
  303. !   h = dc.font.height;
  304. !   y = dc.y + ((h+2) / 2) - (h / 2) + dc.font.ascent;
  305.     x = dc.x + (h / 2);
  306.     /* shorten text if necessary */
  307.     for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
  308. --- 319,338 ----
  309.     if(!text)
  310.         return;
  311.     olen = strlen(text);
  312. !   if(!fontxft) {
  313. !     h = dc.font.height;
  314. !     a = dc.font.ascent;
  315. !   } else {
  316. !     h = dc.xftfont.height;
  317. !     a = dc.xftfont.ascent;
  318. !   }
  319. !   y = dc.y + ((h+2) / 2) - (h / 2) + a;
  320. ! #if 0
  321. !   if(dc.xftfont.xft_font) {  
  322. !       h = dc.xftfont.ascent + dc.xftfont.descent;
  323. !       y = dc.y + (dc.h / 2) - (h / 2) + dc.xftfont.ascent;
  324. !   }
  325. ! #endif
  326.     x = dc.x + (h / 2);
  327.     /* shorten text if necessary */
  328.     for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
  329. ***************
  330. *** 287,293 ****
  331.     if(len < olen)
  332.         for(i = len; i && i > len - 3; buf[--i] = '.');
  333.     XSetForeground(dpy, dc.gc, col[ColFG]);
  334. !   if(dc.font.set)
  335.         XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  336.     else
  337.         XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  338. --- 342,356 ----
  339.     if(len < olen)
  340.         for(i = len; i && i > len - 3; buf[--i] = '.');
  341.     XSetForeground(dpy, dc.gc, col[ColFG]);
  342. !   if(fontxft) {
  343. !       if (!dc.xftdraw)
  344. !           eprint("error, creating xft drawable failed");
  345. !       if(dc.selected) {
  346. !           XftDrawStringUtf8(dc.xftdraw, &dc.xftselcolor, dc.xftfont.xft_font, x, y, (unsigned char*)buf, len);
  347. !       } else {
  348. !           XftDrawStringUtf8(dc.xftdraw, &dc.xftcolor, dc.xftfont.xft_font, x, y, (unsigned char*)buf, len);
  349. !       }
  350. !   } else if(dc.font.set)
  351.         XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
  352.     else
  353.         XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  354. ***************
  355. *** 359,364 ****
  356. --- 421,435 ----
  357.   }
  358.  
  359.   void
  360. + initxft() {
  361. +   if(!(dc.xftfont.xft_font = XftFontOpenName (dpy, screen, fontxft)))
  362. +       eprint("error, cannot load xft font\n" );
  363. +   dc.xftfont.ascent = dc.xftfont.xft_font->ascent;
  364. +   dc.xftfont.descent = dc.xftfont.xft_font->descent;
  365. +   dc.xftfont.height = dc.xftfont.ascent + dc.xftfont.descent;
  366. + }
  367. +
  368. + void
  369.   kpress(XKeyEvent * e) {
  370.     char buf[sizeof text];
  371.     int i, num, off;
  372. ***************
  373. *** 697,703 ****
  374.     dc.norm[ColFG] = getcolor(normfgcolor);
  375.     dc.sel[ColBG] = getcolor(selbgcolor);
  376.     dc.sel[ColFG] = getcolor(selfgcolor);
  377. !   initfont(font);
  378.  
  379.     /* menu window */
  380.     wa.override_redirect = True;
  381. --- 768,782 ----
  382.     dc.norm[ColFG] = getcolor(normfgcolor);
  383.     dc.sel[ColBG] = getcolor(selbgcolor);
  384.     dc.sel[ColFG] = getcolor(selfgcolor);
  385. !   dc.selected = False;
  386. !   if(fontxft){
  387. !       if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), (const char*)normfgcolor, &dc.xftcolor))
  388. !           eprint("error, cannot allocate xft font color '%s'\n", normfgcolor);
  389. !       if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), (const char*)selfgcolor, &dc.xftselcolor))
  390. !           eprint("error, cannot allocate xft font color '%s'\n", normfgcolor);
  391. !         else
  392. !           initxft();
  393. !   } else initfont(font);
  394.  
  395.     /* menu window */
  396.     wa.override_redirect = True;
  397. ***************
  398. *** 705,711 ****
  399.     wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask | VisibilityChangeMask;
  400.  
  401.     /* menu window geometry */
  402. !   mh = (dc.font.height + 2) * (lines + 1);
  403.   #if XINERAMA
  404.     if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
  405.         i = 0;
  406. --- 784,793 ----
  407.     wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask | VisibilityChangeMask;
  408.  
  409.     /* menu window geometry */
  410. !   if(fontxft)
  411. !     mh = (dc.xftfont.height + 2) * (lines + 1);
  412. !   else
  413. !     mh = (dc.font.height + 2) * (lines + 1);
  414.   #if XINERAMA
  415.     if(parent == RootWindow(dpy, screen) && XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
  416.         i = 0;
  417. ***************
  418. *** 741,747 ****
  419.     dc.drawable = XCreatePixmap(dpy, parent, mw, mh, DefaultDepth(dpy, screen));
  420.     dc.gc = XCreateGC(dpy, parent, 0, NULL);
  421.     XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  422. !   if(!dc.font.set)
  423.         XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  424.     if(maxname)
  425.         cmdw = MIN(textw(maxname), mw / 3);
  426. --- 823,829 ----
  427.     dc.drawable = XCreatePixmap(dpy, parent, mw, mh, DefaultDepth(dpy, screen));
  428.     dc.gc = XCreateGC(dpy, parent, 0, NULL);
  429.     XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  430. !   if(!dc.font.set && !fontxft)
  431.         XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  432.     if(maxname)
  433.         cmdw = MIN(textw(maxname), mw / 3);
  434. ***************
  435. *** 750,762 ****
  436.     text[0] = '\0';
  437.     match(text);
  438.     XMapRaised(dpy, win);
  439.   }
  440.  
  441.   int
  442.   textnw(const char *text, unsigned int len) {
  443. !   XRectangle r;
  444. !
  445. !   if(dc.font.set) {
  446.         XmbTextExtents(dc.font.set, text, len, NULL, &r);
  447.         return r.width;
  448.     }
  449. --- 832,851 ----
  450.     text[0] = '\0';
  451.     match(text);
  452.     XMapRaised(dpy, win);
  453. +   if(fontxft) {
  454. +       dc.xftdraw = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy,screen), DefaultColormap(dpy,screen));
  455. +       if(!dc.xftdraw)
  456. +           eprint("error, cannot create xft drawable\n");
  457. +   }
  458.   }
  459.  
  460.   int
  461.   textnw(const char *text, unsigned int len) {
  462. !   if(fontxft) {
  463. !       XftTextExtentsUtf8(dpy, dc.xftfont.xft_font, (const FcChar8*)text, len, &dc.gi);
  464. !       return dc.gi.width;
  465. !     } else if(dc.font.set) {
  466. !       XRectangle r;
  467.         XmbTextExtents(dc.font.set, text, len, NULL, &r);
  468.         return r.width;
  469.     }
  470. ***************
  471. *** 765,770 ****
  472. --- 854,861 ----
  473.  
  474.   int
  475.   textw(const char *text) {
  476. +   if(fontxft)
  477. +       return textnw(text, strlen(text)) + dc.xftfont.height;
  478.     return textnw(text, strlen(text)) + dc.font.height;
  479.   }
  480.  
  481. ***************
  482. *** 791,796 ****
  483. --- 882,890 ----
  484.         else if(!strcmp(argv[i], "-fn")) {
  485.             if(++i < argc) font = argv[i];
  486.         }
  487. +       else if(!strcmp(argv[i], "-fa")) {
  488. +           if(++i < argc) fontxft = argv[i];
  489. +       }
  490.         else if(!strcmp(argv[i], "-nb")) {
  491.             if(++i < argc) normbgcolor = argv[i];
  492.         }
  493. ***************
  494. *** 809,815 ****
  495.         else if(!strcmp(argv[i], "-v"))
  496.             eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
  497.         else
  498. !           eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
  499.                    "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
  500.     if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
  501.         fprintf(stderr, "warning: no locale support\n");
  502. --- 903,909 ----
  503.         else if(!strcmp(argv[i], "-v"))
  504.             eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
  505.         else
  506. !           eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-fa <xftfont>] [-nb <color>]\n"
  507.                    "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
  508.     if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
  509.         fprintf(stderr, "warning: no locale support\n");