logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

tabbed-0.6-xft.diff (6590B)


  1. diff --git a/config.def.h b/config.def.h
  2. index ceda9f7..bc7cfe2 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -1,7 +1,7 @@
  6. /* See LICENSE file for copyright and license details. */
  7. /* appearance */
  8. -static const char font[] = "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*";
  9. +static const char font[] = "monospace-9";
  10. static const char* normbgcolor = "#222222";
  11. static const char* normfgcolor = "#cccccc";
  12. static const char* selbgcolor = "#555555";
  13. diff --git a/config.mk b/config.mk
  14. index 5279711..037f9d7 100644
  15. --- a/config.mk
  16. +++ b/config.mk
  17. @@ -8,8 +8,8 @@ PREFIX = /usr/local
  18. MANPREFIX = ${PREFIX}/share/man
  19. # includes and libs
  20. -INCS = -I. -I/usr/include
  21. -LIBS = -lX11
  22. +INCS = -I. -I/usr/include -I/usr/include/freetype2
  23. +LIBS = -L/usr/lib -lc -lX11 -lfontconfig -lXft
  24. # flags
  25. CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE
  26. diff --git a/tabbed.c b/tabbed.c
  27. index d30206b..d08348c 100644
  28. --- a/tabbed.c
  29. +++ b/tabbed.c
  30. @@ -15,6 +15,7 @@
  31. #include <X11/Xproto.h>
  32. #include <X11/Xutil.h>
  33. #include <X11/XKBlib.h>
  34. +#include <X11/Xft/Xft.h>
  35. #include "arg.h"
  36. @@ -64,16 +65,15 @@ typedef struct {
  37. typedef struct {
  38. int x, y, w, h;
  39. - unsigned long norm[ColLast];
  40. - unsigned long sel[ColLast];
  41. + XftColor norm[ColLast];
  42. + XftColor sel[ColLast];
  43. Drawable drawable;
  44. GC gc;
  45. struct {
  46. int ascent;
  47. int descent;
  48. int height;
  49. - XFontSet set;
  50. - XFontStruct *xfont;
  51. + XftFont *xfont;
  52. } font;
  53. } DC; /* draw context */
  54. @@ -95,7 +95,7 @@ static void createnotify(const XEvent *e);
  55. static void destroynotify(const XEvent *e);
  56. static void die(const char *errstr, ...);
  57. static void drawbar(void);
  58. -static void drawtext(const char *text, unsigned long col[ColLast]);
  59. +static void drawtext(const char *text, XftColor col[ColLast]);
  60. static void *emallocz(size_t size);
  61. static void *erealloc(void *o, size_t size);
  62. static void expose(const XEvent *e);
  63. @@ -105,7 +105,7 @@ static void focusonce(const Arg *arg);
  64. static void fullscreen(const Arg *arg);
  65. static char* getatom(int a);
  66. static int getclient(Window w);
  67. -static unsigned long getcolor(const char *colstr);
  68. +static XftColor getcolor(const char *colstr);
  69. static int getfirsttab(void);
  70. static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
  71. static void initfont(const char *fontstr);
  72. @@ -219,12 +219,6 @@ cleanup(void) {
  73. free(clients);
  74. clients = NULL;
  75. - if(dc.font.set) {
  76. - XFreeFontSet(dpy, dc.font.set);
  77. - } else {
  78. - XFreeFont(dpy, dc.font.xfont);
  79. - }
  80. -
  81. XFreePixmap(dpy, dc.drawable);
  82. XFreeGC(dpy, dc.gc);
  83. XDestroyWindow(dpy, win);
  84. @@ -305,7 +299,7 @@ die(const char *errstr, ...) {
  85. void
  86. drawbar(void) {
  87. - unsigned long *col;
  88. + XftColor *col;
  89. int c, fc, width, n = 0;
  90. char *name = NULL;
  91. @@ -362,12 +356,13 @@ drawbar(void) {
  92. }
  93. void
  94. -drawtext(const char *text, unsigned long col[ColLast]) {
  95. +drawtext(const char *text, XftColor col[ColLast]) {
  96. int i, x, y, h, len, olen;
  97. char buf[256];
  98. + XftDraw *d;
  99. XRectangle r = { dc.x, dc.y, dc.w, dc.h };
  100. - XSetForeground(dpy, dc.gc, col[ColBG]);
  101. + XSetForeground(dpy, dc.gc, col[ColBG].pixel);
  102. XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
  103. if(!text)
  104. return;
  105. @@ -388,13 +383,10 @@ drawtext(const char *text, unsigned long col[ColLast]) {
  106. for(i = len; i && i > len - 3; buf[--i] = '.');
  107. }
  108. - XSetForeground(dpy, dc.gc, col[ColFG]);
  109. - if(dc.font.set) {
  110. - XmbDrawString(dpy, dc.drawable, dc.font.set,
  111. - dc.gc, x, y, buf, len);
  112. - } else {
  113. - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
  114. - }
  115. + d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen));
  116. +
  117. + XftDrawStringUtf8(d, &col[ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len);
  118. + XftDrawDestroy(d);
  119. }
  120. void *
  121. @@ -524,15 +516,14 @@ getclient(Window w) {
  122. return -1;
  123. }
  124. -unsigned long
  125. +XftColor
  126. getcolor(const char *colstr) {
  127. - Colormap cmap = DefaultColormap(dpy, screen);
  128. - XColor color;
  129. + XftColor color;
  130. - if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
  131. + if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color))
  132. die("tabbed: cannot allocate color '%s'\n", colstr);
  133. - return color.pixel;
  134. + return color;
  135. }
  136. int
  137. @@ -585,41 +576,12 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
  138. void
  139. initfont(const char *fontstr) {
  140. - char *def, **missing, **font_names;
  141. - int i, n;
  142. - XFontStruct **xfonts;
  143. -
  144. - missing = NULL;
  145. - if(dc.font.set)
  146. - XFreeFontSet(dpy, dc.font.set);
  147. -
  148. - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
  149. - if(missing) {
  150. - while(n--)
  151. - fprintf(stderr, "tabbed: missing fontset: %s\n", missing[n]);
  152. - XFreeStringList(missing);
  153. - }
  154. + if(!(dc.font.xfont = XftFontOpenName(dpy, screen, fontstr))
  155. + && !(dc.font.xfont = XftFontOpenName(dpy, screen, "fixed")))
  156. + die("error, cannot load font: '%s'\n", fontstr);
  157. - if(dc.font.set) {
  158. - dc.font.ascent = dc.font.descent = 0;
  159. - n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
  160. - for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
  161. - dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
  162. - dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
  163. - xfonts++;
  164. - }
  165. - } else {
  166. - if(dc.font.xfont)
  167. - XFreeFont(dpy, dc.font.xfont);
  168. - dc.font.xfont = NULL;
  169. - if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
  170. - && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) {
  171. - die("tabbed: cannot load font: '%s'\n", fontstr);
  172. - }
  173. -
  174. - dc.font.ascent = dc.font.xfont->ascent;
  175. - dc.font.descent = dc.font.xfont->descent;
  176. - }
  177. + dc.font.ascent = dc.font.xfont->ascent;
  178. + dc.font.descent = dc.font.xfont->descent;
  179. dc.font.height = dc.font.ascent + dc.font.descent;
  180. }
  181. @@ -972,11 +934,9 @@ setup(void) {
  182. dc.drawable = XCreatePixmap(dpy, root, ww, wh,
  183. DefaultDepth(dpy, screen));
  184. dc.gc = XCreateGC(dpy, root, 0, 0);
  185. - if(!dc.font.set)
  186. - XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  187. win = XCreateSimpleWindow(dpy, root, wx, wy, ww, wh, 0,
  188. - dc.norm[ColFG], dc.norm[ColBG]);
  189. + dc.norm[ColFG].pixel, dc.norm[ColBG].pixel);
  190. XMapRaised(dpy, win);
  191. XSelectInput(dpy, win, SubstructureNotifyMask|FocusChangeMask|
  192. ButtonPressMask|ExposureMask|KeyPressMask|PropertyChangeMask|
  193. @@ -1040,15 +1000,9 @@ spawn(const Arg *arg) {
  194. int
  195. textnw(const char *text, unsigned int len) {
  196. - XRectangle r;
  197. -
  198. - if(dc.font.set) {
  199. - XmbTextExtents(dc.font.set, text, len, NULL, &r);
  200. -
  201. - return r.width;
  202. - }
  203. -
  204. - return XTextWidth(dc.font.xfont, text, len);
  205. + XGlyphInfo ext;
  206. + XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext);
  207. + return ext.xOff;
  208. }
  209. void