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>
17 XSetLineAttributes(dpy
, dc
.gc
, 1, LineSolid
, CapButt
, JoinMiter
);
18 XSetForeground(dpy
, dc
.gc
, dc
.border
);
21 points
[1].x
= dc
.w
- 1;
24 points
[2].y
= dc
.h
- 1;
25 points
[3].x
= -(dc
.w
- 1);
28 points
[4].y
= -(dc
.h
- 1);
29 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
33 textnw(const char *text
, unsigned int len
)
38 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
41 return XTextWidth(dc
.font
.xfont
, text
, len
);
45 drawtext(const char *text
, Bool invert
, Bool border
)
51 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
53 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
54 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
64 if(len
>= sizeof(buf
))
65 len
= sizeof(buf
) - 1;
66 memcpy(buf
, text
, len
);
69 h
= dc
.font
.ascent
+ dc
.font
.descent
;
70 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
73 /* shorten text if necessary */
74 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
78 return; /* too long */
80 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
81 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
83 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
84 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
88 gcv
.font
= dc
.font
.xfont
->fid
;
89 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
90 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
101 for(c
= clients
; c
; c
= getnext(c
->next
))
110 Bool istile
= arrange
== dotile
;
114 drawtext(NULL
, !istile
, False
);
117 for(i
= 0; i
< ntags
; i
++) {
119 dc
.w
= textw(tags
[i
]);
121 drawtext(tags
[i
], (i
== tsel
), True
);
123 drawtext(tags
[i
], (i
!= tsel
), True
);
127 dc
.x
= bx
+ bw
- dc
.w
;
128 drawtext(stext
, !istile
, True
);
129 if(sel
&& ((dc
.w
= dc
.x
- x
) >= bh
)) {
131 drawtext(sel
->name
, istile
, True
);
133 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
141 Bool istile
= arrange
== dotile
;
145 XUnmapWindow(dpy
, c
->title
);
146 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
150 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
151 XMapWindow(dpy
, c
->title
);
156 for(i
= 0; i
< ntags
; i
++) {
159 dc
.w
= textw(tags
[i
]);
160 drawtext(tags
[i
], !istile
, True
);
164 dc
.w
= textw(c
->name
);
165 drawtext(c
->name
, !istile
, True
);
166 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
171 getcolor(const char *colstr
)
173 Colormap cmap
= DefaultColormap(dpy
, screen
);
176 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
181 setfont(const char *fontstr
)
183 char **missing
, *def
;
187 setlocale(LC_ALL
, "");
189 XFreeFontSet(dpy
, dc
.font
.set
);
190 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
193 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
194 XFreeStringList(missing
);
196 XFreeFontSet(dpy
, dc
.font
.set
);
201 XFontSetExtents
*font_extents
;
202 XFontStruct
**xfonts
;
205 dc
.font
.ascent
= dc
.font
.descent
= 0;
206 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
207 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
208 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
209 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
210 dc
.font
.ascent
= (*xfonts
)->ascent
;
211 if(dc
.font
.descent
< (*xfonts
)->descent
)
212 dc
.font
.descent
= (*xfonts
)->descent
;
218 XFreeFont(dpy
, dc
.font
.xfont
);
219 dc
.font
.xfont
= NULL
;
220 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
222 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
224 eprint("error, cannot init 'fixed' font\n");
225 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
226 dc
.font
.descent
= dc
.font
.xfont
->descent
;
228 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
232 textw(const char *text
)
234 return textnw(text
, strlen(text
)) + dc
.font
.height
;