29 #define G_LOG_DOMAIN "Helpers.IconFetcher" 43 #include "nkutils-xdg-theme.h" 44 #include "nkutils-enum.h" 48 #include <gdk-pixbuf/gdk-pixbuf.h> 96 g_free ( entry->
name );
98 for ( GList *iter = g_list_first ( entry->
sizes ); iter; iter = g_list_next ( iter ) ) {
101 cairo_surface_destroy ( sentry->
surface );
105 g_list_free ( entry->
sizes );
113 static const gchar *
const icon_fallback_themes[] = {
128 GSList *l = gdk_pixbuf_get_formats ();
129 for ( GSList *li = l; li != NULL; li = g_slist_next ( li ) ) {
130 gchar **exts = gdk_pixbuf_format_get_extensions ( (GdkPixbufFormat *) li->data );
132 for (
unsigned int i = 0; exts && exts[i]; i++ ) {
134 g_info (
"Add image extension: %s", exts[i] );
165 #if G_BYTE_ORDER == G_LITTLE_ENDIAN 188 return ( ( t >> 8 ) + t ) >> 8;
196 const guchar *pixels;
200 if ( pixbuf == NULL ) {
204 width = gdk_pixbuf_get_width ( pixbuf );
205 height = gdk_pixbuf_get_height ( pixbuf );
206 pixels = gdk_pixbuf_read_pixels ( pixbuf );
207 stride = gdk_pixbuf_get_rowstride ( pixbuf );
208 alpha = gdk_pixbuf_get_has_alpha ( pixbuf );
210 cairo_surface_t *surface = NULL;
215 const guchar *pixels_end, *line, *line_end;
216 guchar *cpixels, *cline;
218 pixels_end = pixels + height * stride;
222 surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, width, height );
223 cpixels = cairo_image_surface_get_data ( surface );
224 cstride = cairo_image_surface_get_stride ( surface );
226 cairo_surface_flush ( surface );
227 while ( pixels < pixels_end ) {
229 line_end = line + lo;
232 while ( line < line_end ) {
248 cairo_surface_mark_dirty ( surface );
249 cairo_surface_flush ( surface );
256 if ( path == NULL ) {
259 const char *suf = strrchr ( path,
'.' );
266 if ( g_ascii_strcasecmp ( iter->data, suf ) == 0 ) {
275 g_debug (
"starting up icon fetching thread." );
279 const gchar *themes[] = {
284 const gchar *icon_path;
285 gchar *icon_path_ = NULL;
287 if ( g_path_is_absolute ( sentry->
entry->
name ) ) {
292 if ( icon_path_ == NULL ) {
293 g_debug (
"failed to get icon %s(%d): n/a", sentry->
entry->
name, sentry->
size );
297 g_debug (
"found icon %s(%d): %s", sentry->
entry->
name, sentry->
size, icon_path );
300 cairo_surface_t *icon_surf = NULL;
302 const char *suf = strrchr ( icon_path,
'.' );
307 GError *error = NULL;
308 GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_scale ( icon_path, sentry->
size, sentry->
size, TRUE, &error );
309 if ( error != NULL ) {
310 g_warning (
"Failed to load image: %s", error->message );
311 g_error_free ( error );
313 g_object_unref ( pb );
318 g_object_unref ( pb );
322 g_free ( icon_path_ );
328 g_debug (
"Query: %s(%d)", name, size );
330 if ( entry == NULL ) {
332 entry->
name = g_strdup ( name );
336 for ( GList *iter = g_list_first ( entry->
sizes ); iter; iter = g_list_next ( iter ) ) {
338 if ( sentry->
size == size ) {
347 sentry->
entry = entry;
350 entry->
sizes = g_list_prepend ( entry->
sizes, sentry );
355 g_thread_pool_push (
tpool, sentry, NULL );
void rofi_icon_fetcher_destroy(void)
cairo_surface_t * surface
IconFetcherNameEntry * entry
void rofi_view_reload(void)
static cairo_surface_t * rofi_icon_fetcher_get_surface_from_pixbuf(GdkPixbuf *pixbuf)
static void rofi_icon_fetcher_worker(thread_state *sdata, G_GNUC_UNUSED gpointer user_data)
GList * supported_extensions
cairo_surface_t * rofi_icon_fetcher_get(const uint32_t uid)
static guchar alpha_mult(guchar c, guchar a)
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
gboolean rofi_icon_fetcher_file_is_image(const char *const path)
void(* callback)(struct _thread_state *t, gpointer data)
void rofi_icon_fetcher_init(void)
GHashTable * icon_cache_uid