]> Dogcows Code - chaz/openbox/blobdiff - render/theme.c
add copyright headers, adjust --version output to include copyright, and --help outpu...
[chaz/openbox] / render / theme.c
index 3c2c8b2e0f7f0b87cd7ebc3d03dafe84e3a2012c..76289a782de8b4bfbdf1e8cdb0ee2f4ff5367fee 100644 (file)
@@ -1,8 +1,28 @@
+/* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
+
+   theme.c for the Openbox window manager
+   Copyright (c) 2003        Ben Jansens
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   See the COPYING file for a copy of the GNU General Public License.
+*/
+
 #include "render.h"
 #include "color.h"
 #include "font.h"
 #include "mask.h"
 #include "theme.h"
+#include "icon.h"
+#include "parser/parse.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xresource.h>
@@ -21,6 +41,7 @@ static gboolean read_mask(const RrInstance *inst,
 static gboolean read_appearance(XrmDatabase db, const RrInstance *inst,
                                 gchar *rname, RrAppearance *value,
                                 gboolean allow_trans);
+static RrPixel32* read_c_image(gint width, gint height, const guint8 *data);
 static void set_default_appearance(RrAppearance *a);
 
 RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
@@ -71,6 +92,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
 
     theme->app_hilite_bg = RrAppearanceNew(inst, 0);
     theme->app_unhilite_bg = RrAppearanceNew(inst, 0);
+    theme->app_hilite_fg = RrAppearanceNew(inst, 0);
+    theme->app_unhilite_fg = RrAppearanceNew(inst, 0);
     theme->app_hilite_label = RrAppearanceNew(inst, 1);
     theme->app_unhilite_label = RrAppearanceNew(inst, 1);
 
@@ -96,21 +119,21 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
     if (!read_string(db, "window.active.label.text.font", &font_str))
         font_str = "arial,sans:bold:pixelsize=10:shadow=y:shadowtint=50";
 
-    if (!(theme->winfont_focused = RrFontOpen(inst, font_str))) {
+    if (!(theme->win_font_focused = RrFontOpen(inst, font_str))) {
         RrThemeFree(theme);
         return NULL;
     }
-    theme->winfont_height = RrFontHeight(theme->winfont_focused);
+    theme->win_font_height = RrFontHeight(theme->win_font_focused);
 
     if (!read_string(db, "window.inactive.label.text.font", &font_str))
         /* font_str will already be set to the last one */;
 
-    if (!(theme->winfont_unfocused = RrFontOpen(inst, font_str))) {
+    if (!(theme->win_font_unfocused = RrFontOpen(inst, font_str))) {
         RrThemeFree(theme);
         return NULL;
     }
-    theme->winfont_height = MAX(theme->winfont_height,
-                                RrFontHeight(theme->winfont_unfocused));
+    theme->win_font_height = MAX(theme->win_font_height,
+                                RrFontHeight(theme->win_font_unfocused));
 
     winjust = RR_JUSTIFY_LEFT;
     if (read_string(db, "window.label.text.justify", &str)) {
@@ -123,11 +146,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
     if (!read_string(db, "menu.title.text.font", &font_str))
         font_str = "arial,sans:bold:pixelsize=12:shadow=y";
 
-    if (!(theme->mtitlefont = RrFontOpen(inst, font_str))) {
+    if (!(theme->menu_title_font = RrFontOpen(inst, font_str))) {
         RrThemeFree(theme);
         return NULL;
     }
-    theme->mtitlefont_height = RrFontHeight(theme->mtitlefont);
+    theme->menu_title_font_height = RrFontHeight(theme->menu_title_font);
 
     mtitlejust = RR_JUSTIFY_LEFT;
     if (read_string(db, "menu.title.text.justify", &str)) {
@@ -140,11 +163,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
     if (!read_string(db, "menu.items.font", &font_str))
         font_str = "arial,sans:bold:pixelsize=11:shadow=y";
 
-    if (!(theme->mfont = RrFontOpen(inst, font_str))) {
+    if (!(theme->menu_font = RrFontOpen(inst, font_str))) {
         RrThemeFree(theme);
         return NULL;
     }
-    theme->mfont_height = RrFontHeight(theme->mfont);
+    theme->menu_font_height = RrFontHeight(theme->menu_font);
 
     /* load direct dimensions */
     if (!read_int(db, "menu.overlap", &theme->menu_overlap) ||
@@ -323,6 +346,10 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
         theme->iconify_hover_mask = RrPixmapMaskCopy(theme->iconify_mask);
     }
 
+    theme->def_win_icon = read_c_image(OB_DEFAULT_ICON_WIDTH,
+                                       OB_DEFAULT_ICON_HEIGHT,
+                                       OB_DEFAULT_ICON_pixel_data);
+
     if (read_mask(inst, "desk.xbm", theme, &theme->desk_mask)) {
         if (!read_mask(inst, "desk_pressed.xbm", theme,
                        &theme->desk_pressed_mask)) {
@@ -472,6 +499,17 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
                          "window.active.label.bg", theme->app_hilite_label,
                          TRUE))
         set_default_appearance(theme->app_hilite_label);
+    if (!read_appearance(db, inst,
+                         "window.active.label.bg", theme->app_hilite_fg,
+                         TRUE))
+        set_default_appearance(theme->app_hilite_fg);
+    else if (theme->app_hilite_label->surface.grad == RR_SURFACE_PARENTREL) {
+        if (!read_appearance(db, inst,
+                             "window.active.title.bg",
+                             theme->app_hilite_fg,
+                             FALSE))
+            set_default_appearance(theme->app_hilite_fg);
+    }
     if (!read_appearance(db, inst,
                          "window.inactive.title.bg", theme->app_unhilite_bg,
                          FALSE))
@@ -480,6 +518,18 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
                          "window.inactive.label.bg", theme->app_unhilite_label,
                          TRUE))
         set_default_appearance(theme->app_unhilite_label);
+    if (!read_appearance(db, inst,
+                         "window.inactive.label.bg", theme->app_unhilite_fg,
+                         TRUE))
+        set_default_appearance(theme->app_unhilite_fg);
+    else if (theme->app_unhilite_label->surface.grad == RR_SURFACE_PARENTREL) {
+        if (!read_appearance(db, inst,
+                             "window.inactive.title.bg",
+                             theme->app_unhilite_fg,
+                             FALSE))
+            set_default_appearance(theme->app_unhilite_fg);
+    }
+        
 
     /* read buttons textures */
     if (!read_appearance(db, inst,
@@ -640,7 +690,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
     theme->app_hilite_label->texture[0].data.text.justify = RR_JUSTIFY_LEFT;
     theme->a_focused_label->texture[0].data.text.font =
         theme->app_hilite_label->texture[0].data.text.font =
-        theme->winfont_focused;
+        theme->win_font_focused;
     theme->a_focused_label->texture[0].data.text.color =
         theme->app_hilite_label->texture[0].data.text.color =
         theme->title_focused_color;
@@ -652,14 +702,14 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
         RR_JUSTIFY_LEFT;
     theme->a_unfocused_label->texture[0].data.text.font =
         theme->app_unhilite_label->texture[0].data.text.font =
-        theme->winfont_unfocused;
+        theme->win_font_unfocused;
     theme->a_unfocused_label->texture[0].data.text.color =
         theme->app_unhilite_label->texture[0].data.text.color =
         theme->title_unfocused_color;
 
     theme->a_menu_title->texture[0].type = RR_TEXTURE_TEXT;
     theme->a_menu_title->texture[0].data.text.justify = mtitlejust;
-    theme->a_menu_title->texture[0].data.text.font = theme->mtitlefont;
+    theme->a_menu_title->texture[0].data.text.font = theme->menu_title_font;
     theme->a_menu_title->texture[0].data.text.color = theme->menu_title_color;
 
     theme->a_menu_text_normal->texture[0].type =
@@ -671,7 +721,8 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
         RR_JUSTIFY_LEFT;
     theme->a_menu_text_normal->texture[0].data.text.font =
         theme->a_menu_text_disabled->texture[0].data.text.font =
-        theme->a_menu_text_selected->texture[0].data.text.font = theme->mfont;
+        theme->a_menu_text_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_disabled->texture[0].data.text.color =
         theme->menu_disabled_color;
@@ -863,13 +914,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
     XrmDestroyDatabase(db);
 
     {
-        gint fl, ft, fr, fb;
-        gint ul, ut, ur, ub;
+        gint ft, fb, fl, fr, ut, ub, ul, ur;
 
         RrMargins(theme->a_focused_label, &fl, &ft, &fr, &fb);
         RrMargins(theme->a_unfocused_label, &ul, &ut, &ur, &ub);
-        theme->label_height = theme->winfont_height
-            + MAX(ft + fb, ut + ub);
+        theme->label_height = theme->win_font_height + MAX(ft + fb, ut + ub);
 
         /* this would be nice I think, since padding.width can now be 0,
            but it breaks frame.c horribly and I don't feel like fixing that
@@ -883,6 +932,10 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
                 MAX(theme->padding * 2, ut + ub));
         */
         theme->title_height = theme->label_height + theme->padding * 2;
+        /* this should match the above title_height given the same font size
+           for both. */
+        theme->menu_title_height = theme->menu_title_font_height +
+            theme->padding * 2;
     }
     theme->button_size = theme->label_height - 2;
     theme->grip_width = theme->title_height * 1.5;
@@ -893,6 +946,7 @@ RrTheme* RrThemeNew(const RrInstance *inst, gchar *name)
 void RrThemeFree(RrTheme *theme)
 {
     if (theme) {
+        g_free(theme->path);
         g_free(theme->name);
 
         RrColorFree(theme->b_color);
@@ -915,6 +969,8 @@ void RrThemeFree(RrTheme *theme)
         RrColorFree(theme->menu_disabled_color);
         RrColorFree(theme->menu_selected_color);
 
+        g_free(theme->def_win_icon);
+
         RrPixmapMaskFree(theme->max_mask);
         RrPixmapMaskFree(theme->max_toggled_mask);
         RrPixmapMaskFree(theme->max_disabled_mask);
@@ -940,10 +996,10 @@ void RrThemeFree(RrTheme *theme)
         RrPixmapMaskFree(theme->close_pressed_mask);
         RrPixmapMaskFree(theme->menu_bullet_mask);
 
-        RrFontClose(theme->winfont_focused); 
-        RrFontClose(theme->winfont_unfocused);
-        RrFontClose(theme->mtitlefont);
-        RrFontClose(theme->mfont);
+        RrFontClose(theme->win_font_focused); 
+        RrFontClose(theme->win_font_unfocused);
+        RrFontClose(theme->menu_title_font);
+        RrFontClose(theme->menu_font);
 
         RrAppearanceFree(theme->a_disabled_focused_max);
         RrAppearanceFree(theme->a_disabled_unfocused_max);
@@ -1014,28 +1070,47 @@ void RrThemeFree(RrTheme *theme)
         RrAppearanceFree(theme->a_clear_tex);
         RrAppearanceFree(theme->app_hilite_bg);
         RrAppearanceFree(theme->app_unhilite_bg);
+        RrAppearanceFree(theme->app_hilite_fg);
+        RrAppearanceFree(theme->app_unhilite_fg);
         RrAppearanceFree(theme->app_hilite_label);
         RrAppearanceFree(theme->app_unhilite_label);
+
+        g_free(theme);
     }
 }
 
 static XrmDatabase loaddb(RrTheme *theme, char *name)
 {
-    XrmDatabase db;
+    GSList *it;
+    XrmDatabase db = NULL;
+    gchar *s;
 
-    char *s = g_build_filename(g_get_home_dir(), ".openbox", "themes",
-                               name, "themerc", NULL);
-    if ((db = XrmGetFileDatabase(s)))
-        theme->path = g_path_get_dirname(s);
-    g_free(s);
-    if (db == NULL) {
-       char *s = g_build_filename(THEMEDIR, name, "themerc", NULL);
+    if (name[0] == '/') {
+        s = g_build_filename(name, "openbox-3", "themerc", NULL);
        if ((db = XrmGetFileDatabase(s)))
             theme->path = g_path_get_dirname(s);
-       g_free(s);
+        g_free(s);
+    } else {
+        /* XXX backwards compatibility, remove me sometime later */
+        s = g_build_filename(g_get_home_dir(), ".themes", name,
+                             "openbox-3", "themerc", NULL);
+        if ((db = XrmGetFileDatabase(s)))
+            theme->path = g_path_get_dirname(s);
+        g_free(s);
+
+        for (it = parse_xdg_data_dir_paths(); !db && it;
+             it = g_slist_next(it))
+        {
+            s = g_build_filename(it->data, "themes", name,
+                                 "openbox-3", "themerc", NULL);
+            if ((db = XrmGetFileDatabase(s)))
+                theme->path = g_path_get_dirname(s);
+            g_free(s);
+        }
     }
+
     if (db == NULL) {
-        char *s = g_build_filename(name, "themerc", NULL);
+        s = g_build_filename(name, "themerc", NULL);
        if ((db = XrmGetFileDatabase(s)))
             theme->path = g_path_get_dirname(s);
         g_free(s);
@@ -1248,3 +1323,28 @@ static void set_default_appearance(RrAppearance *a)
     a->surface.primary = RrColorNew(a->inst, 0, 0, 0);
     a->surface.secondary = RrColorNew(a->inst, 0, 0, 0);
 }
+
+/* Reads the output from gimp's C-Source file format into valid RGBA data for
+   an RrTextureRGBA. */
+static RrPixel32* read_c_image(gint width, gint height, const guint8 *data)
+{
+    RrPixel32 *im, *p;
+    gint i;
+
+    p = im = g_memdup(data, width * height * sizeof(RrPixel32));
+
+    for (i = 0; i < width * height; ++i) {
+        guchar a = ((*p >> 24) & 0xff);
+        guchar b = ((*p >> 16) & 0xff);
+        guchar g = ((*p >>  8) & 0xff);
+        guchar r = ((*p >>  0) & 0xff);
+
+        *p = ((r << RrDefaultRedOffset) +
+              (g << RrDefaultGreenOffset) +
+              (b << RrDefaultBlueOffset) +
+              (a << RrDefaultAlphaOffset));
+        p++;
+    }
+
+    return im;
+}
This page took 0.029626 seconds and 4 git commands to generate.