short cut highlighting with colors works, but there's no sane defaults right now... github/shortcut-color origin/shortcut-color shortcut-color
authorDana Jansens <danakj@orodu.net>
Thu, 19 Jul 2007 16:34:20 +0000 (12:34 -0400)
committerDana Jansens <danakj@orodu.net>
Tue, 24 Jul 2007 18:44:21 +0000 (14:44 -0400)
render/font.c
render/font.h
render/render.h
render/theme.c
render/theme.h

index 8d389d8b5e81b73ff5015d3ee2743c09cb313f0d..47c5f6aa3e5447fddce6d4b42d22a1e7f33aeee1 100644 (file)
@@ -66,23 +66,19 @@ RrFont *RrFontOpen(const RrInstance *inst, const gchar *name, gint size,
     RrFont *out;
     PangoWeight pweight;
     PangoStyle pstyle;
-    PangoAttrList *attrlist;
 
     out = g_new(RrFont, 1);
     out->inst = inst;
     out->ref = 1;
     out->font_desc = pango_font_description_new();
     out->layout = pango_layout_new(inst->pango);
+
     out->shortcut_underline = pango_attr_underline_new(PANGO_UNDERLINE_LOW);
     out->shortcut_underline->start_index = 0;
     out->shortcut_underline->end_index = 0;
 
-    attrlist = pango_attr_list_new();
-    /* shortcut_underline is owned by the attrlist */
-    pango_attr_list_insert(attrlist, out->shortcut_underline);
-    /* the attributes are owned by the layout */
-    pango_layout_set_attributes(out->layout, attrlist);
-    pango_attr_list_unref(attrlist);
+    out->underline_attrlist = pango_attr_list_new();
+    pango_attr_list_insert(out->underline_attrlist, out->shortcut_underline);
 
     switch (weight) {
     case RR_FONTWEIGHT_LIGHT:     pweight = PANGO_WEIGHT_LIGHT;     break;
@@ -131,6 +127,7 @@ void RrFontClose(RrFont *f)
 {
     if (f) {
         if (--f->ref < 1) {
+            pango_attr_list_unref(f->underline_attrlist);
             g_object_unref(f->layout);
             pango_font_description_free(f->font_desc);
             g_free(f);
@@ -205,7 +202,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
     XftColor c;
     gint mw;
     PangoRectangle rect;
-    PangoAttrList *attrlist;
     PangoEllipsizeMode ell;
 
     /* center the text vertically
@@ -279,18 +275,28 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
 
     if (t->shortcut) {
         const gchar *c = t->string + t->shortcut_pos;
+        PangoAttribute *pa;
+        PangoAttrList *al;
+
+        if (t->shortcut_color) {
+            pa = pango_attr_foreground_new
+                (t->shortcut_color->r + (t->shortcut_color->r << 8),
+                 t->shortcut_color->g + (t->shortcut_color->g << 8),
+                 t->shortcut_color->b + (t->shortcut_color->b << 8));
+            al = pango_attr_list_new();
+            pango_attr_list_insert(al, pa);
+        }
+        else {
+            pa = t->font->shortcut_underline;
+            al = t->font->underline_attrlist;
+            pango_attr_list_ref(al);
+        }
 
-        t->font->shortcut_underline->start_index = t->shortcut_pos;
-        t->font->shortcut_underline->end_index = t->shortcut_pos +
-            (g_utf8_next_char(c) - c);
-
-        /* the attributes are owned by the layout.
-           re-add the attributes to the layout after changing the
-           start and end index */
-        attrlist = pango_layout_get_attributes(t->font->layout);
-        pango_attr_list_ref(attrlist);
-        pango_layout_set_attributes(t->font->layout, attrlist);
-        pango_attr_list_unref(attrlist);
+        pa->start_index = t->shortcut_pos;
+        pa->end_index = t->shortcut_pos + (g_utf8_next_char(c) - c);
+
+        pango_layout_set_attributes(t->font->layout, al);
+        pango_attr_list_unref(al);
     }
 
     /* layout_line() uses y to specify the baseline
@@ -299,15 +305,6 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *area)
         (d, &c, pango_layout_get_line(t->font->layout, 0),
          x * PANGO_SCALE, y * PANGO_SCALE);
 
-    if (t->shortcut) {
-        t->font->shortcut_underline->start_index = 0;
-        t->font->shortcut_underline->end_index = 0;
-        /* the attributes are owned by the layout.
-           re-add the attributes to the layout after changing the
-           start and end index */
-        attrlist = pango_layout_get_attributes(t->font->layout);
-        pango_attr_list_ref(attrlist);
-        pango_layout_set_attributes(t->font->layout, attrlist);
-        pango_attr_list_unref(attrlist);
-    }
+    if (t->shortcut)
+        pango_layout_set_attributes(t->font->layout, NULL);
 }
index 07d648d145a0b2cccf3f13bf5a96d33f1ad0013d..e548b75fdf5940917c3830e3ea7fb999d7cd8c95 100644 (file)
@@ -28,7 +28,8 @@ struct _RrFont {
     gint ref;
     PangoFontDescription *font_desc;
     PangoLayout *layout; /*!< Used for measuring and rendering strings */
-    PangoAttribute *shortcut_underline; /*< For underlining the shortcut key */
+    PangoAttribute *shortcut_underline; /*!< For underlining shortcuts */
+    PangoAttrList  *underline_attrlist; /*!< For underlining shortcuts */
     gint ascent; /*!< The font's ascent in pango-units */
     gint descent; /*!< The font's descent in pango-units */
 };
@@ -39,4 +40,9 @@ void RrFontDraw(XftDraw *d, RrTextureText *t, RrRect *position);
   and then really close it */
 void RrFontRef(RrFont *f);
 
+void RrFontSetShortcutNormalColor(RrFont *f, RrColor *c);
+void RrFontSetShortcutDisabledColor(RrFont *f, RrColor *c);
+void RrFontSetShortcutSelectedColor(RrFont *f, RrColor *c);
+void RrFontSetShortcutDisabledSelectedColor(RrFont *f, RrColor *c);
+
 #endif /* __font_h */
index 1f87c6e08a91648b1a0e799f81d36b071c2c317a..311a70f8208ad68bb60af17ea52cbdcb04d2263e 100644 (file)
@@ -25,6 +25,7 @@
 #include "version.h"
 
 #include <X11/Xlib.h> /* some platforms dont include this as needed for Xft */
+#include <pango/pango.h>
 #include <pango/pangoxft.h>
 #include <glib.h>
 
@@ -138,8 +139,9 @@ struct _RrTextureText {
     gint shadow_offset_y;
     RrColor *shadow_color;
     guchar shadow_alpha;
-    gboolean shortcut; /*!< Underline a character */
-    guint shortcut_pos; /*!< Position in bytes of the character to underline */
+    gboolean shortcut; /*!< Underline/hilight a character */
+    guint shortcut_pos; /*!< Position in bytes of the character to hilight */
+    RrColor *shortcut_color; /*!< Color for the hilighted character, or NULL */
     RrEllipsizeMode ellipsize;
 };
 
@@ -247,7 +249,8 @@ void          RrAppearanceFree (RrAppearance *a);
 void          RrAppearanceAddTextures(RrAppearance *a, gint numtex);
 
 RrFont *RrFontOpen          (const RrInstance *inst, const gchar *name,
-                             gint size, RrFontWeight weight, RrFontSlant slant);
+                             gint size, RrFontWeight weight,
+                             RrFontSlant slant);
 RrFont *RrFontOpenDefault   (const RrInstance *inst);
 void    RrFontClose         (RrFont *f);
 RrSize *RrFontMeasureString (const RrFont *f, const gchar *str,
index a793ced71f6a8021ca296f31c2d955bfbd94adba..9c2dc2b31eb02e8cbb8f57015f035299ab015744 100644 (file)
@@ -401,6 +401,37 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
                     "menu.items.active.text.color",
                     &theme->menu_selected_color))
         theme->menu_selected_color = RrColorNew(inst, 0, 0, 0);
