Merge branch 'backport' into work
[mikachu/openbox.git] / render / theme.c
index 8428f1d..8ead967 100644 (file)
@@ -23,7 +23,7 @@
 #include "mask.h"
 #include "theme.h"
 #include "icon.h"
-#include "parser/parse.h"
+#include "obt/paths.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xresource.h>
@@ -46,6 +46,22 @@ 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,
@@ -56,6 +72,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
     RrJustify winjust, mtitlejust;
     gchar *str;
     RrTheme *theme;
+    RrFont *default_font = NULL;
     gchar *path;
     gboolean userdef;
 
@@ -130,17 +147,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
     theme->osd_unhilite_fg = 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 +158,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 +168,9 @@ 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 = get_font(osd_font, &default_font, inst);
 
     /* load direct dimensions */
     if ((!read_int(db, "menu.overlap.x", &theme->menu_overlap_x) &&
@@ -211,6 +207,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,
@@ -408,6 +415,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 */
 
@@ -543,6 +556,16 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
         theme->menu_bullet_mask = RrPixmapMaskNew(inst, 4, 7, (gchar*)data);
     }
 
+    /* up and down arrows */
+    {
+        guchar data[] = { 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00 };
+        theme->down_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
+    }
+    {
+        guchar data[] = { 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00 };
+        theme->up_arrow_mask = RrPixmapMaskNew(inst, 9, 4, (gchar*)data);
+    }
+
     /* setup the default window icon */
     theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
                                        OB_DEFAULT_ICON_HEIGHT,
@@ -550,7 +573,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,
@@ -1408,6 +1430,7 @@ 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);
@@ -1454,6 +1477,8 @@ void RrThemeFree(RrTheme *theme)
         RrPixmapMaskFree(theme->close_hover_mask);
         RrPixmapMaskFree(theme->close_pressed_mask);
         RrPixmapMaskFree(theme->menu_bullet_mask);
+        RrPixmapMaskFree(theme->down_arrow_mask);
+        RrPixmapMaskFree(theme->up_arrow_mask);
 
         RrFontClose(theme->win_font_focused);
         RrFontClose(theme->win_font_unfocused);
@@ -1564,6 +1589,10 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
             *path = g_path_get_dirname(s);
         g_free(s);
     } else {
+        ObtPaths *p;
+
+        p = obt_paths_new();
+
         /* XXX backwards compatibility, remove me sometime later */
         s = g_build_filename(g_get_home_dir(), ".themes", name,
                              "openbox-3", "themerc", NULL);
@@ -1571,8 +1600,7 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
             *path = g_path_get_dirname(s);
         g_free(s);
 
-        for (it = parse_xdg_data_dir_paths(); !db && it;
-             it = g_slist_next(it))
+        for (it = obt_paths_data_dirs(p); !db && it; it = g_slist_next(it))
         {
             s = g_build_filename(it->data, "themes", name,
                                  "openbox-3", "themerc", NULL);
@@ -1580,6 +1608,8 @@ static XrmDatabase loaddb(const gchar *name, gchar **path)
                 *path = g_path_get_dirname(s);
             g_free(s);
         }
+
+        obt_paths_unref(p);
     }
 
     if (db == NULL) {
@@ -1745,7 +1775,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)