]> Dogcows Code - chaz/openbox/blobdiff - render/theme.c
make a config option for the inactive osd font
[chaz/openbox] / render / theme.c
index ec12dafbea9a2ec57d524c774b4b6164635f557d..6c136bf541f541cbc6a79da8de34ef626445022d 100644 (file)
@@ -46,16 +46,34 @@ static int parse_inline_number(const char *p);
 static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
 static void set_default_appearance(RrAppearance *a);
 
+static RrFont *get_font(RrFont *target, RrFont **default_font,
+                        const RrInstance *inst)
+{
+    if (target) {
+        RrFontRef(target);
+        return target;
+    } else {
+        /* Only load the default font once */
+        if (*default_font) {
+            RrFontRef(*default_font);
+        } else {
+            *default_font = RrFontOpenDefault(inst);
+        }
+        return *default_font;
+    }
+}
+
 RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
                     gboolean allow_fallback,
                     RrFont *active_window_font, RrFont *inactive_window_font,
                     RrFont *menu_title_font, RrFont *menu_item_font,
-                    RrFont *osd_font)
+                    RrFont *active_osd_font, RrFont *inactive_osd_font)
 {
     XrmDatabase db = NULL;
     RrJustify winjust, mtitlejust;
     gchar *str;
     RrTheme *theme;
+    RrFont *default_font = NULL;
     gchar *path;
     gboolean userdef;
 
@@ -124,23 +142,17 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
     theme->a_menu_bullet_selected = RrAppearanceNew(inst, 1);
     theme->a_clear = RrAppearanceNew(inst, 0);
     theme->a_clear_tex = RrAppearanceNew(inst, 1);
-    theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
+    theme->osd_bg = RrAppearanceNew(inst, 0);
     theme->osd_hilite_label = RrAppearanceNew(inst, 1);
-    theme->osd_hilite_fg = RrAppearanceNew(inst, 0);
-    theme->osd_unhilite_fg = RrAppearanceNew(inst, 0);
+    theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
+    theme->osd_unhilite_label = RrAppearanceNew(inst, 1);
+    theme->osd_unhilite_bg = RrAppearanceNew(inst, 0);
 
     /* load the font stuff */
-    if (active_window_font) {
-        theme->win_font_focused = active_window_font;
-        RrFontRef(active_window_font);
-    } else
-        theme->win_font_focused = RrFontOpenDefault(inst);
-
-    if (inactive_window_font) {
-        theme->win_font_unfocused = inactive_window_font;
-        RrFontRef(inactive_window_font);
-    } else
-        theme->win_font_unfocused = RrFontOpenDefault(inst);
+    theme->win_font_focused = get_font(active_window_font,
+                                       &default_font, inst);
+    theme->win_font_unfocused = get_font(inactive_window_font,
+                                         &default_font, inst);
 
     winjust = RR_JUSTIFY_LEFT;
     if (read_string(db, "window.label.text.justify", &str)) {
@@ -150,11 +162,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
             winjust = RR_JUSTIFY_CENTER;
     }
 
-    if (menu_title_font) {
-        theme->menu_title_font = menu_title_font;
-        RrFontRef(menu_title_font);
-    } else
-        theme->menu_title_font = RrFontOpenDefault(inst);
+    theme->menu_title_font = get_font(menu_title_font, &default_font, inst);
 
     mtitlejust = RR_JUSTIFY_LEFT;
     if (read_string(db, "menu.title.text.justify", &str)) {
@@ -164,17 +172,10 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
             mtitlejust = RR_JUSTIFY_CENTER;
     }
 
-    if (menu_item_font) {
-        theme->menu_font = menu_item_font;
-        RrFontRef(menu_item_font);
-    } else
-        theme->menu_font = RrFontOpenDefault(inst);
+    theme->menu_font = get_font(menu_item_font, &default_font, inst);
 
-    if (osd_font) {
-        theme->osd_font = osd_font;
-        RrFontRef(osd_font);
-    } else
-        theme->osd_font = RrFontOpenDefault(inst);
+    theme->osd_font_hilite = get_font(active_osd_font, &default_font, inst);
+    theme->osd_font_unhilite = get_font(inactive_osd_font, &default_font,inst);
 
     /* load direct dimensions */
     if ((!read_int(db, "menu.overlap.x", &theme->menu_overlap_x) &&
@@ -211,6 +212,17 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
     if (!read_int(db, "window.client.padding.height", &theme->cbwidthy) ||
         theme->cbwidthy < 0 || theme->cbwidthy > 100)
         theme->cbwidthy = theme->cbwidthx;
+    if (!read_int(db, "menu.separator.width", &theme->menu_sep_width) ||
+        theme->menu_sep_width < 1 || theme->menu_sep_width > 100)
+        theme->menu_sep_width = 1;
+    if (!read_int(db, "menu.separator.padding.width",
+                  &theme->menu_sep_paddingx) ||
+        theme->menu_sep_paddingx < 0 || theme->menu_sep_paddingx > 100)
+        theme->menu_sep_paddingx = 6;
+    if (!read_int(db, "menu.separator.padding.height",
+                  &theme->menu_sep_paddingy) ||
+        theme->menu_sep_paddingy < 0 || theme->menu_sep_paddingy > 100)
+        theme->menu_sep_paddingy = 3;
 
     /* load colors */
     if (!read_color(db, inst,
@@ -220,7 +232,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
                     "border.color",
                     &theme->frame_focused_border_color))
         theme->frame_focused_border_color = RrColorNew(inst, 0, 0, 0);
-    /* title separator focused color inherits from focused boder color */
+    /* title separator focused color inherits from focused border color */
     if (!read_color(db, inst,
                     "window.active.title.separator.color",
                     &theme->title_separator_focused_color))
@@ -237,7 +249,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
             RrColorNew(inst, theme->frame_focused_border_color->r,
                        theme->frame_focused_border_color->g,
                        theme->frame_focused_border_color->b);
-    /* title separator unfocused color inherits from unfocused boder color */
+    /* title separator unfocused color inherits from unfocused border color */
     if (!read_color(db, inst,
                     "window.inactive.title.separator.color",
                     &theme->title_separator_unfocused_color))
@@ -273,15 +285,26 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
                     "window.active.label.text.color",
                     &theme->title_focused_color))
         theme->title_focused_color = RrColorNew(inst, 0x0, 0x0, 0x0);
-    if (!read_color(db, inst, "osd.label.text.color", &theme->osd_color))
-        theme->osd_color = RrColorNew(inst,
-                                      theme->title_focused_color->r,
-                                      theme->title_focused_color->g,
-                                      theme->title_focused_color->b);
+    if (!read_color(db, inst, "osd.active.label.text.color",
+                    &theme->osd_text_active_color) &&
+        !read_color(db, inst, "osd.label.text.color",
+                    &theme->osd_text_active_color))
+        theme->osd_text_active_color =
+            RrColorNew(inst,
+                       theme->title_focused_color->r,
+                       theme->title_focused_color->g,
+                       theme->title_focused_color->b);
     if (!read_color(db, inst,
                     "window.inactive.label.text.color",
                     &theme->title_unfocused_color))
         theme->title_unfocused_color = RrColorNew(inst, 0xff, 0xff, 0xff);
+    if (!read_color(db, inst, "osd.inactive.label.text.color",
+                    &theme->osd_text_inactive_color))
+        theme->osd_text_inactive_color =
+            RrColorNew(inst,
+                       theme->title_unfocused_color->r,
+                       theme->title_unfocused_color->g,
+                       theme->title_unfocused_color->b);
     if (!read_color(db, inst,
                     "window.active.button.unpressed.image.color",
                     &theme->titlebut_focused_unpressed_color))
@@ -408,6 +431,12 @@ 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.separator.color", &theme->menu_sep_color))
+        theme->menu_sep_color = RrColorNew(inst,
+                                           theme->menu_color->r,
+                                           theme->menu_color->g,
+                                           theme->menu_color->b);
 
     /* load the image masks */
 
@@ -560,7 +589,6 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
     theme->def_win_icon_w = OB_DEFAULT_ICON_WIDTH;
     theme->def_win_icon_h = OB_DEFAULT_ICON_HEIGHT;
 
-
     /* read the decoration textures */
     if (!read_appearance(db, inst,
                          "window.active.title.bg", theme->a_focused_title,
@@ -610,32 +638,39 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
         RrAppearanceCopy(theme->a_menu_selected);
 
     /* read appearances for non-decorations (on-screen-display) */
-    if (!read_appearance(db, inst, "osd.bg", theme->osd_hilite_bg, FALSE)) {
-        RrAppearanceFree(theme->osd_hilite_bg);
-        theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
+    if (!read_appearance(db, inst, "osd.bg", theme->osd_bg, FALSE)) {
+        RrAppearanceFree(theme->osd_bg);
+        theme->osd_bg = RrAppearanceCopy(theme->a_focused_title);
     }
-    if (!read_appearance(db, inst, "osd.label.bg",
+    if (!read_appearance(db, inst, "osd.active.label.bg",
+                         theme->osd_hilite_label, TRUE) &&
+        !read_appearance(db, inst, "osd.label.bg",
                          theme->osd_hilite_label, TRUE)) {
         RrAppearanceFree(theme->osd_hilite_label);
         theme->osd_hilite_label = RrAppearanceCopy(theme->a_focused_label);
     }
+    if (!read_appearance(db, inst, "osd.inactive.label.bg",
+                         theme->osd_unhilite_label, TRUE)) {
+        RrAppearanceFree(theme->osd_unhilite_label);
+        theme->osd_unhilite_label = RrAppearanceCopy(theme->a_unfocused_label);
+    }
     /* osd_hilite_fg can't be parentrel */
     if (!read_appearance(db, inst, "osd.hilight.bg",
-                         theme->osd_hilite_fg, FALSE)) {
-        RrAppearanceFree(theme->osd_hilite_fg);
+                         theme->osd_hilite_bg, FALSE)) {
+        RrAppearanceFree(theme->osd_hilite_bg);
         if (theme->a_focused_label->surface.grad != RR_SURFACE_PARENTREL)
-            theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_label);
+            theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_label);
         else
-            theme->osd_hilite_fg = RrAppearanceCopy(theme->a_focused_title);
+            theme->osd_hilite_bg = RrAppearanceCopy(theme->a_focused_title);
     }
     /* osd_unhilite_fg can't be parentrel either */
     if (!read_appearance(db, inst, "osd.unhilight.bg",
-                         theme->osd_unhilite_fg, FALSE)) {
-        RrAppearanceFree(theme->osd_unhilite_fg);
+                         theme->osd_unhilite_bg, FALSE)) {
+        RrAppearanceFree(theme->osd_unhilite_bg);
         if (theme->a_unfocused_label->surface.grad != RR_SURFACE_PARENTREL)
-            theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_label);
+            theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_label);
         else
-            theme->osd_unhilite_fg=RrAppearanceCopy(theme->a_unfocused_title);
+            theme->osd_unhilite_bg=RrAppearanceCopy(theme->a_unfocused_title);
     }
 
     /* read buttons textures */