+    if (!read_color(db, inst,
+                    "menu.items.text.shortcut.color",
+                    &theme->menu_shortcut_color))
+        theme->menu_shortcut_color = NULL;
+    if (!read_color(db, inst,
+                    "menu.items.disabled.text.shortcut.color",
+                    &theme->menu_disabled_shortcut_color))
+        theme->menu_disabled_shortcut_color =
+            theme->menu_shortcut_color == NULL ? NULL :
+            RrColorNew(inst,
+                       theme->menu_shortcut_color->r,
+                       theme->menu_shortcut_color->g,
+                       theme->menu_shortcut_color->b);
+    if (!read_color(db, inst,
+                    "menu.items.disabled.text.shortcut.color",
+                    &theme->menu_disabled_selected_shortcut_color))
+        theme->menu_disabled_selected_shortcut_color =
+            theme->menu_shortcut_color == NULL ? NULL :
+            RrColorNew(inst,
+                       theme->menu_shortcut_color->r,
+                       theme->menu_shortcut_color->g,
+                       theme->menu_shortcut_color->b);
+    if (!read_color(db, inst,
+                    "menu.items.active.text.shortcut.color",
+                    &theme->menu_selected_shortcut_color))
+        theme->menu_selected_shortcut_color =
+            theme->menu_shortcut_color == NULL ? NULL :
+            RrColorNew(inst,
+                       theme->menu_shortcut_color->r,
+                       theme->menu_shortcut_color->g,
+                       theme->menu_shortcut_color->b);
 
     /* load the image masks */
 
