Xinqi Bao's Git
1 /* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
7 #include <X11/Xlocale.h>
12 isoccupied(unsigned int t
)
15 for(c
= clients
; c
; c
= c
->next
)
22 textnw(const char *text
, unsigned int len
) {
26 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
29 return XTextWidth(dc
.font
.xfont
, text
, len
);
33 drawtext(const char *text
, unsigned long col
[ColLast
], Bool dot
, Bool border
) {
36 unsigned int len
, olen
;
38 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
41 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
42 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
46 olen
= len
= strlen(text
);
49 memcpy(buf
, text
, len
);
51 h
= dc
.font
.ascent
+ dc
.font
.descent
;
52 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
54 /* shorten text if necessary */
55 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
66 return; /* too long */
67 gcv
.foreground
= col
[ColFG
];
69 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
70 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
73 gcv
.font
= dc
.font
.xfont
->fid
;
74 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCFont
, &gcv
);
75 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
80 r
.width
= r
.height
= (h
+ 2) / 4;
81 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
90 pt
[3].x
= -(dc
.w
- 2);
93 pt
[4].y
= -(dc
.h
- 2);
94 XDrawLines(dpy
, dc
.drawable
, dc
.gc
, pt
, 5, CoordModePrevious
);
104 for(c
= clients
; c
; c
= getnext(c
->next
))
114 for(i
= 0; i
< ntags
; i
++) {
115 dc
.w
= textw(tags
[i
]);
117 drawtext(tags
[i
], dc
.sel
, sel
&& sel
->tags
[i
], isoccupied(i
));
119 drawtext(tags
[i
], dc
.norm
, sel
&& sel
->tags
[i
], isoccupied(i
));
123 drawtext(arrange
== dofloat
? FLOATSYMBOL
: TILESYMBOL
, dc
.status
, False
, False
);
131 drawtext(stext
, dc
.status
, False
, False
);
132 if((dc
.w
= dc
.x
- x
) > bh
) {
134 drawtext(sel
? sel
->name
: NULL
, sel
? dc
.sel
: dc
.norm
, False
, False
);
136 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
141 drawtitle(Client
*c
) {
142 if(c
== sel
&& issel
) {
144 XUnmapWindow(dpy
, c
->twin
);
145 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBG
]);
148 XSetWindowBorder(dpy
, c
->win
, dc
.norm
[ColBG
]);
149 XMapWindow(dpy
, c
->twin
);
152 drawtext(c
->name
, dc
.norm
, False
,False
);
153 XCopyArea(dpy
, dc
.drawable
, c
->twin
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
158 getcolor(const char *colstr
) {
159 Colormap cmap
= DefaultColormap(dpy
, screen
);
162 if(!XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
))
163 eprint("error, cannot allocate color '%s'\n", colstr
);
168 setfont(const char *fontstr
) {
169 char **missing
, *def
;
173 setlocale(LC_ALL
, "");
175 XFreeFontSet(dpy
, dc
.font
.set
);
176 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
179 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
180 XFreeStringList(missing
);
182 XFreeFontSet(dpy
, dc
.font
.set
);
187 XFontSetExtents
*font_extents
;
188 XFontStruct
**xfonts
;
190 dc
.font
.ascent
= dc
.font
.descent
= 0;
191 font_extents
= XExtentsOfFontSet(dc
.font
.set
);
192 n
= XFontsOfFontSet(dc
.font
.set
, &xfonts
, &font_names
);
193 for(i
= 0, dc
.font
.ascent
= 0, dc
.font
.descent
= 0; i
< n
; i
++) {
194 if(dc
.font
.ascent
< (*xfonts
)->ascent
)
195 dc
.font
.ascent
= (*xfonts
)->ascent
;
196 if(dc
.font
.descent
< (*xfonts
)->descent
)
197 dc
.font
.descent
= (*xfonts
)->descent
;
203 XFreeFont(dpy
, dc
.font
.xfont
);
204 dc
.font
.xfont
= NULL
;
205 dc
.font
.xfont
= XLoadQueryFont(dpy
, fontstr
);
207 dc
.font
.xfont
= XLoadQueryFont(dpy
, "fixed");
209 eprint("error, cannot init 'fixed' font\n");
210 dc
.font
.ascent
= dc
.font
.xfont
->ascent
;
211 dc
.font
.descent
= dc
.font
.xfont
->descent
;
213 dc
.font
.height
= dc
.font
.ascent
+ dc
.font
.descent
;
217 textw(const char *text
) {
218 return textnw(text
, strlen(text
)) + dc
.font
.height
;