@@ -892,10 +927,21 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
 
     theme->osd_hilite_label->texture[0].type = RR_TEXTURE_TEXT;
     theme->osd_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
-    theme->osd_hilite_label->texture[0].data.text.font = theme->osd_font;
-    theme->osd_hilite_label->texture[0].data.text.color = theme->osd_color;
-
-    if (read_string(db, "osd.label.text.font", &str)) {
+    theme->osd_hilite_label->texture[0].data.text.font =
+        theme->osd_font_hilite;
+    theme->osd_hilite_label->texture[0].data.text.color =
+        theme->osd_text_active_color;
+
+    theme->osd_unhilite_label->texture[0].type = RR_TEXTURE_TEXT;
+    theme->osd_unhilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
+    theme->osd_unhilite_label->texture[0].data.text.font =
+        theme->osd_font_unhilite;
+    theme->osd_unhilite_label->texture[0].data.text.color =
+        theme->osd_text_inactive_color;
+
+    if (read_string(db, "osd.active.label.text.font", &str) ||
+        read_string(db, "osd.label.text.font", &str))
+    {
         char *p;
         gint i = 0;
         gint j;
@@ -904,8 +950,6 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
                 i = parse_inline_number(p + strlen("shadowoffset="));
             else
                 i = 1;
-            theme->a_focused_label->texture[0].data.text.shadow_offset_x = i;
-            theme->a_focused_label->texture[0].data.text.shadow_offset_y = i;
             theme->osd_hilite_label->texture[0].data.text.shadow_offset_x = i;
             theme->osd_hilite_label->texture[0].data.text.shadow_offset_y = i;
         }
@@ -915,11 +959,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
             j = (i > 0 ? 0 : 255);
             i = ABS(i*255/100);
 
-            theme->osd_shadow_color = RrColorNew(inst, j, j, j);
-            theme->osd_shadow_alpha = i;
+            theme->osd_text_active_shadow_color = RrColorNew(inst, j, j, j);
+            theme->osd_text_active_shadow_alpha = i;
         } else {
-            theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
-            theme->osd_shadow_alpha = 50;
+            theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
+            theme->osd_text_active_shadow_alpha = 50;
         }
     } else {
         /* inherit the font settings from the focused label */
@@ -928,20 +972,69 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
         theme->osd_hilite_label->texture[0].data.text.shadow_offset_y =
             theme->a_focused_label->texture[0].data.text.shadow_offset_y;
         if (theme->title_focused_shadow_color)
-            theme->osd_shadow_color =
+            theme->osd_text_active_shadow_color =
                 RrColorNew(inst,
                            theme->title_focused_shadow_color->r,
                            theme->title_focused_shadow_color->g,
                            theme->title_focused_shadow_color->b);
         else
-            theme->osd_shadow_color = RrColorNew(inst, 0, 0, 0);
-        theme->osd_shadow_alpha = theme->title_focused_shadow_alpha;
+            theme->osd_text_active_shadow_color = RrColorNew(inst, 0, 0, 0);
+        theme->osd_text_active_shadow_alpha =
+            theme->title_focused_shadow_alpha;
     }
 
     theme->osd_hilite_label->texture[0].data.text.shadow_color =