@@ -1034,12 +1065,20 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
         theme->a_menu_text_disabled_selected->texture[0].data.text.font =
         theme->menu_font;
     theme->a_menu_text_normal->texture[0].data.text.color = theme->menu_color;
+    theme->a_menu_text_normal->texture[0].data.text.shortcut_color =
+        theme->menu_shortcut_color;
     theme->a_menu_text_selected->texture[0].data.text.color =
         theme->menu_selected_color;
+    theme->a_menu_text_selected->texture[0].data.text.shortcut_color =
+        theme->menu_selected_shortcut_color;
     theme->a_menu_text_disabled->texture[0].data.text.color =
         theme->menu_disabled_color;
+    theme->a_menu_text_disabled->texture[0].data.text.shortcut_color =
+        theme->menu_disabled_shortcut_color;
     theme->a_menu_text_disabled_selected->texture[0].data.text.color =
         theme->menu_disabled_selected_color;
+    theme->a_menu_text_disabled_selected->texture[0].data.text.shortcut_color =
+        theme->menu_disabled_selected_shortcut_color;
 
     if (read_string(db, "menu.items.font", &str)) {
         char *p;
@@ -1421,6 +1460,10 @@ void RrThemeFree(RrTheme *theme)
         RrColorFree(theme->menu_selected_color);
         RrColorFree(theme->menu_disabled_color);
         RrColorFree(theme->menu_disabled_selected_color);
+        RrColorFree(theme->menu_shortcut_color);
+        RrColorFree(theme->menu_selected_shortcut_color);
+        RrColorFree(theme->menu_disabled_shortcut_color);
+        RrColorFree(theme->menu_disabled_selected_shortcut_color);
         RrColorFree(theme->title_focused_shadow_color);
         RrColorFree(theme->title_unfocused_shadow_color);
         RrColorFree(theme->osd_color);
index 2c35284f466b50dba4855edffc75bd57cdf1f572..25ae841dad72e366beec5e828fca8f5e142c0ed5 100644 (file)
@@ -87,6 +87,10 @@ struct _RrTheme {
     RrColor *menu_selected_color;
     RrColor *menu_disabled_color;
     RrColor *menu_disabled_selected_color;
+    RrColor *menu_shortcut_color;
+    RrColor *menu_selected_shortcut_color;
+    RrColor *menu_disabled_shortcut_color;
+    RrColor *menu_disabled_selected_shortcut_color;
     RrColor *title_focused_shadow_color;
     gchar    title_focused_shadow_alpha;
     RrColor *title_unfocused_shadow_color;