29 #define G_LOG_DOMAIN "Helpers.IconFetcher" 40 #include "nkutils-xdg-theme.h" 86 g_free ( entry->
name );
88 for ( GList *iter = g_list_first ( entry->
sizes ); iter; iter = g_list_next ( iter ) ) {
91 cairo_surface_destroy ( sentry->
surface );
95 g_list_free ( entry->
sizes );
101 g_assert ( rofi_icon_fetcher_data == NULL );
103 static const gchar *
const icon_fallback_themes[] = {
110 rofi_icon_fetcher_data = g_malloc0 (
sizeof (
IconFetcher ) );
112 rofi_icon_fetcher_data->
xdg_context = nk_xdg_theme_context_new ( icon_fallback_themes, NULL );
113 nk_xdg_theme_preload_themes_icon ( rofi_icon_fetcher_data->
xdg_context, themes );
115 rofi_icon_fetcher_data->
icon_cache_uid = g_hash_table_new ( g_direct_hash, g_direct_equal );
121 if ( rofi_icon_fetcher_data == NULL ) {
125 nk_xdg_theme_context_free ( rofi_icon_fetcher_data->
xdg_context );
128 g_hash_table_unref ( rofi_icon_fetcher_data->
icon_cache );
130 g_free ( rofi_icon_fetcher_data );
134 g_debug (
"starting up icon fetching thread." );
138 const gchar *themes[] = {
143 const gchar *icon_path;
144 gchar *icon_path_ = NULL;
146 if ( g_path_is_absolute ( sentry->
entry->
name ) ) {
150 icon_path = icon_path_ = nk_xdg_theme_get_icon ( rofi_icon_fetcher_data->
xdg_context, themes, NULL, sentry->
entry->
name, sentry->
size, 1, TRUE );
151 if ( icon_path_ == NULL ) {
152 g_debug (
"failed to get icon %s(%d): n/a", sentry->
entry->
name, sentry->
size );
156 g_debug (
"found icon %s(%d): %s", sentry->
entry->
name, sentry->
size, icon_path );
159 cairo_surface_t *icon_surf = NULL;
160 if ( g_str_has_suffix ( icon_path,
".png" ) ) {
161 icon_surf = cairo_image_surface_create_from_png ( icon_path );
163 else if ( g_str_has_suffix ( icon_path,
".svg" ) ) {
167 g_debug (
"icon type not yet supported: %s", icon_path );
171 if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) {
172 g_debug (
"icon failed to open: %s(%d): %s", sentry->
entry->
name, sentry->
size, icon_path );
173 cairo_surface_destroy ( icon_surf );
178 g_free ( icon_path_ );
184 g_debug (
"Query: %s(%d)", name, size );
186 if ( entry == NULL ) {
188 entry->
name = g_strdup ( name );
189 g_hash_table_insert ( rofi_icon_fetcher_data->
icon_cache, entry->
name, entry );
192 for ( GList *iter = g_list_first ( entry->
sizes ); iter; iter = g_list_next ( iter ) ) {
194 if ( sentry->
size == size ) {
201 sentry->
uid = ++( rofi_icon_fetcher_data->
last_uid );
203 sentry->
entry = entry;
206 entry->
sizes = g_list_prepend ( entry->
sizes, sentry );
207 g_hash_table_insert ( rofi_icon_fetcher_data->
icon_cache_uid, GINT_TO_POINTER ( sentry->
uid ), sentry );
211 g_thread_pool_push (
tpool, sentry, NULL );
void rofi_icon_fetcher_destroy(void)
cairo_surface_t * surface
IconFetcherNameEntry * entry
void rofi_view_reload(void)
cairo_surface_t * cairo_image_surface_create_from_svg(const gchar *file, int height)
static void rofi_icon_fetcher_worker(thread_state *sdata, G_GNUC_UNUSED gpointer user_data)
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
NkXdgThemeContext * xdg_context
uint32_t rofi_icon_fetcher_query(const char *name, const int size)
static void rofi_icon_fetch_entry_free(gpointer data)
IconFetcher * rofi_icon_fetcher_data
void(* callback)(struct _thread_state *t, gpointer data)
void rofi_icon_fetcher_init(void)
GHashTable * icon_cache_uid