-        theme->osd_shadow_color;
+        theme->osd_text_active_shadow_color;
     theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
-        theme->osd_shadow_alpha;
+        theme->osd_text_active_shadow_alpha;
+
+    if (read_string(db, "osd.inactive.label.text.font", &str))
+    {
+        char *p;
+        gint i = 0;
+        gint j;
+        if (strstr(str, "shadow=y")) {
+            if ((p = strstr(str, "shadowoffset=")))
+                i = parse_inline_number(p + strlen("shadowoffset="));
+            else
+                i = 1;
+            theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x=i;
+            theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y=i;
+        }
+        if ((p = strstr(str, "shadowtint=")))
+        {
+            i = parse_inline_number(p + strlen("shadowtint="));
+            j = (i > 0 ? 0 : 255);
+            i = ABS(i*255/100);
+
+            theme->osd_text_inactive_shadow_color = RrColorNew(inst, j, j, j);
+            theme->osd_text_inactive_shadow_alpha = i;
+        } else {
+            theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
+            theme->osd_text_inactive_shadow_alpha = 50;
+        }
+    } else {
+        /* inherit the font settings from the focused label */
+        theme->osd_unhilite_label->texture[0].data.text.shadow_offset_x =
+            theme->a_unfocused_label->texture[0].data.text.shadow_offset_x;
+        theme->osd_unhilite_label->texture[0].data.text.shadow_offset_y =
+            theme->a_unfocused_label->texture[0].data.text.shadow_offset_y;
+        if (theme->title_unfocused_shadow_color)
+            theme->osd_text_inactive_shadow_color =
+                RrColorNew(inst,
+                           theme->title_unfocused_shadow_color->r,
+                           theme->title_unfocused_shadow_color->g,
+                           theme->title_unfocused_shadow_color->b);
+        else
+            theme->osd_text_inactive_shadow_color = RrColorNew(inst, 0, 0, 0);
+        theme->osd_text_inactive_shadow_alpha =
+            theme->title_unfocused_shadow_alpha;
+    }
+
+    theme->osd_unhilite_label->texture[0].data.text.shadow_color =
+        theme->osd_text_inactive_shadow_color;
+    theme->osd_unhilite_label->texture[0].data.text.shadow_alpha =
+        theme->osd_text_inactive_shadow_alpha;
 
     theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
     theme->a_unfocused_label->texture[0].data.text.justify = winjust;
