Skip to content

Commit bd2696a

Browse files
committed
Add determine_icon_destination() function
1 parent 9809314 commit bd2696a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fi
144144
rm -f a.out
145145

146146
# appimaged, an optional component
147-
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags gio-2.0) $(pkg-config --libs gio-2.0) -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimaged # liblz4
147+
cc -std=gnu99 -D_FILE_OFFSET_BITS=64 -DHAVE_LIBARCHIVE3=$have_libarchive3 -DVERSION_NUMBER=\"$(git describe --tags --always --abbrev=7)\" ../getsection.c ../notify.c -Wl,-Bdynamic ../elf.c ../appimaged.c ../squashfuse/.libs/libsquashfuse.a ../squashfuse/.libs/libfuseprivate.a -I../squashfuse/ -Wl,-Bstatic -linotifytools -Wl,-Bdynamic -larchive${archive_n} $(pkg-config --cflags --libs glib-2.0) $(pkg-config --cflags --libs gio-2.0) $(pkg-config --libs --cflags cairo) -ldl -lpthread -lz -Wl,-Bstatic -llzma -Wl,-Bdynamic -o appimaged # liblz4
148148

149149
cd ..
150150

shared.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656

5757
#include <regex.h>
5858

59+
#include <cairo.h> // To get the size of icons, determine_icon_destination()
60+
5961
#define FNM_FILE_NAME 2
6062

6163
#define URI_MAX (FILE_MAX * 3 + 8)
@@ -125,6 +127,56 @@ char * get_thumbnail_path(char *path, char *thumbnail_size, gboolean verbose)
125127
return thumbnail_path;
126128
}
127129

130+
/* Return the path where a given icon can be installed in $HOME.
131+
* This is needed because png and xpm icons cannot be installed in a generic
132+
* location but are only picked up in directories that have the size of
133+
* the icon as part of their directory name, as specified in the theme.index
134+
* See https://github.com/probonopd/AppImageKit/issues/258
135+
*/
136+
137+
gchar* determine_icon_destination(gchar *icon_path)
138+
{
139+
gchar *dest_dir;
140+
141+
if((g_str_has_suffix (icon_path, ".svg")) || (g_str_has_suffix (icon_path, ".svgz"))) {
142+
dest_dir = g_build_path("/", g_get_user_data_dir(), "/icons/hicolor/scalable", NULL);
143+
}
144+
145+
if((g_str_has_suffix (icon_path, ".png")) || (g_str_has_suffix (icon_path, ".xpm"))) {
146+
147+
cairo_surface_t *image;
148+
149+
if(g_str_has_suffix (icon_path, ".xpm")) {
150+
// TODO: GdkPixbuf has a convenient way to load XPM data. Then you can call
151+
// gdk_cairo_set_source_pixbuf() to transfer the data to a Cairo surface.
152+
fprintf(stderr, "XPM size parsing not yet implemented\n");
153+
return NULL;
154+
}
155+
156+
if(g_str_has_suffix (icon_path, ".png")) {
157+
image = cairo_image_surface_create_from_png(icon_path);
158+
}
159+
160+
int w = cairo_image_surface_get_width (image);
161+
int h = cairo_image_surface_get_height (image);
162+
163+
// FIXME: The following sizes are taken from the hicolor icon theme.
164+
// Probably the right thing to do would be to figure out at runtime which icon sizes are allowable.
165+
// Or could we put our own index.theme into .local/share/icons/ and have it observed?
166+
if((w != h) || ((w != 16) && (w != 24) && (w != 32) && (w != 36) && (w != 48) && (w != 64) && (w != 72) && (w != 96) && (w != 128) && (w != 192) && (w != 256) && (w != 512))){
167+
fprintf(stderr, "%s has nonstandard size w = %i, h = %i; please fix it\n", icon_path, w, h);
168+
return NULL;
169+
}
170+
171+
cairo_surface_destroy (image);
172+
173+
dest_dir = g_build_path("/", g_get_user_data_dir(), "/icons/hicolor/", g_strdup_printf("%ix%i", w, h), NULL);
174+
}
175+
176+
return(dest_dir);
177+
178+
}
179+
128180
/* Check if a file is an AppImage. Returns the image type if it is, or -1 if it isn't */
129181
int check_appimage_type(char *path, gboolean verbose)
130182
{

0 commit comments

Comments
 (0)