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
, Bool highlight
)
29 unsigned int len
, olen
;
32 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
34 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
35 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
38 points
[1].x
= dc
.w
- 1;
41 points
[2].y
= dc
.h
- 1;
42 points
[3].x
= -(dc
.w
- 1);
45 points
[4].y
= -(dc
.h
- 1);
46 XSetForeground(dpy
, dc
.gc
, dc
.border
);
47 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, points
, 5, CoordModePrevious
);
53 olen
= len
= strlen(text
);
54 if(len
>= sizeof(buf
))
55 len
= sizeof(buf
) - 1;
56 memcpy(buf
, text
, len
);
59 h
= dc
.font
.ascent
+ dc
.font
.descent
;
60 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
63 /* shorten text if necessary */
64 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
76 return; /* too long */
77 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
78 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
80 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
81 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
84 gcv
.font
= dc
.font
.xfont
->fid
;
85 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
86 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
91 r
.width
= r
.height
= 3;
92 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
103 for(c
= clients
; c
; c
= getnext(c
->next
))
112 Bool istile
= arrange
== dotile
;
116 drawtext(NULL
, !istile
, False
);
119 for(i
= 0; i
< ntags
; i
++) {
121 dc
.w
= textw(tags
[i
]);
123 drawtext(tags
[i
], seltag
[i
], sel
&& sel
->tags
[i
]);
125 drawtext(tags
[i
], !seltag
[i
], sel
&& sel
->tags
[i
]);
129 dc
.x
= bx
+ bw
- dc
.w
;
134 drawtext(stext
, !istile
, False
);
136 if(sel
&& ((dc
.w
= dc
.x
- x
) > bh
)) {
138 drawtext(sel
->name
, istile
, False
);
140 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
148 Bool istile
= arrange
== dotile
;
150 if(c
== sel
&& issel
) {
152 XUnmapWindow(dpy
, c
->twin
);
153 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
157 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
158 XMapWindow(dpy
, c
->twin
);
161 drawtext(c
->name
, !istile
, False
);
162 XCopyArea(dpy
, dc
.drawable
, c
->twin
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
167 getcolor(const char *colstr
)
169 Colormap cmap
= DefaultColormap(dpy
, screen
);
172 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
177 setfont(const char *fontstr
)
179 char **missing
, *def
;
183 setlocale(LC_ALL
, "");
185 XFreeFontSet(dpy
, dc
.font
.set
);
186 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
189 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
190 XFreeStringList(missing
);
192 XFreeFontSet(dpy
, dc
.font
.set
);
197 XFontSetExtents
*font_extents
;
198 XFontStruct
**xfonts
;
201 dc
.font
.ascent
= dc
.font
.descent
= 0;
202 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
203 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
204 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
205 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
206 dc
.font
.ascent
= (*xfonts
)->ascent
;
207 if(dc
.font
.descent
< (*xfonts
)->descent
)
208 dc
.font
.descent
= (*xfonts
)->descent
;
214 XFreeFont(dpy
, dc
.font
.xfont
);
215 dc
.font
.xfont
= NULL
;
216 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
218 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
220 eprint("error, cannot init 'fixed' font\n");
221 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
222 dc
.font
.descent
= dc
.font
.xfont
->descent
;
224 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
228 textw(const char *text
)
230 return textnw(text
, strlen(text
)) + dc
.font
.height
;