@@ -1418,14 +1511,17 @@ void RrThemeFree(RrTheme *theme)
         RrColorFree(theme->titlebut_focused_unpressed_color);
         RrColorFree(theme->titlebut_unfocused_unpressed_color);
         RrColorFree(theme->menu_title_color);
+        RrColorFree(theme->menu_sep_color);
         RrColorFree(theme->menu_color);
         RrColorFree(theme->menu_selected_color);
         RrColorFree(theme->menu_disabled_color);
         RrColorFree(theme->menu_disabled_selected_color);
         RrColorFree(theme->title_focused_shadow_color);
         RrColorFree(theme->title_unfocused_shadow_color);
-        RrColorFree(theme->osd_color);
-        RrColorFree(theme->osd_shadow_color);
+        RrColorFree(theme->osd_text_active_color);
+        RrColorFree(theme->osd_text_inactive_color);
+        RrColorFree(theme->osd_text_active_shadow_color);
+        RrColorFree(theme->osd_text_inactive_shadow_color);
         RrColorFree(theme->menu_title_shadow_color);
         RrColorFree(theme->menu_text_normal_shadow_color);
         RrColorFree(theme->menu_text_selected_shadow_color);
@@ -1471,7 +1567,8 @@ void RrThemeFree(RrTheme *theme)
         RrFontClose(theme->win_font_unfocused);
         RrFontClose(theme->menu_title_font);
         RrFontClose(theme->menu_font);
