commit c46e7e5b622670ea1528ab9ac3c9c8c47adc872c
parent 923b7d40f5aae53a13f75782ab67d64c920fe33b
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Tue, 25 Apr 2006 13:33:30 +0200
proceeded with better name property rendering
Diffstat:
8 files changed, 34 insertions(+), 39 deletions(-)
diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c
@@ -127,7 +127,7 @@ draw_bar()
l->rect.y = 0;
l->rect.width = brect.height;
if(strlen(l->data))
- l->rect.width += XTextWidth(blitzfont.xfont, l->data, strlen(l->data));
+ l->rect.width += blitz_textwidth(dpy, &blitzfont, l->data);
l->rect.height = brect.height;
w += l->rect.width;
}
diff --git a/cmd/wm/client.c b/cmd/wm/client.c
@@ -22,25 +22,25 @@ static void
update_client_name(Client *c)
{
XTextProperty name;
+ int n;
+ char **list = nil;
+ name.nitems = 0;
c->name[0] = 0;
- XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
- if(name.value && name.nitems && name.encoding == UTF8_STRING && name.format == 8) {
- int n;
- char **list = nil;
- if(Xutf8TextPropertyToTextList(dpy, &name, &list, &n) == Success
+ XGetWMName(dpy, c->win, &name);
+ if(!name.nitems)
+ return;
+ if(name.encoding == XA_STRING)
+ cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
+ else {
+ if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
&& n > 0 && *list)
{
cext_strlcpy(c->name, *list, sizeof(c->name));
XFreeStringList(list);
}
- XFree(name.value);
- return;
- }
- if(XGetWMName(dpy, c->win, &name) && name.value) {
- cext_strlcpy(c->name, (char *)name.value, sizeof(c->name));
- XFree(name.value);
}
+ XFree(name.value);
}
Client *
@@ -217,7 +217,7 @@ prop_client(Client *c, XPropertyEvent *e)
}
break;
}
- if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) {
+ if(e->atom == XA_WM_NAME) {
update_client_name(c);
if(c->frame.size)
draw_client(c);
@@ -265,7 +265,7 @@ draw_client(Client *c)
idx_of_frame(c->frame.data[c->sel]) + 1,
c->frame.data[c->sel]->area->frame.size);
d.align = CENTER;
- d.rect.width = d.rect.height + XTextWidth(blitzfont.xfont, buf, strlen(buf));
+ d.rect.width = d.rect.height + blitz_textwidth(dpy, &blitzfont, buf);
d.data = buf;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
@@ -275,7 +275,7 @@ draw_client(Client *c)
}
/* tag bar */
- d.rect.width = d.rect.height + XTextWidth(blitzfont.xfont, c->tags, strlen(c->tags));
+ d.rect.width = d.rect.height + blitz_textwidth(dpy, &blitzfont, c->tags);
d.data = c->tags;
blitz_drawlabel(dpy, &d);
blitz_drawborder(dpy, &d);
diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c
@@ -121,14 +121,6 @@ init_atoms()
wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
-
- net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
- net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
-
- XChangeProperty(dpy, root, net_atom[NetSupported],
- XA_ATOM, 32, PropModeReplace, (unsigned char *)net_atom, NetLast);
-
- UTF8_STRING = XInternAtom(dpy, "UTF8_STRING", False);
}
static void
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -18,13 +18,6 @@ enum {
WMLast
};
-/* NET atoms */
-enum {
- NetSupported,
- NetWMName,
- NetLast
-};
-
/* Column modes */
enum {
Coldefault,
@@ -189,8 +182,6 @@ XRectangle brect;
Qid root_qid;
Default def;
Atom wm_atom[WMLast];
-Atom net_atom[NetLast];
-Atom UTF8_STRING;
Cursor cursor[CurLast];
unsigned int valid_mask;
unsigned int num_lock_mask;
diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c
@@ -68,7 +68,7 @@ update_offsets()
return;
for(i = curroff; i < item.size; i++) {
- w += XTextWidth(draw.font.xfont, item.data[i], strlen(item.data[i])) + mrect.height;
+ w += blitz_textwidth(dpy, &draw.font, item.data[i]) + mrect.height;
if(w > mrect.width)
break;
}
@@ -76,7 +76,7 @@ update_offsets()
w = cmdw + 2 * seek;
for(i = curroff; i > 0; i--) {
- w += XTextWidth(draw.font.xfont, item.data[i], strlen(item.data[i])) + mrect.height;
+ w += blitz_textwidth(dpy, &draw.font, item.data[i]) + mrect.height;
if(w > mrect.width)
break;
}
@@ -143,8 +143,7 @@ draw_menu()
for(i = curroff; i < nextoff; i++) {
draw.data = item.data[i];
draw.rect.x = offx;
- draw.rect.width = XTextWidth(draw.font.xfont, draw.data,
- strlen(draw.data)) + mrect.height;
+ draw.rect.width = blitz_textwidth(dpy, &draw.font, draw.data) + mrect.height;
offx += draw.rect.width;
if(sel == i) {
draw.color = selcolor;
@@ -308,7 +307,7 @@ read_allitems()
}
if(maxname)
- cmdw = XTextWidth(draw.font.xfont, maxname, max) + mrect.height;
+ cmdw = blitz_textwidth(dpy, &draw.font, maxname) + mrect.height;
}
int
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -37,6 +37,7 @@ typedef struct {
} BlitzDraw;
/* font.c */
+unsigned int blitz_textwidth(Display *dpy, BlitzFont *font, char *text);
void blitz_loadfont(Display *dpy, BlitzFont *font, char *fontstr);
/* color.c */
diff --git a/liblitz/draw.c b/liblitz/draw.c
@@ -102,8 +102,8 @@ xdrawtext(Display *dpy, BlitzDraw *d)
}
XSetBackground(dpy, d->gc, d->color.bg);
XSetForeground(dpy, d->gc, d->color.fg);
- if(0 && d->font.set)
- Xutf8DrawString(dpy, d->drawable, d->font.set, d->gc, x, y, text, len);
+ if(d->font.set)
+ XmbDrawString(dpy, d->drawable, d->font.set, d->gc, x, y, text, len);
else
XDrawString(dpy, d->drawable, d->gc, x, y, text, len);
}
diff --git a/liblitz/font.c b/liblitz/font.c
@@ -5,10 +5,22 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <cext.h>
#include "blitz.h"
+unsigned int
+blitz_textwidth(Display *dpy, BlitzFont *font, char *text)
+{
+ XRectangle r;
+ if(font->set) {
+ XmbTextExtents(font->set, text, strlen(text), nil, &r);
+ return r.width;
+ }
+ return XTextWidth(font->xfont, text, strlen(text));
+}
+
void
blitz_loadfont(Display *dpy, BlitzFont *font, char *fontstr)
{