Xinqi Bao's Git
de4bdb0e4feb377d2a3803d8c9076d35f7ebd9dd
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>
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(char *text
, unsigned int len
)
37 XmbTextExtents(dc
.font
.set
, text
, len
, NULL
, &r
);
40 return XTextWidth(dc
.font
.xfont
, text
, len
);
44 drawtext(const char *text
, Bool invert
, Bool border
)
50 XRectangle r
= { dc
.x
, dc
.y
, dc
.w
, dc
.h
};
52 XSetForeground(dpy
, dc
.gc
, invert
? dc
.fg
: dc
.bg
);
53 XFillRectangles(dpy
, dc
.drawable
, dc
.gc
, &r
, 1);
63 if(len
>= sizeof(buf
))
64 len
= sizeof(buf
) - 1;
65 memcpy(buf
, text
, len
);
68 h
= dc
.font
.ascent
+ dc
.font
.descent
;
69 y
= dc
.y
+ (dc
.h
/ 2) - (h
/ 2) + dc
.font
.ascent
;
72 /* shorten text if necessary */
73 while(len
&& (w
= textnw(buf
, len
)) > dc
.w
- h
)
77 return; /* too long */
79 gcv
.foreground
= invert
? dc
.bg
: dc
.fg
;
80 gcv
.background
= invert
? dc
.fg
: dc
.bg
;
82 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
, &gcv
);
83 XmbDrawImageString(dpy
, dc
.drawable
, dc
.font
.set
, dc
.gc
,
87 gcv
.font
= dc
.font
.xfont
->fid
;
88 XChangeGC(dpy
, dc
.gc
, GCForeground
| GCBackground
| GCFont
, &gcv
);
89 XDrawImageString(dpy
, dc
.drawable
, dc
.gc
, x
, y
, buf
, len
);
100 for(c
= clients
; c
; c
= getnext(c
->next
, tsel
))
109 Bool istile
= arrange
== dotile
;
113 drawtext(NULL
, !istile
, False
);
116 for(i
= 0; i
< TLast
; i
++) {
118 dc
.w
= textw(tags
[i
]);
120 drawtext(tags
[i
], (i
== tsel
), True
);
122 drawtext(tags
[i
], (i
!= tsel
), True
);
126 dc
.w
= textw(sel
->name
);
127 drawtext(sel
->name
, istile
, True
);
130 dc
.x
= bx
+ bw
- dc
.w
;
131 drawtext(stext
, !istile
, False
);
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
< TLast
; i
++) {
159 dc
.w
= textw(c
->tags
[i
]);
160 drawtext(c
->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
)
174 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
;
234 return textnw(text
, strlen(text
)) + dc
.font
.height
;