-        RrFontClose(theme->osd_font);
+        RrFontClose(theme->osd_font_hilite);
+        RrFontClose(theme->osd_font_unhilite);
 
         RrAppearanceFree(theme->a_disabled_focused_max);
         RrAppearanceFree(theme->a_disabled_unfocused_max);
@@ -1555,10 +1652,11 @@ void RrThemeFree(RrTheme *theme)
         RrAppearanceFree(theme->a_menu_bullet_selected);
         RrAppearanceFree(theme->a_clear);
         RrAppearanceFree(theme->a_clear_tex);
+        RrAppearanceFree(theme->osd_bg);
         RrAppearanceFree(theme->osd_hilite_bg);
-        RrAppearanceFree(theme->osd_hilite_fg);
         RrAppearanceFree(theme->osd_hilite_label);
-        RrAppearanceFree(theme->osd_unhilite_fg);
+        RrAppearanceFree(theme->osd_unhilite_bg);
+        RrAppearanceFree(theme->osd_unhilite_label);
 
         g_free(theme);
     }
@@ -1762,7 +1860,6 @@ static void parse_appearance(gchar *tex, RrSurfaceColorType *grad,
         *interlaced = FALSE;
 }
 
-
 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
                                 const gchar *rname, RrAppearance *value,
                                 gboolean allow_trans)
This page took 0.034692 seconds and 4 git commands to generate.