Xinqi Bao's Git
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
8 #include <X11/Xlocale.h>
13 textnw(const char *text
, unsigned int len
)
18 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
21 return XTextWidth(dc
.font
.xfont
, text
, len
);
25 drawtext(const char *text
, Bool invert
)
31 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
33 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
34 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
41 if(len
>= sizeof(buf
))
42 len
= sizeof(buf
) - 1;
43 memcpy(buf
, text
, len
);
46 h
= dc
.font
.ascent
+ dc
.font
.descent
;
47 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
50 /* shorten text if necessary */
51 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
55 return; /* too long */
57 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
58 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
60 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
61 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
65 gcv
.font
= dc
.font
.xfont
->fid
;
66 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
67 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
78 for(c
= clients
; c
; c
= getnext(c
->next
))
87 Bool istile
= arrange
== dotile
;
91 drawtext(NULL
, !istile
);
94 for(i
= 0; i
< ntags
; i
++) {
96 dc
.w
= textw(tags
[i
]);
98 drawtext(tags
[i
], (i
== tsel
));
100 drawtext(tags
[i
], (i
!= tsel
));
104 dc
.x
= bx
+ bw
- dc
.w
;
105 drawtext(stext
, !istile
);
106 if(sel
&& ((dc
.w
= dc
.x
- x
) >= bh
)) {
108 drawtext(sel
->name
, istile
);
110 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
118 Bool istile
= arrange
== dotile
;
122 XUnmapWindow(dpy
, c
->title
);
123 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
127 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
128 XMapWindow(dpy
, c
->title
);
133 for(i
= 0; i
< ntags
; i
++) {
136 dc
.w
= textw(tags
[i
]);
137 drawtext(tags
[i
], !istile
);
141 dc
.w
= textw(c
->name
);
142 drawtext(c
->name
, !istile
);
143 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
148 getcolor(const char *colstr
)
150 Colormap cmap
= DefaultColormap(dpy
, screen
);
153 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
158 setfont(const char *fontstr
)
160 char **missing
, *def
;
164 setlocale(LC_ALL
, "");
166 XFreeFontSet(dpy
, dc
.font
.set
);
167 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
170 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
171 XFreeStringList(missing
);
173 XFreeFontSet(dpy
, dc
.font
.set
);
178 XFontSetExtents
*font_extents
;
179 XFontStruct
**xfonts
;
182 dc
.font
.ascent
= dc
.font
.descent
= 0;
183 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
184 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
185 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
186 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
187 dc
.font
.ascent
= (*xfonts
)->ascent
;
188 if(dc
.font
.descent
< (*xfonts
)->descent
)
189 dc
.font
.descent
= (*xfonts
)->descent
;
195 XFreeFont(dpy
, dc
.font
.xfont
);
196 dc
.font
.xfont
= NULL
;
197 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
199 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
201 eprint("error, cannot init 'fixed' font\n");
202 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
203 dc
.font
.descent
= dc
.font
.xfont
->descent
;
205 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
209 textw(const char *text
)
211 return textnw(text
, strlen(text
)) + dc
.font
.height
;