Beispiel #1
0
static void drun_icon_fetch ( gpointer data, gpointer user_data )
{
    g_debug ( "Starting up icon fetching thread." );
    // as long as dr->icon is updated atomicly.. (is a pointer write atomic?)
    // this should be fine running in another thread.
    DRunModePrivateData *pd        = (DRunModePrivateData *) user_data;
    DRunModeEntry       *dr        = (DRunModeEntry *) data;
    const gchar         *themes[2] = {
        config.drun_icon_theme,
        NULL
    };

    if ( dr->icon_name == NULL ) {
        return;
    }
    gchar *icon_path = nk_xdg_theme_get_icon ( pd->xdg_context, themes, NULL, dr->icon_name, dr->icon_size, 1, TRUE );
    if ( icon_path == NULL ) {
        g_debug ( "Failed to get Icon %s(%d): n/a", dr->icon_name, dr->icon_size  );
        return;
    }
    else{
        g_debug ( "Found Icon %s(%d): %s", dr->icon_name, dr->icon_size, icon_path  );
    }
    cairo_surface_t *icon_surf = NULL;
    if ( g_str_has_suffix ( icon_path, ".png" ) ) {
        icon_surf = cairo_image_surface_create_from_png ( icon_path );
    }
    else if ( g_str_has_suffix ( icon_path, ".svg" ) ) {
        icon_surf = cairo_image_surface_create_from_svg ( icon_path, dr->icon_size );
    }
    else {
        g_debug ( "Icon type not yet supported: %s", icon_path  );
    }
    if ( icon_surf ) {
        // Check if surface is valid.
        if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) {
            g_debug ( "Icon failed to open: %s(%d): %s", dr->icon_name, dr->icon_size, icon_path );
            cairo_surface_destroy ( icon_surf );
            icon_surf = NULL;
        }
        dr->icon = icon_surf;
    }
    g_free ( icon_path );
    rofi_view_reload ();
}
Beispiel #2
0
GdkPixbuf *
eventd_nd_pixbuf_from_theme(NkXdgThemeContext *context, gchar *uri, gint size)
{
    GdkPixbuf *pixbuf = NULL;
    const gchar *theme = NULL;
    const gchar *name = uri + strlen("theme:");
    gchar *file;

    gchar *c;
    if ( ( c = g_utf8_strchr(name, -1, '/') ) != NULL )
    {
        *c = '\0';
        theme = name;
        name = ++c;
    }

    file = nk_xdg_theme_get_icon(context, theme, name, size, TRUE);
    if ( file != NULL )
        pixbuf = _eventd_nd_pixbuf_from_file(file, size, size);
    g_free(file);
    g_free(uri);

    return pixbuf;
}