Support icons other than the precached ones

This commit is contained in:
Kevin Lange 2014-05-03 13:51:37 -07:00
parent 9fce12f10c
commit 15ff21f104
4 changed files with 41 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -143,6 +143,44 @@ void panel_check_click(struct yutani_msg_window_mouse_event * evt) {
}
}
static char * icon_directories[] = {
"/usr/share/icons/24",
"/usr/share/icons/48",
"/usr/share/icons",
NULL
};
static sprite_t * icon_get(char * name) {
if (!strcmp(name,"")) {
return hashmap_get(icon_cache, "generic");
}
sprite_t * icon = hashmap_get(icon_cache, name);
if (!icon) {
/* See if we can find an icon by that name in any of our known icon directories */
int i = 0;
char path[100];
while (icon_directories[i]) {
sprintf(path, "%s/%s.png", icon_directories[i], name);
fprintf(stderr, "Checking %s for icon\n", path);
if (access(path, R_OK) == 0) {
icon = malloc(sizeof(sprite_t));
load_sprite_png(icon, path);
hashmap_set(icon_cache, name, icon);
return icon;
}
i++;
}
icon = hashmap_get(icon_cache, "generic");
hashmap_set(icon_cache, name, icon);
}
return icon;
}
void redraw(void) {
spin_lock(&drawlock);
@ -203,11 +241,7 @@ void redraw(void) {
}
}
sprite_t * icon = hashmap_get(icon_cache, ad->icon);
if (!icon) {
/* XXX try to find it */
icon = hashmap_get(icon_cache, "generic");
}
sprite_t * icon = icon_get(ad->icon);
if (icon->width == 24) {
draw_sprite(ctx, icon, 140 + i, 0);

View File

@ -290,6 +290,8 @@ int main (int argc, char ** argv) {
ctx = init_graphics_yutani_double_buffer(wina);
draw_fill(ctx, rgb(0,0,0));
yutani_window_advertise_icon(yctx, wina, "Mesa Gears", "gears");
OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
if (resize(ctx, gl_ctx)) {
fprintf(stderr, "%s: Something bad happened.\n", argv[0]);