Xinqi Bao's Git
1 /* (C)opyright MMIV-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
11 isoccupied(unsigned int t
)
14 for(c
= clients
; c
; c
= c
->next
)
21 textnw(const char *text
, unsigned int len
) {
25 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
28 return XTextWidth(dc
.font
.xfont
, text
, len
);
32 drawtext(const char *text
, unsigned long col
[ColLast
], Bool filledsquare
, Bool emptysquare
) {
35 unsigned int len
, olen
;
37 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
39 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
40 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
44 olen
= len
= strlen(text
);
47 memcpy(buf
, text
, len
);
49 h
= dc
.font
.ascent
+ dc
.font
.descent
;
50 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
52 /* shorten text if necessary */
53 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
64 return; /* too long */
65 gcv
.foreground
= col
[ColFG
];
67 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
68 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
71 gcv
.font
= dc
.font
.xfont
->fid
;
72 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCFont
, &gcv
);
73 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
79 r
.width
= r
.height
= x
+ 1;
80 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
82 else if(emptysquare
) {
83 r
.width
= r
.height
= x
;
84 XDrawRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
95 for(i
= 0; i
< ntags
; i
++) {
96 dc
.w
= textw(tags
[i
]);
98 drawtext(tags
[i
], dc
.sel
, sel
&& sel
->tags
[i
], isoccupied(i
));
100 drawtext(tags
[i
], dc
.norm
, sel
&& sel
->tags
[i
], isoccupied(i
));
104 drawtext(arrange
== dofloat
? FLOATSYMBOL
: TILESYMBOL
, dc
.norm
, False
, False
);
112 drawtext(stext
, dc
.norm
, False
, False
);
113 if((dc
.w
= dc
.x
- x
) > bh
) {
115 drawtext(sel
? sel
->name
: NULL
, sel
? dc
.sel
: dc
.norm
, False
, False
);
117 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, sw
, bh
, 0, 0);
122 getcolor(const char *colstr
) {
123 Colormap cmap
= DefaultColormap(dpy
, screen
);
126 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
127 eprint("error, cannot allocate color '%s'\n", colstr
);
132 setfont(const char *fontstr
) {
133 char *def
, **missing
;
138 XFreeFontSet(dpy
, dc
.font
.set
);
139 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
142 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
143 XFreeStringList(missing
);
146 XFontSetExtents
*font_extents
;
147 XFontStruct
**xfonts
;
149 dc
.font
.ascent
= dc
.font
.descent
= 0;
150 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
151 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
152 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
153 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
154 dc
.font
.ascent
= (*xfonts
)->ascent
;
155 if(dc
.font
.descent
< (*xfonts
)->descent
)
156 dc
.font
.descent
= (*xfonts
)->descent
;
162 XFreeFont(dpy
, dc
.font
.xfont
);
163 dc
.font
.xfont
= NULL
;
164 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
)))
165 eprint("error, cannot load font: '%s'\n", fontstr
);
166 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
167 dc
.font
.descent
= dc
.font
.xfont
->descent
;
169 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
173 textw(const char *text
) {
174 return textnw(text
, strlen(text
)) + dc
.font
.height
;