|
|
@ -8,7 +8,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlocale.h>
|
|
|
|
#include <X11/Xlocale.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
#include "dwm.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
drawborder(void)
|
|
|
|
drawborder(void)
|
|
|
@ -59,7 +59,7 @@ draw(Bool border, const char *text)
|
|
|
|
x = dc.x + (h / 2);
|
|
|
|
x = dc.x + (h / 2);
|
|
|
|
|
|
|
|
|
|
|
|
/* shorten text if necessary */
|
|
|
|
/* shorten text if necessary */
|
|
|
|
while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h)
|
|
|
|
while(len && (w = textnw(buf, len)) > dc.w - h)
|
|
|
|
buf[--len] = 0;
|
|
|
|
buf[--len] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(w > dc.w)
|
|
|
|
if(w > dc.w)
|
|
|
@ -79,93 +79,80 @@ draw(Bool border, const char *text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
unsigned long
|
|
|
|
xinitcolors(Colormap cmap, const char *colstr)
|
|
|
|
initcolor(const char *colstr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XColor color;
|
|
|
|
XColor color;
|
|
|
|
|
|
|
|
Colormap cmap = DefaultColormap(dpy, screen);
|
|
|
|
|
|
|
|
|
|
|
|
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
|
|
|
|
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
|
|
|
|
return color.pixel;
|
|
|
|
return color.pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
initcolors(const char *bg, const char *fg, const char *border)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Colormap cmap = DefaultColormap(dpy, screen);
|
|
|
|
|
|
|
|
dc.bg = xinitcolors(cmap, bg);
|
|
|
|
|
|
|
|
dc.fg = xinitcolors(cmap, fg);
|
|
|
|
|
|
|
|
dc.border = xinitcolors(cmap, border);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
unsigned int
|
|
|
|
textnw(Fnt *font, char *text, unsigned int len)
|
|
|
|
textnw(char *text, unsigned int len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XRectangle r;
|
|
|
|
XRectangle r;
|
|
|
|
if(font->set) {
|
|
|
|
if(dc.font.set) {
|
|
|
|
XmbTextExtents(font->set, text, len, NULL, &r);
|
|
|
|
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
|
|
|
return r.width;
|
|
|
|
return r.width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return XTextWidth(font->xfont, text, len);
|
|
|
|
return XTextWidth(dc.font.xfont, text, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
unsigned int
|
|
|
|
textw(Fnt *font, char *text)
|
|
|
|
textw(char *text)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return textnw(font, text, strlen(text));
|
|
|
|
return textnw(text, strlen(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
|
|
|
|
texth(Fnt *font)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return font->height + 4;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
initfont(Fnt *font, const char *fontstr)
|
|
|
|
initfont(const char *fontstr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char **missing, *def;
|
|
|
|
char **missing, *def;
|
|
|
|
int i, n;
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
|
|
|
|
missing = NULL;
|
|
|
|
missing = NULL;
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
if(font->set)
|
|
|
|
if(dc.font.set)
|
|
|
|
XFreeFontSet(dpy, font->set);
|
|
|
|
XFreeFontSet(dpy, dc.font.set);
|
|
|
|
font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
|
|
|
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
|
|
|
if(missing) {
|
|
|
|
if(missing) {
|
|
|
|
while(n--)
|
|
|
|
while(n--)
|
|
|
|
fprintf(stderr, "missing fontset: %s\n", missing[n]);
|
|
|
|
fprintf(stderr, "missing fontset: %s\n", missing[n]);
|
|
|
|
XFreeStringList(missing);
|
|
|
|
XFreeStringList(missing);
|
|
|
|
if(font->set) {
|
|
|
|
if(dc.font.set) {
|
|
|
|
XFreeFontSet(dpy, font->set);
|
|
|
|
XFreeFontSet(dpy, dc.font.set);
|
|
|
|
font->set = NULL;
|
|
|
|
dc.font.set = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(font->set) {
|
|
|
|
if(dc.font.set) {
|
|
|
|
XFontSetExtents *font_extents;
|
|
|
|
XFontSetExtents *font_extents;
|
|
|
|
XFontStruct **xfonts;
|
|
|
|
XFontStruct **xfonts;
|
|
|
|
char **font_names;
|
|
|
|
char **font_names;
|
|
|
|
|
|
|
|
|
|
|
|
font->ascent = font->descent = 0;
|
|
|
|
dc.font.ascent = dc.font.descent = 0;
|
|
|
|
font_extents = XExtentsOfFontSet(font->set);
|
|
|
|
font_extents = XExtentsOfFontSet(dc.font.set);
|
|
|
|
n = XFontsOfFontSet(font->set, &xfonts, &font_names);
|
|
|
|
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
|
|
|
for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
|
|
|
|
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
|
|
|
if(font->ascent < (*xfonts)->ascent)
|
|
|
|
if(dc.font.ascent < (*xfonts)->ascent)
|
|
|
|
font->ascent = (*xfonts)->ascent;
|
|
|
|
dc.font.ascent = (*xfonts)->ascent;
|
|
|
|
if(font->descent < (*xfonts)->descent)
|
|
|
|
if(dc.font.descent < (*xfonts)->descent)
|
|
|
|
font->descent = (*xfonts)->descent;
|
|
|
|
dc.font.descent = (*xfonts)->descent;
|
|
|
|
xfonts++;
|
|
|
|
xfonts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
if(font->xfont)
|
|
|
|
if(dc.font.xfont)
|
|
|
|
XFreeFont(dpy, font->xfont);
|
|
|
|
XFreeFont(dpy, dc.font.xfont);
|
|
|
|
font->xfont = NULL;
|
|
|
|
dc.font.xfont = NULL;
|
|
|
|
font->xfont = XLoadQueryFont(dpy, fontstr);
|
|
|
|
dc.font.xfont = XLoadQueryFont(dpy, fontstr);
|
|
|
|
if (!font->xfont)
|
|
|
|
if (!dc.font.xfont)
|
|
|
|
font->xfont = XLoadQueryFont(dpy, "fixed");
|
|
|
|
dc.font.xfont = XLoadQueryFont(dpy, "fixed");
|
|
|
|
if (!font->xfont)
|
|
|
|
if (!dc.font.xfont)
|
|
|
|
error("error, cannot init 'fixed' font\n");
|
|
|
|
error("error, cannot init 'fixed' font\n");
|
|
|
|
font->ascent = font->xfont->ascent;
|
|
|
|
dc.font.ascent = dc.font.xfont->ascent;
|
|
|
|
font->descent = font->xfont->descent;
|
|
|
|
dc.font.descent = dc.font.xfont->descent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font->height = font->ascent + font->descent;
|
|
|
|
dc.font.height = dc.font.ascent + dc.font.descent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|