From f26f23de50cb7941a7702198e3b4d1b2f9de062e Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 9 May 2003 16:57:17 +0000 Subject: all my changes while i was offline. better alt-tabbing. better transient handling. i dont even know. lots of fucking cool shit so WATCH the FUCK OUT. --- render/font.c | 38 +++++++++++++++----- render/image.c | 110 +++++++++++++++++++++++++++++--------------------------- render/render.c | 23 +++++++----- render/render.h | 9 ++--- render/theme.c | 51 +++++++++++++------------- render/theme.h | 3 ++ 6 files changed, 134 insertions(+), 100 deletions(-) (limited to 'render') diff --git a/render/font.c b/render/font.c index 7ffcb53b..504063b9 100644 --- a/render/font.c +++ b/render/font.c @@ -8,6 +8,10 @@ #include #include "../kernel/geom.h" +#define ELIPSES "..." +#define ELIPSES_LENGTH(font, shadow, offset) \ + (font->elipses_length + (shadow ? offset : 0)) + void font_startup(void) { #ifdef DEBUG @@ -38,6 +42,11 @@ static void measure_height(ObFont *f) XftTextExtentsUtf8(ob_display, f->xftfont, (FcChar8*)str, strlen(str), &info); f->height = (signed) info.height; + + /* measure an elipses */ + XftTextExtentsUtf8(ob_display, f->xftfont, + (FcChar8*)ELIPSES, strlen(ELIPSES), &info); + f->elipses_length = (signed) info.xOff; } ObFont *font_open(char *fontstring) @@ -98,9 +107,10 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position) { int x,y,w,h; XftColor c; - char *text; - int m; + GString *text; + int m, em; size_t l; + gboolean shortened = FALSE; y = position->y; w = position->width; @@ -110,12 +120,22 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position) y -= (2 * (t->font->xftfont->ascent + t->font->xftfont->descent) - (t->font->height + h) - 1) / 2; - text = g_strdup(t->string); - l = strlen(text); - m = font_measure_string(t->font, text, t->shadow, t->offset); + text = g_string_new(t->string); + l = g_utf8_strlen(text->str, -1); + m = font_measure_string(t->font, text->str, t->shadow, t->offset); while (l && m > position->width) { - text[--l] = '\0'; - m = font_measure_string(t->font, text, t->shadow, t->offset); + shortened = TRUE; + /* remove a character from the middle */ + text = g_string_erase(text, l-- / 2, 1); + em = ELIPSES_LENGTH(t->font, t->shadow, t->offset); + /* if the elipses are too large, don't show them at all */ + if (em > position->width) + shortened = FALSE; + m = font_measure_string(t->font, text->str, t->shadow, t->offset) + em; + } + if (shortened) { + text = g_string_insert(text, (l + 1) / 2, ELIPSES); + l += 3; } if (!l) return; @@ -147,7 +167,7 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position) } XftDrawStringUtf8(d, &c, t->font->xftfont, x + t->offset, t->font->xftfont->ascent + y + t->offset, - (FcChar8*)text, l); + (FcChar8*)text->str, l); } c.color.red = t->color->r | t->color->r << 8; c.color.green = t->color->g | t->color->g << 8; @@ -157,6 +177,6 @@ void font_draw(XftDraw *d, TextureText *t, Rect *position) XftDrawStringUtf8(d, &c, t->font->xftfont, x, t->font->xftfont->ascent + y, - (FcChar8*)text, l); + (FcChar8*)text->str, l); return; } diff --git a/render/image.c b/render/image.c index bdc51eed..e0c5540f 100644 --- a/render/image.c +++ b/render/image.c @@ -5,66 +5,72 @@ void image_draw(pixel32 *target, TextureRGBA *rgba, Rect *position, Rect *surarea) { - unsigned long *draw = rgba->data; - int c, sfw, sfh; - unsigned int i, e; - sfw = position->width; - sfh = position->height; + gulong *draw = rgba->data; + guint c, i, e, t, sfw, sfh; + sfw = position->width; + sfh = position->height; - /* it would be nice if this worked, but this function is well broken in these - cercumstances. */ - g_assert(position->width == surarea->width && - position->height == surarea->height); + /* it would be nice if this worked, but this function is well broken in + these circumstances. */ + g_assert(position->width == surarea->width && + position->height == surarea->height); - g_assert(rgba->data != NULL); + g_assert(rgba->data != NULL); - if ((rgba->width != sfw || rgba->height != sfh) && - (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) { - double dx = rgba->width / (double)sfw; - double dy = rgba->height / (double)sfh; - double px = 0.0; - double py = 0.0; - int iy = 0; + if ((rgba->width != sfw || rgba->height != sfh) && + (rgba->width != rgba->cwidth || rgba->height != rgba->cheight)) { + double dx = rgba->width / (double)sfw; + double dy = rgba->height / (double)sfh; + double px = 0.0; + double py = 0.0; + int iy = 0; - /* scale it and cache it */ - if (rgba->cache != NULL) - g_free(rgba->cache); - rgba->cache = g_new(unsigned long, sfw * sfh); - rgba->cwidth = sfw; - rgba->cheight = sfh; - for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) { - rgba->cache[i] = rgba->data[(int)px + iy]; - if (++c >= sfw) { - c = 0; - px = 0; - py += dy; - iy = (int)py * rgba->width; - } else - px += dx; - } + /* scale it and cache it */ + if (rgba->cache != NULL) + g_free(rgba->cache); + rgba->cache = g_new(unsigned long, sfw * sfh); + rgba->cwidth = sfw; + rgba->cheight = sfh; + for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) { + rgba->cache[i] = rgba->data[(int)px + iy]; + if (++c >= sfw) { + c = 0; + px = 0; + py += dy; + iy = (int)py * rgba->width; + } else + px += dx; + } + + /* do we use the cache we may have just created, or the original? */ + if (rgba->width != sfw || rgba->height != sfh) + draw = rgba->cache; + + /* apply the alpha channel */ + for (i = 0, c = 0, t = position->x, e = sfw*sfh; i < e; ++i, ++t) { + guchar alpha, r, g, b, bgr, bgg, bgb; -/* do we use the cache we may have just created, or the original? */ - if (rgba->width != sfw || rgba->height != sfh) - draw = rgba->cache; + alpha = draw[i] >> 24; + r = draw[i] >> 16; + g = draw[i] >> 8; + b = draw[i]; - /* apply the alpha channel */ - for (i = 0, c = 0, e = sfw*sfh; i < e; ++i) { - unsigned char alpha = draw[i] >> 24; - unsigned char r = draw[i] >> 16; - unsigned char g = draw[i] >> 8; - unsigned char b = draw[i]; + if (c >= sfw) { + c = 0; + t += surarea->width - sfw; + } - /* background color */ - unsigned char bgr = target[i] >> default_red_shift; - unsigned char bgg = target[i] >> default_green_shift; - unsigned char bgb = target[i] >> default_blue_shift; + /* background color */ + bgr = target[t] >> default_red_shift; + bgg = target[t] >> default_green_shift; + bgb = target[t] >> default_blue_shift; - r = bgr + (((r - bgr) * alpha) >> 8); - g = bgg + (((g - bgg) * alpha) >> 8); - b = bgb + (((b - bgb) * alpha) >> 8); + r = bgr + (((r - bgr) * alpha) >> 8); + g = bgg + (((g - bgg) * alpha) >> 8); + b = bgb + (((b - bgb) * alpha) >> 8); - target[i] = (r << default_red_shift) | (g << default_green_shift) | - (b << default_blue_shift); + target[t] = (r << default_red_shift) | (g << default_green_shift) | + (b << default_blue_shift); + } } - } } diff --git a/render/render.c b/render/render.c index a1412741..804e6c36 100644 --- a/render/render.c +++ b/render/render.c @@ -7,6 +7,7 @@ #include "mask.h" #include "color.h" #include "image.h" +#include "theme.h" #include "kernel/openbox.h" #ifdef HAVE_STDLIB_H @@ -421,6 +422,7 @@ void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h) void appearance_minsize(Appearance *l, int *w, int *h) { int i; + int m; *w = *h = 1; switch (l->surface.type) { @@ -437,20 +439,22 @@ void appearance_minsize(Appearance *l, int *w, int *h) } else if (l->surface.data.planar.border) *w = *h = 2; - for (i = 0; i < l->textures; ++i) + for (i = 0; i < l->textures; ++i) { switch (l->texture[i].type) { case Bitmask: *w += l->texture[i].data.mask.mask->w; *h += l->texture[i].data.mask.mask->h; break; case Text: - *w +=font_measure_string(l->texture[i].data.text.font, - l->texture[i].data.text.string, - l->texture[i].data.text.shadow, - l->texture[i].data.text.offset); - *h += font_height(l->texture[i].data.text.font, - l->texture[i].data.text.shadow, - l->texture[i].data.text.offset); + m = font_measure_string(l->texture[i].data.text.font, + l->texture[i].data.text.string, + l->texture[i].data.text.shadow, + l->texture[i].data.text.offset); + *w += m; + m = font_height(l->texture[i].data.text.font, + l->texture[i].data.text.shadow, + l->texture[i].data.text.offset); + *h += m; break; case RGBA: *w += l->texture[i].data.rgba.width; @@ -458,7 +462,8 @@ void appearance_minsize(Appearance *l, int *w, int *h) break; case NoTexture: break; - } + } + } break; } } diff --git a/render/render.h b/render/render.h index d98cebde..006eaf4c 100644 --- a/render/render.h +++ b/render/render.h @@ -79,6 +79,7 @@ typedef struct Surface { typedef struct { XftFont *xftfont; int height; + int elipses_length; } ObFont; typedef enum { @@ -109,12 +110,12 @@ typedef struct TextureMask { } TextureMask; typedef struct TextureRGBA { - int width; - int height; + guint width; + guint height; unsigned long *data; /* cached scaled so we don't have to scale often */ - int cwidth; - int cheight; + guint cwidth; + guint cheight; unsigned long *cache; } TextureRGBA; diff --git a/render/theme.c b/render/theme.c index eccc2c8a..39079bd8 100644 --- a/render/theme.c +++ b/render/theme.c @@ -93,8 +93,11 @@ Appearance *theme_a_menu_item; Appearance *theme_a_menu_disabled; Appearance *theme_a_menu_hilite; +Appearance *theme_app_hilite_bg; +Appearance *theme_app_unhilite_bg; Appearance *theme_app_hilite_label; Appearance *theme_app_unhilite_label; +Appearance *theme_app_icon; void theme_startup() { @@ -151,8 +154,11 @@ void theme_startup() theme_a_menu_disabled = appearance_new(Surface_Planar, 1); theme_a_menu_hilite = appearance_new(Surface_Planar, 1); + theme_app_hilite_bg = appearance_new(Surface_Planar, 0); + theme_app_unhilite_bg = appearance_new(Surface_Planar, 0); theme_app_hilite_label = appearance_new(Surface_Planar, 1); theme_app_unhilite_label = appearance_new(Surface_Planar, 1); + theme_app_icon = appearance_new(Surface_Planar, 1); } @@ -221,8 +227,11 @@ void theme_shutdown() appearance_free(theme_a_menu_item); appearance_free(theme_a_menu_disabled); appearance_free(theme_a_menu_hilite); + appearance_free(theme_app_hilite_bg); + appearance_free(theme_app_unhilite_bg); appearance_free(theme_app_hilite_label); appearance_free(theme_app_unhilite_label); + appearance_free(theme_app_icon); } static XrmDatabase loaddb(char *theme) @@ -330,7 +339,7 @@ static gboolean read_mask(XrmDatabase db, char *rname, char *theme, if (XrmGetResource(db, rname, rclass, &rettype, &retvalue) && retvalue.addr != NULL) { - button_dir = g_strdup_printf("%s_buttons", theme); + button_dir = g_strdup_printf("%s_data", theme); s = g_build_filename(g_get_home_dir(), ".openbox", "themes", button_dir, retvalue.addr, NULL); @@ -348,7 +357,7 @@ static gboolean read_mask(XrmDatabase db, char *rname, char *theme, g_free(s); themename = g_path_get_basename(theme); - s = g_strdup_printf("%s/%s_buttons/%s", theme, + s = g_strdup_printf("%s/%s_data/%s", theme, themename, retvalue.addr); g_free(themename); if (XReadBitmapFileData(s, &w, &h, &b, &hx, &hy) == @@ -728,26 +737,15 @@ char *theme_load(char *theme) if (!read_appearance(db, "menu.hilite", theme_a_menu_hilite)) set_default_appearance(theme_a_menu_hilite); - /* read the appearances for rendering non-decorations. these cannot be - parent-relative */ - if (theme_a_focused_label->surface.data.planar.grad != - Background_ParentRelative) { - if (!read_appearance(db, "window.label.focus", theme_app_hilite_label)) - set_default_appearance(theme_app_hilite_label); - } else { - if (!read_appearance(db, "window.title.focus", theme_app_hilite_label)) - set_default_appearance(theme_app_hilite_label); - } - if (theme_a_unfocused_label->surface.data.planar.grad != - Background_ParentRelative) { - if (!read_appearance(db, "window.label.unfocus", - theme_app_unhilite_label)) - set_default_appearance(theme_app_unhilite_label); - } else { - if (!read_appearance(db, "window.title.unfocus", - theme_app_unhilite_label)) - set_default_appearance(theme_app_unhilite_label); - } + /* read the appearances for rendering non-decorations */ + if (!read_appearance(db, "window.title.focus", theme_app_hilite_bg)) + set_default_appearance(theme_app_hilite_bg); + if (!read_appearance(db, "window.label.focus", theme_app_hilite_label)) + set_default_appearance(theme_app_hilite_label); + if (!read_appearance(db, "window.title.unfocus", theme_app_unhilite_bg)) + set_default_appearance(theme_app_unhilite_bg); + if (!read_appearance(db, "window.label.unfocus", theme_app_unhilite_label)) + set_default_appearance(theme_app_unhilite_label); /* read buttons textures */ if (!read_appearance(db, "window.button.pressed.focus", @@ -817,8 +815,8 @@ char *theme_load(char *theme) /* set up the textures */ theme_a_focused_label->texture[0].type = theme_app_hilite_label->texture[0].type = Text; - theme_a_focused_label->texture[0].data.text.justify = - theme_app_hilite_label->texture[0].data.text.justify = winjust; + theme_a_focused_label->texture[0].data.text.justify = winjust; + theme_app_hilite_label->texture[0].data.text.justify = Justify_Left; theme_a_focused_label->texture[0].data.text.font = theme_app_hilite_label->texture[0].data.text.font = theme_winfont; theme_a_focused_label->texture[0].data.text.shadow = @@ -836,8 +834,8 @@ char *theme_load(char *theme) theme_a_unfocused_label->texture[0].type = theme_app_unhilite_label->texture[0].type = Text; - theme_a_unfocused_label->texture[0].data.text.justify = - theme_app_unhilite_label->texture[0].data.text.justify = winjust; + theme_a_unfocused_label->texture[0].data.text.justify = winjust; + theme_app_unhilite_label->texture[0].data.text.justify = Justify_Left; theme_a_unfocused_label->texture[0].data.text.font = theme_app_unhilite_label->texture[0].data.text.font = theme_winfont; theme_a_unfocused_label->texture[0].data.text.shadow = @@ -865,6 +863,7 @@ char *theme_load(char *theme) theme_a_menu_item->surface.data.planar.grad = theme_a_menu_disabled->surface.data.planar.grad = + theme_app_icon->surface.data.planar.grad = Background_ParentRelative; theme_a_menu_item->texture[0].type = diff --git a/render/theme.h b/render/theme.h index 97a58f9f..2a93c8df 100644 --- a/render/theme.h +++ b/render/theme.h @@ -78,8 +78,11 @@ extern Appearance *theme_a_menu_item; extern Appearance *theme_a_menu_disabled; extern Appearance *theme_a_menu_hilite; +extern Appearance *theme_app_hilite_bg; +extern Appearance *theme_app_unhilite_bg; extern Appearance *theme_app_hilite_label; extern Appearance *theme_app_unhilite_label; +extern Appearance *theme_app_icon; void theme_startup(); void theme_shutdown(); -- cgit v1.2.3