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
};
40 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
41 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
45 olen
= len
= strlen(text
);
48 memcpy(buf
, text
, len
);
50 h
= dc
.font
.ascent
+ dc
.font
.descent
;
51 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
53 /* shorten text if necessary */
54 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
65 return; /* too long */
66 gcv
.foreground
= col
[ColFG
];
68 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
69 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
72 gcv
.font
= dc
.font
.xfont
->fid
;
73 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCFont
, &gcv
);
74 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
80 r
.width
= r
.height
= x
+ 1;
81 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
83 else if(emptysquare
) {
94 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, pt
, 5, CoordModePrevious
);
105 for(i
= 0; i
< ntags
; i
++) {
106 dc
.w
= textw(tags
[i
]);
108 drawtext(tags
[i
], dc
.sel
, sel
&& sel
->tags
[i
], isoccupied(i
));
110 drawtext(tags
[i
], dc
.norm
, sel
&& sel
->tags
[i
], isoccupied(i
));
114 drawtext(arrange
== dofloat
? FLOATSYMBOL
: TILESYMBOL
, dc
.norm
, False
, False
);
122 drawtext(stext
, dc
.norm
, False
, False
);
123 if((dc
.w
= dc
.x
- x
) > bh
) {
125 drawtext(sel
? sel
->name
: NULL
, sel
? dc
.sel
: dc
.norm
, False
, False
);
127 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, sw
, bh
, 0, 0);
132 getcolor(const char *colstr
) {
133 Colormap cmap
= DefaultColormap(dpy
, screen
);
136 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
137 eprint("error, cannot allocate color '%s'\n", colstr
);
142 setfont(const char *fontstr
) {
143 char *def
, **missing
;
148 XFreeFontSet(dpy
, dc
.font
.set
);
149 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
152 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
153 XFreeStringList(missing
);
156 XFontSetExtents
*font_extents
;
157 XFontStruct
**xfonts
;
159 dc
.font
.ascent
= dc
.font
.descent
= 0;
160 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
161 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
162 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
163 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
164 dc
.font
.ascent
= (*xfonts
)->ascent
;
165 if(dc
.font
.descent
< (*xfonts
)->descent
)
166 dc
.font
.descent
= (*xfonts
)->descent
;
172 XFreeFont(dpy
, dc
.font
.xfont
);
173 dc
.font
.xfont
= NULL
;
174 if(!(dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
)))
175 eprint("error, cannot load font: '%s'\n", fontstr
);
176 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
177 dc
.font
.descent
= dc
.font
.xfont
->descent
;
179 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
183 textw(const char *text
) {
184 return textnw(text
, strlen(text
)) + dc
.font
.height
;