Xinqi Bao's Git
4c47c1a8c4c0501b9b542f633301c3715d06de94
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 for(c
= clients
; c
; c
= getnext(c
->next
))
27 Bool istile
= arrange
== dotile
;
31 drawtext(NULL
, !istile
, False
);
34 for(i
= 0; i
< TLast
; i
++) {
36 dc
.w
= textw(tags
[i
]);
38 drawtext(tags
[i
], (i
== tsel
), True
);
40 drawtext(tags
[i
], (i
!= tsel
), True
);
44 dc
.w
= textw(sel
->name
);
45 drawtext(sel
->name
, istile
, True
);
48 dc
.x
= bx
+ bw
- dc
.w
;
49 drawtext(stext
, !istile
, False
);
51 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
59 Bool istile
= arrange
== dotile
;
63 XUnmapWindow(dpy
, c
->title
);
64 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
68 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
69 XMapWindow(dpy
, c
->title
);
74 for(i
= 0; i
< TLast
; i
++) {
77 dc
.w
= textw(c
->tags
[i
]);
78 drawtext(c
->tags
[i
], !istile
, True
);
82 dc
.w
= textw(c
->name
);
83 drawtext(c
->name
, !istile
, True
);
84 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
,
85 0, 0, c
->tw
, c
->th
, 0, 0);
93 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
94 XSetForeground(dpy
, dc
.gc
, dc
.border
);
97 points
[1].x
= dc
.w
- 1;
100 points
[2].y
= dc
.h
- 1;
101 points
[3].x
= -(dc
.w
- 1);
104 points
[4].y
= -(dc
.h
- 1);
105 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
109 drawtext(const char *text
, Bool invert
, Bool border
)
113 static char buf
[256];
115 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
117 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
118 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
128 if(len
>= sizeof(buf
))
129 len
= sizeof(buf
) - 1;
130 memcpy(buf
, text
, len
);
133 h
= dc
.font
.ascent
+ dc
.font
.descent
;
134 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
137 /* shorten text if necessary */
138 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
142 return; /* too long */
144 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
145 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
147 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
148 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
152 gcv
.font
= dc
.font
.xfont
->fid
;
153 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
154 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
159 getcolor(const char *colstr
)
162 Colormap cmap
= DefaultColormap(dpy
, screen
);
164 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
169 textnw(char *text
, unsigned int len
)
173 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
176 return XTextWidth(dc
.font
.xfont
, text
, len
);
182 return textnw(text
, strlen(text
)) + dc
.font
.height
;
186 setfont(const char *fontstr
)
188 char **missing
, *def
;
192 setlocale(LC_ALL
, "");
194 XFreeFontSet(dpy
, dc
.font
.set
);
195 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
198 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
199 XFreeStringList(missing
);
201 XFreeFontSet(dpy
, dc
.font
.set
);
206 XFontSetExtents
*font_extents
;
207 XFontStruct
**xfonts
;
210 dc
.font
.ascent
= dc
.font
.descent
= 0;
211 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
212 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
213 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
214 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
215 dc
.font
.ascent
= (*xfonts
)->ascent
;
216 if(dc
.font
.descent
< (*xfonts
)->descent
)
217 dc
.font
.descent
= (*xfonts
)->descent
;
223 XFreeFont(dpy
, dc
.font
.xfont
);
224 dc
.font
.xfont
= NULL
;
225 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
227 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
229 eprint("error, cannot init 'fixed' font\n");
230 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
231 dc
.font
.descent
= dc
.font
.xfont
->descent
;
233 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;