--- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./Makefile.am 2008-03-27 15:24:29.000000000 +0100 +++ ./Makefile.am 2008-04-04 16:30:45.000000000 +0200 @@ -132,6 +132,7 @@ openbox_openbox_CPPFLAGS = \ $(GLIB_CFLAGS) \ $(LIBSN_CFLAGS) \ $(XML_CFLAGS) \ + $(IMLIB2_CFLAGS) \ -DLOCALEDIR=\"$(localedir)\" \ -DDATADIR=\"$(datadir)\" \ -DCONFIGDIR=\"$(configdir)\" \ @@ -150,6 +151,7 @@ openbox_openbox_LDADD = \ $(XML_LIBS) \ $(EFENCE_LIBS) \ $(LIBINTL) \ + $(IMLIB2_LIBS) \ render/libobrender.la \ parser/libobparser.la openbox_openbox_LDFLAGS = -export-dynamic @@ -231,6 +233,7 @@ openbox_openbox_SOURCES = \ openbox/grab.h \ openbox/group.c \ openbox/group.h \ + openbox/imageload.h \ openbox/keyboard.c \ openbox/keyboard.h \ openbox/keytree.c \ @@ -278,6 +281,10 @@ openbox_openbox_SOURCES = \ openbox/xerror.c \ openbox/xerror.h +if USE_IMLIB2 + openbox_openbox_SOURCES += openbox/imageload.c +endif + ## gnome-panel-control ## --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./openbox/imageload.h 1970-01-01 01:00:00.000000000 +0100 +++ ./openbox/imageload.h 2008-04-02 23:10:37.000000000 +0200 @@ -0,0 +1,11 @@ +#ifndef __imageload_h +#define __imageload_h + +#ifdef USE_IMLIB2 +#include "render/render.h" +RrImage* RrImageFetchFromFile(RrImageCache *cache, const gchar *name); +#else +#define RrImageFetchFromFile(cache, name) NULL +#endif + +#endif --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./openbox/menu.c 2008-03-27 14:56:31.000000000 +0100 +++ ./openbox/menu.c 2008-04-03 22:08:15.000000000 +0200 @@ -36,6 +36,7 @@ #include "client_list_combined_menu.h" #include "gettext.h" #include "parser/parse.h" +#include "imageload.h" typedef struct _ObMenuParseState ObMenuParseState; @@ -267,8 +268,20 @@ static void parse_menu_item(ObParseInst { ObMenuParseState *state = data; gchar *label; + #ifdef USE_IMLIB2 + gchar *icon; + #endif + ObMenuEntry *e; if (state->parent) { + #ifdef USE_IMLIB2 + /* Don't try to extract "icon" attribute if icons in user-defined + menus are not enabled. */ + if (!(config_menu_user_show_icons && + parse_attr_string("icon", node, &icon))) + icon = NULL; + #endif + if (parse_attr_string("label", node, &label)) { GSList *acts = NULL; @@ -278,7 +291,17 @@ static void parse_menu_item(ObParseInst if (a) acts = g_slist_append(acts, a); } - menu_add_normal(state->parent, -1, label, acts, TRUE); + e = menu_add_normal(state->parent, -1, label, acts, TRUE); + + #ifdef USE_IMLIB2 + if (icon) { /* Icon will be used. */ + e->data.normal.icon = RrImageFetchFromFile(ob_rr_icons, icon); + if (e->data.normal.icon) { + e->data.normal.icon_alpha = 0xff; + } + g_free(icon); + } + #endif g_free(label); } } --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./openbox/config.h 2008-03-27 14:56:32.000000000 +0100 +++ ./openbox/config.h 2008-04-02 23:19:44.000000000 +0200 @@ -183,6 +183,8 @@ extern guint config_submenu_show_dela extern gboolean config_menu_client_list_icons; /*! Show manage desktops in client_list_menu */ extern gboolean config_menu_manage_desktops; +/*! Load & show icons in user-defined menus */ +extern gboolean config_menu_user_show_icons; /*! User-specified menu files */ extern GSList *config_menu_files; /*! Per app settings */ --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./openbox/imageload.c 1970-01-01 01:00:00.000000000 +0100 +++ ./openbox/imageload.c 2008-04-05 16:07:46.000000000 +0200 @@ -0,0 +1,135 @@ +/* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- + imageload.c for the Openbox window manager + by Libor Kadlcik (aka KadlSoft) +*/ + +/* + All loaded images are cached. There's no separate cache for the images, + instead they are simply stored in image cache (RrImageCache) as RrImages, + ready to be used. + Every RrImage loaded from file is associated with name of the file. This is + done by file name table (RrImageCache.file_name_table), which is a simple + hash table, where file names are keys to pointers to RrImage. + If you request to load file that is already in image cache, nothing will be + loaded and you just got the RrImage from cache. + When RrImage is destroyed (see RrImageDestroyNotify), the file name - pointer + to RrImage pair is removed from the file name table. +*/ + +#include "debug.h" +#include "menu.h" +#include "openbox.h" +#include "gettext.h" +#include "render/render.h" +#include "render/image.h" +#include "render/imagecache.h" +#include "imageload.h" +#include + + +static void CreateFileNameTable(RrImageCache *self) +{ + g_assert(self->file_name_table == NULL); + self->file_name_table = g_hash_table_new(&g_str_hash, &g_str_equal); +} + +static void DestroyFileNameTable(RrImageCache *self) +{ + g_assert(g_hash_table_size(self->file_name_table) == 0); + g_hash_table_destroy(self->file_name_table); + self->file_name_table = NULL; +} + +/*! Return file name from which this image has been loaded. */ +static gchar* GetFileName(RrImage *image) +{ + GHashTableIter iter; + void *key, *value; + + g_hash_table_iter_init(&iter, image->cache->file_name_table); + while (g_hash_table_iter_next(&iter, &key, &value)) { + if (value == image) + return key; + } + return NULL; +} + +/* RrImage is about to be deleted. So remove it from file name table. */ +static void RrImageDestroyNotify(RrImage *image) +{ + gchar *file_name = GetFileName(image); + g_assert(file_name != NULL); + ob_debug("Image \"%s\" no longer needed\n", file_name); + g_hash_table_remove(image->cache->file_name_table, file_name); + g_free(file_name); + + if (g_hash_table_size(image->cache->file_name_table) == 0) { + ob_debug("No RrImage in file_name_table, destroying\n"); + DestroyFileNameTable(image->cache); + } +} + +#if (RrDefaultAlphaOffset != 24 || RrDefaultRedOffset != 16 \ + || RrDefaultGreenOffset != 8 || RrDefaultBlueOffset != 0) +#error RrImageFetchFromFile cannot handle current bit layout of RrPixel32. +#endif + +/*! Load image from specified file and create RrImage for it (RrImage will be + linked into specified image cache). Reference count of the RrImage will + be set to 1. + If that image has already been loaded into the image cache, RrImage + from the cache will be returned and its reference count will be incremented. +*/ +RrImage* RrImageFetchFromFile(RrImageCache *cache, const gchar *name) +{ + RrImage *rr_image, *found_rr_image; + gint w, h; + DATA32 *ro_data; + + imlib_set_color_usage(128); + + if (cache->file_name_table == NULL) + CreateFileNameTable(cache); + + /* Find out if that image has already been loaded to this cache. */ + rr_image = g_hash_table_lookup(cache->file_name_table, name); + if (rr_image && rr_image->cache == cache) { + ob_debug("\"%s\" already loaded in this image cache.\n", name); + RrImageRef(rr_image); + return rr_image; + } + + Imlib_Image imlib_image = imlib_load_image(name); + if (imlib_image == NULL) { + g_message(_("Cannot load image from file \"%s\""), name); + return NULL; + } + + /* Get data and dimensions of the image. */ + imlib_context_set_image(imlib_image); + g_message("Alpha = %d\n", imlib_image_has_alpha()); + ro_data = imlib_image_get_data_for_reading_only(); + w = imlib_image_get_width(); + h = imlib_image_get_height(); + ob_debug("Loaded \"%s\", dimensions %dx%d\n", name, w, h); + + /* There must not be any duplicated pictures in RrImageCache. */ + found_rr_image = RrImageCacheFind(cache, ro_data, w, h); + if (found_rr_image) { + rr_image = found_rr_image; + RrImageRef(rr_image); + ob_debug("Image \"%s\" is duplicate\n", name); + } + else { + /* Create RrImage from the image and add it to file name table. */ + rr_image = RrImageNew(cache); + RrImageSetDestroyFunc(rr_image, &RrImageDestroyNotify); + /* XXX: Is Imlib2's format of DATA32 always identical to RrPixel32? */ + RrImageAddPicture(rr_image, ro_data, w, h); + g_hash_table_insert(cache->file_name_table, g_strdup(name), rr_image); + } + + imlib_free_image(); + + return rr_image; +} --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./openbox/config.c 2008-04-03 19:57:27.000000000 +0200 +++ ./openbox/config.c 2008-04-05 16:23:27.000000000 +0200 @@ -90,6 +90,7 @@ gboolean config_menu_middle; guint config_submenu_show_delay; gboolean config_menu_client_list_icons; gboolean config_menu_manage_desktops; +gboolean config_menu_user_show_icons; GSList *config_menu_files; @@ -800,6 +801,14 @@ static void parse_menu(ObParseInst *i, x config_menu_client_list_icons = parse_bool(doc, n); if ((n = parse_find_node("manageDesktops", node))) config_menu_manage_desktops = parse_bool(doc, n); + if ((n = parse_find_node("showIcons", node))) { + config_menu_user_show_icons = parse_bool(doc, n); + #ifndef USE_IMLIB2 + if (config_menu_user_show_icons) + g_message(_("Openbox was compiled without Imlib2." + " Icons in user-defined menus will NOT be loaded.")); + #endif + } while ((node = parse_find_node("file", node))) { gchar *c = parse_string(doc, node); @@ -1000,6 +1009,7 @@ void config_startup(ObParseInst *i) config_menu_client_list_icons = TRUE; config_menu_manage_desktops = TRUE; config_menu_files = NULL; + config_menu_user_show_icons = TRUE; parse_register(i, "menu", parse_menu, NULL); --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./render/image.c 2008-03-27 14:56:32.000000000 +0100 +++ ./render/image.c 2008-04-03 23:11:11.000000000 +0200 @@ -315,6 +315,12 @@ RrImage* RrImageNew(RrImageCache *cache) return self; } +/*! Set function that will be called just before RrImage is destroyed. */ +void RrImageSetDestroyFunc(RrImage *image, RrImageDestroyFunc func) +{ + image->destroy_func = func; +} + void RrImageRef(RrImage *self) { ++self->ref; @@ -327,6 +333,8 @@ void RrImageUnref(RrImage *self) g_message("Refcount to 0, removing ALL pictures from the cache:\n " "Image 0x%x", (guint)self); #endif + if (self->destroy_func) + self->destroy_func(self); while (self->n_original > 0) RemovePicture(self, &self->original, 0, &self->n_original); while (self->n_resized > 0) --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./render/imagecache.c 2008-02-29 22:18:12.000000000 +0100 +++ ./render/imagecache.c 2008-04-03 23:12:32.000000000 +0200 @@ -34,6 +34,7 @@ RrImageCache* RrImageCacheNew(gint max_r self->max_resized_saved = max_resized_saved; self->table = g_hash_table_new((GHashFunc)RrImagePicHash, (GEqualFunc)RrImagePicEqual); + self->file_name_table = NULL; return self; } @@ -46,6 +47,7 @@ void RrImageCacheUnref(RrImageCache *sel { if (self && --self->ref == 0) { g_assert(g_hash_table_size(self->table) == 0); + g_assert(self->file_name_table == NULL); g_hash_table_unref(self->table); g_free(self); --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./render/render.h 2008-02-29 22:18:08.000000000 +0100 +++ ./render/render.h 2008-04-05 11:37:15.000000000 +0200 @@ -232,6 +232,8 @@ struct _RrImagePic { gint sum; }; +typedef void (*RrImageDestroyFunc)(RrImage *image); + /*! An RrImage is a sort of meta-image. It can contain multiple versions of an image at different sizes, which may or may not be completely different pictures */ @@ -250,6 +252,10 @@ struct _RrImage { RrImage. */ RrImagePic **resized; gint n_resized; + + /* This function (if not NULL) will be called just before destroying + RrImage. */ + RrImageDestroyFunc destroy_func; }; /* these are the same on all endian machines because it seems to be dependant --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./render/image.h 2008-02-29 22:18:12.000000000 +0100 +++ ./render/image.h 2008-04-05 11:38:52.000000000 +0200 @@ -32,4 +32,6 @@ void RrImageDrawRGBA(RrPixel32 *target, gint target_w, gint target_h, RrRect *area); +void RrImageSetDestroyFunc(RrImage *image, RrImageDestroyFunc func); + #endif --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./render/imagecache.h 2008-02-29 22:18:12.000000000 +0100 +++ ./render/imagecache.h 2008-04-03 23:11:27.000000000 +0200 @@ -46,6 +46,10 @@ struct _RrImageCache { gint max_resized_saved; GHashTable *table; + + /* Used to find out if an image file has already been loaded. + Quick file_name -> RrImage lookup. */ + GHashTable *file_name_table; }; #endif --- /usr/src/orig/openbox-3.4.7-pre3-parse_menu/./configure.ac 2008-03-27 15:01:50.000000000 +0100 +++ ./configure.ac 2008-04-04 16:49:52.000000000 +0200 @@ -136,6 +136,33 @@ else xcursor_found=no fi +AC_ARG_ENABLE(imlib2, + AC_HELP_STRING( + [--disable-imlib2], + [disable use of Imlib2 image library for loading icons. [[default=enabled]]] + ), + [enable_imlib2=$enableeval], + [enable_imlib2=yes] +) + +if test "$enable_imlib2" = yes; then +PKG_CHECK_MODULES(IMLIB2, [imlib2], + [ + AC_DEFINE(USE_IMLIB2, [1], [Use Imlib2 image library]) + AC_SUBST(IMLIB2_CFLAGS) + AC_SUBST(IMLIB2_LIBS) + imlib2_found=yes + ], + [ + imlib2_found=no + ] +) +else + imlib2_found=no +fi + +AM_CONDITIONAL(USE_IMLIB2, [test $imlib2_found = yes]) + dnl Check for session management X11_SM @@ -171,5 +198,6 @@ AC_MSG_RESULT([Compiling with these opti Startup Notification... $sn_found X Cursor Library... $xcursor_found Session Management... $SM + Imlib2 library... $imlib2_found ]) AC_MSG_RESULT([configure complete, now type "make"])