Xinqi Bao's Git
b5d8bd2eed8bfb99af76dc480401129c556bfe81
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
9 #include <X11/Xlocale.h>
18 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
19 XSetForeground(dpy
, dc
.gc
, dc
.border
);
22 points
[1].x
= dc
.w
- 1;
25 points
[2].y
= dc
.h
- 1;
26 points
[3].x
= -(dc
.w
- 1);
29 points
[4].y
= -(dc
.h
- 1);
30 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
34 textnw(char *text
, unsigned int len
)
39 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
42 return XTextWidth(dc
.font
.xfont
, text
, len
);
46 drawtext(const char *text
, Bool invert
, Bool border
)
52 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
54 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
55 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
65 if(len
>= sizeof(buf
))
66 len
= sizeof(buf
) - 1;
67 memcpy(buf
, text
, len
);
70 h
= dc
.font
.ascent
+ dc
.font
.descent
;
71 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
74 /* shorten text if necessary */
75 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
79 return; /* too long */
81 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
82 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
84 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
85 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
89 gcv
.font
= dc
.font
.xfont
->fid
;
90 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
91 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
102 for(c
= clients
; c
; c
= getnext(c
->next
, tsel
))
111 Bool istile
= arrange
== dotile
;
115 drawtext(NULL
, !istile
, False
);
118 for(i
= 0; i
< TLast
; i
++) {
120 dc
.w
= textw(tags
[i
]);
122 drawtext(tags
[i
], (i
== tsel
), True
);
124 drawtext(tags
[i
], (i
!= tsel
), True
);
128 dc
.w
= textw(sel
->name
);
129 drawtext(sel
->name
, istile
, True
);
132 dc
.x
= bx
+ bw
- dc
.w
;
133 drawtext(stext
, !istile
, False
);
135 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
143 Bool istile
= arrange
== dotile
;
147 XUnmapWindow(dpy
, c
->title
);
148 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
152 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
153 XMapWindow(dpy
, c
->title
);
158 for(i
= 0; i
< TLast
; i
++) {
161 dc
.w
= textw(c
->tags
[i
]);
162 drawtext(c
->tags
[i
], !istile
, True
);
166 dc
.w
= textw(c
->name
);
167 drawtext(c
->name
, !istile
, True
);
168 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
173 getcolor(const char *colstr
)
175 Colormap cmap
= DefaultColormap(dpy
, screen
);
178 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
183 setfont(const char *fontstr
)
185 char **missing
, *def
;
189 setlocale(LC_ALL
, "");
191 XFreeFontSet(dpy
, dc
.font
.set
);
192 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
195 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
196 XFreeStringList(missing
);
198 XFreeFontSet(dpy
, dc
.font
.set
);
203 XFontSetExtents
*font_extents
;
204 XFontStruct
**xfonts
;
207 dc
.font
.ascent
= dc
.font
.descent
= 0;
208 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
209 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
210 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
211 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
212 dc
.font
.ascent
= (*xfonts
)->ascent
;
213 if(dc
.font
.descent
< (*xfonts
)->descent
)
214 dc
.font
.descent
= (*xfonts
)->descent
;
220 XFreeFont(dpy
, dc
.font
.xfont
);
221 dc
.font
.xfont
= NULL
;
222 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
224 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
226 eprint("error, cannot init 'fixed' font\n");
227 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
228 dc
.font
.descent
= dc
.font
.xfont
->descent
;
230 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
236 return textnw(text
, strlen(text
)) + dc
.font
.height
;