st/icon-theme: Copy GTK3 code in-tree

GTK4 changed icon loading significantly, it is now closely tied
to snapshots and paintables. This makes a port highly unrealistic,
so to avoid staying stuck on GTK3 forever, copy the relevant code
into the tree.

The code is unmodified except for the include names and replacing
some stray tab indentation. It is still full of GTK internals, so
it will take a while before we can actually build it.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2620>
This commit is contained in:
Florian Müllner 2023-01-10 20:40:21 +01:00 committed by Marge Bot
parent 83d427fc2b
commit 93319e7c11
6 changed files with 6689 additions and 0 deletions

View File

@ -85,6 +85,7 @@ src/shell-global.c
src/shell-keyring-prompt.c
src/shell-polkit-authentication-agent.c
src/shell-util.c
src/st/st-icon-theme.c
subprojects/extensions-app/data/metainfo/org.gnome.Extensions.metainfo.xml.in
subprojects/extensions-app/data/org.gnome.Extensions.desktop.in.in
subprojects/extensions-app/js/main.js

542
src/st/st-icon-cache.c Normal file
View File

@ -0,0 +1,542 @@
/* gtkiconcache.c
* Copyright (C) 2004 Anders Carlsson <andersca@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "st-icon-cache.h"
#include "gtkdebug.h"
#include "gtkiconcachevalidator.h"
#include <glib/gstdio.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#ifndef _O_BINARY
#define _O_BINARY 0
#endif
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define GET_UINT16(cache, offset) (GUINT16_FROM_BE (*(guint16 *)((cache) + (offset))))
#define GET_UINT32(cache, offset) (GUINT32_FROM_BE (*(guint32 *)((cache) + (offset))))
struct _GtkIconCache {
gint ref_count;
GMappedFile *map;
gchar *buffer;
guint32 last_chain_offset;
};
GtkIconCache *
_gtk_icon_cache_ref (GtkIconCache *cache)
{
cache->ref_count++;
return cache;
}
void
_gtk_icon_cache_unref (GtkIconCache *cache)
{
cache->ref_count --;
if (cache->ref_count == 0)
{
GTK_NOTE (ICONTHEME, g_message ("unmapping icon cache"));
if (cache->map)
g_mapped_file_unref (cache->map);
g_free (cache);
}
}
GtkIconCache *
_gtk_icon_cache_new_for_path (const gchar *path)
{
GtkIconCache *cache = NULL;
GMappedFile *map;
gchar *cache_filename;
gint fd = -1;
GStatBuf st;
GStatBuf path_st;
/* Check if we have a cache file */
cache_filename = g_build_filename (path, "icon-theme.cache", NULL);
GTK_NOTE (ICONTHEME, g_message ("look for icon cache in %s", path));
if (g_stat (path, &path_st) < 0)
goto done;
/* Open the file and map it into memory */
fd = g_open (cache_filename, O_RDONLY|_O_BINARY, 0);
if (fd < 0)
goto done;
#ifdef G_OS_WIN32
/* Bug 660730: _fstat32 is only defined in msvcrt80.dll+/VS 2005+ */
/* or possibly in the msvcrt.dll linked to by the Windows DDK */
/* (will need to check on the Windows DDK part later) */
#if ((_MSC_VER >= 1400 || __MSVCRT_VERSION__ >= 0x0800) || defined (__MINGW64_VERSION_MAJOR)) && !defined(_WIN64)
#undef fstat /* Just in case */
#define fstat _fstat32
#elif defined(__MINGW64_VERSION_MAJOR) && defined(_WIN64)
#undef fstat
#define fstat _fstat64
#endif
#endif
if (fstat (fd, &st) < 0 || st.st_size < 4)
goto done;
/* Verify cache is uptodate */
if (st.st_mtime < path_st.st_mtime)
{
GTK_NOTE (ICONTHEME, g_message ("icon cache outdated"));
goto done;
}
map = g_mapped_file_new (cache_filename, FALSE, NULL);
if (!map)
goto done;
#ifdef G_ENABLE_DEBUG
if (GTK_DEBUG_CHECK (ICONTHEME))
{
CacheInfo info;
info.cache = g_mapped_file_get_contents (map);
info.cache_size = g_mapped_file_get_length (map);
info.n_directories = 0;
info.flags = CHECK_OFFSETS|CHECK_STRINGS;
if (!_gtk_icon_cache_validate (&info))
{
g_mapped_file_unref (map);
g_warning ("Icon cache '%s' is invalid", cache_filename);
goto done;
}
}
#endif
GTK_NOTE (ICONTHEME, g_message ("found icon cache for %s", path));
cache = g_new0 (GtkIconCache, 1);
cache->ref_count = 1;
cache->map = map;
cache->buffer = g_mapped_file_get_contents (map);
done:
g_free (cache_filename);
if (fd >= 0)
close (fd);
return cache;
}
GtkIconCache *
_gtk_icon_cache_new (const gchar *data)
{
GtkIconCache *cache;
cache = g_new0 (GtkIconCache, 1);
cache->ref_count = 1;
cache->map = NULL;
cache->buffer = (gchar *)data;
return cache;
}
static gint
get_directory_index (GtkIconCache *cache,
const gchar *directory)
{
guint32 dir_list_offset;
gint n_dirs;
gint i;
dir_list_offset = GET_UINT32 (cache->buffer, 8);
n_dirs = GET_UINT32 (cache->buffer, dir_list_offset);
for (i = 0; i < n_dirs; i++)
{
guint32 name_offset = GET_UINT32 (cache->buffer, dir_list_offset + 4 + 4 * i);
gchar *name = cache->buffer + name_offset;
if (strcmp (name, directory) == 0)
return i;
}
return -1;
}
gint
_gtk_icon_cache_get_directory_index (GtkIconCache *cache,
const gchar *directory)
{
return get_directory_index (cache, directory);
}
static guint
icon_name_hash (gconstpointer key)
{
const signed char *p = key;
guint32 h = *p;
if (h)
for (p += 1; *p != '\0'; p++)
h = (h << 5) - h + *p;
return h;
}
static gint
find_image_offset (GtkIconCache *cache,
const gchar *icon_name,
gint directory_index)
{
guint32 hash_offset;
guint32 n_buckets;
guint32 chain_offset;
int hash;
guint32 image_list_offset, n_images;
int i;
if (!icon_name)
return 0;
chain_offset = cache->last_chain_offset;
if (chain_offset)
{
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
gchar *name = cache->buffer + name_offset;
if (strcmp (name, icon_name) == 0)
goto find_dir;
}
hash_offset = GET_UINT32 (cache->buffer, 4);
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
hash = icon_name_hash (icon_name) % n_buckets;
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
while (chain_offset != 0xffffffff)
{
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
gchar *name = cache->buffer + name_offset;
if (strcmp (name, icon_name) == 0)
{
cache->last_chain_offset = chain_offset;
goto find_dir;
}
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
}
cache->last_chain_offset = 0;
return 0;
find_dir:
/* We've found an icon list, now check if we have the right icon in it */
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
n_images = GET_UINT32 (cache->buffer, image_list_offset);
for (i = 0; i < n_images; i++)
{
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) ==
directory_index)
return image_list_offset + 4 + 8 * i;
}
return 0;
}
gint
_gtk_icon_cache_get_icon_flags (GtkIconCache *cache,
const gchar *icon_name,
gint directory_index)
{
guint32 image_offset;
image_offset = find_image_offset (cache, icon_name, directory_index);
if (!image_offset)
return 0;
return GET_UINT16 (cache->buffer, image_offset + 2);
}
gboolean
_gtk_icon_cache_has_icons (GtkIconCache *cache,
const gchar *directory)
{
int directory_index;
guint32 hash_offset, n_buckets;
guint32 chain_offset;
guint32 image_list_offset, n_images;
int i, j;
directory_index = get_directory_index (cache, directory);
if (directory_index == -1)
return FALSE;
hash_offset = GET_UINT32 (cache->buffer, 4);
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
for (i = 0; i < n_buckets; i++)
{
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
while (chain_offset != 0xffffffff)
{
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
n_images = GET_UINT32 (cache->buffer, image_list_offset);
for (j = 0; j < n_images; j++)
{
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
directory_index)
return TRUE;
}
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
}
}
return FALSE;
}
void
_gtk_icon_cache_add_icons (GtkIconCache *cache,
const gchar *directory,
GHashTable *hash_table)
{
int directory_index;
guint32 hash_offset, n_buckets;
guint32 chain_offset;
guint32 image_list_offset, n_images;
int i, j;
directory_index = get_directory_index (cache, directory);
if (directory_index == -1)
return;
hash_offset = GET_UINT32 (cache->buffer, 4);
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
for (i = 0; i < n_buckets; i++)
{
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
while (chain_offset != 0xffffffff)
{
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
gchar *name = cache->buffer + name_offset;
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
n_images = GET_UINT32 (cache->buffer, image_list_offset);
for (j = 0; j < n_images; j++)
{
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
directory_index)
g_hash_table_insert (hash_table, name, NULL);
}
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
}
}
}
gboolean
_gtk_icon_cache_has_icon (GtkIconCache *cache,
const gchar *icon_name)
{
guint32 hash_offset;
guint32 n_buckets;
guint32 chain_offset;
gint hash;
hash_offset = GET_UINT32 (cache->buffer, 4);
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
hash = icon_name_hash (icon_name) % n_buckets;
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
while (chain_offset != 0xffffffff)
{
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
gchar *name = cache->buffer + name_offset;
if (strcmp (name, icon_name) == 0)
return TRUE;
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
}
return FALSE;
}
gboolean
_gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
const gchar *icon_name,
const gchar *directory)
{
guint32 hash_offset;
guint32 n_buckets;
guint32 chain_offset;
gint hash;
gboolean found_icon = FALSE;
gint directory_index;
directory_index = get_directory_index (cache, directory);
if (directory_index == -1)
return FALSE;
hash_offset = GET_UINT32 (cache->buffer, 4);
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
hash = icon_name_hash (icon_name) % n_buckets;
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
while (chain_offset != 0xffffffff)
{
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
gchar *name = cache->buffer + name_offset;
if (strcmp (name, icon_name) == 0)
{
found_icon = TRUE;
break;
}
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
}
if (found_icon)
{
guint32 image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
guint32 n_images = GET_UINT32 (cache->buffer, image_list_offset);
guint32 image_offset = image_list_offset + 4;
gint i;
for (i = 0; i < n_images; i++)
{
guint16 index = GET_UINT16 (cache->buffer, image_offset);
if (index == directory_index)
return TRUE;
image_offset += 8;
}
}
return FALSE;
}
static void
pixbuf_destroy_cb (guchar *pixels,
gpointer data)
{
GtkIconCache *cache = data;
_gtk_icon_cache_unref (cache);
}
GdkPixbuf *
_gtk_icon_cache_get_icon (GtkIconCache *cache,
const gchar *icon_name,
gint directory_index)
{
guint32 offset, image_data_offset, pixel_data_offset;
guint32 length, type;
GdkPixbuf *pixbuf;
GdkPixdata pixdata;
GError *error = NULL;
offset = find_image_offset (cache, icon_name, directory_index);
if (!offset)
return NULL;
image_data_offset = GET_UINT32 (cache->buffer, offset + 4);
if (!image_data_offset)
return NULL;
pixel_data_offset = GET_UINT32 (cache->buffer, image_data_offset);
type = GET_UINT32 (cache->buffer, pixel_data_offset);
if (type != 0)
{
GTK_NOTE (ICONTHEME, g_message ("invalid pixel data type %u", type));
return NULL;
}
length = GET_UINT32 (cache->buffer, pixel_data_offset + 4);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
if (!gdk_pixdata_deserialize (&pixdata, length,
(guchar *)(cache->buffer + pixel_data_offset + 8),
&error))
{
GTK_NOTE (ICONTHEME, g_message ("could not deserialize data: %s", error->message));
g_error_free (error);
return NULL;
}
G_GNUC_END_IGNORE_DEPRECATIONS
pixbuf = gdk_pixbuf_new_from_data (pixdata.pixel_data, GDK_COLORSPACE_RGB,
(pixdata.pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA,
8, pixdata.width, pixdata.height, pixdata.rowstride,
(GdkPixbufDestroyNotify)pixbuf_destroy_cb,
cache);
if (!pixbuf)
{
GTK_NOTE (ICONTHEME, g_message ("could not convert pixdata to pixbuf: %s", error->message));
g_error_free (error);
return NULL;
}
_gtk_icon_cache_ref (cache);
return pixbuf;
}

51
src/st/st-icon-cache.h Normal file
View File

@ -0,0 +1,51 @@
/* gtkiconcache.h
* Copyright (C) 2004 Anders Carlsson <andersca@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_ICON_CACHE_H__
#define __GTK_ICON_CACHE_H__
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
typedef struct _GtkIconCache GtkIconCache;
GtkIconCache *_gtk_icon_cache_new (const gchar *data);
GtkIconCache *_gtk_icon_cache_new_for_path (const gchar *path);
gint _gtk_icon_cache_get_directory_index (GtkIconCache *cache,
const gchar *directory);
gboolean _gtk_icon_cache_has_icon (GtkIconCache *cache,
const gchar *icon_name);
gboolean _gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
const gchar *icon_name,
const gchar *directory);
gboolean _gtk_icon_cache_has_icons (GtkIconCache *cache,
const gchar *directory);
void _gtk_icon_cache_add_icons (GtkIconCache *cache,
const gchar *directory,
GHashTable *hash_table);
gint _gtk_icon_cache_get_icon_flags (GtkIconCache *cache,
const gchar *icon_name,
gint directory_index);
GdkPixbuf *_gtk_icon_cache_get_icon (GtkIconCache *cache,
const gchar *icon_name,
gint directory_index);
GtkIconCache *_gtk_icon_cache_ref (GtkIconCache *cache);
void _gtk_icon_cache_unref (GtkIconCache *cache);
#endif /* __GTK_ICON_CACHE_H__ */

View File

@ -0,0 +1,41 @@
/* GTK - The GIMP Toolkit
* Copyright (C) 2015 Benjamin Otte <otte@gnome.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_ICON_THEME_PRIVATE_H__
#define __GTK_ICON_THEME_PRIVATE_H__
#include "st-icon-theme.h"
#include <gtk/gtkcssstyleprivate.h>
void gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
GdkRGBA *color_out,
GdkRGBA *success_out,
GdkRGBA *warning_out,
GdkRGBA *error_out);
GtkIconInfo *gtk_icon_info_new_for_file (GFile *file,
gint size,
gint scale);
GdkPixbuf * gtk_icon_theme_color_symbolic_pixbuf (GdkPixbuf *symbolic,
const GdkRGBA *fg_color,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color);
#endif /* __GTK_ICON_THEME_PRIVATE_H__ */

5678
src/st/st-icon-theme.c Normal file

File diff suppressed because it is too large Load Diff

376
src/st/st-icon-theme.h Normal file
View File

@ -0,0 +1,376 @@
/* GtkIconTheme - a loader for icon themes
* gtk-icon-loader.h Copyright (C) 2002, 2003 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GTK_ICON_THEME_H__
#define __GTK_ICON_THEME_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
#include <gtk/gtkstylecontext.h>
G_BEGIN_DECLS
#define GTK_TYPE_ICON_INFO (gtk_icon_info_get_type ())
#define GTK_ICON_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_INFO, GtkIconInfo))
#define GTK_ICON_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ICON_INFO, GtkIconInfoClass))
#define GTK_IS_ICON_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_INFO))
#define GTK_IS_ICON_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ICON_INFO))
#define GTK_ICON_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_INFO, GtkIconInfoClass))
#define GTK_TYPE_ICON_THEME (gtk_icon_theme_get_type ())
#define GTK_ICON_THEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_THEME, GtkIconTheme))
#define GTK_ICON_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ICON_THEME, GtkIconThemeClass))
#define GTK_IS_ICON_THEME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_THEME))
#define GTK_IS_ICON_THEME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ICON_THEME))
#define GTK_ICON_THEME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_THEME, GtkIconThemeClass))
/**
* GtkIconInfo:
*
* Contains information found when looking up an icon in
* an icon theme.
*/
typedef struct _GtkIconInfo GtkIconInfo;
typedef struct _GtkIconInfoClass GtkIconInfoClass;
typedef struct _GtkIconTheme GtkIconTheme;
typedef struct _GtkIconThemeClass GtkIconThemeClass;
typedef struct _GtkIconThemePrivate GtkIconThemePrivate;
/**
* GtkIconTheme:
*
* Acts as a database of information about an icon theme.
* Normally, you retrieve the icon theme for a particular
* screen using gtk_icon_theme_get_for_screen() and it
* will contain information about current icon theme for
* that screen, but you can also create a new #GtkIconTheme
* object and set the icon theme name explicitly using
* gtk_icon_theme_set_custom_theme().
*/
struct _GtkIconTheme
{
/*< private >*/
GObject parent_instance;
GtkIconThemePrivate *priv;
};
/**
* GtkIconThemeClass:
* @parent_class: The parent class.
* @changed: Signal emitted when the current icon theme is switched or
* GTK+ detects that a change has occurred in the contents of the
* current icon theme.
*/
struct _GtkIconThemeClass
{
GObjectClass parent_class;
/*< public >*/
void (* changed) (GtkIconTheme *icon_theme);
/*< private >*/
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
void (*_gtk_reserved2) (void);
void (*_gtk_reserved3) (void);
void (*_gtk_reserved4) (void);
};
/**
* GtkIconLookupFlags:
* @GTK_ICON_LOOKUP_NO_SVG: Never get SVG icons, even if gdk-pixbuf
* supports them. Cannot be used together with %GTK_ICON_LOOKUP_FORCE_SVG.
* @GTK_ICON_LOOKUP_FORCE_SVG: Get SVG icons, even if gdk-pixbuf
* doesnt support them.
* Cannot be used together with %GTK_ICON_LOOKUP_NO_SVG.
* @GTK_ICON_LOOKUP_USE_BUILTIN: When passed to
* gtk_icon_theme_lookup_icon() includes builtin icons
* as well as files. For a builtin icon, gtk_icon_info_get_filename()
* is %NULL and you need to call gtk_icon_info_get_builtin_pixbuf().
* @GTK_ICON_LOOKUP_GENERIC_FALLBACK: Try to shorten icon name at '-'
* characters before looking at inherited themes. This flag is only
* supported in functions that take a single icon name. For more general
* fallback, see gtk_icon_theme_choose_icon(). Since 2.12.
* @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the
* requested size. Since 2.14.
* @GTK_ICON_LOOKUP_FORCE_REGULAR: Try to always load regular icons, even
* when symbolic icon names are given. Since 3.14.
* @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Try to always load symbolic icons, even
* when regular icon names are given. Since 3.14.
* @GTK_ICON_LOOKUP_DIR_LTR: Try to load a variant of the icon for left-to-right
* text direction. Since 3.14.
* @GTK_ICON_LOOKUP_DIR_RTL: Try to load a variant of the icon for right-to-left
* text direction. Since 3.14.
*
* Used to specify options for gtk_icon_theme_lookup_icon()
*/
typedef enum
{
GTK_ICON_LOOKUP_NO_SVG = 1 << 0,
GTK_ICON_LOOKUP_FORCE_SVG = 1 << 1,
GTK_ICON_LOOKUP_USE_BUILTIN = 1 << 2,
GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3,
GTK_ICON_LOOKUP_FORCE_SIZE = 1 << 4,
GTK_ICON_LOOKUP_FORCE_REGULAR = 1 << 5,
GTK_ICON_LOOKUP_FORCE_SYMBOLIC = 1 << 6,
GTK_ICON_LOOKUP_DIR_LTR = 1 << 7,
GTK_ICON_LOOKUP_DIR_RTL = 1 << 8
} GtkIconLookupFlags;
/**
* GTK_ICON_THEME_ERROR:
*
* The #GQuark used for #GtkIconThemeError errors.
*/
#define GTK_ICON_THEME_ERROR gtk_icon_theme_error_quark ()
/**
* GtkIconThemeError:
* @GTK_ICON_THEME_NOT_FOUND: The icon specified does not exist in the theme
* @GTK_ICON_THEME_FAILED: An unspecified error occurred.
*
* Error codes for GtkIconTheme operations.
**/
typedef enum {
GTK_ICON_THEME_NOT_FOUND,
GTK_ICON_THEME_FAILED
} GtkIconThemeError;
GDK_AVAILABLE_IN_ALL
GQuark gtk_icon_theme_error_quark (void);
GDK_AVAILABLE_IN_ALL
GType gtk_icon_theme_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkIconTheme *gtk_icon_theme_new (void);
GDK_AVAILABLE_IN_ALL
GtkIconTheme *gtk_icon_theme_get_default (void);
GDK_AVAILABLE_IN_ALL
GtkIconTheme *gtk_icon_theme_get_for_screen (GdkScreen *screen);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_set_screen (GtkIconTheme *icon_theme,
GdkScreen *screen);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
const gchar *path[],
gint n_elements);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
gchar **path[],
gint *n_elements);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
const gchar *path);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
const gchar *path);
GDK_AVAILABLE_IN_3_14
void gtk_icon_theme_add_resource_path (GtkIconTheme *icon_theme,
const gchar *path);
GDK_AVAILABLE_IN_ALL
void gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme,
const gchar *theme_name);
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
const gchar *icon_name);
GDK_AVAILABLE_IN_ALL
gint *gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
const gchar *icon_name);
GDK_AVAILABLE_IN_ALL
GtkIconInfo * gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_3_10
GtkIconInfo * gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
gint scale,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_ALL
GtkIconInfo * gtk_icon_theme_choose_icon (GtkIconTheme *icon_theme,
const gchar *icon_names[],
gint size,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_3_10
GtkIconInfo * gtk_icon_theme_choose_icon_for_scale (GtkIconTheme *icon_theme,
const gchar *icon_names[],
gint size,
gint scale,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
GtkIconLookupFlags flags,
GError **error);
GDK_AVAILABLE_IN_3_10
GdkPixbuf * gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
gint scale,
GtkIconLookupFlags flags,
GError **error);
GDK_AVAILABLE_IN_3_10
cairo_surface_t * gtk_icon_theme_load_surface (GtkIconTheme *icon_theme,
const gchar *icon_name,
gint size,
gint scale,
GdkWindow *for_window,
GtkIconLookupFlags flags,
GError **error);
GDK_AVAILABLE_IN_ALL
GtkIconInfo * gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme,
GIcon *icon,
gint size,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_3_10
GtkIconInfo * gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *icon_theme,
GIcon *icon,
gint size,
gint scale,
GtkIconLookupFlags flags);
GDK_AVAILABLE_IN_ALL
GList * gtk_icon_theme_list_icons (GtkIconTheme *icon_theme,
const gchar *context);
GDK_AVAILABLE_IN_ALL
GList * gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme);
GDK_AVAILABLE_IN_ALL
char * gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme);
GDK_AVAILABLE_IN_ALL
gboolean gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme);
GDK_DEPRECATED_IN_3_14_FOR(gtk_icon_theme_add_resource_path)
void gtk_icon_theme_add_builtin_icon (const gchar *icon_name,
gint size,
GdkPixbuf *pixbuf);
GDK_AVAILABLE_IN_ALL
GType gtk_icon_info_get_type (void) G_GNUC_CONST;
GDK_DEPRECATED_IN_3_8_FOR(g_object_ref)
GtkIconInfo * gtk_icon_info_copy (GtkIconInfo *icon_info);
GDK_DEPRECATED_IN_3_8_FOR(g_object_unref)
void gtk_icon_info_free (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_ALL
GtkIconInfo * gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme,
GdkPixbuf *pixbuf);
GDK_AVAILABLE_IN_ALL
gint gtk_icon_info_get_base_size (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_3_10
gint gtk_icon_info_get_base_scale (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_ALL
const gchar * gtk_icon_info_get_filename (GtkIconInfo *icon_info);
GDK_DEPRECATED_IN_3_14
GdkPixbuf * gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_3_12
gboolean gtk_icon_info_is_symbolic (GtkIconInfo *icon_info);
GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_info_load_icon (GtkIconInfo *icon_info,
GError **error);
GDK_AVAILABLE_IN_3_10
cairo_surface_t * gtk_icon_info_load_surface (GtkIconInfo *icon_info,
GdkWindow *for_window,
GError **error);
GDK_AVAILABLE_IN_3_8
void gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_3_8
GdkPixbuf * gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info,
GAsyncResult *res,
GError **error);
GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
const GdkRGBA *fg,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color,
gboolean *was_symbolic,
GError **error);
GDK_AVAILABLE_IN_3_8
void gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info,
const GdkRGBA *fg,
const GdkRGBA *success_color,
const GdkRGBA *warning_color,
const GdkRGBA *error_color,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_3_8
GdkPixbuf * gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info,
GAsyncResult *res,
gboolean *was_symbolic,
GError **error);
GDK_AVAILABLE_IN_ALL
GdkPixbuf * gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
GtkStyleContext *context,
gboolean *was_symbolic,
GError **error);
GDK_AVAILABLE_IN_3_8
void gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info,
GtkStyleContext *context,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GDK_AVAILABLE_IN_3_8
GdkPixbuf * gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info,
GAsyncResult *res,
gboolean *was_symbolic,
GError **error);
GDK_DEPRECATED_IN_3_0_FOR(gtk_icon_info_load_symbol_for_context)
GdkPixbuf * gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
GtkStyle *style,
GtkStateType state,
gboolean *was_symbolic,
GError **error);
GDK_DEPRECATED_IN_3_14
void gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,
gboolean raw_coordinates);
GDK_DEPRECATED_IN_3_14
gboolean gtk_icon_info_get_embedded_rect (GtkIconInfo *icon_info,
GdkRectangle *rectangle);
GDK_DEPRECATED_IN_3_14
gboolean gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,
GdkPoint **points,
gint *n_points);
GDK_DEPRECATED_IN_3_14
const gchar * gtk_icon_info_get_display_name (GtkIconInfo *icon_info);
G_END_DECLS
#endif /* __GTK_ICON_THEME_H__ */