summaryrefslogtreecommitdiff
path: root/obrender
diff options
context:
space:
mode:
authorKadlcik Libor <KadlSoft@seznam.cz>2008-03-25 21:58:12 +0100
committerDana Jansens <danakj@orodu.net>2010-01-08 17:55:19 -0500
commit0352abfa88892bc17bdff2022745e3c1b312edd0 (patch)
treeec8ec1c23f98e1bada7beb8b80acd22e2df2cebe /obrender
parent63f748aa3fac4d3ed004a2c5343a51c3a046e21d (diff)
This patch implements support for icons in user-defined menus into Openbox
Image loading is done using the Imlib2 library. I chose Imlib2 because it's pretty fast, it's easy to use, supports many file formats (tested xpm, gif, jpeg, png) and doesn't introduce too much bloat (it depends :)). I ported the patch to 3.4.7-pre3 and added some enhancements. Caching is much better now, and icons can be disabled at compile time using --disable-imlib2 option. What's new? Syntax of configuration files (namely rc.xml and menu.xml) has been changed slightly to allow users to associate icons to menu entries. This is done by specifying path to icon file in the new "icon" attribute in "<item>" element, e.g: <item label="Vim" icon="/usr/share/pixmaps/vim-32.xpm"> <action name="Execute"><execute>x-terminal-emulator -T Vim -e vim</execute></action> </item> If user doesn't want to display any icons in his user-defined menus, he/she can disable icons in rc.xml, inside "<menu>" section: <menu> ... <showIcons>no</showIcons> ... </menu> Default value is "yes". (New boolean variable "config_menu_user_show_icons" has been added to source code.) An icon is loaded (using menu_item_attach_icon()) when a new entry of menu is created. Fortunately, I haven't notice any performance problems because of this :).
Diffstat (limited to 'obrender')
-rw-r--r--obrender/image.c8
-rw-r--r--obrender/imagecache.c2
-rw-r--r--obrender/imagecache.h4
-rw-r--r--obrender/render.h6
4 files changed, 20 insertions, 0 deletions
diff --git a/obrender/image.c b/obrender/image.c
index 924504fd..c65cd2a5 100644
--- a/obrender/image.c
+++ b/obrender/image.c
@@ -325,6 +325,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;
@@ -339,6 +345,8 @@ void RrImageUnref(RrImage *self)
"Image 0x%lx", (gulong)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)
diff --git a/obrender/imagecache.c b/obrender/imagecache.c
index 9c605f9d..fde1e7a0 100644
--- a/obrender/imagecache.c
+++ b/obrender/imagecache.c
@@ -34,6 +34,7 @@ RrImageCache* RrImageCacheNew(gint max_resized_saved)
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 *self)
{
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);
diff --git a/obrender/imagecache.h b/obrender/imagecache.h
index 4ad2deae..a61fae67 100644
--- a/obrender/imagecache.h
+++ b/obrender/imagecache.h
@@ -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
diff --git a/obrender/render.h b/obrender/render.h
index 7bea1b54..7aa9d698 100644
--- a/obrender/render.h
+++ b/obrender/render.h
@@ -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