diff options
| author | anselm@garbe.us <unknown> | 2012-11-02 12:17:50 +0100 |
|---|---|---|
| committer | anselm@garbe.us <unknown> | 2012-11-02 12:17:50 +0100 |
| commit | fd3c19bd550e346d515c8e124c7fa55599a1aa22 (patch) | |
| tree | c7707d903864e29091542694d10059a88e37e9a6 /dwm.c | |
| parent | keep 6.1 intact (diff) | |
| download | dwm-fd3c19bd550e346d515c8e124c7fa55599a1aa22.tar.gz dwm-fd3c19bd550e346d515c8e124c7fa55599a1aa22.zip | |
incorporating Xft instead of cairo, cairo provides far too many options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 102 |
1 files changed, 36 insertions, 66 deletions
| @@ -37,6 +37,8 @@ | |||
| 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> | ||
| 40 | #ifdef XINERAMA | 42 | #ifdef XINERAMA |
| 41 | #include <X11/extensions/Xinerama.h> | 43 | #include <X11/extensions/Xinerama.h> |
| 42 | #endif /* XINERAMA */ | 44 | #endif /* XINERAMA */ |
| @@ -100,16 +102,15 @@ struct Client { | |||
| 100 | 102 | ||
| 101 | typedef struct { | 103 | typedef struct { |
| 102 | int x, y, w, h; | 104 | int x, y, w, h; |
| 103 | unsigned long norm[ColLast]; | 105 | XftColor norm[ColLast]; |
| 104 | unsigned long sel[ColLast]; | 106 | XftColor sel[ColLast]; |
| 105 | Drawable drawable; | 107 | Drawable drawable; |
| 106 | GC gc; | 108 | GC gc; |
| 107 | struct { | 109 | struct { |
| 108 | int ascent; | 110 | int ascent; |
| 109 | int descent; | 111 | int descent; |
| 110 | int height; | 112 | int height; |
| 111 | XFontSet set; | 113 | XftFont *xfont; |
| 112 | XFontStruct *xfont; | ||
| 113 | } font; | 114 | } font; |
| 114 | } DC; /* draw context */ | 115 | } DC; /* draw context */ |
| 115 | 116 | ||
| @@ -179,15 +180,15 @@ static void die(const char *errstr, ...); | |||
| 179 | static Monitor *dirtomon(int dir); | 180 | static Monitor *dirtomon(int dir); |
| 180 | static void drawbar(Monitor *m); | 181 | static void drawbar(Monitor *m); |
| 181 | static void drawbars(void); | 182 | static void drawbars(void); |
| 182 | static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); | 183 | static void drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]); |
| 183 | static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); | 184 | static void drawtext(const char *text, XftColor col[ColLast], Bool invert); |
| 184 | static void enternotify(XEvent *e); | 185 | static void enternotify(XEvent *e); |
| 185 | static void expose(XEvent *e); | 186 | static void expose(XEvent *e); |
| 186 | static void focus(Client *c); | 187 | static void focus(Client *c); |
| 187 | static void focusin(XEvent *e); | 188 | static void focusin(XEvent *e); |
| 188 | static void focusmon(const Arg *arg); | 189 | static void focusmon(const Arg *arg); |
| 189 | static void focusstack(const Arg *arg); | 190 | static void focusstack(const Arg *arg); |
| 190 | static unsigned long getcolor(const char *colstr); | 191 | static XftColor getcolor(const char *colstr); |
| 191 | static Bool getrootptr(int *x, int *y); | 192 | static Bool getrootptr(int *x, int *y); |
| 192 | static long getstate(Window w); | 193 | static long getstate(Window w); |
| 193 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); | 194 | static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
| @@ -487,10 +488,6 @@ cleanup(void) { | |||
| 487 | for(m = mons; m; m = m->next) | 488 | for(m = mons; m; m = m->next) |
| 488 | while(m->stack) | 489 | while(m->stack) |
| 489 | unmanage(m->stack, False); | 490 | unmanage(m->stack, False); |
| 490 | if(dc.font.set) | ||
| 491 | XFreeFontSet(dpy, dc.font.set); | ||
| 492 | else | ||
| 493 | XFreeFont(dpy, dc.font.xfont); | ||
| 494 | XUngrabKey(dpy, AnyKey, AnyModifier, root); | 491 | XUngrabKey(dpy, AnyKey, AnyModifier, root); |
| 495 | XFreePixmap(dpy, dc.drawable); | 492 | XFreePixmap(dpy, dc.drawable); |
| 496 | XFreeGC(dpy, dc.gc); | 493 | XFreeGC(dpy, dc.gc); |
| @@ -723,7 +720,7 @@ void | |||
| 723 | drawbar(Monitor *m) { | 720 | drawbar(Monitor *m) { |
| 724 | int x; | 721 | int x; |
| 725 | unsigned int i, occ = 0, urg = 0; | 722 | unsigned int i, occ = 0, urg = 0; |
| 726 | unsigned long *col; | 723 | XftColor *col; |
| 727 | Client *c; | 724 | Client *c; |
| 728 | 725 | ||
| 729 | for(c = m->clients; c; c = c->next) { | 726 | for(c = m->clients; c; c = c->next) { |
| @@ -778,10 +775,10 @@ drawbars(void) { | |||
| 778 | } | 775 | } |
| 779 | 776 | ||
| 780 | void | 777 | void |
| 781 | drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { | 778 | drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) { |
| 782 | int x; | 779 | int x; |
| 783 | 780 | ||
| 784 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | 781 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG].pixel); |
| 785 | x = (dc.font.ascent + dc.font.descent + 2) / 4; | 782 | x = (dc.font.ascent + dc.font.descent + 2) / 4; |
| 786 | if(filled) | 783 | if(filled) |
| 787 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); | 784 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x+1, dc.y+1, x+1, x+1); |
| @@ -790,11 +787,12 @@ drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { | |||
| 790 | } | 787 | } |
| 791 | 788 | ||
| 792 | void | 789 | void |
| 793 | drawtext(const char *text, unsigned long col[ColLast], Bool invert) { | 790 | drawtext(const char *text, XftColor col[ColLast], Bool invert) { |
| 794 | char buf[256]; | 791 | char buf[256]; |
| 795 | int i, x, y, h, len, olen; | 792 | int i, x, y, h, len, olen; |
| 793 | XftDraw *d; | ||
| 796 | 794 | ||
| 797 | XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); | 795 | XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG].pixel); |
| 798 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); | 796 | XFillRectangle(dpy, dc.drawable, dc.gc, dc.x, dc.y, dc.w, dc.h); |
| 799 | if(!text) | 797 | if(!text) |
| 800 | return; | 798 | return; |
| @@ -809,11 +807,11 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { | |||
| 809 | memcpy(buf, text, len); | 807 | memcpy(buf, text, len); |
| 810 | if(len < olen) | 808 | if(len < olen) |
| 811 | for(i = len; i && i > len - 3; buf[--i] = '.'); | 809 | for(i = len; i && i > len - 3; buf[--i] = '.'); |
| 812 | XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); | 810 | |
| 813 | if(dc.font.set) | 811 | d = XftDrawCreate(dpy, dc.drawable, DefaultVisual(dpy, screen), DefaultColormap(dpy,screen)); |
| 814 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); | 812 | |
| 815 | else | 813 | XftDrawStringUtf8(d, &col[invert ? ColBG : ColFG], dc.font.xfont, x, y, (XftChar8 *) buf, len); |
| 816 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); | 814 | XftDrawDestroy(d); |
| 817 | } | 815 | } |
| 818 | 816 | ||
| 819 | void | 817 | void |
| @@ -859,7 +857,7 @@ focus(Client *c) { | |||
| 859 | detachstack(c); | 857 | detachstack(c); |
| 860 | attachstack(c); | 858 | attachstack(c); |
| 861 | grabbuttons(c, True); | 859 | grabbuttons(c, True); |
| 862 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); | 860 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder].pixel); |
| 863 | setfocus(c); | 861 | setfocus(c); |
| 864 | } | 862 | } |
| 865 | else { | 863 | else { |
| @@ -933,14 +931,14 @@ getatomprop(Client *c, Atom prop) { | |||
| 933 | return atom; | 931 | return atom; |
| 934 | } | 932 | } |
| 935 | 933 | ||
| 936 | unsigned long | 934 | XftColor |
| 937 | getcolor(const char *colstr) { | 935 | getcolor(const char *colstr) { |
| 938 | Colormap cmap = DefaultColormap(dpy, screen); | 936 | XftColor color; |
| 939 | XColor color; | ||
| 940 | 937 | ||
| 941 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) | 938 | if(!XftColorAllocName(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), colstr, &color)) |
| 942 | die("error, cannot allocate color '%s'\n", colstr); | 939 | die("error, cannot allocate color '%s'\n", colstr); |
| 943 | return color.pixel; | 940 | |
| 941 | return color; | ||
| 944 | } | 942 | } |
| 945 | 943 | ||
| 946 | Bool | 944 | Bool |
| @@ -1041,35 +1039,13 @@ incnmaster(const Arg *arg) { | |||
| 1041 | 1039 | ||
| 1042 | void | 1040 | void |
| 1043 | initfont(const char *fontstr) { | 1041 | initfont(const char *fontstr) { |
| 1044 | char *def, **missing; | ||
| 1045 | int n; | ||
| 1046 | 1042 | ||
| 1047 | dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | 1043 | if(!(dc.font.xfont = XftFontOpenName(dpy,screen,fontstr)) |
| 1048 | if(missing) { | 1044 | && !(dc.font.xfont = XftFontOpenName(dpy,screen,"fixed"))) |
| 1049 | while(n--) | 1045 | die("error, cannot load font: '%s'\n", fontstr); |
| 1050 | fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); | 1046 | |
| 1051 | XFreeStringList(missing); | 1047 | dc.font.ascent = dc.font.xfont->ascent; |
| 1052 | } | 1048 | dc.font.descent = dc.font.xfont->descent; |
| 1053 | if(dc.font.set) { | ||
| 1054 | XFontStruct **xfonts; | ||
| 1055 | char **font_names; | ||
| 1056 | |||
| 1057 | dc.font.ascent = dc.font.descent = 0; | ||
| 1058 | XExtentsOfFontSet(dc.font.set); | ||
| 1059 | n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | ||
| 1060 | while(n--) { | ||
| 1061 | dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent); | ||
| 1062 | dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent); | ||
| 1063 | xfonts++; | ||
| 1064 | } | ||
| 1065 | } | ||
| 1066 | else { | ||
| 1067 | if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) | ||
| 1068 | && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) | ||
| 1069 | die("error, cannot load font: '%s'\n", fontstr); | ||
| 1070 | dc.font.ascent = dc.font.xfont->ascent; | ||
| 1071 | dc.font.descent = dc.font.xfont->descent; | ||
| 1072 | } | ||
| 1073 | dc.font.height = dc.font.ascent + dc.font.descent; | 1049 | dc.font.height = dc.font.ascent + dc.font.descent; |
| 1074 | } | 1050 | } |
| 1075 | 1051 | ||
| @@ -1151,7 +1127,7 @@ manage(Window w, XWindowAttributes *wa) { | |||
| 1151 | 1127 | ||
| 1152 | wc.border_width = c->bw; | 1128 | wc.border_width = c->bw; |
| 1153 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); | 1129 | XConfigureWindow(dpy, w, CWBorderWidth, &wc); |
| 1154 | XSetWindowBorder(dpy, w, dc.norm[ColBorder]); | 1130 | XSetWindowBorder(dpy, w, dc.norm[ColBorder].pixel); |
| 1155 | configure(c); /* propagates border_width, if size doesn't change */ | 1131 | configure(c); /* propagates border_width, if size doesn't change */ |
| 1156 | updatewindowtype(c); | 1132 | updatewindowtype(c); |
| 1157 | updatesizehints(c); | 1133 | updatesizehints(c); |
| @@ -1640,8 +1616,6 @@ setup(void) { | |||
| 1640 | dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); | 1616 | dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); |
| 1641 | dc.gc = XCreateGC(dpy, root, 0, NULL); | 1617 | dc.gc = XCreateGC(dpy, root, 0, NULL); |
| 1642 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | 1618 | XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
| 1643 | if(!dc.font.set) | ||
| 1644 | XSetFont(dpy, dc.gc, dc.font.xfont->fid); | ||
| 1645 | /* init bars */ | 1619 | /* init bars */ |
| 1646 | updatebars(); | 1620 | updatebars(); |
| 1647 | updatestatus(); | 1621 | updatestatus(); |
| @@ -1712,13 +1686,9 @@ tagmon(const Arg *arg) { | |||
| 1712 | 1686 | ||
| 1713 | int | 1687 | int |
| 1714 | textnw(const char *text, unsigned int len) { | 1688 | textnw(const char *text, unsigned int len) { |
| 1715 | XRectangle r; | 1689 | XGlyphInfo ext; |
| 1716 | 1690 | XftTextExtentsUtf8(dpy, dc.font.xfont, (XftChar8 *) text, len, &ext); | |
| 1717 | if(dc.font.set) { | 1691 | return ext.xOff; |
| 1718 | XmbTextExtents(dc.font.set, text, len, NULL, &r); | ||
| 1719 | return r.width; | ||
| 1720 | } | ||
| 1721 | return XTextWidth(dc.font.xfont, text, len); | ||
| 1722 | } | 1692 | } |
| 1723 | 1693 | ||
| 1724 | void | 1694 | void |
| @@ -1798,7 +1768,7 @@ unfocus(Client *c, Bool setfocus) { | |||
| 1798 | if(!c) | 1768 | if(!c) |
| 1799 | return; | 1769 | return; |
| 1800 | grabbuttons(c, False); | 1770 | grabbuttons(c, False); |
| 1801 | XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); | 1771 | XSetWindowBorder(dpy, c->win, dc.norm[ColBorder].pixel); |
| 1802 | if(setfocus) { | 1772 | if(setfocus) { |
| 1803 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); | 1773 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
| 1804 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); | 1774 | XDeleteProperty(dpy, root, netatom[NetActiveWindow]); |
