Xinqi Bao's Git
ff6f779dd32633ea1491c5836d2d41d716ba9541
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
, unsigned long col
[ColLast
], Bool highlight
)
29 unsigned int len
, olen
;
31 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
33 XSetForeground(dpy
, dc
.gc
, col
[ColBG
]);
34 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
40 olen
= len
= strlen(text
);
41 if(len
>= sizeof(buf
))
42 len
= sizeof(buf
) - 1;
43 memcpy(buf
, text
, len
);
46 h
= dc
.font
.ascent
+ dc
.font
.descent
;
47 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
50 /* shorten text if necessary */
51 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
63 return; /* too long */
64 gcv
.foreground
= col
[ColFG
];
66 XChangeGC(dpy
, dc
.gc
, GCForeground
, &gcv
);
67 XmbDrawString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
, x
, y
, buf
, len
);
70 gcv
.font
= dc
.font
.xfont
->fid
;
71 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCFont
, &gcv
);
72 XDrawString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
77 r
.width
= r
.height
= 3;
78 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
89 for(c
= clients
; c
; c
= getnext(c
->next
))
97 static const char *mode
[] = { "~", "=" };
104 modew
= textw(mode
[0]) > textw(mode
[1]) ? textw(mode
[0]) : textw(mode
[1]);
105 drawtext(mode
[arrange
== dotile
? 1 : 0], dc
.status
, False
);
109 for(i
= 0; i
< ntags
; i
++) {
111 dc
.w
= textw(tags
[i
]);
113 drawtext(tags
[i
], dc
.sel
, sel
&& sel
->tags
[i
]);
115 drawtext(tags
[i
], dc
.norm
, sel
&& sel
->tags
[i
]);
119 dc
.x
= bx
+ bw
- dc
.w
;
124 drawtext(stext
, dc
.status
, False
);
126 if(sel
&& ((dc
.w
= dc
.x
- x
) > bh
)) {
128 drawtext(sel
->name
, dc
.sel
, False
);
130 XCopyArea(dpy
, dc
.drawable
, barwin
, dc
.gc
, 0, 0, bw
, bh
, 0, 0);
139 if(c
== sel
&& issel
) {
141 XUnmapWindow(dpy
, c
->twin
);
142 XSetWindowBorder(dpy
, c
->win
, dc
.sel
[ColBG
]);
146 XSetWindowBorder(dpy
, c
->win
, dc
.norm
[ColBG
]);
147 XMapWindow(dpy
, c
->twin
);
150 drawtext(c
->name
, dc
.norm
, False
);
151 XCopyArea(dpy
, dc
.drawable
, c
->twin
, dc
.gc
, 0, 0, c
->tw
, c
->th
, 0, 0);
156 getcolor(const char *colstr
)
158 Colormap cmap
= DefaultColormap(dpy
, screen
);
161 XAllocNamedColor(dpy
, cmap
, colstr
, &color
, &color
);
166 setfont(const char *fontstr
)
168 char **missing
, *def
;
172 setlocale(LC_ALL
, "");
174 XFreeFontSet(dpy
, dc
.font
.set
);
175 dc
.font
.set
= XCreateFontSet(dpy
, fontstr
, &missing
, &n
, &def
);
178 fprintf(stderr
, "missing fontset: %s\n", missing
[n
]);
179 XFreeStringList(missing
);
181 XFreeFontSet(dpy
, dc
.font
.set
);
186 XFontSetExtents
*font_extents
;
187 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
)
219 return textnw(text
, strlen(text
)) + dc
.font
.height
;