summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c102
1 files changed, 66 insertions, 36 deletions
diff --git a/dwm.c b/dwm.c
index 7bab478..6695ddf 100644
--- a/dwm.c
+++ b/dwm.c
@@ -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
105typedef struct { 103typedef 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, ...);
182static Monitor *dirtomon(int dir); 181static Monitor *dirtomon(int dir);
183static void drawbar(Monitor *m); 182static void drawbar(Monitor *m);
184static void drawbars(void); 183static void drawbars(void);
185static void drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]); 184static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
186static void drawtext(const char *text, XftColor col[ColLast], Bool invert); 185static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
187static void enternotify(XEvent *e); 186static void enternotify(XEvent *e);
188static void expose(XEvent *e); 187static void expose(XEvent *e);
189static void focus(Client *c); 188static void focus(Client *c);
190static void focusin(XEvent *e); 189static void focusin(XEvent *e);
191static void focusmon(const Arg *arg); 190static void focusmon(const Arg *arg);
192static void focusstack(const Arg *arg); 191static void focusstack(const Arg *arg);
193static XftColor getcolor(const char *colstr); 192static unsigned long getcolor(const char *colstr);
194static Bool getrootptr(int *x, int *y); 193static Bool getrootptr(int *x, int *y);
195static long getstate(Window w); 194static long getstate(Window w);
196static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 195static 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
722drawbar(Monitor *m) { 725drawbar(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
779void 782void
780drawsquare(Bool filled, Bool empty, Bool invert, XftColor col[ColLast]) { 783drawsquare(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
791void 794void
792drawtext(const char *text, XftColor col[ColLast], Bool invert) { 795drawtext(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
819void 821void
@@ -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
936XftColor 938unsigned long
937getcolor(const char *colstr) { 939getcolor(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
946Bool 948Bool
@@ -1041,13 +1043,35 @@ incnmaster(const Arg *arg) {
1041 1043
1042void 1044void
1043initfont(const char *fontstr) { 1045initfont(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
1695int 1721int
1696textnw(const char *text, unsigned int len) { 1722textnw(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
1702void 1732void
@@ -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]);