[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: disappearing title bar text, switching screens
On Mon, Oct 15, 2007 at 11:41:22PM +0200, Julien Danjou wrote:
> At 1192172648 time_t, Nikos Ntarmos wrote:
> > I just tried compiling awesome against latest cairo from git and
> > pixman-0.9.4 and the problem persists. The previously attached patch
> > also fixes the situation.
>
> I finally could reproduce this bug using Xephyr.
> The problem disapear if you diable the Xrender extension.
>
> I have no idea where the bug is for now.
Could you please try with the attached patch? It uses cairo primitives
to draw the text on the statusbar instead of Xft*() functions. It works
for me but cairo is not actually my field of expertise, so <insert
standard disclaimer> and ymmv.
--- patch-drawtext-cairo begins here ---
diff --git a/draw.c b/draw.c
index f038315..eaf5424 100644
--- a/draw.c
+++ b/draw.c
@@ -20,6 +20,7 @@
*/
#include <cairo.h>
+#include <cairo-ft.h>
#include <cairo-xlib.h>
#include <math.h>
#include "layout.h"
@@ -32,19 +33,30 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, Drawable drawabl
int nw = 0;
static char buf[256];
size_t len, olen;
- XRenderColor xrcolor;
- XftColor xftcolor;
- XftDraw *xftdrawable;
+ int realx = 0, realy = 0;
+ cairo_font_extents_t fe;
+ cairo_font_face_t *font_face;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_text_extents_t te;
drawrectangle(disp, screen, x, y, w, h, drawable, dw, dh, True, color[ColBG]);
if(!a_strlen(text))
return;
+
+ surface = cairo_xlib_surface_create(disp, drawable, DefaultVisual(disp, screen), dw, dh);
+ cr = cairo_create(surface);
+ font_face = (cairo_font_face_t *)cairo_ft_font_face_create_for_pattern(font->pattern);
+ cairo_set_font_face(cr, font_face);
+ cairo_set_font_size(cr, font->height);
+ cairo_set_source_rgb(cr, color[ColFG].red / 65535.0, color[ColFG].green / 65535.0, color[ColFG].blue / 65535.0);
+
olen = len = a_strlen(text);
if(len >= sizeof(buf))
len = sizeof(buf) - 1;
memcpy(buf, text, len);
buf[len] = 0;
- while(len && (nw = textwidth(disp, font, buf, len)) > w - font->height)
+ while(len && (nw = textwidth(disp, font, buf, len)) > w)
buf[--len] = 0;
if(nw > w)
return; /* too long */
@@ -57,17 +69,17 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, Drawable drawabl
if(len > 3)
buf[len - 3] = '.';
}
- xrcolor.red = color[ColFG].red;
- xrcolor.green = color[ColFG].green;
- xrcolor.blue = color[ColFG].blue;
- XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xrcolor, &xftcolor);
- xftdrawable = XftDrawCreate(disp, drawable, DefaultVisual(disp, screen), DefaultColormap(disp, screen));
- XftDrawStringUtf8(xftdrawable, &xftcolor, font,
- x + (font->height / 2),
- y + (h / 2) - (font->height / 2) + font->ascent,
- (XftChar8 *) buf, len);
- XftColorFree(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xftcolor);
- XftDrawDestroy(xftdrawable);
+
+ cairo_font_extents(cr, &fe);
+ cairo_text_extents(cr, buf, &te);
+ realx = font->height / 2 + x;
+ realy = y + fe.height - fe.descent;
+ cairo_move_to(cr, realx, realy);
+ cairo_show_text(cr, buf);
+
+ cairo_font_face_destroy(font_face);
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
}
void
@@ -123,9 +135,27 @@ drawcircle(Display *disp, int screen, int x, int y, int r, Drawable drawable, in
unsigned short
textwidth(Display *disp, XftFont *font, char *text, ssize_t len)
{
- XGlyphInfo gi;
- XftTextExtentsUtf8(disp, font, (FcChar8 *) text, len, &gi);
- return gi.width;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_font_face_t *font_face;
+ cairo_text_extents_t te;
+ char * tmpstr = strdup(text);
+ tmpstr[len] = 0;
+ int dw = DisplayWidth(disp, 0);
+ int dh = DisplayHeight(disp, 0);
+
+ surface = cairo_xlib_surface_create(disp, 0, DefaultVisual(disp, 0), dw, dh);
+ cr = cairo_create(surface);
+ font_face = (cairo_font_face_t *)cairo_ft_font_face_create_for_pattern(font->pattern);
+ cairo_set_font_face(cr, font_face);
+ cairo_set_font_size(cr, font->height);
+ cairo_text_extents(cr, tmpstr, &te);
+ free(tmpstr);
+ cairo_destroy(cr);
+ cairo_surface_destroy(surface);
+ cairo_font_face_destroy(font_face);
+
+ return MAX(te.x_advance, te.width) + font->height;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99
diff --git a/event.c b/event.c
index 5ebc72d..a055d88 100644
--- a/event.c
+++ b/event.c
@@ -159,7 +159,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
{
for(i = 0; i < awesomeconf[screen].ntags; i++)
{
- x += textwidth(e->xany.display, awesomeconf[screen].font, awesomeconf[screen].tags[i].name, a_strlen(awesomeconf[screen].tags[i].name)) + awesomeconf[screen].font->height;
+ x += textwidth(e->xany.display, awesomeconf[screen].font, awesomeconf[screen].tags[i].name, a_strlen(awesomeconf[screen].tags[i].name));
if(ev->x < x)
{
if(ev->button == Button1)
diff --git a/statusbar.c b/statusbar.c
index ff889b7..04970c2 100644
--- a/statusbar.c
+++ b/statusbar.c
@@ -53,8 +53,7 @@ drawstatusbar(awesome_config * awesomeconf)
for(i = 0; i < awesomeconf->ntags; i++)
{
w = textwidth(awesomeconf->display, awesomeconf->font,
- awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name))
- + awesomeconf->font->height;
+ awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name));
if(awesomeconf->tags[i].selected)
{
drawtext(awesomeconf->display, awesomeconf->phys_screen,
@@ -108,8 +107,7 @@ drawstatusbar(awesome_config * awesomeconf)
awesomeconf->font,
awesomeconf->current_layout->symbol, awesomeconf->colors_normal);
z = x + awesomeconf->statusbar.txtlayoutwidth;
- w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext))
- + awesomeconf->font->height;
+ w = textwidth(awesomeconf->display, awesomeconf->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext));
x = awesomeconf->statusbar.width - w;
if(x < z)
{
@@ -212,7 +210,7 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf
for(i = 0; i < nlayouts; i++)
statusbar->txtlayoutwidth = MAX(statusbar->txtlayoutwidth,
- (font->height + textwidth(disp, font, layouts[i].symbol, a_strlen(layouts[i].symbol))));
+ (textwidth(disp, font, layouts[i].symbol, a_strlen(layouts[i].symbol))));
}
void
--- patch-drawtext-cairo ends here ---
Cheers...
\n\n
--
To unsubscribe, send mail to awesome-unsubscribe@xxxxxxxxxxxxx