diff options
| author | anselm@garbe.us <unknown> | 2012-11-18 10:56:54 +0100 |
|---|---|---|
| committer | anselm@garbe.us <unknown> | 2012-11-18 10:56:54 +0100 |
| commit | 61fe833a062b0e027ec48ed7c7adeb2ed63089d3 (patch) | |
| tree | bd6e1775834c08f0158e4d645c1a9c93a1b8b644 /dwm.c | |
| parent | removed obsolete bugs from BUGS file (diff) | |
| download | dwm-61fe833a062b0e027ec48ed7c7adeb2ed63089d3.tar.gz dwm-61fe833a062b0e027ec48ed7c7adeb2ed63089d3.zip | |
reverting to plain X11 fonts in order to implement draw.c default
Diffstat (limited to '')
| -rw-r--r-- | dwm.c | 102 |
1 files changed, 66 insertions, 36 deletions
| @@ -37,8 +37,6 @@ | |||
| 37 | #include <X11/Xproto.h> | 37 | #include <X11/Xproto.h> |
| 38 | #include <X11/Xutil.h> | 38 | #include <X11/Xutil.h> |
| 39 | #include <X11/XKBlib.h> | 39 | #include <X11/XKBlib.h> |
| 40 | #include <fontconfig/fontconfig.h> | ||
| 41 | #include <X11/Xft/Xft.h> | ||
| 42 | #ifdef XINERAMA | 40 | #ifdef XINERAMA |
| 43 | #include <X11/extensions/Xinerama.h> | 41 | #include <X11/extensions/Xinerama.h> |
| 44 | #endif /* XINERAMA */ | 42 | #endif /* XINERAMA */ |
| @@ -104,15 +102,16 @@ struct Client { | |||
| 104 | 102 | ||
| 105 | typedef struct { | 103 | typedef struct { |
| 106 | int x, y, w, h; | 104 | int x, y, w, h; |
| 107 | XftColor norm[ColLast]; | 105 | unsigned long norm[ColLast]; |
| 108 | XftColor sel[ColLast]; | 106 | unsigned long sel[ColLast]; |
| 109 | Drawable drawable; | 107 | Drawable drawable; |
| 110 | GC gc; | 108 | GC gc; |
| 111 | struct { | 109 | struct { |
| 112 | int ascent; | 110 | int ascent; |
| 113 | int descent; | 111 | int descent; |
| 114 | int height; | 112 | int height; |
| 115 | XftFont *xfont; | 113 | XFontSet set; |
| 114 | XFontStruct *xfont; | ||
| 116 | } font; | 115 | } font; |
| 117 | } DC; /* draw context */ | 116 | } DC; /* draw context */ |
| 118 | 117 | ||
| @@ -182,15 +181,15 @@ static void die(const char *errstr, ...); | |||
| 182 | static Monitor *dirtomon(int dir); | 181 | static Monitor *dirtomon(int dir); |
| 183 | static void drawbar(Monitor *m); | 182 | static void drawbar(Monitor *m); |
| 184 | static void drawbars(void); | 183 | static void drawbars(void); |
| 185 | static void drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]); | 184 | static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
| 186 | static void drawtext(const char *text, XftColor col[ColLast], Bool invert); | 185 | static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
| 187 | static void enternotify(XEvent *e); | 186 | static void enternotify(XEvent *e); |
| 188 | static void expose(XEvent *e); | 187 | static void expose(XEvent *e); |
| 189 | static void focus(Client *c); | 188 | static void focus(Client *c); |
| 190 | static void focusin(XEvent *e); | 189 | static void focusin(XEvent *e); |
| 191 | static void focusmon(const Arg *arg); | 190 | static void focusmon(const Arg *arg); |
| 192 | static void focusstack(const Arg *arg); | 191 | static void focusstack(const Arg *arg); |
| 193 | static XftColor getcolor(const char *colstr); | 192 | static unsigned long getcolor(const char *colstr); |
| 194 | static Bool getrootptr(int *x, int *y); | 193 | static Bool getrootptr(int *x, int *y); |
| 195 | static long getstate(Window w); | 194 | static long getstate(Window w); |
| 196 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); | 195 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
| @@ -490,6 +489,10 @@ cleanup(void) { | |||
| 490 | for(m = mons; m; m = m->next) | 489 | for(m = mons; m; m = m->next) |
| 491 | while(m->stack) | 490 | while(m->stack) |
| 492 | unmanage(m->stack, False); | 491 | unmanage(m->stack, False); |
| 492 | if(dc.font.set) | ||
| 493 | XFreeFontSet(dpy, dc.font.set); | ||
| 494 | else | ||
| 495 | XFreeFont(dpy, dc.font.xfont); | ||
| 493 | XUngrabKey(dpy, AnyKey, AnyModifier, root); | 496 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
| 494 | XFreePixmap(dpy, dc.drawable); | 497 | XFreePixmap(dpy, dc.drawable); |
| 495 | XFreeGC(dpy, dc.gc); | 498 | XFreeGC(dpy, dc.gc); |
| @@ -722,7 +725,7 @@ void | |||
| 722 | drawbar(Monitor *m) { | 725 | drawbar(Monitor *m) { |
| 723 | int x; | 726 | int x; |
| 724 | unsigned int i, occ = 0, urg = 0; | 727 | unsigned int i, occ = 0, urg = 0; |
| 725 | XftColor *col; | 728 | unsigned long *col; |
| 726 | Client *c; | 729 | Client *c; |
| 727 | 730 | ||
| 728 | for(c = m->clients; c; c = c->next) { | 731 | for(c = m->clients; c; c = c->next) { |
| @@ -777,10 +780,10 @@ drawbars(void) { | |||
| 777 | } | 780 | } |
| 778 | 781 | ||
| 779 | void | 782 | void |
| 780 | drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) { | 783 | drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { |
| 781 | int x; | 784 | int x; |
| 782 | 785 | ||
| 783 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG].pixel); | 786 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); |
| 784 | x = (dc.font.ascent + dc.font.descent + 2) / 4; | 787 | x = (dc.font.ascent + dc.font.descent + 2) / 4; |
| 785 | if(filled) | 788 | if(filled) |
| 786 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); | 789 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); |
| @@ -789,12 +792,11 @@ drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) { | |||
| 789 | } | 792 | } |
| 790 | 793 | ||
| 791 | void | 794 | void |
| 792 | drawtext(const char *text, XftColor col[ColLast], Bool invert) { | 795 | drawtext(const char *text, unsigned long col[ColLast], Bool invert) { |
| 793 | char buf[256]; | 796 | char buf[256]; |
| 794 | int i, x, y, h, len, olen; | 797 | int i, x, y, h, len, olen; |
| 795 | XftDraw *d; | ||
| 796 | 798 | ||
| 797 | XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG].pixel); | 799 | XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); |
| 798 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); | 800 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); |
| 799 | if(!text) | 801 | if(!text) |
| 800 | return; | 802 | return; |
| @@ -809,11 +811,11 @@ drawtext(const char *text, XftColor col[ColLast], Bool invert) { | |||
| 809 | memcpy(buf, text, len); | 811 | memcpy(buf, text, len); |
| 810 | if(len < olen) | 812 | if(len < olen) |
| 811 | for(i = len; i && i > len - 3; buf[--i] = '.'); | 813 | for(i = len; i && i > len - 3; buf[--i] = '.'); |
| 812 | 814 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | |
| 813 | d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen)); | 815 | if(dc.font.set) |
| 814 | 816 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | |
| 815 | XftDrawStringUtf8(d, &col[invert ? ColBG : ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len); | 817 | else |
| 816 | XftDrawDestroy(d); | 818 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
| 817 | } | 819 | } |
| 818 | 820 | ||
| 819 | void | 821 | void |
| @@ -859,7 +861,7 @@ focus(Client *c) { | |||
| 859 | detachstack(c); | 861 | detachstack(c); |
| 860 | attachstack(c); | 862 | attachstack(c); |
| 861 | grabbuttons(c, True); | 863 | grabbuttons(c, True); |
| 862 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder].pixel); | 864 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); |
| 863 | setfocus(c); | 865 | setfocus(c); |
| 864 | } | 866 | } |
| 865 | else { | 867 | else { |
| @@ -933,14 +935,14 @@ getatomprop(Client *c, Atom prop) { | |||
| 933 | return atom; | 935 | return atom; |
| 934 | } | 936 | } |
| 935 | 937 | ||
| 936 | XftColor | 938 | unsigned long |
| 937 | getcolor(const char *colstr) { | 939 | getcolor(const char *colstr) { |
| 938 | XftColor color; | 940 | Colormap cmap = DefaultColormap(dpy, screen); |
| 941 | XColor color; | ||
| 939 | 942 | ||
| 940 | if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color)) | 943 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
| 941 | die("error, cannot allocate color '%s'\n", colstr); | 944 | die("error, cannot allocate color '%s'\n", colstr); |
| 942 | 945 | return color.pixel; | |
| 943 | return color; | ||
| 944 | } | 946 | } |
| 945 | 947 | ||
| 946 | Bool | 948 | Bool |
| @@ -1041,13 +1043,35 @@ incnmaster(const Arg *arg) { | |||
| 1041 | 1043 | ||
| 1042 | void | 1044 | void |
| 1043 | initfont(const char *fontstr) { | 1045 | initfont(const char *fontstr) { |
| 1046 | char *def, **missing; | ||
| 1047 | int n; | ||
| 1044 | 1048 | ||
| 1045 | if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr)) | 1049 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); |
| 1046 | && !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed"))) | 1050 | if(missing) { |
| 1047 | die("error, cannot load font: '%s'\n", fontstr); | 1051 | while(n--) |
| 1048 | 1052 | fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); | |
| 1049 | dc.font.ascent = dc.font.xfont->ascent; | 1053 | XFreeStringList(missing); |
| 1050 | dc.font.descent = dc.font.xfont->descent; | 1054 | } |
| 1055 | if(dc.font.set) { | ||
| 1056 | XFontStruct **xfonts; | ||
| 1057 | char **font_names; | ||
| 1058 | |||
| 1059 | dc.font.ascent = dc.font.descent = 0; | ||
| 1060 | XExtentsOfFontSet(dc.font.set); | ||
| 1061 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | ||
| 1062 | while(n--) { | ||
| 1063 | dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); | ||
| 1064 | dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); | ||
| 1065 | xfonts++; | ||
| 1066 | } | ||
| 1067 | } | ||
| 1068 | else { | ||
| 1069 | if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) | ||
| 1070 | && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) | ||
| 1071 | die("error, cannot load font: '%s'\n", fontstr); | ||
| 1072 | dc.font.ascent = dc.font.xfont->ascent; | ||
| 1073 | dc.font.descent = dc.font.xfont->descent; | ||
| 1074 | } | ||
| 1051 | dc.font.height = dc.font.ascent + dc.font.descent; | 1075 | dc.font.height = dc.font.ascent + dc.font.descent; |
| 1052 | } | 1076 | } |
| 1053 | 1077 | ||
| @@ -1132,7 +1156,7 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1132 | 1156 | ||
| 1133 | wc.border_width = c->bw; | 1157 | wc.border_width = c->bw; |
| 1134 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); | 1158 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); |
| 1135 | XSetWindowBorder(dpy, w, dc.norm[ColBorder].pixel); | 1159 | XSetWindowBorder(dpy, w, dc.norm[ColBorder]); |
| 1136 | configure(c); /* propagates border_width, if size doesn't change */ | 1160 | configure(c); /* propagates border_width, if size doesn't change */ |
| 1137 | updatewindowtype(c); | 1161 | updatewindowtype(c); |
| 1138 | updatesizehints(c); | 1162 | updatesizehints(c); |
| @@ -1622,6 +1646,8 @@ setup(void) { | |||
| 1622 | dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); | 1646 | dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); |
| 1623 | dc.gc = XCreateGC(dpy, root, 0, NULL); | 1647 | dc.gc = XCreateGC(dpy, root, 0, NULL); |
| 1624 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | 1648 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
| 1649 | if(!dc.font.set) | ||
| 1650 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | ||
| 1625 | /* init bars */ | 1651 | /* init bars */ |
| 1626 | updatebars(); | 1652 | updatebars(); |
| 1627 | updatestatus(); | 1653 | updatestatus(); |
| @@ -1694,9 +1720,13 @@ tagmon(const Arg *arg) { | |||
| 1694 | 1720 | ||
| 1695 | int | 1721 | int |
| 1696 | textnw(const char *text, unsigned int len) { | 1722 | textnw(const char *text, unsigned int len) { |
| 1697 | XGlyphInfo ext; | 1723 | XRectangle r; |
| 1698 | XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext); | 1724 | |
| 1699 | return ext.xOff; | 1725 | if(dc.font.set) { |
| 1726 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 1727 | return r.width; | ||
| 1728 | } | ||
| 1729 | return XTextWidth(dc.font.xfont, text, len); | ||
| 1700 | } | 1730 | } |
| 1701 | 1731 | ||
| 1702 | void | 1732 | void |
| @@ -1776,7 +1806,7 @@ unfocus(Client *c, Bool setfocus) { | |||
| 1776 | if(!c) | 1806 | if(!c) |
| 1777 | return; | 1807 | return; |
| 1778 | grabbuttons(c, False); | 1808 | grabbuttons(c, False); |
| 1779 | XSetWindowBorder(dpy, c->win, dc.norm[ColBorder].pixel); | 1809 | XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); |
| 1780 | if(setfocus) { | 1810 | if(setfocus) { |
| 1781 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | 1811 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
| 1782 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 1812 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
