2003-07-02 22:44:09 +00:00
|
|
|
|
/* GtkIconTheme - a loader for icon themes
|
|
|
|
|
* gtk-icon-theme.c 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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-02 22:44:09 +00:00
|
|
|
|
#include <unistd.h>
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2012-11-26 12:52:05 +00:00
|
|
|
|
#include <math.h>
|
2003-07-02 22:44:09 +00:00
|
|
|
|
#include <glib.h>
|
2004-12-12 21:09:13 +00:00
|
|
|
|
#include <glib/gstdio.h>
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
|
#define S_ISDIR(mode) ((mode)&_S_IFDIR)
|
|
|
|
|
#endif
|
2018-12-21 23:48:10 +00:00
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2008-06-16 13:27:46 +00:00
|
|
|
|
#include <windows.h>
|
2018-12-21 23:48:10 +00:00
|
|
|
|
#include <shellapi.h>
|
2008-06-16 13:27:46 +00:00
|
|
|
|
#include "win32/gdkwin32.h"
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
|
2016-01-14 17:53:50 +00:00
|
|
|
|
#include "gtkiconthemeprivate.h"
|
2015-12-02 23:33:51 +00:00
|
|
|
|
#include "gtkcsspalettevalueprivate.h"
|
2020-01-10 12:02:33 +00:00
|
|
|
|
#include "gtkcsscolorvalueprivate.h"
|
2010-09-18 23:57:32 +00:00
|
|
|
|
#include "gtkdebug.h"
|
2018-02-01 14:34:57 +00:00
|
|
|
|
#include "gtkiconcacheprivate.h"
|
2003-07-02 22:44:09 +00:00
|
|
|
|
#include "gtkintl.h"
|
2006-08-15 17:44:09 +00:00
|
|
|
|
#include "gtkmain.h"
|
2014-07-10 01:18:18 +00:00
|
|
|
|
#include "gtksettingsprivate.h"
|
2015-12-02 23:33:51 +00:00
|
|
|
|
#include "gtkstylecontextprivate.h"
|
2003-07-20 15:50:14 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2016-01-29 22:27:35 +00:00
|
|
|
|
#include "gdkpixbufutilsprivate.h"
|
2019-08-29 15:07:45 +00:00
|
|
|
|
#include "gdk/gdktextureprivate.h"
|
2020-01-22 19:49:17 +00:00
|
|
|
|
#include "gdk/gdkprofilerprivate.h"
|
2011-11-08 13:15:30 +00:00
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
/* this is in case round() is not provided by the compiler,
|
|
|
|
|
* such as in the case of C89 compilers, like MSVC
|
|
|
|
|
*/
|
|
|
|
|
#include "fallback-c89.c"
|
2011-04-14 21:07:29 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkicontheme
|
|
|
|
|
* @Short_description: Looking up icons by name
|
|
|
|
|
* @Title: GtkIconTheme
|
|
|
|
|
*
|
|
|
|
|
* #GtkIconTheme provides a facility for looking up icons by name
|
|
|
|
|
* and size. The main reason for using a name rather than simply
|
|
|
|
|
* providing a filename is to allow different icons to be used
|
2014-02-04 23:10:11 +00:00
|
|
|
|
* depending on what “icon theme” is selected
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* by the user. The operation of icon themes on Linux and Unix
|
2014-02-04 23:53:51 +00:00
|
|
|
|
* follows the [Icon Theme Specification](http://www.freedesktop.org/Standards/icon-theme-spec)
|
2014-06-22 20:46:11 +00:00
|
|
|
|
* There is a fallback icon theme, named `hicolor`, where applications
|
|
|
|
|
* should install their icons, but additional icon themes can be installed
|
|
|
|
|
* as operating system vendors and users choose.
|
2011-04-14 21:07:29 +00:00
|
|
|
|
*
|
|
|
|
|
* In many cases, named themes are used indirectly, via #GtkImage
|
2016-10-22 15:25:57 +00:00
|
|
|
|
* rather than directly, but looking up icons
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* directly is also simple. The #GtkIconTheme object acts
|
|
|
|
|
* as a database of all the icons in the current theme. You
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* can create new #GtkIconTheme objects, but it’s much more
|
2017-10-31 07:25:10 +00:00
|
|
|
|
* efficient to use the standard icon theme for the #GdkDisplay
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* so that the icon information is shared with other people
|
2014-06-22 20:46:11 +00:00
|
|
|
|
* looking up icons.
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* GError *error = NULL;
|
|
|
|
|
* GtkIconTheme *icon_theme;
|
2019-09-02 07:35:37 +00:00
|
|
|
|
* GdkPaintable *paintable;
|
2011-04-14 21:07:29 +00:00
|
|
|
|
*
|
|
|
|
|
* icon_theme = gtk_icon_theme_get_default ();
|
2019-09-02 07:35:37 +00:00
|
|
|
|
* paintable = gtk_icon_theme_load_icon (icon_theme,
|
|
|
|
|
* "my-icon-name", // icon name
|
|
|
|
|
* 48, // icon size
|
|
|
|
|
* 0, // flags
|
|
|
|
|
* &error);
|
|
|
|
|
* if (!paintable)
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* {
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* g_warning ("Couldn’t load icon: %s", error->message);
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* g_error_free (error);
|
|
|
|
|
* }
|
|
|
|
|
* else
|
|
|
|
|
* {
|
2019-09-02 07:35:37 +00:00
|
|
|
|
* // Use the icon
|
|
|
|
|
* g_object_unref (paintable);
|
2011-04-14 21:07:29 +00:00
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2011-04-14 21:07:29 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2014-07-10 01:12:08 +00:00
|
|
|
|
#define FALLBACK_ICON_THEME "hicolor"
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
ICON_THEME_DIR_FIXED,
|
|
|
|
|
ICON_THEME_DIR_SCALABLE,
|
|
|
|
|
ICON_THEME_DIR_THRESHOLD,
|
|
|
|
|
ICON_THEME_DIR_UNTHEMED
|
|
|
|
|
} IconThemeDirType;
|
|
|
|
|
|
|
|
|
|
/* In reverse search order: */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
ICON_SUFFIX_NONE = 0,
|
|
|
|
|
ICON_SUFFIX_XPM = 1 << 0,
|
|
|
|
|
ICON_SUFFIX_SVG = 1 << 1,
|
2004-10-19 18:45:41 +00:00
|
|
|
|
ICON_SUFFIX_PNG = 1 << 2,
|
2014-07-30 16:05:48 +00:00
|
|
|
|
HAS_ICON_FILE = 1 << 3,
|
|
|
|
|
ICON_SUFFIX_SYMBOLIC_PNG = 1 << 4
|
2003-07-02 22:44:09 +00:00
|
|
|
|
} IconSuffix;
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
#if 0
|
|
|
|
|
#define DEBUG_CACHE(args) g_print args
|
|
|
|
|
#else
|
|
|
|
|
#define DEBUG_CACHE(args)
|
|
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-01 11:25:44 +00:00
|
|
|
|
#define LRU_CACHE_SIZE 100
|
|
|
|
|
#define MAX_LRU_TEXTURE_SIZE 128
|
|
|
|
|
|
2019-05-26 19:33:10 +00:00
|
|
|
|
typedef struct _GtkIconInfoClass GtkIconInfoClass;
|
|
|
|
|
typedef struct _GtkIconThemeClass GtkIconThemeClass;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkIconTheme:
|
|
|
|
|
*
|
|
|
|
|
* Acts as a database of information about an icon theme.
|
|
|
|
|
* Normally, you retrieve the icon theme for a particular
|
|
|
|
|
* display using gtk_icon_theme_get_for_display() and it
|
|
|
|
|
* will contain information about current icon theme for
|
|
|
|
|
* that display, 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
|
|
|
|
|
{
|
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
GHashTable *info_cache;
|
|
|
|
|
|
2019-09-01 11:25:44 +00:00
|
|
|
|
GtkIconInfo *lru_cache[LRU_CACHE_SIZE];
|
|
|
|
|
int lru_cache_next;
|
|
|
|
|
|
2011-04-12 16:33:04 +00:00
|
|
|
|
gchar *current_theme;
|
|
|
|
|
gchar **search_path;
|
|
|
|
|
gint search_path_len;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
GList *resource_paths;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
guint custom_theme : 1;
|
|
|
|
|
guint is_display_singleton : 1;
|
|
|
|
|
guint pixbuf_supports_svg : 1;
|
|
|
|
|
guint themes_valid : 1;
|
|
|
|
|
guint loading_themes : 1;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
/* A list of all the themes needed to look up icons.
|
|
|
|
|
* In search order, without duplicates
|
|
|
|
|
*/
|
|
|
|
|
GList *themes;
|
|
|
|
|
GHashTable *unthemed_icons;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
/* GdkDisplay for the icon theme (may be NULL) */
|
|
|
|
|
GdkDisplay *display;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* time when we last stat:ed for theme changes */
|
2011-04-12 16:33:04 +00:00
|
|
|
|
glong last_stat_time;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GList *dir_mtimes;
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
|
gulong theme_changed_idle;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-05-26 19:33:10 +00:00
|
|
|
|
struct _GtkIconThemeClass
|
|
|
|
|
{
|
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
void (* changed) (GtkIconTheme *self);
|
2019-05-26 19:33:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
gchar **icon_names;
|
|
|
|
|
gint size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
gint scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
GtkIconLookupFlags flags;
|
|
|
|
|
} IconInfoKey;
|
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
struct _GtkIconInfoClass
|
|
|
|
|
{
|
|
|
|
|
GObjectClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-26 19:33:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkIconInfo:
|
|
|
|
|
*
|
|
|
|
|
* Contains information found when looking up an icon in
|
|
|
|
|
* an icon theme.
|
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
struct _GtkIconInfo
|
|
|
|
|
{
|
2013-02-13 14:05:02 +00:00
|
|
|
|
GObject parent_instance;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* Information about the source
|
|
|
|
|
*/
|
2012-11-26 12:49:49 +00:00
|
|
|
|
IconInfoKey key;
|
|
|
|
|
GtkIconTheme *in_cache;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gchar *filename;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
GLoadableIcon *loadable;
|
|
|
|
|
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
/* Cache pixbuf (if there is any) */
|
|
|
|
|
GdkPixbuf *cache_pixbuf;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* Information about the directory where
|
|
|
|
|
* the source was found
|
|
|
|
|
*/
|
|
|
|
|
IconThemeDirType dir_type;
|
|
|
|
|
gint dir_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
gint dir_scale;
|
2014-06-20 18:17:47 +00:00
|
|
|
|
gint min_size;
|
|
|
|
|
gint max_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
/* Parameters influencing the scaled icon
|
|
|
|
|
*/
|
|
|
|
|
gint desired_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
gint desired_scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
guint forced_size : 1;
|
2014-06-14 22:54:24 +00:00
|
|
|
|
guint is_svg : 1;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
guint is_resource : 1;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* Cached information if we go ahead and try to load
|
|
|
|
|
* the icon.
|
|
|
|
|
*/
|
2017-11-02 20:39:00 +00:00
|
|
|
|
GdkTexture *texture;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GError *load_error;
|
2014-06-22 15:01:43 +00:00
|
|
|
|
gdouble unscaled_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gdouble scale;
|
2012-06-06 16:16:05 +00:00
|
|
|
|
|
2015-06-08 23:35:31 +00:00
|
|
|
|
gint symbolic_width;
|
|
|
|
|
gint symbolic_height;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *display_name;
|
|
|
|
|
gchar *comment;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
/* In search order */
|
|
|
|
|
GList *dirs;
|
|
|
|
|
} IconTheme;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
IconThemeDirType type;
|
|
|
|
|
GQuark context;
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint size;
|
|
|
|
|
gint min_size;
|
|
|
|
|
gint max_size;
|
|
|
|
|
gint threshold;
|
|
|
|
|
gint scale;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
gboolean is_resource;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *dir;
|
|
|
|
|
gchar *subdir;
|
|
|
|
|
gint subdir_index;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
|
|
GtkIconCache *cache;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
GHashTable *icons;
|
|
|
|
|
} IconThemeDir;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *svg_filename;
|
|
|
|
|
gchar *no_svg_filename;
|
2014-06-30 21:02:41 +00:00
|
|
|
|
gboolean is_resource;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
} UnthemedIcon;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *dir;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
time_t mtime;
|
2005-04-06 03:34:38 +00:00
|
|
|
|
GtkIconCache *cache;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
gboolean exists;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
} IconThemeDirMtime;
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static void gtk_icon_theme_finalize (GObject *object);
|
|
|
|
|
static void theme_dir_destroy (IconThemeDir *dir);
|
|
|
|
|
static void theme_destroy (IconTheme *theme);
|
|
|
|
|
static GtkIconInfo *theme_lookup_icon (IconTheme *theme,
|
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
2019-05-21 12:53:03 +00:00
|
|
|
|
gboolean allow_svg);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static void theme_list_icons (IconTheme *theme,
|
|
|
|
|
GHashTable *icons,
|
|
|
|
|
GQuark context);
|
2014-06-20 01:37:01 +00:00
|
|
|
|
static gboolean theme_has_icon (IconTheme *theme,
|
|
|
|
|
const gchar *icon_name);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
static void theme_subdir_load (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
IconTheme *theme,
|
|
|
|
|
GKeyFile *theme_file,
|
|
|
|
|
gchar *subdir);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
static void do_theme_change (GtkIconTheme *self);
|
|
|
|
|
static void blow_themes (GtkIconTheme *self);
|
|
|
|
|
static gboolean rescan_themes (GtkIconTheme *self);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
|
2019-05-21 12:51:09 +00:00
|
|
|
|
const gchar *icon_name);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static GtkIconInfo *icon_info_new (IconThemeDirType type,
|
|
|
|
|
gint dir_size,
|
|
|
|
|
gint dir_scale);
|
|
|
|
|
static IconSuffix suffix_from_name (const gchar *name);
|
2019-09-01 09:25:48 +00:00
|
|
|
|
static gboolean icon_info_ensure_scale_and_texture (GtkIconInfo* icon_info);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
static guint signal_changed = 0;
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
static guint
|
|
|
|
|
icon_info_key_hash (gconstpointer _key)
|
|
|
|
|
{
|
|
|
|
|
const IconInfoKey *key = _key;
|
|
|
|
|
guint h = 0;
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; key->icon_names[i] != NULL; i++)
|
|
|
|
|
h ^= g_str_hash (key->icon_names[i]);
|
|
|
|
|
|
|
|
|
|
h ^= key->size * 0x10001;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
h ^= key->scale * 0x1000010;
|
|
|
|
|
h ^= key->flags * 0x100000100;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info_key_equal (gconstpointer _a,
|
|
|
|
|
gconstpointer _b)
|
2012-11-26 12:49:49 +00:00
|
|
|
|
{
|
|
|
|
|
const IconInfoKey *a = _a;
|
|
|
|
|
const IconInfoKey *b = _b;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (a->size != b->size)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
if (a->scale != b->scale)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
if (a->flags != b->flags)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
|
a->icon_names[i] != NULL &&
|
|
|
|
|
b->icon_names[i] != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (a->icon_names[i], b->icon_names[i]) != 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return FALSE;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return a->icon_names[i] == NULL && b->icon_names[i] == NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-01 11:25:44 +00:00
|
|
|
|
static void
|
|
|
|
|
add_to_lru_cache (GtkIconInfo *info)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self = info->in_cache;
|
2019-09-01 11:25:44 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (!self)
|
2019-09-01 11:25:44 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (info->texture &&
|
|
|
|
|
info->texture->width <= MAX_LRU_TEXTURE_SIZE &&
|
|
|
|
|
info->texture->height <= MAX_LRU_TEXTURE_SIZE)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_set_object (&self->lru_cache[self->lru_cache_next], info);
|
|
|
|
|
self->lru_cache_next = (self->lru_cache_next + 1) % LRU_CACHE_SIZE;
|
2019-09-01 11:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
clear_lru_cache (GtkIconTheme *self)
|
2019-09-01 11:25:44 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < LRU_CACHE_SIZE; i ++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_clear_object (&self->lru_cache[i]);
|
2019-09-01 11:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new icon theme object. Icon theme objects are used
|
|
|
|
|
* to lookup up an icon by name in a particular icon theme.
|
2014-02-07 18:35:54 +00:00
|
|
|
|
* Usually, you’ll want to use gtk_icon_theme_get_default()
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* or gtk_icon_theme_get_for_display() rather than creating
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* a new icon theme object for scratch.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the newly created #GtkIconTheme object.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GtkIconTheme *
|
|
|
|
|
gtk_icon_theme_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_ICON_THEME, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_get_default:
|
|
|
|
|
*
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* Gets the icon theme for the default display. See
|
|
|
|
|
* gtk_icon_theme_get_for_display().
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): A unique #GtkIconTheme associated with
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* the default display. This icon theme is associated with
|
|
|
|
|
* the display and can be used as long as the display
|
2014-06-22 20:46:11 +00:00
|
|
|
|
* is open. Do not ref or unref it.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GtkIconTheme *
|
|
|
|
|
gtk_icon_theme_get_default (void)
|
|
|
|
|
{
|
2017-10-31 01:59:06 +00:00
|
|
|
|
return gtk_icon_theme_get_for_display (gdk_display_get_default ());
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* gtk_icon_theme_get_for_display:
|
|
|
|
|
* @display: a #GdkDisplay
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* Gets the icon theme object associated with @display; if this
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* function has not previously been called for the given
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* display, a new icon theme object will be created and
|
|
|
|
|
* associated with the display. Icon theme objects are
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* fairly expensive to create, so using this function
|
|
|
|
|
* is usually a better choice than calling than gtk_icon_theme_new()
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* and setting the display yourself; by using this function
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* a single icon theme object will be shared between users.
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): A unique #GtkIconTheme associated with
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* the given display. This icon theme is associated with
|
|
|
|
|
* the display and can be used as long as the display
|
2005-07-13 04:53:49 +00:00
|
|
|
|
* is open. Do not ref or unref it.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GtkIconTheme *
|
2017-10-31 01:59:06 +00:00
|
|
|
|
gtk_icon_theme_get_for_display (GdkDisplay *display)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self = g_object_get_data (G_OBJECT (display), "gtk-icon-theme");
|
|
|
|
|
if (!self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self = gtk_icon_theme_new ();
|
|
|
|
|
gtk_icon_theme_set_display (self, display);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->is_display_singleton = TRUE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (display), I_("gtk-icon-theme"), self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return self;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_icon_theme_class_init (GtkIconThemeClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_icon_theme_finalize;
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkIconTheme::changed:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: the icon theme
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*
|
|
|
|
|
* Emitted when the current icon theme is switched or GTK+ detects
|
|
|
|
|
* that a change has occurred in the contents of the current
|
|
|
|
|
* icon theme.
|
|
|
|
|
*/
|
2005-09-01 05:11:46 +00:00
|
|
|
|
signal_changed = g_signal_new (I_("changed"),
|
2014-06-19 23:42:53 +00:00
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkIconThemeClass, changed),
|
|
|
|
|
NULL, NULL,
|
2019-05-29 20:05:19 +00:00
|
|
|
|
NULL,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
/* Callback when the display that the icon theme is attached
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* to is closed; unset the display, and if it’s the unique theme
|
|
|
|
|
* for the display, drop the reference
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
display_closed (GdkDisplay *display,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gboolean is_error,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gboolean was_display_singleton = self->is_display_singleton;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
if (was_display_singleton)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2017-10-31 01:59:06 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (display), I_("gtk-icon-theme"), NULL);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->is_display_singleton = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_set_display (self, NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
if (was_display_singleton)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_object_unref (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
update_current_theme (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2007-03-06 18:26:41 +00:00
|
|
|
|
#define theme_changed(_old, _new) \
|
|
|
|
|
((_old && !_new) || (!_old && _new) || \
|
|
|
|
|
(_old && _new && strcmp (_old, _new) != 0))
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (!self->custom_theme)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *theme = NULL;
|
2006-01-11 06:20:17 +00:00
|
|
|
|
gboolean changed = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->display)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkSettings *settings = gtk_settings_get_for_display (self->display);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (theme_changed (self->current_theme, theme))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_free (self->current_theme);
|
|
|
|
|
self->current_theme = theme;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
changed = TRUE;
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_free (theme);
|
2006-01-11 06:20:17 +00:00
|
|
|
|
|
|
|
|
|
if (changed)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2007-03-06 18:26:41 +00:00
|
|
|
|
#undef theme_changed
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback when the icon theme GtkSetting changes
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
theme_changed (GtkSettings *settings,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
GParamSpec *pspec,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
update_current_theme (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
unset_display (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->display)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
settings = gtk_settings_get_for_display (self->display);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (self->display,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(gpointer) display_closed,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (settings,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(gpointer) theme_changed,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->display = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* gtk_icon_theme_set_display:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* @display: a #GdkDisplay
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* Sets the display for an icon theme; the display is used
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* to track the user’s currently configured icon theme,
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* which might be different for different displays.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_set_display (GtkIconTheme *self,
|
2017-10-31 01:59:06 +00:00
|
|
|
|
GdkDisplay *display)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_ICON_THEME (self));
|
2017-10-31 01:59:06 +00:00
|
|
|
|
g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
unset_display (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
if (display)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2017-10-31 01:59:06 +00:00
|
|
|
|
settings = gtk_settings_get_for_display (display);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->display = display;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
g_signal_connect (display, "closed",
|
2019-09-08 12:57:40 +00:00
|
|
|
|
G_CALLBACK (display_closed), self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_signal_connect (settings, "notify::gtk-icon-theme-name",
|
2019-09-08 12:57:40 +00:00
|
|
|
|
G_CALLBACK (theme_changed), self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
update_current_theme (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Checks whether a loader for SVG files has been registered
|
|
|
|
|
* with GdkPixbuf.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2004-10-28 15:00:05 +00:00
|
|
|
|
pixbuf_supports_svg (void)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2006-10-15 22:58:08 +00:00
|
|
|
|
GSList *formats;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GSList *tmp_list;
|
2006-04-04 04:14:17 +00:00
|
|
|
|
static gint found_svg = -1;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2006-04-04 04:14:17 +00:00
|
|
|
|
if (found_svg != -1)
|
2004-10-19 18:45:41 +00:00
|
|
|
|
return found_svg;
|
2006-10-15 22:58:08 +00:00
|
|
|
|
|
|
|
|
|
formats = gdk_pixbuf_get_formats ();
|
|
|
|
|
|
2006-04-04 04:14:17 +00:00
|
|
|
|
found_svg = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
for (tmp_list = formats; tmp_list && !found_svg; tmp_list = tmp_list->next)
|
|
|
|
|
{
|
|
|
|
|
gchar **mime_types = gdk_pixbuf_format_get_mime_types (tmp_list->data);
|
|
|
|
|
gchar **mime_type;
|
|
|
|
|
|
|
|
|
|
for (mime_type = mime_types; *mime_type && !found_svg; mime_type++)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (strcmp (*mime_type, "image/svg") == 0)
|
|
|
|
|
found_svg = TRUE;
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2003-07-11 20:36:25 +00:00
|
|
|
|
g_strfreev (mime_types);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_slist_free (formats);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return found_svg;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
/* The icon info was removed from the icon_info_hash hash table */
|
|
|
|
|
static void
|
|
|
|
|
icon_info_uncached (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
DEBUG_CACHE (("removing %p (%s %d 0x%x) from cache (icon_them: %p) (cache size %d)\n",
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info,
|
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self,
|
|
|
|
|
icon_theme != NULL ? g_hash_table_size (self->info_cache) : 0));
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
|
|
icon_info->in_cache = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_init (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-08-18 15:45:13 +00:00
|
|
|
|
const gchar * const *xdg_data_dirs;
|
2004-08-17 19:51:11 +00:00
|
|
|
|
int i, j;
|
2010-06-22 14:42:00 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->info_cache = g_hash_table_new_full (icon_info_key_hash, icon_info_key_equal, NULL,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(GDestroyNotify)icon_info_uncached);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->custom_theme = FALSE;
|
2004-08-17 19:51:11 +00:00
|
|
|
|
|
|
|
|
|
xdg_data_dirs = g_get_system_data_dirs ();
|
|
|
|
|
for (i = 0; xdg_data_dirs[i]; i++) ;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path_len = 2 * i + 2;
|
2004-08-17 19:51:11 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path = g_new (char *, self->search_path_len);
|
2004-08-17 19:51:11 +00:00
|
|
|
|
|
|
|
|
|
i = 0;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path[i++] = g_build_filename (g_get_user_data_dir (), "icons", NULL);
|
|
|
|
|
self->search_path[i++] = g_build_filename (g_get_home_dir (), ".icons", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2004-08-17 19:51:11 +00:00
|
|
|
|
for (j = 0; xdg_data_dirs[j]; j++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path[i++] = g_build_filename (xdg_data_dirs[j], "icons", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2005-02-02 04:31:21 +00:00
|
|
|
|
for (j = 0; xdg_data_dirs[j]; j++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path[i++] = g_build_filename (xdg_data_dirs[j], "pixmaps", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->resource_paths = g_list_append (NULL, g_strdup ("/org/gtk/libgtk/icons/"));
|
2014-06-20 05:04:16 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->themes_valid = FALSE;
|
|
|
|
|
self->themes = NULL;
|
|
|
|
|
self->unthemed_icons = NULL;
|
2019-09-01 09:25:48 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->pixbuf_supports_svg = pixbuf_supports_svg ();
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_dir_mtime (IconThemeDirMtime *dir_mtime)
|
|
|
|
|
{
|
2005-04-06 03:34:38 +00:00
|
|
|
|
if (dir_mtime->cache)
|
2018-02-01 15:05:58 +00:00
|
|
|
|
gtk_icon_cache_unref (dir_mtime->cache);
|
2005-04-06 03:34:38 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_free (dir_mtime->dir);
|
2006-07-07 05:24:00 +00:00
|
|
|
|
g_slice_free (IconThemeDirMtime, dir_mtime);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-12 18:39:17 +00:00
|
|
|
|
static gboolean
|
2013-06-19 09:06:20 +00:00
|
|
|
|
theme_changed_idle (gpointer user_data)
|
2005-08-12 18:39:17 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self;
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self = GTK_ICON_THEME (user_data);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_signal_emit (self, signal_changed, 0);
|
2013-06-19 09:06:20 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->display && self->is_display_singleton)
|
|
|
|
|
gtk_style_context_reset_widgets (self->display);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->theme_changed_idle = 0;
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
queue_theme_changed (GtkIconTheme *self)
|
2013-06-19 09:06:20 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (!self->theme_changed_idle)
|
2014-03-22 11:44:01 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->theme_changed_idle = g_idle_add_full (GTK_PRIORITY_RESIZE - 2,
|
2018-02-02 14:08:02 +00:00
|
|
|
|
theme_changed_idle,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self,
|
2018-02-02 14:08:02 +00:00
|
|
|
|
NULL);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_source_set_name_by_id (self->theme_changed_idle, "[gtk] theme_changed_idle");
|
2014-03-22 11:44:01 +00:00
|
|
|
|
}
|
2013-06-19 09:06:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_remove_all (self->info_cache);
|
|
|
|
|
clear_lru_cache (self);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (!self->themes_valid)
|
2007-03-06 18:26:41 +00:00
|
|
|
|
return;
|
2013-06-19 09:06:20 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME,
|
|
|
|
|
g_message ("change to icon theme \"%s\"", self->current_theme));
|
|
|
|
|
blow_themes (self);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
queue_theme_changed (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
blow_themes (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->themes_valid)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_list_free_full (self->themes, (GDestroyNotify) theme_destroy);
|
|
|
|
|
g_list_free_full (self->dir_mtimes, (GDestroyNotify) free_dir_mtime);
|
|
|
|
|
g_hash_table_destroy (self->unthemed_icons);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->themes = NULL;
|
|
|
|
|
self->unthemed_icons = NULL;
|
|
|
|
|
self->dir_mtimes = NULL;
|
|
|
|
|
self->themes_valid = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_icon_theme_finalize (GObject *object)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GtkIconTheme *self = GTK_ICON_THEME (object);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_destroy (self->info_cache);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->theme_changed_idle)
|
|
|
|
|
g_source_remove (self->theme_changed_idle);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
unset_display (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_free (self->current_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; i < self->search_path_len; i++)
|
|
|
|
|
g_free (self->search_path[i]);
|
|
|
|
|
g_free (self->search_path);
|
2014-06-20 04:35:57 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_list_free_full (self->resource_paths, g_free);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
blow_themes (self);
|
|
|
|
|
clear_lru_cache (self);
|
2004-02-22 02:06:49 +00:00
|
|
|
|
|
2019-09-01 11:25:44 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_icon_theme_parent_class)->finalize (object);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_set_search_path:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 09:10:30 +00:00
|
|
|
|
* @path: (array length=n_elements) (element-type filename): array of
|
|
|
|
|
* directories that are searched for icon themes
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* @n_elements: number of elements in @path.
|
|
|
|
|
*
|
|
|
|
|
* Sets the search path for the icon theme object. When looking
|
|
|
|
|
* for an icon theme, GTK+ will search for a subdirectory of
|
|
|
|
|
* one or more of the directories in @path with the same name
|
2014-06-22 20:46:11 +00:00
|
|
|
|
* as the icon theme containing an index.theme file. (Themes from
|
|
|
|
|
* multiple of the path elements are combined to allow themes to be
|
|
|
|
|
* extended by adding icons in the user’s home directory.)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* In addition if an icon found isn’t found either in the current
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* icon theme or the default icon theme, and an image file with
|
|
|
|
|
* the right name is found directly in one of the elements of
|
|
|
|
|
* @path, then that image will be used for the icon name.
|
|
|
|
|
* (This is legacy feature, and new icons should be put
|
2014-06-22 20:46:11 +00:00
|
|
|
|
* into the fallback icon theme, which is called hicolor,
|
2004-01-20 16:32:54 +00:00
|
|
|
|
* rather than directly on the icon path.)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_set_search_path (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *path[],
|
|
|
|
|
gint n_elements)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
gint i;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; i < self->search_path_len; i++)
|
|
|
|
|
g_free (self->search_path[i]);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_free (self->search_path);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path = g_new (gchar *, n_elements);
|
|
|
|
|
self->search_path_len = n_elements;
|
2006-06-07 04:16:52 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; i < self->search_path_len; i++)
|
|
|
|
|
self->search_path[i] = g_strdup (path[i]);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_get_search_path:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
|
* @path: (allow-none) (array length=n_elements) (element-type filename) (out):
|
2011-02-09 04:14:46 +00:00
|
|
|
|
* location to store a list of icon theme path directories or %NULL.
|
|
|
|
|
* The stored value should be freed with g_strfreev().
|
|
|
|
|
* @n_elements: location to store number of elements in @path, or %NULL
|
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* Gets the current search path. See gtk_icon_theme_set_search_path().
|
2011-02-09 04:14:46 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_get_search_path (GtkIconTheme *self,
|
2011-02-09 04:14:46 +00:00
|
|
|
|
gchar **path[],
|
|
|
|
|
gint *n_elements)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint i;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (n_elements)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
*n_elements = self->search_path_len;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
*path = g_new (gchar *, self->search_path_len + 1);
|
|
|
|
|
for (i = 0; i < self->search_path_len; i++)
|
|
|
|
|
(*path)[i] = g_strdup (self->search_path[i]);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
(*path)[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_append_search_path:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
|
* @path: (type filename): directory name to append to the icon path
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2004-11-10 02:03:36 +00:00
|
|
|
|
* Appends a directory to the search path.
|
|
|
|
|
* See gtk_icon_theme_set_search_path().
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_append_search_path (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *path)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path_len++;
|
2006-06-07 04:16:52 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path = g_renew (gchar *, self->search_path, self->search_path_len);
|
|
|
|
|
self->search_path[self->search_path_len-1] = g_strdup (path);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_prepend_search_path:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
|
* @path: (type filename): directory name to prepend to the icon path
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2004-11-10 02:03:36 +00:00
|
|
|
|
* Prepends a directory to the search path.
|
|
|
|
|
* See gtk_icon_theme_set_search_path().
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_prepend_search_path (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *path)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint i;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path_len++;
|
|
|
|
|
self->search_path = g_renew (gchar *, self->search_path, self->search_path_len);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = self->search_path_len - 1; i > 0; i--)
|
|
|
|
|
self->search_path[i] = self->search_path[i - 1];
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->search_path[0] = g_strdup (path);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 04:46:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_add_resource_path:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2014-06-20 04:46:09 +00:00
|
|
|
|
* @path: a resource path
|
|
|
|
|
*
|
|
|
|
|
* Adds a resource path that will be looked at when looking
|
|
|
|
|
* for icons, similar to search paths.
|
|
|
|
|
*
|
|
|
|
|
* This function should be used to make application-specific icons
|
|
|
|
|
* available as part of the icon theme.
|
|
|
|
|
*
|
|
|
|
|
* The resources are considered as part of the hicolor icon theme
|
|
|
|
|
* and must be located in subdirectories that are defined in the
|
|
|
|
|
* hicolor icon theme, such as `@path/16x16/actions/run.png`.
|
|
|
|
|
* Icons that are directly placed in the resource path instead
|
|
|
|
|
* of a subdirectory are also considered as ultimate fallback.
|
|
|
|
|
*/
|
2014-06-20 04:35:57 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_add_resource_path (GtkIconTheme *self,
|
2014-06-20 04:35:57 +00:00
|
|
|
|
const gchar *path)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2014-06-20 04:35:57 +00:00
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->resource_paths = g_list_append (self->resource_paths, g_strdup (path));
|
2014-06-20 04:35:57 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2014-06-20 04:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_set_custom_theme:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 08:25:47 +00:00
|
|
|
|
* @theme_name: (allow-none): name of icon theme to use instead of
|
|
|
|
|
* configured theme, or %NULL to unset a previously set custom theme
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the name of the icon theme that the #GtkIconTheme object uses
|
|
|
|
|
* overriding system configuration. This function cannot be called
|
|
|
|
|
* on the icon theme objects returned from gtk_icon_theme_get_default()
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* and gtk_icon_theme_get_for_display().
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_set_custom_theme (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *theme_name)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (self));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_if_fail (!self->is_display_singleton);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (theme_name != NULL)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->custom_theme = TRUE;
|
|
|
|
|
if (!self->current_theme || strcmp (theme_name, self->current_theme) != 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_free (self->current_theme);
|
|
|
|
|
self->current_theme = g_strdup (theme_name);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->custom_theme)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->custom_theme = FALSE;
|
|
|
|
|
update_current_theme (self);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 05:04:16 +00:00
|
|
|
|
static const gchar builtin_hicolor_index[] =
|
|
|
|
|
"[Icon Theme]\n"
|
|
|
|
|
"Name=Hicolor\n"
|
|
|
|
|
"Hidden=True\n"
|
2016-03-31 11:11:24 +00:00
|
|
|
|
"Directories=16x16/actions,16x16/status,22x22/actions,24x24/actions,24x24/status,32x32/actions,32x32/status,48x48/status,64x64/actions\n"
|
2014-06-20 05:04:16 +00:00
|
|
|
|
"[16x16/actions]\n"
|
|
|
|
|
"Size=16\n"
|
|
|
|
|
"Type=Threshold\n"
|
2016-03-31 11:11:24 +00:00
|
|
|
|
"[16x16/status]\n"
|
|
|
|
|
"Size=16\n"
|
|
|
|
|
"Type=Threshold\n"
|
2014-06-20 05:04:16 +00:00
|
|
|
|
"[22x22/actions]\n"
|
|
|
|
|
"Size=22\n"
|
|
|
|
|
"Type=Threshold\n"
|
|
|
|
|
"[24x24/actions]\n"
|
|
|
|
|
"Size=24\n"
|
|
|
|
|
"Type=Threshold\n"
|
2016-03-31 11:11:24 +00:00
|
|
|
|
"[24x24/status]\n"
|
|
|
|
|
"Size=24\n"
|
|
|
|
|
"Type=Threshold\n"
|
2014-06-20 05:04:16 +00:00
|
|
|
|
"[32x32/actions]\n"
|
|
|
|
|
"Size=32\n"
|
2016-03-31 11:11:24 +00:00
|
|
|
|
"Type=Threshold\n"
|
|
|
|
|
"[32x32/status]\n"
|
|
|
|
|
"Size=32\n"
|
|
|
|
|
"Type=Threshold\n"
|
|
|
|
|
"[48x48/status]\n"
|
|
|
|
|
"Size=48\n"
|
|
|
|
|
"Type=Threshold\n"
|
|
|
|
|
"[64x64/actions]\n"
|
|
|
|
|
"Size=64\n"
|
2014-06-20 05:04:16 +00:00
|
|
|
|
"Type=Threshold\n";
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
insert_theme (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *theme_name)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint i;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GList *l;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar **dirs;
|
|
|
|
|
gchar **scaled_dirs;
|
|
|
|
|
gchar **themes;
|
2006-10-08 05:07:55 +00:00
|
|
|
|
IconTheme *theme = NULL;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *path;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
GKeyFile *theme_file;
|
|
|
|
|
GError *error = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
IconThemeDirMtime *dir_mtime;
|
2011-10-03 15:25:33 +00:00
|
|
|
|
GStatBuf stat_buf;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l != NULL; l = l->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
theme = l->data;
|
|
|
|
|
if (strcmp (theme->name, theme_name) == 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; i < self->search_path_len; i++)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
path = g_build_filename (self->search_path[i],
|
2014-06-19 23:42:53 +00:00
|
|
|
|
theme_name,
|
|
|
|
|
NULL);
|
2006-07-07 05:24:00 +00:00
|
|
|
|
dir_mtime = g_slice_new (IconThemeDirMtime);
|
2005-04-06 03:34:38 +00:00
|
|
|
|
dir_mtime->cache = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
dir_mtime->dir = path;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode)) {
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir_mtime->mtime = stat_buf.st_mtime;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
dir_mtime->exists = TRUE;
|
|
|
|
|
} else {
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir_mtime->mtime = 0;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
dir_mtime->exists = FALSE;
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->dir_mtimes = g_list_prepend (self->dir_mtimes, dir_mtime);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
theme_file = NULL;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; i < self->search_path_len && !theme_file; i++)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
path = g_build_filename (self->search_path[i],
|
2014-06-19 23:42:53 +00:00
|
|
|
|
theme_name,
|
|
|
|
|
"index.theme",
|
|
|
|
|
NULL);
|
2004-10-24 05:48:16 +00:00
|
|
|
|
if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
theme_file = g_key_file_new ();
|
|
|
|
|
g_key_file_set_list_separator (theme_file, ',');
|
2015-07-17 19:54:40 +00:00
|
|
|
|
if (!g_key_file_load_from_file (theme_file, path, 0, &error))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
g_key_file_free (theme_file);
|
|
|
|
|
theme_file = NULL;
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
error = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-10 01:12:08 +00:00
|
|
|
|
if (theme_file || strcmp (theme_name, FALLBACK_ICON_THEME) == 0)
|
2005-11-12 06:59:49 +00:00
|
|
|
|
{
|
|
|
|
|
theme = g_new0 (IconTheme, 1);
|
|
|
|
|
theme->name = g_strdup (theme_name);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->themes = g_list_prepend (self->themes, theme);
|
2014-06-20 05:04:16 +00:00
|
|
|
|
if (!theme_file)
|
|
|
|
|
{
|
|
|
|
|
theme_file = g_key_file_new ();
|
|
|
|
|
g_key_file_set_list_separator (theme_file, ',');
|
|
|
|
|
g_key_file_load_from_data (theme_file, builtin_hicolor_index, -1, 0, NULL);
|
|
|
|
|
}
|
2005-11-12 06:59:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
if (theme_file == NULL)
|
|
|
|
|
return;
|
2005-11-12 06:59:49 +00:00
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
theme->display_name =
|
|
|
|
|
g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
|
|
|
|
|
if (!theme->display_name)
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Theme file for %s has no name", theme_name);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
|
|
|
|
|
if (!dirs)
|
2006-04-12 04:22:51 +00:00
|
|
|
|
{
|
2016-02-28 16:06:25 +00:00
|
|
|
|
g_warning ("Theme file for %s has no directories", theme_name);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->themes = g_list_remove (self->themes, theme);
|
2006-12-02 19:48:22 +00:00
|
|
|
|
g_free (theme->name);
|
2006-04-12 04:22:51 +00:00
|
|
|
|
g_free (theme->display_name);
|
|
|
|
|
g_free (theme);
|
|
|
|
|
g_key_file_free (theme_file);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-19 13:42:30 +00:00
|
|
|
|
|
|
|
|
|
scaled_dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "ScaledDirectories", NULL, NULL);
|
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
theme->comment =
|
|
|
|
|
g_key_file_get_locale_string (theme_file,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
"Icon Theme", "Comment",
|
|
|
|
|
NULL, NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
theme->dirs = NULL;
|
2006-04-12 04:22:51 +00:00
|
|
|
|
for (i = 0; dirs[i] != NULL; i++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
theme_subdir_load (self, theme, theme_file, dirs[i]);
|
2006-04-12 04:22:51 +00:00
|
|
|
|
|
2013-08-19 13:42:30 +00:00
|
|
|
|
if (scaled_dirs)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; scaled_dirs[i] != NULL; i++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
theme_subdir_load (self, theme, theme_file, scaled_dirs[i]);
|
2013-08-19 13:42:30 +00:00
|
|
|
|
}
|
2006-04-12 04:22:51 +00:00
|
|
|
|
g_strfreev (dirs);
|
2013-08-19 13:42:30 +00:00
|
|
|
|
g_strfreev (scaled_dirs);
|
2006-04-12 04:22:51 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
theme->dirs = g_list_reverse (theme->dirs);
|
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
themes = g_key_file_get_string_list (theme_file,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
"Icon Theme",
|
|
|
|
|
"Inherits",
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2004-10-24 05:48:16 +00:00
|
|
|
|
if (themes)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
for (i = 0; themes[i] != NULL; i++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
insert_theme (self, themes[i]);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
g_strfreev (themes);
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
g_key_file_free (theme_file);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_unthemed_icon (UnthemedIcon *unthemed_icon)
|
|
|
|
|
{
|
2007-03-09 21:57:37 +00:00
|
|
|
|
g_free (unthemed_icon->svg_filename);
|
|
|
|
|
g_free (unthemed_icon->no_svg_filename);
|
2006-03-31 05:17:56 +00:00
|
|
|
|
g_slice_free (UnthemedIcon, unthemed_icon);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static gchar *
|
|
|
|
|
strip_suffix (const gchar *filename)
|
2006-04-18 13:58:30 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *dot;
|
2006-04-18 13:58:30 +00:00
|
|
|
|
|
2014-07-30 16:05:48 +00:00
|
|
|
|
if (g_str_has_suffix (filename, ".symbolic.png"))
|
|
|
|
|
return g_strndup (filename, strlen(filename)-13);
|
|
|
|
|
|
2006-04-18 13:58:30 +00:00
|
|
|
|
dot = strrchr (filename, '.');
|
|
|
|
|
|
|
|
|
|
if (dot == NULL)
|
|
|
|
|
return g_strdup (filename);
|
|
|
|
|
|
|
|
|
|
return g_strndup (filename, dot - filename);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 21:02:41 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
add_unthemed_icon (GtkIconTheme *self,
|
2014-06-30 21:02:41 +00:00
|
|
|
|
const gchar *dir,
|
|
|
|
|
const gchar *file,
|
|
|
|
|
gboolean is_resource)
|
|
|
|
|
{
|
|
|
|
|
IconSuffix new_suffix, old_suffix;
|
|
|
|
|
gchar *abs_file;
|
|
|
|
|
gchar *base_name;
|
|
|
|
|
UnthemedIcon *unthemed_icon;
|
|
|
|
|
|
|
|
|
|
new_suffix = suffix_from_name (file);
|
|
|
|
|
|
|
|
|
|
if (new_suffix == ICON_SUFFIX_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
abs_file = g_build_filename (dir, file, NULL);
|
|
|
|
|
base_name = strip_suffix (file);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
unthemed_icon = g_hash_table_lookup (self->unthemed_icons, base_name);
|
2014-06-30 21:02:41 +00:00
|
|
|
|
|
|
|
|
|
if (unthemed_icon)
|
|
|
|
|
{
|
|
|
|
|
if (new_suffix == ICON_SUFFIX_SVG)
|
|
|
|
|
{
|
|
|
|
|
if (unthemed_icon->svg_filename)
|
|
|
|
|
g_free (abs_file);
|
|
|
|
|
else
|
|
|
|
|
unthemed_icon->svg_filename = abs_file;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (unthemed_icon->no_svg_filename)
|
|
|
|
|
{
|
|
|
|
|
old_suffix = suffix_from_name (unthemed_icon->no_svg_filename);
|
|
|
|
|
if (new_suffix > old_suffix)
|
|
|
|
|
{
|
|
|
|
|
g_free (unthemed_icon->no_svg_filename);
|
|
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_free (abs_file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (base_name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
unthemed_icon = g_slice_new0 (UnthemedIcon);
|
|
|
|
|
|
|
|
|
|
unthemed_icon->is_resource = is_resource;
|
|
|
|
|
|
|
|
|
|
if (new_suffix == ICON_SUFFIX_SVG)
|
|
|
|
|
unthemed_icon->svg_filename = abs_file;
|
|
|
|
|
else
|
|
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
|
|
|
|
|
|
|
|
|
/* takes ownership of base_name */
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_replace (self->unthemed_icons, base_name, unthemed_icon);
|
2014-06-30 21:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
load_themes (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GDir *gdir;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint base;
|
|
|
|
|
gchar *dir;
|
|
|
|
|
const gchar *file;
|
2003-07-20 15:50:14 +00:00
|
|
|
|
GTimeVal tv;
|
2005-07-13 14:07:10 +00:00
|
|
|
|
IconThemeDirMtime *dir_mtime;
|
2011-10-03 15:25:33 +00:00
|
|
|
|
GStatBuf stat_buf;
|
2014-06-30 21:02:41 +00:00
|
|
|
|
GList *d;
|
2020-01-23 03:20:17 +00:00
|
|
|
|
gint64 before = g_get_monotonic_time ();
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->current_theme)
|
|
|
|
|
insert_theme (self, self->current_theme);
|
2006-01-11 06:20:17 +00:00
|
|
|
|
|
2014-06-22 20:46:11 +00:00
|
|
|
|
/* Always look in the Adwaita, gnome and hicolor icon themes.
|
|
|
|
|
* Looking in hicolor is mandated by the spec, looking in Adwaita
|
|
|
|
|
* and gnome is a pragmatic solution to prevent missing icons in
|
|
|
|
|
* GTK+ applications when run under, e.g. KDE.
|
2013-10-21 16:58:29 +00:00
|
|
|
|
*/
|
2019-02-12 18:31:58 +00:00
|
|
|
|
#if 0
|
2019-09-08 12:57:40 +00:00
|
|
|
|
insert_theme (self, DEFAULT_self);
|
|
|
|
|
insert_theme (self, "gnome");
|
2019-02-12 18:31:58 +00:00
|
|
|
|
#endif
|
2019-09-08 12:57:40 +00:00
|
|
|
|
insert_theme (self, FALLBACK_ICON_THEME);
|
|
|
|
|
self->themes = g_list_reverse (self->themes);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->unthemed_icons = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_free, (GDestroyNotify)free_unthemed_icon);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (base = 0; base < self->search_path_len; base++)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
dir = self->search_path[base];
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2006-07-07 05:24:00 +00:00
|
|
|
|
dir_mtime = g_slice_new (IconThemeDirMtime);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->dir_mtimes = g_list_prepend (self->dir_mtimes, dir_mtime);
|
2006-03-31 05:17:56 +00:00
|
|
|
|
|
2007-01-02 04:19:28 +00:00
|
|
|
|
dir_mtime->dir = g_strdup (dir);
|
|
|
|
|
dir_mtime->mtime = 0;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
dir_mtime->exists = FALSE;
|
2007-01-02 04:19:28 +00:00
|
|
|
|
dir_mtime->cache = NULL;
|
|
|
|
|
|
|
|
|
|
if (g_stat (dir, &stat_buf) != 0 || !S_ISDIR (stat_buf.st_mode))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
continue;
|
2007-01-02 04:19:28 +00:00
|
|
|
|
dir_mtime->mtime = stat_buf.st_mtime;
|
2015-02-23 20:49:08 +00:00
|
|
|
|
dir_mtime->exists = TRUE;
|
2007-01-02 04:19:28 +00:00
|
|
|
|
|
2018-02-01 15:05:58 +00:00
|
|
|
|
dir_mtime->cache = gtk_icon_cache_new_for_path (dir);
|
2005-07-13 14:07:10 +00:00
|
|
|
|
if (dir_mtime->cache != NULL)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
continue;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gdir = g_dir_open (dir, 0, NULL);
|
|
|
|
|
if (gdir == NULL)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
continue;
|
2006-03-31 05:17:56 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
while ((file = g_dir_read_name (gdir)))
|
2019-09-08 12:57:40 +00:00
|
|
|
|
add_unthemed_icon (self, dir, file, FALSE);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2014-06-30 21:02:41 +00:00
|
|
|
|
g_dir_close (gdir);
|
|
|
|
|
}
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->dir_mtimes = g_list_reverse (self->dir_mtimes);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (d = self->resource_paths; d; d = d->next)
|
2014-06-30 21:02:41 +00:00
|
|
|
|
{
|
|
|
|
|
gchar **children;
|
|
|
|
|
gint i;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2014-06-30 21:02:41 +00:00
|
|
|
|
dir = d->data;
|
|
|
|
|
children = g_resources_enumerate_children (dir, 0, NULL);
|
|
|
|
|
if (!children)
|
|
|
|
|
continue;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2014-06-30 21:02:41 +00:00
|
|
|
|
for (i = 0; children[i]; i++)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
add_unthemed_icon (self, dir, children[i], TRUE);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2014-06-30 21:02:41 +00:00
|
|
|
|
g_strfreev (children);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->themes_valid = TRUE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_get_current_time (&tv);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->last_stat_time = tv.tv_sec;
|
2014-05-24 15:01:27 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME, {
|
2014-05-24 15:01:27 +00:00
|
|
|
|
GList *l;
|
2016-02-28 20:33:18 +00:00
|
|
|
|
GString *s;
|
|
|
|
|
s = g_string_new ("Current icon themes ");
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l; l = l->next)
|
2014-05-24 15:01:27 +00:00
|
|
|
|
{
|
|
|
|
|
IconTheme *theme = l->data;
|
2016-02-28 20:33:18 +00:00
|
|
|
|
g_string_append (s, theme->name);
|
|
|
|
|
g_string_append_c (s, ' ');
|
2014-05-24 15:01:27 +00:00
|
|
|
|
}
|
2016-02-28 20:33:18 +00:00
|
|
|
|
g_message ("%s", s->str);
|
|
|
|
|
g_string_free (s, TRUE);
|
2014-05-24 15:01:27 +00:00
|
|
|
|
});
|
2020-01-23 03:20:17 +00:00
|
|
|
|
|
|
|
|
|
self->loading_themes = FALSE;
|
|
|
|
|
gdk_profiler_add_mark (before * 1000, (g_get_monotonic_time () - before) * 1000, "icon theme load", self->current_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
ensure_valid_themes (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2003-07-20 15:50:14 +00:00
|
|
|
|
GTimeVal tv;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gboolean was_valid = self->themes_valid;
|
2005-08-22 20:12:15 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->loading_themes)
|
2007-03-15 18:40:16 +00:00
|
|
|
|
return;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->loading_themes = TRUE;
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (self->themes_valid)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-10-20 17:23:02 +00:00
|
|
|
|
g_get_current_time (&tv);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (ABS (tv.tv_sec - self->last_stat_time) > 5 &&
|
|
|
|
|
rescan_themes (self))
|
2013-06-19 07:35:24 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_remove_all (self->info_cache);
|
|
|
|
|
blow_themes (self);
|
|
|
|
|
clear_lru_cache (self);
|
2013-06-19 07:35:24 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2019-09-01 11:25:44 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
if (!self->themes_valid)
|
2005-08-22 20:12:15 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
load_themes (self);
|
2005-08-22 20:12:15 +00:00
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
|
if (was_valid)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
queue_theme_changed (self);
|
2005-08-22 20:12:15 +00:00
|
|
|
|
}
|
2020-01-23 03:20:17 +00:00
|
|
|
|
}
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
2020-01-23 03:20:17 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_icon_theme_ensure_loaded (GtkIconTheme *self)
|
|
|
|
|
{
|
|
|
|
|
ensure_valid_themes (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-21 12:26:19 +00:00
|
|
|
|
static inline gboolean
|
|
|
|
|
icon_name_is_symbolic (const gchar *icon_name,
|
|
|
|
|
int icon_name_len)
|
2014-05-13 13:50:05 +00:00
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
|
|
|
|
|
if (icon_name_len < 0)
|
|
|
|
|
icon_name_len = strlen (icon_name);
|
|
|
|
|
|
|
|
|
|
if (icon_name_len > strlen ("-symbolic"))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (icon_name + icon_name_len - strlen ("-symbolic"), "-symbolic") == 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (icon_name_len > strlen ("-symbolic-ltr"))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (icon_name + icon_name_len - strlen ("-symbolic-ltr"), "-symbolic-ltr") == 0 ||
|
|
|
|
|
strcmp (icon_name + icon_name_len - strlen ("-symbolic-rtl"), "-symbolic-rtl") == 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2014-05-13 13:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 08:14:52 +00:00
|
|
|
|
static inline gboolean
|
|
|
|
|
icon_uri_is_symbolic (const gchar *icon_name,
|
|
|
|
|
int icon_name_len)
|
2014-05-13 13:50:05 +00:00
|
|
|
|
{
|
2019-05-28 08:14:52 +00:00
|
|
|
|
if (icon_name_len < 0)
|
|
|
|
|
icon_name_len = strlen (icon_name);
|
|
|
|
|
|
|
|
|
|
if (icon_name_len > strlen ("-symbolic.svg"))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (icon_name + icon_name_len - strlen ("-symbolic.svg"), "-symbolic.svg") == 0 ||
|
|
|
|
|
strcmp (icon_name + icon_name_len - strlen (".symbolic.png"), ".symbolic.png") == 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (icon_name_len > strlen ("-symbolic-ltr.svg"))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (icon_name + icon_name_len - strlen ("-symbolic.ltr.svg"), "-symbolic-ltr.svg") == 0 ||
|
|
|
|
|
strcmp (icon_name + icon_name_len - strlen ("-symbolic.rtl.svg"), "-symbolic-rtl.svg") == 0)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2014-05-13 13:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
static GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
real_choose_icon (GtkIconTheme *self,
|
2014-05-10 13:35:12 +00:00
|
|
|
|
const gchar *icon_names[],
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
GtkIconInfo *icon_info = NULL;
|
2013-09-23 10:42:30 +00:00
|
|
|
|
GtkIconInfo *unscaled_icon_info;
|
2007-06-03 20:44:10 +00:00
|
|
|
|
UnthemedIcon *unthemed_icon = NULL;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_name = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gboolean allow_svg;
|
2013-09-23 10:42:30 +00:00
|
|
|
|
IconTheme *theme = NULL;
|
2007-05-18 20:19:12 +00:00
|
|
|
|
gint i;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
IconInfoKey key;
|
2004-10-20 17:23:02 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
ensure_valid_themes (self);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
key.icon_names = (gchar **)icon_names;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
key.size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
key.scale = scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
key.flags = flags;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = g_hash_table_lookup (self->info_cache, &key);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
if (icon_info != NULL)
|
|
|
|
|
{
|
|
|
|
|
DEBUG_CACHE (("cache hit %p (%s %d 0x%x) (cache size %d)\n",
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info,
|
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_size (self->info_cache)));
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2013-02-16 00:35:44 +00:00
|
|
|
|
icon_info = g_object_ref (icon_info);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2019-09-01 11:25:44 +00:00
|
|
|
|
/* Move item to front in LRU cache */
|
|
|
|
|
add_to_lru_cache (icon_info);
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
return icon_info;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
if (flags & GTK_ICON_LOOKUP_NO_SVG)
|
|
|
|
|
allow_svg = FALSE;
|
|
|
|
|
else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
|
|
|
|
|
allow_svg = TRUE;
|
|
|
|
|
else
|
2019-09-08 12:57:40 +00:00
|
|
|
|
allow_svg = self->pixbuf_supports_svg;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-05-14 02:13:58 +00:00
|
|
|
|
/* This is used in the icontheme unit test */
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME,
|
2014-05-14 02:13:58 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
2016-02-28 20:33:18 +00:00
|
|
|
|
g_message ("\tlookup name: %s", icon_names[i]));
|
2014-05-14 02:13:58 +00:00
|
|
|
|
|
2014-09-21 18:46:09 +00:00
|
|
|
|
/* For symbolic icons, do a search in all registered themes first;
|
2012-04-25 01:47:33 +00:00
|
|
|
|
* a theme that inherits them from a parent theme might provide
|
2014-09-21 18:29:36 +00:00
|
|
|
|
* an alternative full-color version, but still expect the symbolic icon
|
2012-04-25 01:47:33 +00:00
|
|
|
|
* to show up instead.
|
2014-09-21 18:46:09 +00:00
|
|
|
|
*
|
|
|
|
|
* In other words: We prefer symbolic icons in inherited themes over
|
|
|
|
|
* generic icons in the theme.
|
2012-04-25 01:47:33 +00:00
|
|
|
|
*/
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l; l = l->next)
|
2012-04-25 01:47:33 +00:00
|
|
|
|
{
|
2014-09-21 18:46:09 +00:00
|
|
|
|
theme = l->data;
|
2019-05-21 12:26:19 +00:00
|
|
|
|
for (i = 0; icon_names[i] && icon_name_is_symbolic (icon_names[i], -1); i++)
|
2012-04-25 01:47:33 +00:00
|
|
|
|
{
|
2014-09-21 18:46:09 +00:00
|
|
|
|
icon_name = icon_names[i];
|
2019-05-21 12:53:03 +00:00
|
|
|
|
icon_info = theme_lookup_icon (theme, icon_name, size, scale, allow_svg);
|
2012-04-25 01:47:33 +00:00
|
|
|
|
if (icon_info)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l; l = l->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2013-09-23 10:42:30 +00:00
|
|
|
|
theme = l->data;
|
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
2007-04-19 04:14:39 +00:00
|
|
|
|
{
|
2013-09-23 10:42:30 +00:00
|
|
|
|
icon_name = icon_names[i];
|
2019-05-21 12:53:03 +00:00
|
|
|
|
icon_info = theme_lookup_icon (theme, icon_name, size, scale, allow_svg);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
if (icon_info)
|
|
|
|
|
goto out;
|
2007-04-19 04:14:39 +00:00
|
|
|
|
}
|
2007-05-18 20:19:12 +00:00
|
|
|
|
}
|
2007-04-19 04:14:39 +00:00
|
|
|
|
|
2013-09-23 10:42:30 +00:00
|
|
|
|
theme = NULL;
|
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
unthemed_icon = g_hash_table_lookup (self->unthemed_icons, icon_names[i]);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
if (unthemed_icon)
|
|
|
|
|
break;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2008-06-16 13:27:46 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
/* Still not found an icon, check if reference to a Win32 resource */
|
|
|
|
|
if (!unthemed_icon)
|
|
|
|
|
{
|
|
|
|
|
gchar **resources;
|
|
|
|
|
HICON hIcon = NULL;
|
|
|
|
|
|
|
|
|
|
resources = g_strsplit (icon_names[0], ",", 0);
|
|
|
|
|
if (resources[0])
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
wchar_t *wfile = g_utf8_to_utf16 (resources[0], -1, NULL, NULL, NULL);
|
|
|
|
|
ExtractIconExW (wfile, resources[1] ? atoi (resources[1]) : 0, &hIcon, NULL, 1);
|
|
|
|
|
g_free (wfile);
|
|
|
|
|
}
|
2008-06-16 13:27:46 +00:00
|
|
|
|
|
|
|
|
|
if (hIcon)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
icon_info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
|
|
|
|
icon_info->cache_pixbuf = gdk_win32_icon_to_pixbuf_libgtk_only (hIcon, NULL, NULL);
|
|
|
|
|
DestroyIcon (hIcon);
|
|
|
|
|
}
|
2008-06-16 13:27:46 +00:00
|
|
|
|
g_strfreev (resources);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (unthemed_icon)
|
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
|
icon_info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-06-23 02:04:00 +00:00
|
|
|
|
/* A SVG icon, when allowed, beats out a XPM icon, but not a PNG icon */
|
2003-07-02 22:44:09 +00:00
|
|
|
|
if (allow_svg &&
|
2014-06-19 23:42:53 +00:00
|
|
|
|
unthemed_icon->svg_filename &&
|
|
|
|
|
(!unthemed_icon->no_svg_filename ||
|
2014-07-30 16:05:48 +00:00
|
|
|
|
suffix_from_name (unthemed_icon->no_svg_filename) < ICON_SUFFIX_PNG))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->filename = g_strdup (unthemed_icon->svg_filename);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else if (unthemed_icon->no_svg_filename)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->filename = g_strdup (unthemed_icon->no_svg_filename);
|
2019-08-07 17:20:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
static gboolean warned_once = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!warned_once)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Found an icon but could not load it. "
|
|
|
|
|
"Most likely gdk-pixbuf does not provide SVG support.");
|
|
|
|
|
warned_once = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_clear_object (&icon_info);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-06-17 16:05:22 +00:00
|
|
|
|
icon_info->is_svg = suffix_from_name (icon_info->filename) == ICON_SUFFIX_SVG;
|
2014-06-30 21:02:41 +00:00
|
|
|
|
icon_info->is_resource = unthemed_icon->is_resource;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
2012-11-26 12:49:49 +00:00
|
|
|
|
if (icon_info)
|
2008-05-29 14:33:49 +00:00
|
|
|
|
{
|
|
|
|
|
icon_info->desired_size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
icon_info->desired_scale = scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
icon_info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
2014-06-18 22:21:51 +00:00
|
|
|
|
/* In case we're not scaling the icon we want to reuse the exact same
|
|
|
|
|
* size as a scale==1 lookup would be, rather than not scaling at all
|
|
|
|
|
* and causing a different layout
|
|
|
|
|
*/
|
2013-09-23 10:42:30 +00:00
|
|
|
|
icon_info->unscaled_scale = 1.0;
|
|
|
|
|
if (scale != 1 && !icon_info->forced_size && theme != NULL)
|
|
|
|
|
{
|
2019-05-21 12:53:03 +00:00
|
|
|
|
unscaled_icon_info = theme_lookup_icon (theme, icon_name, size, 1, allow_svg);
|
2013-09-23 10:42:30 +00:00
|
|
|
|
if (unscaled_icon_info)
|
|
|
|
|
{
|
|
|
|
|
icon_info->unscaled_scale =
|
|
|
|
|
(gdouble) unscaled_icon_info->dir_size * scale / (icon_info->dir_size * icon_info->dir_scale);
|
|
|
|
|
g_object_unref (unscaled_icon_info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
|
icon_info->key.icon_names = g_strdupv ((char **)icon_names);
|
|
|
|
|
icon_info->key.size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
icon_info->key.scale = scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
icon_info->key.flags = flags;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info->in_cache = self;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
DEBUG_CACHE (("adding %p (%s %d 0x%x) to cache (cache size %d)\n",
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info,
|
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_size (self->info_cache)));
|
|
|
|
|
g_hash_table_insert (self->info_cache, &icon_info->key, icon_info);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
}
|
2004-01-20 16:32:54 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
static gboolean check_for_default_theme = TRUE;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *default_theme_path;
|
2004-01-20 16:32:54 +00:00
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
|
|
|
|
|
if (check_for_default_theme)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
check_for_default_theme = FALSE;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (i = 0; !found && i < self->search_path_len; i++)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
default_theme_path = g_build_filename (self->search_path[i],
|
2014-07-10 01:12:08 +00:00
|
|
|
|
FALLBACK_ICON_THEME,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
"index.theme",
|
|
|
|
|
NULL);
|
|
|
|
|
found = g_file_test (default_theme_path, G_FILE_TEST_IS_REGULAR);
|
|
|
|
|
g_free (default_theme_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Could not find the icon '%s'. The '%s' theme\n"
|
|
|
|
|
"was not found either, perhaps you need to install it.\n"
|
|
|
|
|
"You can get a copy from:\n"
|
|
|
|
|
"\t%s",
|
2014-07-10 01:12:08 +00:00
|
|
|
|
icon_names[0], FALLBACK_ICON_THEME, "http://icon-theme.freedesktop.org/releases");
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-20 16:32:54 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
return icon_info;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 01:34:49 +00:00
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_name_list_add_icon (GPtrArray *icons,
|
|
|
|
|
const gchar *dir_suffix,
|
|
|
|
|
gchar *icon_name)
|
2014-05-14 01:34:49 +00:00
|
|
|
|
{
|
|
|
|
|
if (dir_suffix)
|
|
|
|
|
g_ptr_array_add (icons, g_strconcat (icon_name, dir_suffix, NULL));
|
|
|
|
|
g_ptr_array_add (icons, icon_name);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-10 13:35:12 +00:00
|
|
|
|
static GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
choose_icon (GtkIconTheme *self,
|
2014-05-10 13:35:12 +00:00
|
|
|
|
const gchar *icon_names[],
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags)
|
|
|
|
|
{
|
|
|
|
|
gboolean has_regular = FALSE, has_symbolic = FALSE;
|
|
|
|
|
GtkIconInfo *icon_info;
|
2014-05-11 00:30:50 +00:00
|
|
|
|
GPtrArray *new_names;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *dir_suffix;
|
2014-05-10 13:35:12 +00:00
|
|
|
|
guint i;
|
|
|
|
|
|
2014-05-14 01:34:49 +00:00
|
|
|
|
if (flags & GTK_ICON_LOOKUP_DIR_LTR)
|
|
|
|
|
dir_suffix = "-ltr";
|
|
|
|
|
else if (flags & GTK_ICON_LOOKUP_DIR_RTL)
|
|
|
|
|
dir_suffix = "-rtl";
|
|
|
|
|
else
|
|
|
|
|
dir_suffix = NULL;
|
|
|
|
|
|
2014-05-10 13:35:12 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
if (icon_name_is_symbolic (icon_names[i], -1))
|
2014-05-10 13:35:12 +00:00
|
|
|
|
has_symbolic = TRUE;
|
|
|
|
|
else
|
|
|
|
|
has_regular = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
|
|
|
|
|
{
|
2014-05-11 00:30:50 +00:00
|
|
|
|
new_names = g_ptr_array_new_with_free_func (g_free);
|
2014-05-10 13:35:12 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
if (icon_name_is_symbolic (icon_names[i], -1))
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic")));
|
2014-05-10 13:35:12 +00:00
|
|
|
|
else
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
|
2014-05-10 13:35:12 +00:00
|
|
|
|
}
|
2014-05-11 00:30:50 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
if (icon_name_is_symbolic (icon_names[i], -1))
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
|
2014-05-11 00:30:50 +00:00
|
|
|
|
}
|
|
|
|
|
g_ptr_array_add (new_names, NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = real_choose_icon (self,
|
2014-05-11 00:30:50 +00:00
|
|
|
|
(const gchar **) new_names->pdata,
|
|
|
|
|
size,
|
|
|
|
|
scale,
|
|
|
|
|
flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
|
|
|
|
|
|
|
|
|
|
g_ptr_array_free (new_names, TRUE);
|
2014-05-10 13:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
|
|
|
|
|
{
|
2014-05-11 00:30:50 +00:00
|
|
|
|
new_names = g_ptr_array_new_with_free_func (g_free);
|
2014-05-10 13:35:12 +00:00
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
if (!icon_name_is_symbolic (icon_names[i], -1))
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strconcat (icon_names[i], "-symbolic", NULL));
|
2014-05-10 13:35:12 +00:00
|
|
|
|
else
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
|
2014-05-11 00:30:50 +00:00
|
|
|
|
}
|
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
if (!icon_name_is_symbolic (icon_names[i], -1))
|
2014-05-14 01:34:49 +00:00
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
|
|
|
|
|
}
|
|
|
|
|
g_ptr_array_add (new_names, NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = real_choose_icon (self,
|
2014-05-14 01:34:49 +00:00
|
|
|
|
(const gchar **) new_names->pdata,
|
|
|
|
|
size,
|
|
|
|
|
scale,
|
|
|
|
|
flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
|
|
|
|
|
|
|
|
|
|
g_ptr_array_free (new_names, TRUE);
|
|
|
|
|
}
|
|
|
|
|
else if (dir_suffix)
|
|
|
|
|
{
|
|
|
|
|
new_names = g_ptr_array_new_with_free_func (g_free);
|
|
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
icon_name_list_add_icon (new_names, dir_suffix, g_strdup (icon_names[i]));
|
2014-05-10 13:35:12 +00:00
|
|
|
|
}
|
2014-05-11 00:30:50 +00:00
|
|
|
|
g_ptr_array_add (new_names, NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = real_choose_icon (self,
|
2014-05-11 00:30:50 +00:00
|
|
|
|
(const gchar **) new_names->pdata,
|
|
|
|
|
size,
|
|
|
|
|
scale,
|
|
|
|
|
flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
|
|
|
|
|
|
|
|
|
|
g_ptr_array_free (new_names, TRUE);
|
2014-05-10 13:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = real_choose_icon (self,
|
2014-05-11 00:30:50 +00:00
|
|
|
|
icon_names,
|
|
|
|
|
size,
|
|
|
|
|
scale,
|
|
|
|
|
flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
|
2014-05-10 13:35:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return icon_info;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_lookup_icon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2007-05-18 20:19:12 +00:00
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
|
* Looks up a named icon and returns a #GtkIconInfo containing
|
2007-05-18 20:19:12 +00:00
|
|
|
|
* information such as the filename of the icon. The icon
|
|
|
|
|
* can then be rendered into a pixbuf using
|
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
|
|
|
|
|
* combines these two steps if all you need is the pixbuf.)
|
2015-11-04 11:50:37 +00:00
|
|
|
|
*
|
|
|
|
|
* When rendering on displays with high pixel densities you should not
|
|
|
|
|
* use a @size multiplied by the scaling factor returned by functions
|
2018-03-20 10:40:08 +00:00
|
|
|
|
* like gdk_surface_get_scale_factor(). Instead, you should use
|
2015-11-04 11:50:37 +00:00
|
|
|
|
* gtk_icon_theme_lookup_icon_for_scale(), as the assets loaded
|
|
|
|
|
* for a given scaling factor may be different.
|
2007-05-18 20:19:12 +00:00
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo object
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* containing information about the icon, or %NULL if the
|
|
|
|
|
* icon wasn’t found.
|
2007-05-18 20:19:12 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_lookup_icon (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2013-05-10 16:06:00 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME,
|
2018-01-14 14:53:48 +00:00
|
|
|
|
g_message ("looking up icon %s", icon_name));
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return gtk_icon_theme_lookup_icon_for_scale (self, icon_name,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
size, 1, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_lookup_icon_for_scale:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @scale: the desired scale
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
|
|
|
|
* Looks up a named icon for a particular window scale and returns a
|
2014-01-27 22:04:46 +00:00
|
|
|
|
* #GtkIconInfo containing information such as the filename of the
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* icon. The icon can then be rendered into a pixbuf using
|
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines
|
|
|
|
|
* these two steps if all you need is the pixbuf.)
|
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo object
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* containing information about the icon, or %NULL if the
|
|
|
|
|
* icon wasn’t found.
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *self,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2007-05-18 20:19:12 +00:00
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME,
|
2018-01-14 14:53:48 +00:00
|
|
|
|
g_message ("looking up icon %s for scale %d", icon_name, scale));
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
|
|
|
|
if (flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK)
|
|
|
|
|
{
|
2013-08-13 13:41:08 +00:00
|
|
|
|
gchar **names, **nonsymbolic_names;
|
2007-05-18 20:19:12 +00:00
|
|
|
|
gint dashes, i;
|
2013-08-13 13:41:08 +00:00
|
|
|
|
gchar *p, *nonsymbolic_icon_name;
|
|
|
|
|
gboolean is_symbolic;
|
2019-05-21 12:26:19 +00:00
|
|
|
|
int icon_name_len = strlen (icon_name);
|
2013-08-13 13:41:08 +00:00
|
|
|
|
|
2019-05-21 12:26:19 +00:00
|
|
|
|
is_symbolic = icon_name_is_symbolic (icon_name, icon_name_len);
|
2013-08-13 13:41:08 +00:00
|
|
|
|
if (is_symbolic)
|
2019-05-21 12:26:19 +00:00
|
|
|
|
nonsymbolic_icon_name = g_strndup (icon_name, icon_name_len - strlen ("-symbolic"));
|
2013-08-13 13:41:08 +00:00
|
|
|
|
else
|
|
|
|
|
nonsymbolic_icon_name = g_strdup (icon_name);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
|
|
|
|
dashes = 0;
|
2013-08-13 13:41:08 +00:00
|
|
|
|
for (p = (gchar *) nonsymbolic_icon_name; *p; p++)
|
2007-05-18 20:19:12 +00:00
|
|
|
|
if (*p == '-')
|
|
|
|
|
dashes++;
|
|
|
|
|
|
2013-08-13 13:41:08 +00:00
|
|
|
|
nonsymbolic_names = g_new (gchar *, dashes + 2);
|
|
|
|
|
nonsymbolic_names[0] = nonsymbolic_icon_name;
|
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
for (i = 1; i <= dashes; i++)
|
|
|
|
|
{
|
2013-08-13 13:41:08 +00:00
|
|
|
|
nonsymbolic_names[i] = g_strdup (nonsymbolic_names[i - 1]);
|
|
|
|
|
p = strrchr (nonsymbolic_names[i], '-');
|
2007-05-18 20:19:12 +00:00
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
2013-08-13 13:41:08 +00:00
|
|
|
|
nonsymbolic_names[dashes + 1] = NULL;
|
|
|
|
|
|
|
|
|
|
if (is_symbolic)
|
|
|
|
|
{
|
2013-10-16 01:19:17 +00:00
|
|
|
|
names = g_new (gchar *, 2 * dashes + 3);
|
2013-08-13 13:41:08 +00:00
|
|
|
|
for (i = 0; nonsymbolic_names[i] != NULL; i++)
|
2013-10-16 01:19:17 +00:00
|
|
|
|
{
|
|
|
|
|
names[i] = g_strconcat (nonsymbolic_names[i], "-symbolic", NULL);
|
|
|
|
|
names[dashes + 1 + i] = nonsymbolic_names[i];
|
|
|
|
|
}
|
2013-08-13 13:41:08 +00:00
|
|
|
|
|
2013-10-16 01:19:17 +00:00
|
|
|
|
names[dashes + 1 + i] = NULL;
|
|
|
|
|
g_free (nonsymbolic_names);
|
2013-08-13 13:41:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
names = nonsymbolic_names;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = choose_icon (self, (const gchar **) names, size, scale, flags);
|
2013-10-16 01:19:17 +00:00
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
g_strfreev (names);
|
|
|
|
|
}
|
2013-10-16 01:19:17 +00:00
|
|
|
|
else
|
2007-05-18 20:19:12 +00:00
|
|
|
|
{
|
2008-01-09 17:02:50 +00:00
|
|
|
|
const gchar *names[2];
|
2013-10-16 01:19:17 +00:00
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
names[0] = icon_name;
|
|
|
|
|
names[1] = NULL;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = choose_icon (self, names, size, scale, flags);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_choose_icon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 09:10:30 +00:00
|
|
|
|
* @icon_names: (array zero-terminated=1): %NULL-terminated array of
|
|
|
|
|
* icon names to lookup
|
2007-05-18 20:19:12 +00:00
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
|
* Looks up a named icon and returns a #GtkIconInfo containing
|
2007-05-18 20:19:12 +00:00
|
|
|
|
* information such as the filename of the icon. The icon
|
|
|
|
|
* can then be rendered into a pixbuf using
|
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
|
|
|
|
|
* combines these two steps if all you need is the pixbuf.)
|
|
|
|
|
*
|
|
|
|
|
* If @icon_names contains more than one name, this function
|
|
|
|
|
* tries them all in the given order before falling back to
|
|
|
|
|
* inherited icon themes.
|
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo object
|
|
|
|
|
* containing information about the icon, or %NULL if the icon wasn’t
|
|
|
|
|
* found.
|
2007-05-18 20:19:12 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_choose_icon (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_names[],
|
|
|
|
|
gint size,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2007-05-18 20:19:12 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
g_return_val_if_fail (icon_names != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2015-10-09 13:41:00 +00:00
|
|
|
|
g_warn_if_fail ((flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK) == 0);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return choose_icon (self, icon_names, size, 1, flags);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_choose_icon_for_scale:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* @icon_names: (array zero-terminated=1): %NULL-terminated
|
|
|
|
|
* array of icon names to lookup
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @scale: desired scale
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Looks up a named icon for a particular window scale and returns
|
|
|
|
|
* a #GtkIconInfo containing information such as the filename of the
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* icon. The icon can then be rendered into a pixbuf using
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
|
|
|
|
|
* combines these two steps if all you need is the pixbuf.)
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*
|
|
|
|
|
* If @icon_names contains more than one name, this function
|
|
|
|
|
* tries them all in the given order before falling back to
|
|
|
|
|
* inherited icon themes.
|
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo object
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* containing information about the icon, or %NULL if the
|
|
|
|
|
* icon wasn’t found.
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_choose_icon_for_scale (GtkIconTheme *self,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
const gchar *icon_names[],
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags)
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (icon_names != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
2015-10-09 13:41:00 +00:00
|
|
|
|
g_warn_if_fail ((flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK) == 0);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return choose_icon (self, icon_names, size, scale, flags);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* Error quark */
|
|
|
|
|
GQuark
|
|
|
|
|
gtk_icon_theme_error_quark (void)
|
|
|
|
|
{
|
2006-04-04 03:25:16 +00:00
|
|
|
|
return g_quark_from_static_string ("gtk-icon-theme-error-quark");
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_load_icon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
|
* @size: the desired icon size. The resulting icon may not be
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* exactly this size; see gtk_icon_info_load_icon().
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* @error: (allow-none): Location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* Looks up an icon in an icon theme, scales it to the given size
|
|
|
|
|
* and renders it into a pixbuf. This is a convenience function;
|
|
|
|
|
* if more details about the icon are needed, use
|
|
|
|
|
* gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
|
2005-08-22 16:38:46 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that you probably want to listen for icon theme changes and
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* update the icon. This is usually done by connecting to the
|
2005-08-22 16:38:46 +00:00
|
|
|
|
* GtkWidget::style-set signal. If for some reason you do not want to
|
|
|
|
|
* update the icon when the icon theme changes, you should consider
|
|
|
|
|
* using gdk_pixbuf_copy() to make a private copy of the pixbuf
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* returned by this function. Otherwise GTK+ may need to keep the old
|
2005-08-22 16:38:46 +00:00
|
|
|
|
* icon theme loaded, which would be a waste of memory.
|
2010-09-21 04:18:11 +00:00
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): the rendered icon; this may be
|
|
|
|
|
* a newly created icon or a new reference to an internal icon, so
|
2010-09-21 04:18:11 +00:00
|
|
|
|
* you must not modify the icon. Use g_object_unref() to release
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* your reference to the icon. %NULL if the icon isn’t found.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 18:54:16 +00:00
|
|
|
|
GdkPaintable *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_load_icon (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
GtkIconLookupFlags flags,
|
|
|
|
|
GError **error)
|
2013-05-10 16:06:00 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return gtk_icon_theme_load_icon_for_scale (self, icon_name,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
size, 1, flags, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_load_icon_for_scale:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
|
* @size: the desired icon size. The resulting icon may not be
|
|
|
|
|
* exactly this size; see gtk_icon_info_load_icon().
|
|
|
|
|
* @scale: desired scale
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
* @error: (allow-none): Location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Looks up an icon in an icon theme for a particular window scale,
|
|
|
|
|
* scales it to the given size and renders it into a pixbuf. This is a
|
|
|
|
|
* convenience function; if more details about the icon are needed,
|
|
|
|
|
* use gtk_icon_theme_lookup_icon() followed by
|
|
|
|
|
* gtk_icon_info_load_icon().
|
|
|
|
|
*
|
|
|
|
|
* Note that you probably want to listen for icon theme changes and
|
|
|
|
|
* update the icon. This is usually done by connecting to the
|
|
|
|
|
* GtkWidget::style-set signal. If for some reason you do not want to
|
|
|
|
|
* update the icon when the icon theme changes, you should consider
|
|
|
|
|
* using gdk_pixbuf_copy() to make a private copy of the pixbuf
|
|
|
|
|
* returned by this function. Otherwise GTK+ may need to keep the old
|
|
|
|
|
* icon theme loaded, which would be a waste of memory.
|
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): the rendered icon; this may be
|
|
|
|
|
* a newly created icon or a new reference to an internal icon, so
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* you must not modify the icon. Use g_object_unref() to release
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* your reference to the icon. %NULL if the icon isn’t found.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 18:54:16 +00:00
|
|
|
|
GdkPaintable *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_load_icon_for_scale (GtkIconTheme *self,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags,
|
|
|
|
|
GError **error)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *icon_info;
|
2019-08-30 20:58:41 +00:00
|
|
|
|
GdkPaintable *paintable = NULL;
|
2019-08-30 18:54:16 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_return_val_if_fail (icon_name != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_info = gtk_icon_theme_lookup_icon_for_scale (self, icon_name, size, scale,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
flags | GTK_ICON_LOOKUP_USE_BUILTIN);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
if (!icon_info)
|
|
|
|
|
{
|
|
|
|
|
g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
|
2019-09-08 12:57:40 +00:00
|
|
|
|
_("Icon “%s” not present in theme %s"), icon_name, self->current_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 20:58:41 +00:00
|
|
|
|
paintable = gtk_icon_info_load_icon (icon_info, error);
|
2017-06-08 00:08:22 +00:00
|
|
|
|
g_prefix_error (error, "Failed to load %s: ", icon_info->filename);
|
2013-02-16 00:35:44 +00:00
|
|
|
|
g_object_unref (icon_info);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-08-30 20:58:41 +00:00
|
|
|
|
return paintable;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_has_icon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* @icon_name: the name of an icon
|
|
|
|
|
*
|
|
|
|
|
* Checks whether an icon theme includes an icon
|
|
|
|
|
* for a particular name.
|
|
|
|
|
*
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* Returns: %TRUE if @self includes an
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* icon for @icon_name.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gboolean
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_has_icon (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_name)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-10-21 18:44:08 +00:00
|
|
|
|
GList *l;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), FALSE);
|
2009-01-22 15:15:40 +00:00
|
|
|
|
g_return_val_if_fail (icon_name != NULL, FALSE);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
ensure_valid_themes (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->dir_mtimes; l; l = l->next)
|
2004-10-21 18:44:08 +00:00
|
|
|
|
{
|
2005-04-06 03:34:38 +00:00
|
|
|
|
IconThemeDirMtime *dir_mtime = l->data;
|
|
|
|
|
GtkIconCache *cache = dir_mtime->cache;
|
|
|
|
|
|
2018-02-01 15:05:58 +00:00
|
|
|
|
if (cache && gtk_icon_cache_has_icon (cache, icon_name))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return TRUE;
|
2004-10-21 18:44:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l; l = l->next)
|
2014-06-20 01:37:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (theme_has_icon (l->data, icon_name))
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2003-12-07 22:53:22 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-17 03:55:07 +00:00
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
add_size (gpointer key,
|
|
|
|
|
gpointer value,
|
|
|
|
|
gpointer user_data)
|
2004-07-17 03:55:07 +00:00
|
|
|
|
{
|
|
|
|
|
gint **res_p = user_data;
|
|
|
|
|
|
|
|
|
|
**res_p = GPOINTER_TO_INT (key);
|
|
|
|
|
|
2004-08-03 18:51:26 +00:00
|
|
|
|
(*res_p)++;
|
2004-07-17 03:55:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_get_icon_sizes:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2004-07-17 03:55:07 +00:00
|
|
|
|
* @icon_name: the name of an icon
|
|
|
|
|
*
|
|
|
|
|
* Returns an array of integers describing the sizes at which
|
|
|
|
|
* the icon is available without scaling. A size of -1 means
|
|
|
|
|
* that the icon is available in a scalable format. The array
|
|
|
|
|
* is zero-terminated.
|
|
|
|
|
*
|
2019-08-25 12:52:24 +00:00
|
|
|
|
* Returns: (array zero-terminated=1) (transfer full): A newly
|
2014-05-26 16:42:23 +00:00
|
|
|
|
* allocated array describing the sizes at which the icon is
|
|
|
|
|
* available. The array should be freed with g_free() when it is no
|
|
|
|
|
* longer needed.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2004-07-17 03:55:07 +00:00
|
|
|
|
gint *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_get_icon_sizes (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *icon_name)
|
2004-07-17 03:55:07 +00:00
|
|
|
|
{
|
2017-11-30 03:25:57 +00:00
|
|
|
|
GList *l, *d;
|
2004-07-17 03:55:07 +00:00
|
|
|
|
GHashTable *sizes;
|
2004-08-16 18:38:55 +00:00
|
|
|
|
gint *result, *r;
|
2005-11-12 06:59:49 +00:00
|
|
|
|
guint suffix;
|
2004-07-17 03:55:07 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
ensure_valid_themes (self);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
|
|
|
|
|
sizes = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (l = self->themes; l; l = l->next)
|
2004-07-17 03:55:07 +00:00
|
|
|
|
{
|
|
|
|
|
IconTheme *theme = l->data;
|
|
|
|
|
for (d = theme->dirs; d; d = d->next)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
IconThemeDir *dir = d->data;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
|
if (dir->type != ICON_THEME_DIR_SCALABLE && g_hash_table_lookup_extended (sizes, GINT_TO_POINTER (dir->size), NULL, NULL))
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-05-21 12:51:09 +00:00
|
|
|
|
suffix = theme_dir_get_icon_suffix (dir, icon_name);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
if (suffix != ICON_SUFFIX_NONE)
|
|
|
|
|
{
|
|
|
|
|
if (suffix == ICON_SUFFIX_SVG)
|
|
|
|
|
g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
|
|
|
|
|
else
|
|
|
|
|
g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-17 03:55:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-08-16 18:38:55 +00:00
|
|
|
|
r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
|
2004-08-16 18:38:55 +00:00
|
|
|
|
g_hash_table_foreach (sizes, add_size, &r);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
g_hash_table_destroy (sizes);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
add_key_to_hash (gpointer key,
|
|
|
|
|
gpointer value,
|
|
|
|
|
gpointer user_data)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GHashTable *hash = user_data;
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert (hash, key, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
add_key_to_list (gpointer key,
|
|
|
|
|
gpointer value,
|
|
|
|
|
gpointer user_data)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GList **list = user_data;
|
|
|
|
|
|
|
|
|
|
*list = g_list_prepend (*list, g_strdup (key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_list_icons:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2011-01-18 08:25:47 +00:00
|
|
|
|
* @context: (allow-none): a string identifying a particular type of
|
|
|
|
|
* icon, or %NULL to list all icons.
|
2014-04-11 16:52:39 +00:00
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* Lists the icons in the current icon theme. Only a subset
|
|
|
|
|
* of the icons can be listed by providing a context string.
|
|
|
|
|
* The set of values for the context string is system dependent,
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* but will typically include such values as “Applications” and
|
2014-04-11 16:52:39 +00:00
|
|
|
|
* “MimeTypes”. Contexts are explained in the
|
|
|
|
|
* [Icon Theme Specification](http://www.freedesktop.org/wiki/Specifications/icon-theme-spec).
|
|
|
|
|
* The standard contexts are listed in the
|
|
|
|
|
* [Icon Naming Specification](http://www.freedesktop.org/wiki/Specifications/icon-naming-spec).
|
2009-12-10 10:23:40 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (element-type utf8) (transfer full): a #GList list
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* holding the names of all the icons in the theme. You must
|
|
|
|
|
* first free each element in the list with g_free(), then
|
|
|
|
|
* free the list itself with g_list_free().
|
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GList *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_list_icons (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *context)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GHashTable *icons;
|
|
|
|
|
GList *list, *l;
|
|
|
|
|
GQuark context_quark;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
ensure_valid_themes (self);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
|
{
|
|
|
|
|
context_quark = g_quark_try_string (context);
|
|
|
|
|
|
|
|
|
|
if (!context_quark)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
context_quark = 0;
|
|
|
|
|
|
|
|
|
|
icons = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
l = self->themes;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
while (l != NULL)
|
|
|
|
|
{
|
|
|
|
|
theme_list_icons (l->data, icons, context_quark);
|
|
|
|
|
l = l->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context_quark == 0)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_foreach (self->unthemed_icons,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
add_key_to_hash,
|
|
|
|
|
icons);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2004-10-28 15:00:05 +00:00
|
|
|
|
list = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
g_hash_table_foreach (icons,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
add_key_to_list,
|
|
|
|
|
&list);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
g_hash_table_destroy (icons);
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
|
static gboolean
|
2019-09-08 12:57:40 +00:00
|
|
|
|
rescan_themes (GtkIconTheme *self)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
IconThemeDirMtime *dir_mtime;
|
|
|
|
|
GList *d;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint stat_res;
|
2011-10-03 15:25:33 +00:00
|
|
|
|
GStatBuf stat_buf;
|
2003-07-20 15:50:14 +00:00
|
|
|
|
GTimeVal tv;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (d = self->dir_mtimes; d != NULL; d = d->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
dir_mtime = d->data;
|
|
|
|
|
|
2004-12-12 21:09:13 +00:00
|
|
|
|
stat_res = g_stat (dir_mtime->dir, &stat_buf);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
/* dir mtime didn't change */
|
2015-02-23 20:49:08 +00:00
|
|
|
|
if (stat_res == 0 && dir_mtime->exists &&
|
2014-06-19 23:42:53 +00:00
|
|
|
|
S_ISDIR (stat_buf.st_mode) &&
|
|
|
|
|
dir_mtime->mtime == stat_buf.st_mtime)
|
|
|
|
|
continue;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* didn't exist before, and still doesn't */
|
2015-02-23 20:49:08 +00:00
|
|
|
|
if (!dir_mtime->exists &&
|
2014-06-19 23:42:53 +00:00
|
|
|
|
(stat_res != 0 || !S_ISDIR (stat_buf.st_mode)))
|
|
|
|
|
continue;
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
|
g_get_current_time (&tv);
|
2019-09-08 12:57:40 +00:00
|
|
|
|
self->last_stat_time = tv.tv_sec;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_rescan_if_needed:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2007-03-15 18:40:16 +00:00
|
|
|
|
*
|
|
|
|
|
* Checks to see if the icon theme has changed; if it has, any
|
|
|
|
|
* currently cached information is discarded and will be reloaded
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* next time @self is accessed.
|
2007-03-15 18:40:16 +00:00
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the icon theme has changed and needed
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* to be reloaded.
|
|
|
|
|
*/
|
2007-03-15 18:40:16 +00:00
|
|
|
|
gboolean
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_rescan_if_needed (GtkIconTheme *self)
|
2007-03-15 18:40:16 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), FALSE);
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
retval = rescan_themes (self);
|
2007-03-15 18:40:16 +00:00
|
|
|
|
if (retval)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
do_theme_change (self);
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static void
|
|
|
|
|
theme_destroy (IconTheme *theme)
|
|
|
|
|
{
|
|
|
|
|
g_free (theme->display_name);
|
|
|
|
|
g_free (theme->comment);
|
|
|
|
|
g_free (theme->name);
|
|
|
|
|
|
2012-01-02 03:20:59 +00:00
|
|
|
|
g_list_free_full (theme->dirs, (GDestroyNotify) theme_dir_destroy);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_free (theme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
theme_dir_destroy (IconThemeDir *dir)
|
|
|
|
|
{
|
2004-10-19 18:45:41 +00:00
|
|
|
|
if (dir->cache)
|
2018-02-01 15:05:58 +00:00
|
|
|
|
gtk_icon_cache_unref (dir->cache);
|
2014-06-20 16:11:55 +00:00
|
|
|
|
if (dir->icons)
|
2004-10-19 18:45:41 +00:00
|
|
|
|
g_hash_table_destroy (dir->icons);
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_free (dir->dir);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
g_free (dir->subdir);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_free (dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2013-05-10 16:06:00 +00:00
|
|
|
|
theme_dir_size_difference (IconThemeDir *dir,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint size,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
gint scale)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint scaled_size, scaled_dir_size;
|
|
|
|
|
gint min, max;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
scaled_size = size * scale;
|
|
|
|
|
scaled_dir_size = dir->size * dir->scale;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
switch (dir->type)
|
|
|
|
|
{
|
|
|
|
|
case ICON_THEME_DIR_FIXED:
|
2013-05-10 16:06:00 +00:00
|
|
|
|
return abs (scaled_size - scaled_dir_size);
|
2017-10-06 19:19:42 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
case ICON_THEME_DIR_SCALABLE:
|
2013-05-10 16:06:00 +00:00
|
|
|
|
if (scaled_size < (dir->min_size * dir->scale))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return (dir->min_size * dir->scale) - scaled_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
if (size > (dir->max_size * dir->scale))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return scaled_size - (dir->max_size * dir->scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return 0;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
case ICON_THEME_DIR_THRESHOLD:
|
2013-05-10 16:06:00 +00:00
|
|
|
|
min = (dir->size - dir->threshold) * dir->scale;
|
|
|
|
|
max = (dir->size + dir->threshold) * dir->scale;
|
|
|
|
|
if (scaled_size < min)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return min - scaled_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
if (scaled_size > max)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return scaled_size - max;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return 0;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
case ICON_THEME_DIR_UNTHEMED:
|
2017-10-06 19:19:42 +00:00
|
|
|
|
default:
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_assert_not_reached ();
|
2017-10-06 19:19:42 +00:00
|
|
|
|
return 1000;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
static const gchar *
|
2003-07-02 22:44:09 +00:00
|
|
|
|
string_from_suffix (IconSuffix suffix)
|
|
|
|
|
{
|
|
|
|
|
switch (suffix)
|
|
|
|
|
{
|
|
|
|
|
case ICON_SUFFIX_XPM:
|
|
|
|
|
return ".xpm";
|
|
|
|
|
case ICON_SUFFIX_SVG:
|
|
|
|
|
return ".svg";
|
|
|
|
|
case ICON_SUFFIX_PNG:
|
|
|
|
|
return ".png";
|
2014-07-30 16:05:48 +00:00
|
|
|
|
case ICON_SUFFIX_SYMBOLIC_PNG:
|
|
|
|
|
return ".symbolic.png";
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case ICON_SUFFIX_NONE:
|
|
|
|
|
case HAS_ICON_FILE:
|
2003-07-02 22:44:09 +00:00
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached();
|
2017-10-06 19:19:42 +00:00
|
|
|
|
return NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 08:20:00 +00:00
|
|
|
|
static inline IconSuffix
|
2014-06-19 23:42:53 +00:00
|
|
|
|
suffix_from_name (const gchar *name)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2019-09-01 08:20:00 +00:00
|
|
|
|
const gsize name_len = strlen (name);
|
2014-09-05 17:15:14 +00:00
|
|
|
|
|
2019-09-01 08:20:00 +00:00
|
|
|
|
if (name_len > 4)
|
2014-09-05 17:15:14 +00:00
|
|
|
|
{
|
2019-09-01 08:20:00 +00:00
|
|
|
|
if (name_len > strlen (".symbolic.png"))
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (name + name_len - strlen (".symbolic.png"), ".symbolic.png") == 0)
|
|
|
|
|
return ICON_SUFFIX_SYMBOLIC_PNG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp (name + name_len - strlen (".png"), ".png") == 0)
|
|
|
|
|
return ICON_SUFFIX_PNG;
|
|
|
|
|
|
|
|
|
|
if (strcmp (name + name_len - strlen (".svg"), ".svg") == 0)
|
|
|
|
|
return ICON_SUFFIX_SVG;
|
|
|
|
|
|
|
|
|
|
if (strcmp (name + name_len - strlen (".xpm"), ".xpm") == 0)
|
|
|
|
|
return ICON_SUFFIX_XPM;
|
2014-09-05 17:15:14 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-01 08:20:00 +00:00
|
|
|
|
return ICON_SUFFIX_NONE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static IconSuffix
|
|
|
|
|
best_suffix (IconSuffix suffix,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gboolean allow_svg)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-07-30 16:05:48 +00:00
|
|
|
|
if ((suffix & ICON_SUFFIX_SYMBOLIC_PNG) != 0)
|
|
|
|
|
return ICON_SUFFIX_SYMBOLIC_PNG;
|
|
|
|
|
else if ((suffix & ICON_SUFFIX_PNG) != 0)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return ICON_SUFFIX_PNG;
|
|
|
|
|
else if (allow_svg && ((suffix & ICON_SUFFIX_SVG) != 0))
|
|
|
|
|
return ICON_SUFFIX_SVG;
|
|
|
|
|
else if ((suffix & ICON_SUFFIX_XPM) != 0)
|
|
|
|
|
return ICON_SUFFIX_XPM;
|
|
|
|
|
else
|
|
|
|
|
return ICON_SUFFIX_NONE;
|
|
|
|
|
}
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
|
static IconSuffix
|
|
|
|
|
theme_dir_get_icon_suffix (IconThemeDir *dir,
|
2019-05-21 12:51:09 +00:00
|
|
|
|
const gchar *icon_name)
|
2004-10-19 18:45:41 +00:00
|
|
|
|
{
|
2014-07-30 16:05:48 +00:00
|
|
|
|
IconSuffix suffix, symbolic_suffix;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
|
|
if (dir->cache)
|
|
|
|
|
{
|
2019-05-21 12:26:19 +00:00
|
|
|
|
int icon_name_len = strlen (icon_name);
|
|
|
|
|
|
|
|
|
|
if (icon_name_is_symbolic (icon_name, icon_name_len))
|
2014-07-30 16:05:48 +00:00
|
|
|
|
{
|
|
|
|
|
/* Look for foo-symbolic.symbolic.png, as the cache only stores the ".png" suffix */
|
|
|
|
|
char *icon_name_with_prefix = g_strconcat (icon_name, ".symbolic", NULL);
|
2018-02-01 15:05:58 +00:00
|
|
|
|
symbolic_suffix = (IconSuffix)gtk_icon_cache_get_icon_flags (dir->cache,
|
2014-07-30 16:05:48 +00:00
|
|
|
|
icon_name_with_prefix,
|
|
|
|
|
dir->subdir_index);
|
|
|
|
|
g_free (icon_name_with_prefix);
|
|
|
|
|
|
|
|
|
|
if (symbolic_suffix & ICON_SUFFIX_PNG)
|
|
|
|
|
suffix = ICON_SUFFIX_SYMBOLIC_PNG;
|
2019-05-21 09:07:23 +00:00
|
|
|
|
else
|
|
|
|
|
suffix = (IconSuffix)gtk_icon_cache_get_icon_flags (dir->cache,
|
|
|
|
|
icon_name,
|
|
|
|
|
dir->subdir_index);
|
2014-07-30 16:05:48 +00:00
|
|
|
|
}
|
2019-05-21 09:07:23 +00:00
|
|
|
|
else
|
|
|
|
|
suffix = (IconSuffix)gtk_icon_cache_get_icon_flags (dir->cache,
|
|
|
|
|
icon_name,
|
|
|
|
|
dir->subdir_index);
|
2014-07-30 16:05:48 +00:00
|
|
|
|
|
2004-10-21 18:44:08 +00:00
|
|
|
|
suffix = suffix & ~HAS_ICON_FILE;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2005-08-26 16:29:40 +00:00
|
|
|
|
suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2016-02-28 20:33:18 +00:00
|
|
|
|
GTK_NOTE (ICONTHEME, g_message ("get icon suffix%s: %u", dir->cache ? " (cached)" : "", suffix));
|
2005-08-15 13:28:22 +00:00
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
|
return suffix;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
/* returns TRUE if dir_a is a better match */
|
|
|
|
|
static gboolean
|
2014-06-19 23:42:53 +00:00
|
|
|
|
compare_dir_matches (IconThemeDir *dir_a, gint difference_a,
|
|
|
|
|
IconThemeDir *dir_b, gint difference_b,
|
|
|
|
|
gint requested_size,
|
|
|
|
|
gint requested_scale)
|
2013-05-10 16:06:00 +00:00
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint diff_a;
|
|
|
|
|
gint diff_b;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
if (difference_a == 0)
|
|
|
|
|
{
|
|
|
|
|
if (difference_b != 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return TRUE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
/* a and b both exact matches */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If scaling, *always* prefer downscaling */
|
|
|
|
|
if (dir_a->size >= requested_size &&
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir_b->size < requested_size)
|
|
|
|
|
return TRUE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
if (dir_a->size < requested_size &&
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir_b->size >= requested_size)
|
|
|
|
|
return FALSE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
/* Otherwise prefer the closest match */
|
|
|
|
|
|
|
|
|
|
if (difference_a < difference_b)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return TRUE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
if (difference_a > difference_b)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
return FALSE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
|
|
/* same pixel difference */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dir_a->scale == requested_scale &&
|
|
|
|
|
dir_b->scale != requested_scale)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (dir_a->scale != requested_scale &&
|
|
|
|
|
dir_b->scale == requested_scale)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* a and b both match the scale */
|
|
|
|
|
|
|
|
|
|
if (dir_a->type != ICON_THEME_DIR_SCALABLE &&
|
|
|
|
|
dir_b->type == ICON_THEME_DIR_SCALABLE)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (dir_a->type == ICON_THEME_DIR_SCALABLE &&
|
|
|
|
|
dir_b->type != ICON_THEME_DIR_SCALABLE)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* a and b both are scalable */
|
|
|
|
|
|
|
|
|
|
diff_a = abs (requested_size * requested_scale - dir_a->size * dir_a->scale);
|
|
|
|
|
diff_b = abs (requested_size * requested_scale - dir_b->size * dir_b->scale);
|
|
|
|
|
|
|
|
|
|
return diff_a <= diff_b;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
static GtkIconInfo *
|
2014-06-19 23:42:53 +00:00
|
|
|
|
theme_lookup_icon (IconTheme *theme,
|
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
2019-05-21 12:53:03 +00:00
|
|
|
|
gboolean allow_svg)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2005-11-04 15:43:40 +00:00
|
|
|
|
GList *dirs, *l;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
IconThemeDir *dir, *min_dir;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *file;
|
|
|
|
|
gint min_difference, difference;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
IconSuffix suffix;
|
2019-05-25 14:51:30 +00:00
|
|
|
|
IconSuffix min_suffix;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
min_difference = G_MAXINT;
|
|
|
|
|
min_dir = NULL;
|
|
|
|
|
|
2014-06-18 02:06:08 +00:00
|
|
|
|
dirs = theme->dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
|
l = dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
while (l != NULL)
|
|
|
|
|
{
|
|
|
|
|
dir = l->data;
|
|
|
|
|
|
2016-02-28 20:33:18 +00:00
|
|
|
|
GTK_NOTE (ICONTHEME, g_message ("look up icon dir %s", dir->dir));
|
2019-05-21 12:51:09 +00:00
|
|
|
|
suffix = theme_dir_get_icon_suffix (dir, icon_name);
|
2004-10-20 17:23:02 +00:00
|
|
|
|
if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
|
|
|
|
difference = theme_dir_size_difference (dir, size, scale);
|
|
|
|
|
if (min_dir == NULL ||
|
|
|
|
|
compare_dir_matches (dir, difference,
|
|
|
|
|
min_dir, min_difference,
|
|
|
|
|
size, scale))
|
|
|
|
|
{
|
|
|
|
|
min_dir = dir;
|
2019-05-25 14:51:30 +00:00
|
|
|
|
min_suffix = suffix;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
min_difference = difference;
|
|
|
|
|
}
|
2007-01-15 02:56:33 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
l = l->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (min_dir)
|
|
|
|
|
{
|
2014-06-20 18:17:47 +00:00
|
|
|
|
GtkIconInfo *icon_info;
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
2014-06-20 18:17:47 +00:00
|
|
|
|
icon_info = icon_info_new (min_dir->type, min_dir->size, min_dir->scale);
|
|
|
|
|
icon_info->min_size = min_dir->min_size;
|
|
|
|
|
icon_info->max_size = min_dir->max_size;
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
2019-05-25 14:51:30 +00:00
|
|
|
|
suffix = min_suffix;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
suffix = best_suffix (suffix, allow_svg);
|
|
|
|
|
g_assert (suffix != ICON_SUFFIX_NONE);
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
2007-04-25 18:01:44 +00:00
|
|
|
|
if (min_dir->dir)
|
|
|
|
|
{
|
|
|
|
|
file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
|
|
|
|
|
icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
|
2014-07-15 16:42:39 +00:00
|
|
|
|
|
2014-06-17 16:05:22 +00:00
|
|
|
|
icon_info->is_svg = suffix == ICON_SUFFIX_SVG;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
icon_info->is_resource = min_dir->is_resource;
|
2007-04-25 18:01:44 +00:00
|
|
|
|
g_free (file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
icon_info->filename = NULL;
|
|
|
|
|
}
|
2013-06-19 07:32:38 +00:00
|
|
|
|
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
if (min_dir->cache)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2018-02-01 15:05:58 +00:00
|
|
|
|
icon_info->cache_pixbuf = gtk_icon_cache_get_icon (min_dir->cache, icon_name,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
min_dir->subdir_index);
|
|
|
|
|
}
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return icon_info;
|
|
|
|
|
}
|
2007-01-15 02:56:33 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-02-13 02:31:28 +00:00
|
|
|
|
theme_list_icons (IconTheme *theme,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
GHashTable *icons,
|
|
|
|
|
GQuark context)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GList *l = theme->dirs;
|
|
|
|
|
IconThemeDir *dir;
|
|
|
|
|
|
|
|
|
|
while (l != NULL)
|
|
|
|
|
{
|
|
|
|
|
dir = l->data;
|
|
|
|
|
|
|
|
|
|
if (context == dir->context ||
|
2014-06-19 23:42:53 +00:00
|
|
|
|
context == 0)
|
|
|
|
|
{
|
|
|
|
|
if (dir->cache)
|
2018-02-01 15:05:58 +00:00
|
|
|
|
gtk_icon_cache_add_icons (dir->cache, dir->subdir, icons);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
else
|
|
|
|
|
g_hash_table_foreach (dir->icons, add_key_to_hash, icons);
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
l = l->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 01:37:01 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
theme_has_icon (IconTheme *theme,
|
|
|
|
|
const gchar *icon_name)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
for (l = theme->dirs; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
IconThemeDir *dir = l->data;
|
|
|
|
|
|
|
|
|
|
if (dir->cache)
|
|
|
|
|
{
|
2018-02-01 15:05:58 +00:00
|
|
|
|
if (gtk_icon_cache_has_icon (dir->cache, icon_name))
|
2014-06-20 01:37:01 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (g_hash_table_lookup (dir->icons, icon_name) != NULL)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
static GHashTable *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
scan_directory (GtkIconTheme *self,
|
|
|
|
|
char *full_dir)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
GDir *gdir;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
const gchar *name;
|
2019-09-01 08:04:32 +00:00
|
|
|
|
GHashTable *icons = NULL;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
GTK_DISPLAY_NOTE (self->display, ICONTHEME,
|
2018-01-14 14:53:48 +00:00
|
|
|
|
g_message ("scanning directory %s", full_dir));
|
2014-06-20 16:11:55 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gdir = g_dir_open (full_dir, 0, NULL);
|
|
|
|
|
|
|
|
|
|
if (gdir == NULL)
|
2019-09-01 08:04:32 +00:00
|
|
|
|
return NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
while ((name = g_dir_read_name (gdir)))
|
|
|
|
|
{
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *base_name;
|
2006-04-18 13:58:30 +00:00
|
|
|
|
IconSuffix suffix, hash_suffix;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
suffix = suffix_from_name (name);
|
|
|
|
|
if (suffix == ICON_SUFFIX_NONE)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
continue;
|
2006-04-18 13:58:30 +00:00
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
if (!icons)
|
|
|
|
|
icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
|
2006-04-18 13:58:30 +00:00
|
|
|
|
base_name = strip_suffix (name);
|
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (icons, base_name));
|
2011-05-05 14:13:13 +00:00
|
|
|
|
/* takes ownership of base_name */
|
2019-09-01 08:04:32 +00:00
|
|
|
|
g_hash_table_replace (icons, base_name, GUINT_TO_POINTER (hash_suffix|suffix));
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2019-09-01 08:04:32 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_dir_close (gdir);
|
2014-06-20 16:11:55 +00:00
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
return icons;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-09-08 12:57:40 +00:00
|
|
|
|
theme_subdir_load (GtkIconTheme *self,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
IconTheme *theme,
|
|
|
|
|
GKeyFile *theme_file,
|
|
|
|
|
gchar *subdir)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-11-02 02:07:30 +00:00
|
|
|
|
GList *d;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *type_string;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
IconThemeDir *dir;
|
|
|
|
|
IconThemeDirType type;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gchar *context_string;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GQuark context;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint size;
|
|
|
|
|
gint min_size;
|
|
|
|
|
gint max_size;
|
|
|
|
|
gint threshold;
|
|
|
|
|
gchar *full_dir;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
GError *error = NULL;
|
2004-11-02 02:07:30 +00:00
|
|
|
|
IconThemeDirMtime *dir_mtime;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gint scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
|
size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
|
|
|
|
|
if (error)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
g_warning ("Theme directory %s of theme %s has no size field\n",
|
2014-06-19 23:42:53 +00:00
|
|
|
|
subdir, theme->name);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-09-01 08:04:32 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
type = ICON_THEME_DIR_THRESHOLD;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
type_string = g_key_file_get_string (theme_file, subdir, "Type", NULL);
|
|
|
|
|
if (type_string)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (strcmp (type_string, "Fixed") == 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
type = ICON_THEME_DIR_FIXED;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else if (strcmp (type_string, "Scalable") == 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
type = ICON_THEME_DIR_SCALABLE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else if (strcmp (type_string, "Threshold") == 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
type = ICON_THEME_DIR_THRESHOLD;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
g_free (type_string);
|
|
|
|
|
}
|
2019-09-01 08:04:32 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
context = 0;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
context_string = g_key_file_get_string (theme_file, subdir, "Context", NULL);
|
|
|
|
|
if (context_string)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
|
|
|
|
context = g_quark_from_string (context_string);
|
|
|
|
|
g_free (context_string);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
|
if (g_key_file_has_key (theme_file, subdir, "MaxSize", NULL))
|
|
|
|
|
max_size = g_key_file_get_integer (theme_file, subdir, "MaxSize", NULL);
|
|
|
|
|
else
|
|
|
|
|
max_size = size;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
|
if (g_key_file_has_key (theme_file, subdir, "MinSize", NULL))
|
|
|
|
|
min_size = g_key_file_get_integer (theme_file, subdir, "MinSize", NULL);
|
|
|
|
|
else
|
|
|
|
|
min_size = size;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
|
if (g_key_file_has_key (theme_file, subdir, "Threshold", NULL))
|
|
|
|
|
threshold = g_key_file_get_integer (theme_file, subdir, "Threshold", NULL);
|
|
|
|
|
else
|
|
|
|
|
threshold = 2;
|
2004-11-02 02:07:30 +00:00
|
|
|
|
|
2013-08-19 13:41:49 +00:00
|
|
|
|
if (g_key_file_has_key (theme_file, subdir, "Scale", NULL))
|
|
|
|
|
scale = g_key_file_get_integer (theme_file, subdir, "Scale", NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
else
|
|
|
|
|
scale = 1;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (d = self->dir_mtimes; d; d = d->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2004-11-02 02:07:30 +00:00
|
|
|
|
dir_mtime = (IconThemeDirMtime *)d->data;
|
|
|
|
|
|
2015-02-23 20:49:08 +00:00
|
|
|
|
if (!dir_mtime->exists)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
continue; /* directory doesn't exist */
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
2014-06-20 04:35:57 +00:00
|
|
|
|
full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
|
|
/* First, see if we have a cache for the directory */
|
2005-04-06 03:34:38 +00:00
|
|
|
|
if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-01 08:04:32 +00:00
|
|
|
|
gboolean has_icons;
|
|
|
|
|
GtkIconCache *dir_cache;
|
|
|
|
|
GHashTable *icon_table = NULL;
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
if (dir_mtime->cache == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* This will return NULL if the cache doesn't exist or is outdated */
|
2018-02-01 15:05:58 +00:00
|
|
|
|
dir_mtime->cache = gtk_icon_cache_new_for_path (dir_mtime->dir);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
if (dir_mtime->cache != NULL)
|
|
|
|
|
{
|
|
|
|
|
dir_cache = dir_mtime->cache;
|
|
|
|
|
has_icons = gtk_icon_cache_has_icons (dir_cache, subdir);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dir_cache = NULL;
|
2019-09-08 12:57:40 +00:00
|
|
|
|
icon_table = scan_directory (self, full_dir);
|
2019-09-01 08:04:32 +00:00
|
|
|
|
has_icons = icon_table != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!has_icons)
|
|
|
|
|
{
|
|
|
|
|
g_assert (!icon_table);
|
|
|
|
|
g_free (full_dir);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-20 16:11:55 +00:00
|
|
|
|
dir = g_new0 (IconThemeDir, 1);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir->type = type;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
dir->is_resource = FALSE;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
dir->context = context;
|
|
|
|
|
dir->size = size;
|
|
|
|
|
dir->min_size = min_size;
|
|
|
|
|
dir->max_size = max_size;
|
|
|
|
|
dir->threshold = threshold;
|
|
|
|
|
dir->dir = full_dir;
|
|
|
|
|
dir->subdir = g_strdup (subdir);
|
2013-05-10 16:06:00 +00:00
|
|
|
|
dir->scale = scale;
|
2019-09-01 08:04:32 +00:00
|
|
|
|
dir->icons = icon_table;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
if (dir_cache)
|
2007-12-03 17:44:27 +00:00
|
|
|
|
{
|
2019-09-01 08:04:32 +00:00
|
|
|
|
dir->cache = gtk_icon_cache_ref (dir_cache);
|
2018-02-01 15:05:58 +00:00
|
|
|
|
dir->subdir_index = gtk_icon_cache_get_directory_index (dir->cache, dir->subdir);
|
2007-12-03 17:44:27 +00:00
|
|
|
|
}
|
2014-06-19 23:42:53 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-01 08:04:32 +00:00
|
|
|
|
dir_cache = NULL;
|
2007-12-03 17:44:27 +00:00
|
|
|
|
dir->subdir_index = -1;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-01 08:04:32 +00:00
|
|
|
|
theme->dirs = g_list_prepend (theme->dirs, dir);
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_free (full_dir);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
2014-06-20 04:35:57 +00:00
|
|
|
|
|
2014-07-10 01:12:08 +00:00
|
|
|
|
if (strcmp (theme->name, FALLBACK_ICON_THEME) == 0)
|
2019-09-01 07:26:16 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
for (d = self->resource_paths; d; d = d->next)
|
2014-06-30 20:03:03 +00:00
|
|
|
|
{
|
2019-09-01 07:26:16 +00:00
|
|
|
|
int i;
|
|
|
|
|
char **children;
|
|
|
|
|
|
2017-11-13 17:12:52 +00:00
|
|
|
|
/* Force a trailing / here, to avoid extra copies in GResource */
|
|
|
|
|
full_dir = g_build_filename ((const gchar *)d->data, subdir, " ", NULL);
|
|
|
|
|
full_dir[strlen (full_dir) - 1] = '\0';
|
2019-09-01 07:26:16 +00:00
|
|
|
|
|
|
|
|
|
children = g_resources_enumerate_children (full_dir, 0, NULL);
|
|
|
|
|
|
|
|
|
|
if (!children)
|
|
|
|
|
{
|
|
|
|
|
g_free (full_dir);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 20:03:03 +00:00
|
|
|
|
dir = g_new0 (IconThemeDir, 1);
|
2019-09-01 07:26:16 +00:00
|
|
|
|
dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2014-06-30 20:03:03 +00:00
|
|
|
|
dir->type = type;
|
|
|
|
|
dir->is_resource = TRUE;
|
|
|
|
|
dir->context = context;
|
|
|
|
|
dir->size = size;
|
|
|
|
|
dir->min_size = min_size;
|
|
|
|
|
dir->max_size = max_size;
|
|
|
|
|
dir->threshold = threshold;
|
|
|
|
|
dir->dir = full_dir;
|
|
|
|
|
dir->subdir = g_strdup (subdir);
|
|
|
|
|
dir->scale = scale;
|
|
|
|
|
dir->cache = NULL;
|
|
|
|
|
dir->subdir_index = -1;
|
|
|
|
|
|
2019-09-01 07:26:16 +00:00
|
|
|
|
for (i = 0; children[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar *base_name;
|
|
|
|
|
IconSuffix suffix, hash_suffix;
|
|
|
|
|
|
|
|
|
|
suffix = suffix_from_name (children[i]);
|
|
|
|
|
if (suffix == ICON_SUFFIX_NONE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
base_name = strip_suffix (children[i]);
|
|
|
|
|
|
|
|
|
|
hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
|
|
|
|
|
/* takes ownership of base_name */
|
|
|
|
|
g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix|suffix));
|
|
|
|
|
}
|
|
|
|
|
g_strfreev (children);
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_size (dir->icons) > 0)
|
2014-06-30 20:03:03 +00:00
|
|
|
|
theme->dirs = g_list_prepend (theme->dirs, dir);
|
|
|
|
|
else
|
|
|
|
|
theme_dir_destroy (dir);
|
|
|
|
|
}
|
2014-06-20 04:35:57 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* GtkIconInfo
|
|
|
|
|
*/
|
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkIconInfo, gtk_icon_info, G_TYPE_OBJECT)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_icon_info_init (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
2003-07-02 22:44:09 +00:00
|
|
|
|
icon_info->scale = -1.;
|
2013-02-13 14:05:02 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
static GtkIconInfo *
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info_new (IconThemeDirType type,
|
|
|
|
|
gint dir_size,
|
|
|
|
|
gint dir_scale)
|
2013-02-13 14:05:02 +00:00
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
|
GtkIconInfo *icon_info;
|
|
|
|
|
|
|
|
|
|
icon_info = g_object_new (GTK_TYPE_ICON_INFO, NULL);
|
|
|
|
|
|
|
|
|
|
icon_info->dir_type = type;
|
|
|
|
|
icon_info->dir_size = dir_size;
|
|
|
|
|
icon_info->dir_scale = dir_scale;
|
2013-09-23 10:42:30 +00:00
|
|
|
|
icon_info->unscaled_scale = 1.0;
|
2014-06-17 16:05:22 +00:00
|
|
|
|
icon_info->is_svg = FALSE;
|
2014-06-20 04:35:57 +00:00
|
|
|
|
icon_info->is_resource = FALSE;
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
|
|
|
|
return icon_info;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 23:42:53 +00:00
|
|
|
|
/* This only copies whatever is needed to load the pixbuf,
|
|
|
|
|
* so that we can do a load in a thread without affecting
|
|
|
|
|
* the original IconInfo from the thread.
|
2013-02-14 12:32:30 +00:00
|
|
|
|
*/
|
|
|
|
|
static GtkIconInfo *
|
|
|
|
|
icon_info_dup (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
|
|
2013-09-23 10:37:36 +00:00
|
|
|
|
dup = icon_info_new (icon_info->dir_type, icon_info->dir_size, icon_info->dir_scale);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
|
|
dup->filename = g_strdup (icon_info->filename);
|
2014-06-16 14:41:35 +00:00
|
|
|
|
dup->is_svg = icon_info->is_svg;
|
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
|
if (icon_info->loadable)
|
|
|
|
|
dup->loadable = g_object_ref (icon_info->loadable);
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (icon_info->texture)
|
|
|
|
|
dup->texture = g_object_ref (icon_info->texture);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
|
|
if (icon_info->cache_pixbuf)
|
|
|
|
|
dup->cache_pixbuf = g_object_ref (icon_info->cache_pixbuf);
|
|
|
|
|
|
2014-06-23 16:20:59 +00:00
|
|
|
|
dup->scale = icon_info->scale;
|
2013-09-23 10:42:30 +00:00
|
|
|
|
dup->unscaled_scale = icon_info->unscaled_scale;
|
2013-02-14 12:32:30 +00:00
|
|
|
|
dup->desired_size = icon_info->desired_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
dup->desired_scale = icon_info->desired_scale;
|
2013-02-14 12:32:30 +00:00
|
|
|
|
dup->forced_size = icon_info->forced_size;
|
2014-06-23 16:20:59 +00:00
|
|
|
|
dup->is_resource = icon_info->is_resource;
|
|
|
|
|
dup->min_size = icon_info->min_size;
|
|
|
|
|
dup->max_size = icon_info->max_size;
|
2015-06-08 23:35:31 +00:00
|
|
|
|
dup->symbolic_width = icon_info->symbolic_width;
|
|
|
|
|
dup->symbolic_height = icon_info->symbolic_height;
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_icon_info_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *icon_info = (GtkIconInfo *) object;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
|
|
if (icon_info->in_cache)
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_hash_table_remove (icon_info->in_cache->info_cache, &icon_info->key);
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
|
|
g_strfreev (icon_info->key.icon_names);
|
|
|
|
|
|
2007-03-09 21:57:37 +00:00
|
|
|
|
g_free (icon_info->filename);
|
2012-10-28 19:01:30 +00:00
|
|
|
|
|
2013-10-02 12:28:00 +00:00
|
|
|
|
g_clear_object (&icon_info->loadable);
|
2019-09-01 09:25:48 +00:00
|
|
|
|
g_clear_object (&icon_info->texture);
|
2013-10-02 12:28:00 +00:00
|
|
|
|
g_clear_object (&icon_info->cache_pixbuf);
|
2013-10-02 12:30:14 +00:00
|
|
|
|
g_clear_error (&icon_info->load_error);
|
2005-08-19 04:39:30 +00:00
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_icon_info_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_icon_info_class_init (GtkIconInfoClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_icon_info_finalize;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_get_base_size:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the base size for the icon. The base size
|
|
|
|
|
* is a size for the icon that was specified by
|
|
|
|
|
* the icon theme creator. This may be different
|
2018-10-30 15:18:23 +00:00
|
|
|
|
* than the actual size of image;
|
|
|
|
|
* These icons will be given
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* the same base size as the larger icons to which
|
|
|
|
|
* they are attached.
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that for scaled icons the base size does
|
|
|
|
|
* not include the base scale.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the base size, or 0, if no base
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* size is known for the icon.
|
|
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gint
|
|
|
|
|
gtk_icon_info_get_base_size (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, 0);
|
|
|
|
|
|
|
|
|
|
return icon_info->dir_size;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_get_base_scale:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Gets the base scale for the icon. The base scale is a scale
|
|
|
|
|
* for the icon that was specified by the icon theme creator.
|
2017-10-31 01:59:06 +00:00
|
|
|
|
* For instance an icon drawn for a high-dpi monitor with window
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* scale 2 for a base size of 32 will be 64 pixels tall and have
|
|
|
|
|
* a base scale of 2.
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Returns: the base scale
|
|
|
|
|
*/
|
2013-05-10 16:06:00 +00:00
|
|
|
|
gint
|
|
|
|
|
gtk_icon_info_get_base_scale (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, 0);
|
|
|
|
|
|
|
|
|
|
return icon_info->dir_scale;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_get_filename:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Gets the filename for the icon. If the %GTK_ICON_LOOKUP_USE_BUILTIN
|
|
|
|
|
* flag was passed to gtk_icon_theme_lookup_icon(), there may be no
|
|
|
|
|
* filename if a builtin icon is returned; in this case, you should
|
|
|
|
|
* use gtk_icon_info_get_builtin_pixbuf().
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (type filename): the filename for the icon, or %NULL
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* if gtk_icon_info_get_builtin_pixbuf() should be used instead.
|
|
|
|
|
* The return value is owned by GTK+ and should not be modified
|
|
|
|
|
* or freed.
|
|
|
|
|
*/
|
2011-06-06 18:13:44 +00:00
|
|
|
|
const gchar *
|
2003-07-02 22:44:09 +00:00
|
|
|
|
gtk_icon_info_get_filename (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return icon_info->filename;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_is_symbolic:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2013-12-15 02:41:49 +00:00
|
|
|
|
*
|
|
|
|
|
* Checks if the icon is symbolic or not. This currently uses only
|
|
|
|
|
* the file name and not the file contents for determining this.
|
|
|
|
|
* This behaviour may change in the future.
|
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Returns: %TRUE if the icon is symbolic, %FALSE otherwise
|
|
|
|
|
*/
|
2013-12-15 02:41:49 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_icon_info_is_symbolic (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_INFO (icon_info), FALSE);
|
|
|
|
|
|
2019-10-17 12:55:25 +00:00
|
|
|
|
return icon_info->filename != NULL &&
|
|
|
|
|
icon_uri_is_symbolic (icon_info->filename, -1);
|
2013-12-15 02:41:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
/* If this returns TRUE, its safe to call icon_info_ensure_scale_and_texture
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* without blocking
|
|
|
|
|
*/
|
2013-02-14 12:32:30 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
icon_info_get_pixbuf_ready (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (icon_info->texture)
|
2013-02-14 12:32:30 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 12:22:11 +00:00
|
|
|
|
static GLoadableIcon *
|
|
|
|
|
icon_info_get_loadable (GtkIconInfo *icon_info)
|
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
|
|
|
|
GLoadableIcon *loadable;
|
|
|
|
|
|
|
|
|
|
if (icon_info->loadable)
|
|
|
|
|
return g_object_ref (icon_info->loadable);
|
|
|
|
|
|
|
|
|
|
if (icon_info->is_resource)
|
|
|
|
|
{
|
|
|
|
|
char *uri = g_strconcat ("resource://", icon_info->filename, NULL);
|
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
file = g_file_new_for_path (icon_info->filename);
|
|
|
|
|
|
|
|
|
|
loadable = G_LOADABLE_ICON (g_file_icon_new (file));
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
|
|
return loadable;
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
|
/* This function contains the complicated logic for deciding
|
2003-07-02 22:44:09 +00:00
|
|
|
|
* on the size at which to load the icon and loading it at
|
|
|
|
|
* that size.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2019-09-01 09:25:48 +00:00
|
|
|
|
icon_info_ensure_scale_and_texture (GtkIconInfo *icon_info)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2014-06-14 22:54:24 +00:00
|
|
|
|
gint image_width, image_height, image_size;
|
|
|
|
|
gint scaled_desired_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
GdkPixbuf *source_pixbuf;
|
2014-07-17 04:59:34 +00:00
|
|
|
|
gdouble dir_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (icon_info->texture)
|
2018-10-30 15:18:23 +00:00
|
|
|
|
return TRUE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
scaled_desired_size = icon_info->desired_size * icon_info->desired_scale;
|
|
|
|
|
|
2014-07-17 04:59:34 +00:00
|
|
|
|
dir_scale = icon_info->dir_scale;
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* In many cases, the scale can be determined without actual access
|
|
|
|
|
* to the icon file. This is generally true when we have a size
|
|
|
|
|
* for the directory where the icon is; the image size doesn't
|
|
|
|
|
* matter in that case.
|
|
|
|
|
*/
|
2014-06-30 19:45:17 +00:00
|
|
|
|
if (icon_info->forced_size ||
|
|
|
|
|
icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
|
2008-05-29 14:33:49 +00:00
|
|
|
|
icon_info->scale = -1;
|
2014-06-20 18:17:47 +00:00
|
|
|
|
else if (icon_info->dir_type == ICON_THEME_DIR_FIXED ||
|
|
|
|
|
icon_info->dir_type == ICON_THEME_DIR_THRESHOLD)
|
2013-09-23 10:42:30 +00:00
|
|
|
|
icon_info->scale = icon_info->unscaled_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else if (icon_info->dir_type == ICON_THEME_DIR_SCALABLE)
|
|
|
|
|
{
|
2014-07-17 04:59:34 +00:00
|
|
|
|
/* For svg icons, treat scalable directories as if they had
|
|
|
|
|
* a Scale=<desired_scale> entry. In particular, this means
|
|
|
|
|
* spinners that are restriced to size 32 will loaded at size
|
|
|
|
|
* up to 64 with Scale=2.
|
|
|
|
|
*/
|
|
|
|
|
if (icon_info->is_svg)
|
|
|
|
|
dir_scale = icon_info->desired_scale;
|
|
|
|
|
|
|
|
|
|
if (scaled_desired_size < icon_info->min_size * dir_scale)
|
2014-06-20 18:17:47 +00:00
|
|
|
|
icon_info->scale = (gdouble) icon_info->min_size / (gdouble) icon_info->dir_size;
|
2014-07-17 04:59:34 +00:00
|
|
|
|
else if (scaled_desired_size > icon_info->max_size * dir_scale)
|
2014-06-20 18:17:47 +00:00
|
|
|
|
icon_info->scale = (gdouble) icon_info->max_size / (gdouble) icon_info->dir_size;
|
|
|
|
|
else
|
2014-07-17 04:59:34 +00:00
|
|
|
|
icon_info->scale = (gdouble) scaled_desired_size / (icon_info->dir_size * dir_scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-22 19:49:17 +00:00
|
|
|
|
gdk_profiler_add_mark (g_get_monotonic_time () * 1000, 0, "icon load", icon_info->filename);
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* At this point, we need to actually get the icon; either from the
|
2007-03-23 14:06:52 +00:00
|
|
|
|
* builtin image or by loading the file
|
2003-07-02 22:44:09 +00:00
|
|
|
|
*/
|
2008-05-29 14:33:49 +00:00
|
|
|
|
source_pixbuf = NULL;
|
2005-11-04 15:43:40 +00:00
|
|
|
|
if (icon_info->cache_pixbuf)
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
|
2014-06-20 04:35:57 +00:00
|
|
|
|
else if (icon_info->is_resource)
|
|
|
|
|
{
|
|
|
|
|
if (icon_info->is_svg)
|
|
|
|
|
{
|
|
|
|
|
gint size;
|
|
|
|
|
|
2015-02-23 01:53:18 +00:00
|
|
|
|
if (icon_info->forced_size || icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
|
2014-06-20 04:35:57 +00:00
|
|
|
|
size = scaled_desired_size;
|
|
|
|
|
else
|
2014-07-17 04:59:34 +00:00
|
|
|
|
size = icon_info->dir_size * dir_scale * icon_info->scale;
|
2016-01-29 22:27:35 +00:00
|
|
|
|
|
2017-11-07 23:55:01 +00:00
|
|
|
|
if (gtk_icon_info_is_symbolic (icon_info))
|
|
|
|
|
source_pixbuf = gtk_make_symbolic_pixbuf_from_resource (icon_info->filename,
|
|
|
|
|
size, size,
|
2017-11-08 02:27:38 +00:00
|
|
|
|
icon_info->desired_scale,
|
2017-11-07 23:55:01 +00:00
|
|
|
|
&icon_info->load_error);
|
|
|
|
|
else if (size == 0)
|
2016-01-29 22:27:35 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_resource_scaled (icon_info->filename,
|
2019-10-15 23:05:52 +00:00
|
|
|
|
"svg",
|
2016-01-29 22:27:35 +00:00
|
|
|
|
icon_info->desired_scale,
|
|
|
|
|
&icon_info->load_error);
|
|
|
|
|
else
|
2019-10-15 23:05:52 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_resource_at_scale (icon_info->filename,
|
|
|
|
|
"svg",
|
|
|
|
|
size, size, TRUE,
|
|
|
|
|
&icon_info->load_error);
|
2014-06-20 04:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-10-15 23:05:52 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_resource (icon_info->filename,
|
|
|
|
|
"png",
|
|
|
|
|
&icon_info->load_error);
|
2014-06-20 04:35:57 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-10-18 12:22:11 +00:00
|
|
|
|
GLoadableIcon *loadable;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
GInputStream *stream;
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
|
2019-10-18 12:22:11 +00:00
|
|
|
|
loadable = icon_info_get_loadable (icon_info);
|
|
|
|
|
stream = g_loadable_icon_load (loadable,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
scaled_desired_size,
|
2008-05-29 14:33:49 +00:00
|
|
|
|
NULL, NULL,
|
|
|
|
|
&icon_info->load_error);
|
2019-10-18 12:22:11 +00:00
|
|
|
|
g_object_unref (loadable);
|
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
|
if (stream)
|
|
|
|
|
{
|
2014-06-23 02:04:00 +00:00
|
|
|
|
/* SVG icons are a special case - we just immediately scale them
|
|
|
|
|
* to the desired size
|
|
|
|
|
*/
|
2014-06-14 22:54:24 +00:00
|
|
|
|
if (icon_info->is_svg)
|
2014-06-14 15:19:12 +00:00
|
|
|
|
{
|
2014-06-18 22:21:51 +00:00
|
|
|
|
gint size;
|
|
|
|
|
|
2015-02-23 01:53:18 +00:00
|
|
|
|
if (icon_info->forced_size || icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
|
2014-06-18 22:21:51 +00:00
|
|
|
|
size = scaled_desired_size;
|
|
|
|
|
else
|
2014-07-17 04:59:34 +00:00
|
|
|
|
size = icon_info->dir_size * dir_scale * icon_info->scale;
|
2017-11-07 23:55:01 +00:00
|
|
|
|
|
2019-10-18 12:48:46 +00:00
|
|
|
|
if (gtk_icon_info_is_symbolic (icon_info))
|
|
|
|
|
source_pixbuf = gtk_make_symbolic_pixbuf_from_path (icon_info->filename,
|
2017-11-07 23:55:01 +00:00
|
|
|
|
size, size,
|
2017-11-08 02:27:38 +00:00
|
|
|
|
icon_info->desired_scale,
|
2017-11-07 23:55:01 +00:00
|
|
|
|
&icon_info->load_error);
|
|
|
|
|
else if (size == 0)
|
2016-01-29 22:27:35 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_stream_scaled (stream,
|
2019-10-15 23:05:52 +00:00
|
|
|
|
"svg",
|
2016-01-29 22:27:35 +00:00
|
|
|
|
icon_info->desired_scale,
|
|
|
|
|
NULL,
|
|
|
|
|
&icon_info->load_error);
|
|
|
|
|
else
|
2019-10-15 23:05:52 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream,
|
|
|
|
|
"svg",
|
|
|
|
|
size, size,
|
|
|
|
|
TRUE, NULL,
|
2016-01-29 22:27:35 +00:00
|
|
|
|
&icon_info->load_error);
|
2014-06-14 15:19:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-10-15 23:05:52 +00:00
|
|
|
|
source_pixbuf = _gdk_pixbuf_new_from_stream (stream,
|
|
|
|
|
"png",
|
|
|
|
|
NULL,
|
|
|
|
|
&icon_info->load_error);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
|
if (!source_pixbuf)
|
2016-05-19 13:03:20 +00:00
|
|
|
|
{
|
|
|
|
|
static gboolean warn_about_load_failure = TRUE;
|
|
|
|
|
|
|
|
|
|
if (warn_about_load_failure)
|
|
|
|
|
{
|
2019-10-17 12:56:27 +00:00
|
|
|
|
const char *path;
|
2016-05-19 13:03:20 +00:00
|
|
|
|
|
2019-10-17 12:56:27 +00:00
|
|
|
|
if (icon_info->filename)
|
|
|
|
|
path = icon_info->filename;
|
2016-05-19 13:03:20 +00:00
|
|
|
|
else if (G_IS_FILE (icon_info->loadable))
|
2019-10-17 12:56:27 +00:00
|
|
|
|
path = g_file_peek_path (G_FILE (icon_info->loadable));
|
2016-05-19 13:03:20 +00:00
|
|
|
|
else
|
2019-10-17 12:56:27 +00:00
|
|
|
|
path = "icon theme";
|
2016-05-19 13:03:20 +00:00
|
|
|
|
|
|
|
|
|
g_warning ("Could not load a pixbuf from %s.\n"
|
|
|
|
|
"This may indicate that pixbuf loaders or the mime database could not be found.",
|
|
|
|
|
path);
|
|
|
|
|
|
|
|
|
|
warn_about_load_failure = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2008-05-29 14:33:49 +00:00
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
/* Do scale calculations that depend on the image size
|
|
|
|
|
*/
|
|
|
|
|
image_width = gdk_pixbuf_get_width (source_pixbuf);
|
|
|
|
|
image_height = gdk_pixbuf_get_height (source_pixbuf);
|
2014-06-14 22:54:24 +00:00
|
|
|
|
image_size = MAX (image_width, image_height);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2014-06-14 22:54:24 +00:00
|
|
|
|
if (icon_info->is_svg)
|
|
|
|
|
icon_info->scale = image_size / 1000.;
|
2014-06-14 15:19:12 +00:00
|
|
|
|
else if (icon_info->scale < 0.0)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
{
|
2016-01-30 04:36:24 +00:00
|
|
|
|
if (image_size > 0 && scaled_desired_size > 0)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->scale = (gdouble)scaled_desired_size / (gdouble)image_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->scale = 1.0;
|
2019-09-01 09:25:48 +00:00
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
|
if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED &&
|
|
|
|
|
!icon_info->forced_size)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->scale = MIN (icon_info->scale, 1.0);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (icon_info->is_svg ||
|
|
|
|
|
icon_info->scale == 1.0)
|
|
|
|
|
{
|
|
|
|
|
icon_info->texture = gdk_texture_new_for_pixbuf (source_pixbuf);
|
|
|
|
|
g_object_unref (source_pixbuf);
|
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-01 09:25:48 +00:00
|
|
|
|
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (source_pixbuf,
|
2019-10-03 04:49:32 +00:00
|
|
|
|
MAX (1, 0.5 + image_width * icon_info->scale),
|
|
|
|
|
MAX (1, 0.5 + image_height * icon_info->scale),
|
2014-06-19 23:42:53 +00:00
|
|
|
|
GDK_INTERP_BILINEAR);
|
2019-09-01 09:25:48 +00:00
|
|
|
|
icon_info->texture = gdk_texture_new_for_pixbuf (scaled);
|
|
|
|
|
g_object_unref (scaled);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
g_object_unref (source_pixbuf);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
g_assert (icon_info->texture != NULL);
|
2019-09-01 11:25:44 +00:00
|
|
|
|
add_to_lru_cache (icon_info);
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 20:20:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_icon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2019-08-30 20:20:51 +00:00
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Renders an icon previously looked up in an icon theme using
|
|
|
|
|
* gtk_icon_theme_lookup_icon(); the size will be based on the size
|
|
|
|
|
* passed to gtk_icon_theme_lookup_icon(). Note that the resulting
|
|
|
|
|
* pixbuf may not be exactly this size; an icon theme may have icons
|
|
|
|
|
* that differ slightly from their nominal sizes, and in addition GTK+
|
|
|
|
|
* will avoid scaling icons that it considers sufficiently close to the
|
|
|
|
|
* requested size or for which the source image would have to be scaled
|
|
|
|
|
* up too far. (This maintains sharpness.). This behaviour can be changed
|
|
|
|
|
* by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining
|
|
|
|
|
* the #GtkIconInfo. If this flag has been specified, the pixbuf
|
|
|
|
|
* returned by this function will be scaled to the exact size.
|
|
|
|
|
*
|
2019-08-30 20:58:41 +00:00
|
|
|
|
* Returns: (transfer full) (nullable): the rendered icon.
|
|
|
|
|
* Use g_object_unref() to release your reference to the icon.
|
2019-08-30 20:20:51 +00:00
|
|
|
|
*/
|
|
|
|
|
GdkPaintable *
|
|
|
|
|
gtk_icon_info_load_icon (GtkIconInfo *icon_info,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
2017-10-23 05:51:45 +00:00
|
|
|
|
if (!icon_info->texture)
|
|
|
|
|
{
|
2019-09-01 09:25:48 +00:00
|
|
|
|
icon_info_ensure_scale_and_texture (icon_info);
|
2019-09-01 08:56:29 +00:00
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
/* Still no texture -> error */
|
|
|
|
|
if (!icon_info->texture)
|
2019-08-29 15:07:45 +00:00
|
|
|
|
{
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
|
{
|
|
|
|
|
if (error)
|
|
|
|
|
*error = g_error_copy (icon_info->load_error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error,
|
|
|
|
|
GTK_ICON_THEME_ERROR,
|
|
|
|
|
GTK_ICON_THEME_NOT_FOUND,
|
|
|
|
|
_("Failed to load icon"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2017-10-23 05:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 20:58:41 +00:00
|
|
|
|
return GDK_PAINTABLE (g_object_ref (icon_info->texture));
|
2017-10-23 05:51:45 +00:00
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
load_icon_thread (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable)
|
2013-02-14 12:32:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *dup = task_data;
|
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
(void)icon_info_ensure_scale_and_texture (dup);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
g_task_return_pointer (task, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_icon_async:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore
|
2013-02-14 12:32:30 +00:00
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
|
* request is satisfied
|
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
|
*
|
|
|
|
|
* Asynchronously load, render and scale an icon previously looked up
|
|
|
|
|
* from the icon theme using gtk_icon_theme_lookup_icon().
|
|
|
|
|
*
|
|
|
|
|
* For more details, see gtk_icon_info_load_icon() which is the synchronous
|
|
|
|
|
* version of this call.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2013-02-14 12:32:30 +00:00
|
|
|
|
void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
2013-02-14 12:32:30 +00:00
|
|
|
|
{
|
|
|
|
|
GTask *task;
|
|
|
|
|
|
|
|
|
|
task = g_task_new (icon_info, cancellable, callback, user_data);
|
|
|
|
|
|
|
|
|
|
if (icon_info_get_pixbuf_ready (icon_info))
|
|
|
|
|
{
|
2019-09-08 09:10:01 +00:00
|
|
|
|
GError *error = NULL;
|
2019-08-30 20:20:51 +00:00
|
|
|
|
GdkPaintable *paintable = gtk_icon_info_load_icon (icon_info, &error);
|
|
|
|
|
|
|
|
|
|
if (paintable == NULL)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
g_task_return_error (task, error);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
else
|
2019-08-30 20:20:51 +00:00
|
|
|
|
g_task_return_pointer (task, paintable, g_object_unref);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-08 09:10:01 +00:00
|
|
|
|
GtkIconInfo *dup = icon_info_dup (icon_info);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
g_task_set_task_data (task, dup, g_object_unref);
|
|
|
|
|
g_task_run_in_thread (task, load_icon_thread);
|
|
|
|
|
}
|
2019-09-08 09:10:01 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (task);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_icon_finish:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 12:32:30 +00:00
|
|
|
|
* @res: a #GAsyncResult
|
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_icon_async().
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer full): the rendered icon; this may be a newly
|
2013-02-14 12:32:30 +00:00
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
|
* to the icon.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
GError **error)
|
2013-02-14 12:32:30 +00:00
|
|
|
|
{
|
|
|
|
|
GTask *task = G_TASK (result);
|
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, icon_info), NULL);
|
|
|
|
|
|
|
|
|
|
dup = g_task_get_task_data (task);
|
|
|
|
|
if (dup == NULL || g_task_had_error (task))
|
|
|
|
|
return g_task_propagate_pointer (task, error);
|
|
|
|
|
|
|
|
|
|
/* We ran the thread and it was not cancelled */
|
|
|
|
|
|
|
|
|
|
/* Check if someone else updated the icon_info in between */
|
|
|
|
|
if (!icon_info_get_pixbuf_ready (icon_info))
|
|
|
|
|
{
|
|
|
|
|
/* If not, copy results from dup back to icon_info */
|
|
|
|
|
icon_info->scale = dup->scale;
|
2019-09-01 09:25:48 +00:00
|
|
|
|
g_clear_object (&icon_info->texture);
|
|
|
|
|
if (dup->texture)
|
|
|
|
|
icon_info->texture = g_object_ref (dup->texture);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
g_clear_error (&icon_info->load_error);
|
|
|
|
|
if (dup->load_error)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
icon_info->load_error = g_error_copy (dup->load_error);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert (icon_info_get_pixbuf_ready (icon_info));
|
|
|
|
|
|
|
|
|
|
/* This is now guaranteed to not block */
|
2019-08-30 20:58:41 +00:00
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 16:05:48 +00:00
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
gtk_icon_info_load_symbolic_png (GtkIconInfo *icon_info,
|
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GdkRGBA fg_default = { 0.7450980392156863, 0.7450980392156863, 0.7450980392156863, 1.0};
|
|
|
|
|
GdkRGBA success_default = { 0.3046921492332342,0.6015716792553597, 0.023437857633325704, 1.0};
|
|
|
|
|
GdkRGBA warning_default = {0.9570458533607996, 0.47266346227206835, 0.2421911955443656, 1.0 };
|
|
|
|
|
GdkRGBA error_default = { 0.796887159533074, 0 ,0, 1.0 };
|
2019-09-01 09:25:48 +00:00
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
GdkPixbuf *colored;
|
2014-07-30 16:05:48 +00:00
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (!icon_info_ensure_scale_and_texture (icon_info))
|
2014-07-30 16:05:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
|
{
|
|
|
|
|
if (error)
|
|
|
|
|
*error = g_error_copy (icon_info->load_error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error,
|
|
|
|
|
GTK_ICON_THEME_ERROR,
|
|
|
|
|
GTK_ICON_THEME_NOT_FOUND,
|
|
|
|
|
_("Failed to load icon"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
pixbuf = gdk_pixbuf_get_from_texture (icon_info->texture);
|
2019-10-18 13:40:00 +00:00
|
|
|
|
colored = gtk_color_symbolic_pixbuf (pixbuf,
|
|
|
|
|
fg ? fg : &fg_default,
|
|
|
|
|
success_color ? success_color : &success_default,
|
|
|
|
|
warning_color ? warning_color : &warning_default,
|
|
|
|
|
error_color ? error_color : &error_default);
|
2019-09-01 09:25:48 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
return colored;
|
2014-07-30 16:05:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 13:40:00 +00:00
|
|
|
|
#define MAX_RGB_STRING_LENGTH (3 + 1 + ((3 + 1) * 3) + 1 + 1)
|
|
|
|
|
static inline void
|
|
|
|
|
rgba_to_string_noalpha (const GdkRGBA *rgba,
|
|
|
|
|
char *buff)
|
|
|
|
|
{
|
|
|
|
|
/* gdk_rgba_to_string inlined in here for the alpha == 1 case,
|
|
|
|
|
* and g_strdup_printf replaced with g_snprintf */
|
|
|
|
|
g_snprintf (buff,
|
|
|
|
|
MAX_RGB_STRING_LENGTH,
|
|
|
|
|
"rgb(%d,%d,%d)",
|
|
|
|
|
(int)(0.5 + CLAMP (rgba->red, 0., 1.) * 255.),
|
|
|
|
|
(int)(0.5 + CLAMP (rgba->green, 0., 1.) * 255.),
|
|
|
|
|
(int)(0.5 + CLAMP (rgba->blue, 0., 1.) * 255.));
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 16:05:48 +00:00
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
gtk_icon_info_load_symbolic_svg (GtkIconInfo *icon_info,
|
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
|
GError **error)
|
2010-10-22 12:21:34 +00:00
|
|
|
|
{
|
|
|
|
|
GInputStream *stream;
|
|
|
|
|
GdkPixbuf *pixbuf;
|
2018-10-29 10:10:42 +00:00
|
|
|
|
char css_fg[MAX_RGB_STRING_LENGTH];
|
|
|
|
|
char css_warning[MAX_RGB_STRING_LENGTH] = "rgb(245,121,62)";
|
|
|
|
|
char css_success[MAX_RGB_STRING_LENGTH] = "rgb(78,154,6)";
|
|
|
|
|
char css_error[MAX_RGB_STRING_LENGTH] = "rgb(204,0,0)";
|
2019-10-18 13:10:01 +00:00
|
|
|
|
gchar *svg_data;
|
2015-06-08 23:35:31 +00:00
|
|
|
|
gchar *width;
|
|
|
|
|
gchar *height;
|
2019-10-18 13:10:01 +00:00
|
|
|
|
char *escaped_file_data;
|
2014-08-12 07:17:59 +00:00
|
|
|
|
double alpha;
|
|
|
|
|
gchar alphastr[G_ASCII_DTOSTR_BUF_SIZE];
|
2010-10-27 16:47:08 +00:00
|
|
|
|
|
2014-08-12 07:17:59 +00:00
|
|
|
|
alpha = fg->alpha;
|
|
|
|
|
|
2018-10-29 10:10:42 +00:00
|
|
|
|
rgba_to_string_noalpha (fg, css_fg);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
|
|
if (warning_color)
|
2018-10-29 10:10:42 +00:00
|
|
|
|
rgba_to_string_noalpha (warning_color, css_warning);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
|
|
if (error_color)
|
2018-10-29 10:10:42 +00:00
|
|
|
|
rgba_to_string_noalpha (error_color, css_error);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
|
|
if (success_color)
|
2018-10-29 10:10:42 +00:00
|
|
|
|
rgba_to_string_noalpha (success_color, css_success);
|
2010-10-27 16:47:08 +00:00
|
|
|
|
|
2019-10-18 13:10:01 +00:00
|
|
|
|
if (icon_info->is_resource)
|
|
|
|
|
{
|
|
|
|
|
GBytes *bytes;
|
|
|
|
|
const char *data;
|
|
|
|
|
gsize file_len;
|
|
|
|
|
|
|
|
|
|
bytes = g_resources_lookup_data (icon_info->filename, G_RESOURCE_LOOKUP_FLAGS_NONE, error);
|
|
|
|
|
if (bytes == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
data = g_bytes_get_data (bytes, &file_len);
|
|
|
|
|
escaped_file_data = g_base64_encode ((guchar *) data, file_len);
|
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *file_data;
|
|
|
|
|
gsize file_len;
|
|
|
|
|
|
|
|
|
|
if (!g_file_get_contents (icon_info->filename, &file_data, &file_len, error))
|
|
|
|
|
return NULL;
|
|
|
|
|
escaped_file_data = g_base64_encode ((guchar *) file_data, file_len);
|
|
|
|
|
g_free (file_data);
|
|
|
|
|
}
|
2013-08-16 22:57:21 +00:00
|
|
|
|
|
2019-09-01 09:25:48 +00:00
|
|
|
|
if (!icon_info_ensure_scale_and_texture (icon_info))
|
2015-10-27 15:05:00 +00:00
|
|
|
|
{
|
|
|
|
|
g_propagate_error (error, icon_info->load_error);
|
|
|
|
|
icon_info->load_error = NULL;
|
2019-10-18 13:10:01 +00:00
|
|
|
|
g_free (escaped_file_data);
|
2015-10-27 15:05:00 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2012-06-06 16:16:05 +00:00
|
|
|
|
|
2015-06-08 23:35:31 +00:00
|
|
|
|
if (icon_info->symbolic_width == 0 ||
|
|
|
|
|
icon_info->symbolic_height == 0)
|
2014-06-23 11:05:29 +00:00
|
|
|
|
{
|
|
|
|
|
/* Fetch size from the original icon */
|
2019-10-18 13:10:01 +00:00
|
|
|
|
if (icon_info->is_resource)
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_resource (icon_info->filename, error);
|
|
|
|
|
else
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (icon_info->filename, error);
|
2014-06-23 11:05:29 +00:00
|
|
|
|
|
|
|
|
|
if (!pixbuf)
|
2016-09-29 16:45:42 +00:00
|
|
|
|
{
|
2019-10-18 13:10:01 +00:00
|
|
|
|
g_free (escaped_file_data);
|
2016-09-29 16:45:42 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-06-23 11:05:29 +00:00
|
|
|
|
|
2015-06-08 23:35:31 +00:00
|
|
|
|
icon_info->symbolic_width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
|
icon_info->symbolic_height = gdk_pixbuf_get_height (pixbuf);
|
2014-06-23 11:05:29 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 17:42:29 +00:00
|
|
|
|
GTK_NOTE (ICONTHEME, {
|
|
|
|
|
int symbolic_size = MAX (icon_info->symbolic_width, icon_info->symbolic_height);
|
2014-06-23 16:13:22 +00:00
|
|
|
|
if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
|
2016-02-28 20:33:18 +00:00
|
|
|
|
g_message ("Symbolic icon %s is not in an icon theme directory",
|
|
|
|
|
icon_info->key.icon_names ? icon_info->key.icon_names[0] : icon_info->filename);
|
2015-06-08 23:35:31 +00:00
|
|
|
|
else if (icon_info->dir_size * icon_info->dir_scale != symbolic_size)
|
2016-02-28 20:33:18 +00:00
|
|
|
|
g_message ("Symbolic icon %s of size %d is in an icon theme directory of size %d",
|
|
|
|
|
icon_info->key.icon_names ? icon_info->key.icon_names[0] : icon_info->filename,
|
|
|
|
|
symbolic_size,
|
2020-01-13 17:42:29 +00:00
|
|
|
|
icon_info->dir_size * icon_info->dir_scale);
|
|
|
|
|
});
|
2014-06-23 11:05:29 +00:00
|
|
|
|
|
2015-06-08 23:35:31 +00:00
|
|
|
|
width = g_strdup_printf ("%d", icon_info->symbolic_width);
|
|
|
|
|
height = g_strdup_printf ("%d", icon_info->symbolic_height);
|
2013-08-16 22:57:21 +00:00
|
|
|
|
|
2014-08-12 07:17:59 +00:00
|
|
|
|
g_ascii_dtostr (alphastr, G_ASCII_DTOSTR_BUF_SIZE, CLAMP (alpha, 0, 1));
|
|
|
|
|
|
2019-10-18 13:10:01 +00:00
|
|
|
|
svg_data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
"<svg version=\"1.1\"\n"
|
|
|
|
|
" xmlns=\"http://www.w3.org/2000/svg\"\n"
|
|
|
|
|
" xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
|
2015-06-08 23:35:31 +00:00
|
|
|
|
" width=\"", width, "\"\n"
|
|
|
|
|
" height=\"", height, "\">\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
" <style type=\"text/css\">\n"
|
2018-12-08 01:40:32 +00:00
|
|
|
|
" rect,path,ellipse,circle,polygon {\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
" fill: ", css_fg," !important;\n"
|
|
|
|
|
" }\n"
|
|
|
|
|
" .warning {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
|
" fill: ", css_warning, " !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
" }\n"
|
|
|
|
|
" .error {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
|
" fill: ", css_error ," !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
" }\n"
|
|
|
|
|
" .success {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
|
" fill: ", css_success, " !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
" }\n"
|
|
|
|
|
" </style>\n"
|
2018-11-27 18:13:31 +00:00
|
|
|
|
" <g opacity=\"", alphastr, "\" ><xi:include href=\"data:text/xml;base64,", escaped_file_data, "\"/></g>\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
|
"</svg>",
|
|
|
|
|
NULL);
|
2013-08-16 22:57:21 +00:00
|
|
|
|
g_free (escaped_file_data);
|
2015-06-08 23:35:31 +00:00
|
|
|
|
g_free (width);
|
|
|
|
|
g_free (height);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
|
2019-10-18 13:10:01 +00:00
|
|
|
|
stream = g_memory_input_stream_new_from_data (svg_data, -1, g_free);
|
2019-10-15 23:05:52 +00:00
|
|
|
|
pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream,
|
|
|
|
|
"svg",
|
2019-09-01 09:25:48 +00:00
|
|
|
|
gdk_texture_get_width (icon_info->texture),
|
|
|
|
|
gdk_texture_get_height (icon_info->texture),
|
2010-10-22 12:21:34 +00:00
|
|
|
|
TRUE,
|
|
|
|
|
NULL,
|
|
|
|
|
error);
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
|
2014-07-30 16:05:48 +00:00
|
|
|
|
return pixbuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
|
gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
|
2019-08-29 14:40:41 +00:00
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
|
GError **error)
|
2014-07-30 16:05:48 +00:00
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
2019-10-18 13:10:01 +00:00
|
|
|
|
if (g_str_has_suffix (icon_info->filename, ".symbolic.png"))
|
2014-07-30 16:05:48 +00:00
|
|
|
|
pixbuf = gtk_icon_info_load_symbolic_png (icon_info, fg, success_color, warning_color, error_color, error);
|
|
|
|
|
else
|
|
|
|
|
pixbuf = gtk_icon_info_load_symbolic_svg (icon_info, fg, success_color, warning_color, error_color, error);
|
|
|
|
|
|
2019-09-01 14:29:30 +00:00
|
|
|
|
return pixbuf;
|
2010-10-22 12:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 10:55:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_symbolic:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2010-10-22 12:21:34 +00:00
|
|
|
|
* @fg: a #GdkRGBA representing the foreground color of the icon
|
|
|
|
|
* @success_color: (allow-none): a #GdkRGBA representing the warning color
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* of the icon or %NULL to use the default color
|
2010-10-22 12:21:34 +00:00
|
|
|
|
* @warning_color: (allow-none): a #GdkRGBA representing the warning color
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* of the icon or %NULL to use the default color
|
2010-10-22 12:21:34 +00:00
|
|
|
|
* @error_color: (allow-none): a #GdkRGBA representing the error color
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* of the icon or %NULL to use the default color (allow-none)
|
2011-01-18 09:10:30 +00:00
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
|
* applied to it.
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
2010-04-26 10:55:34 +00:00
|
|
|
|
*
|
|
|
|
|
* Loads an icon, modifying it to match the system colours for the foreground,
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* success, warning and error colors provided. If the icon is not a symbolic
|
|
|
|
|
* one, the function will return the result from gtk_icon_info_load_icon().
|
2010-04-26 10:55:34 +00:00
|
|
|
|
*
|
|
|
|
|
* This allows loading symbolic icons that will match the system theme.
|
|
|
|
|
*
|
|
|
|
|
* Unless you are implementing a widget, you will want to use
|
|
|
|
|
* g_themed_icon_new_with_default_fallbacks() to load the icon.
|
|
|
|
|
*
|
|
|
|
|
* As implementation details, the icon loaded needs to be of SVG type,
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* contain the “symbolic” term as the last component of the icon name,
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* and use the “fg”, “success”, “warning” and “error” CSS styles in the
|
2010-05-01 03:33:59 +00:00
|
|
|
|
* SVG file itself.
|
|
|
|
|
*
|
2014-02-04 23:53:51 +00:00
|
|
|
|
* See the [Symbolic Icons Specification](http://www.freedesktop.org/wiki/SymbolicIcons)
|
2010-04-26 10:55:34 +00:00
|
|
|
|
* for more information about symbolic icons.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer full): a #GdkPixbuf representing the loaded icon
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *
|
2011-02-10 12:58:07 +00:00
|
|
|
|
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)
|
2010-04-26 10:55:34 +00:00
|
|
|
|
{
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPixbuf *pixbuf;
|
2012-10-28 19:01:30 +00:00
|
|
|
|
gboolean is_symbolic;
|
2010-04-26 10:55:34 +00:00
|
|
|
|
|
2012-11-09 10:55:44 +00:00
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
g_return_val_if_fail (fg != NULL, NULL);
|
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
|
is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
|
|
|
|
|
if (was_symbolic)
|
2012-10-28 19:01:30 +00:00
|
|
|
|
*was_symbolic = is_symbolic;
|
|
|
|
|
|
|
|
|
|
if (!is_symbolic)
|
2019-08-30 20:58:41 +00:00
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2019-08-30 19:26:21 +00:00
|
|
|
|
|
|
|
|
|
pixbuf = gtk_icon_info_load_symbolic_internal (icon_info,
|
|
|
|
|
fg, success_color,
|
|
|
|
|
warning_color, error_color,
|
|
|
|
|
error);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
|
if (pixbuf)
|
|
|
|
|
{
|
|
|
|
|
GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
|
|
return GDK_PAINTABLE (texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2010-04-26 10:55:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
|
|
|
|
|
GdkRGBA *color_out,
|
|
|
|
|
GdkRGBA *success_out,
|
|
|
|
|
GdkRGBA *warning_out,
|
|
|
|
|
GdkRGBA *error_out)
|
2015-12-02 23:33:51 +00:00
|
|
|
|
{
|
|
|
|
|
GtkCssValue *palette, *color;
|
|
|
|
|
const GdkRGBA *lookup;
|
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
|
color = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_COLOR);
|
|
|
|
|
palette = gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_PALETTE);
|
2020-01-10 12:02:33 +00:00
|
|
|
|
*color_out = *gtk_css_color_value_get_rgba (color);
|
2015-12-02 23:33:51 +00:00
|
|
|
|
|
|
|
|
|
lookup = gtk_css_palette_value_get_color (palette, "success");
|
|
|
|
|
if (lookup)
|
|
|
|
|
*success_out = *lookup;
|
|
|
|
|
else
|
|
|
|
|
*success_out = *color_out;
|
|
|
|
|
|
|
|
|
|
lookup = gtk_css_palette_value_get_color (palette, "warning");
|
|
|
|
|
if (lookup)
|
|
|
|
|
*warning_out = *lookup;
|
|
|
|
|
else
|
|
|
|
|
*warning_out = *color_out;
|
|
|
|
|
|
|
|
|
|
lookup = gtk_css_palette_value_get_color (palette, "error");
|
|
|
|
|
if (lookup)
|
|
|
|
|
*error_out = *lookup;
|
|
|
|
|
else
|
|
|
|
|
*error_out = *color_out;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-24 19:40:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_symbolic_for_context:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo
|
2010-12-17 19:51:53 +00:00
|
|
|
|
* @context: a #GtkStyleContext
|
2011-01-18 09:10:30 +00:00
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
2018-10-29 10:27:04 +00:00
|
|
|
|
* loaded icon was a symbolic one and whether the foreground color was
|
2011-01-18 09:10:30 +00:00
|
|
|
|
* applied to it.
|
2010-11-24 19:40:31 +00:00
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Loads an icon, modifying it to match the system colors for the foreground,
|
|
|
|
|
* success, warning and error colors provided. If the icon is not a symbolic
|
|
|
|
|
* one, the function will return the result from gtk_icon_info_load_icon().
|
2011-01-14 02:37:33 +00:00
|
|
|
|
* This function uses the regular foreground color and the symbolic colors
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* with the names “success_color”, “warning_color” and “error_color” from
|
2011-01-14 02:37:33 +00:00
|
|
|
|
* the context.
|
2010-11-24 19:40:31 +00:00
|
|
|
|
*
|
|
|
|
|
* This allows loading symbolic icons that will match the system theme.
|
|
|
|
|
*
|
|
|
|
|
* See gtk_icon_info_load_symbolic() for more details.
|
|
|
|
|
*
|
2019-08-31 08:46:06 +00:00
|
|
|
|
* Returns: (transfer full) (nullable): a #GdkPixbuf representing the loaded icon
|
|
|
|
|
* or %NULL If the icon could not be loaded
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *
|
2010-11-24 19:40:31 +00:00
|
|
|
|
gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
|
|
|
|
|
GtkStyleContext *context,
|
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
2012-11-26 12:52:05 +00:00
|
|
|
|
GdkRGBA fg;
|
|
|
|
|
GdkRGBA success_color;
|
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
|
GdkRGBA error_color;
|
2012-10-28 19:01:30 +00:00
|
|
|
|
gboolean is_symbolic;
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPixbuf *pixbuf;
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
2012-11-09 10:55:44 +00:00
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (context != NULL, NULL);
|
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
|
is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
|
|
|
|
if (was_symbolic)
|
2012-10-28 19:01:30 +00:00
|
|
|
|
*was_symbolic = is_symbolic;
|
|
|
|
|
|
|
|
|
|
if (!is_symbolic)
|
2019-08-30 20:58:41 +00:00
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
|
gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
|
|
|
|
|
&fg, &success_color,
|
|
|
|
|
&warning_color, &error_color);
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
|
pixbuf = gtk_icon_info_load_symbolic_internal (icon_info,
|
|
|
|
|
&fg, &success_color,
|
|
|
|
|
&warning_color, &error_color,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
if (pixbuf)
|
|
|
|
|
{
|
|
|
|
|
GdkTexture *texture = gdk_texture_new_for_pixbuf (pixbuf);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
|
|
return GDK_PAINTABLE (texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2012-11-26 12:52:05 +00:00
|
|
|
|
}
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
2013-02-14 15:01:04 +00:00
|
|
|
|
typedef struct {
|
2018-10-29 10:26:05 +00:00
|
|
|
|
guint is_symbolic : 1;
|
|
|
|
|
guint success_color_set : 1;
|
|
|
|
|
guint warning_color_set : 1;
|
|
|
|
|
guint error_color_set : 1;
|
|
|
|
|
guint fg_set : 1;
|
2013-02-14 15:01:04 +00:00
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
|
GdkRGBA fg;
|
|
|
|
|
GdkRGBA success_color;
|
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
|
GdkRGBA error_color;
|
|
|
|
|
} AsyncSymbolicData;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
async_symbolic_data_free (AsyncSymbolicData *data)
|
|
|
|
|
{
|
|
|
|
|
if (data->dup)
|
|
|
|
|
g_object_unref (data->dup);
|
|
|
|
|
g_slice_free (AsyncSymbolicData, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
async_load_no_symbolic_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *icon_info = GTK_ICON_INFO (source_object);
|
|
|
|
|
GTask *task = user_data;
|
|
|
|
|
GError *error = NULL;
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *paintable;
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
|
paintable = gtk_icon_info_load_icon_finish (icon_info, res, &error);
|
|
|
|
|
if (paintable == NULL)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
else
|
2019-08-30 19:26:21 +00:00
|
|
|
|
g_task_return_pointer (task, paintable, g_object_unref);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
load_symbolic_icon_thread (GTask *task,
|
|
|
|
|
gpointer source_object,
|
|
|
|
|
gpointer task_data,
|
|
|
|
|
GCancellable *cancellable)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
AsyncSymbolicData *data = task_data;
|
|
|
|
|
GError *error;
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
2014-06-20 19:17:18 +00:00
|
|
|
|
pixbuf = gtk_icon_info_load_symbolic_internal (data->dup,
|
|
|
|
|
data->fg_set ? &data->fg : NULL,
|
|
|
|
|
data->success_color_set ? &data->success_color : NULL,
|
|
|
|
|
data->warning_color_set ? &data->warning_color : NULL,
|
|
|
|
|
data->error_color_set ? &data->error_color : NULL,
|
|
|
|
|
&error);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
if (pixbuf == NULL)
|
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
|
else
|
|
|
|
|
g_task_return_pointer (task, pixbuf, g_object_unref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_symbolic_async:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
|
* @fg: a #GdkRGBA representing the foreground color of the icon
|
|
|
|
|
* @success_color: (allow-none): a #GdkRGBA representing the warning color
|
|
|
|
|
* of the icon or %NULL to use the default color
|
|
|
|
|
* @warning_color: (allow-none): a #GdkRGBA representing the warning color
|
|
|
|
|
* of the icon or %NULL to use the default color
|
|
|
|
|
* @error_color: (allow-none): a #GdkRGBA representing the error color
|
|
|
|
|
* of the icon or %NULL to use the default color (allow-none)
|
|
|
|
|
* @cancellable: (allow-none): optional #GCancellable object,
|
|
|
|
|
* %NULL to ignore
|
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
|
* request is satisfied
|
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
|
*
|
|
|
|
|
* Asynchronously load, render and scale a symbolic icon previously looked up
|
|
|
|
|
* from the icon theme using gtk_icon_theme_lookup_icon().
|
|
|
|
|
*
|
|
|
|
|
* For more details, see gtk_icon_info_load_symbolic() which is the synchronous
|
|
|
|
|
* version of this call.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2013-02-14 15:01:04 +00:00
|
|
|
|
void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
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)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
GTask *task;
|
|
|
|
|
AsyncSymbolicData *data;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
|
g_return_if_fail (fg != NULL);
|
|
|
|
|
|
|
|
|
|
task = g_task_new (icon_info, cancellable, callback, user_data);
|
|
|
|
|
|
|
|
|
|
data = g_slice_new0 (AsyncSymbolicData);
|
|
|
|
|
g_task_set_task_data (task, data, (GDestroyNotify) async_symbolic_data_free);
|
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
|
data->is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
|
|
|
|
if (!data->is_symbolic)
|
|
|
|
|
{
|
|
|
|
|
gtk_icon_info_load_icon_async (icon_info, cancellable, async_load_no_symbolic_cb, g_object_ref (task));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-01 14:29:30 +00:00
|
|
|
|
if (fg)
|
2014-06-19 23:42:53 +00:00
|
|
|
|
{
|
2019-09-01 14:29:30 +00:00
|
|
|
|
data->fg = *fg;
|
|
|
|
|
data->fg_set = TRUE;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-01 14:29:30 +00:00
|
|
|
|
if (success_color)
|
|
|
|
|
{
|
|
|
|
|
data->success_color = *success_color;
|
|
|
|
|
data->success_color_set = TRUE;
|
|
|
|
|
}
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2019-09-01 14:29:30 +00:00
|
|
|
|
if (warning_color)
|
|
|
|
|
{
|
|
|
|
|
data->warning_color = *warning_color;
|
|
|
|
|
data->warning_color_set = TRUE;
|
|
|
|
|
}
|
2014-06-19 23:42:53 +00:00
|
|
|
|
|
2019-09-01 14:29:30 +00:00
|
|
|
|
if (error_color)
|
|
|
|
|
{
|
|
|
|
|
data->error_color = *error_color;
|
|
|
|
|
data->error_color_set = TRUE;
|
2014-06-19 23:42:53 +00:00
|
|
|
|
}
|
2019-09-01 14:29:30 +00:00
|
|
|
|
|
|
|
|
|
data->dup = icon_info_dup (icon_info);
|
|
|
|
|
g_task_run_in_thread (task, load_symbolic_icon_thread);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
}
|
|
|
|
|
g_object_unref (task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_symbolic_finish:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
|
* @res: a #GAsyncResult
|
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
|
* applied to it.
|
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_symbolic_async().
|
|
|
|
|
*
|
2019-08-30 19:26:21 +00:00
|
|
|
|
* Returns: (transfer full): the rendered icon;
|
|
|
|
|
* Use g_object_unref() to release your reference
|
|
|
|
|
* to the icon.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *
|
2013-02-14 15:01:04 +00:00
|
|
|
|
gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
|
GError **error)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
GTask *task = G_TASK (result);
|
|
|
|
|
AsyncSymbolicData *data = g_task_get_task_data (task);
|
|
|
|
|
GdkPixbuf *pixbuf;
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkTexture *texture;
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
|
|
|
|
if (was_symbolic)
|
|
|
|
|
*was_symbolic = data->is_symbolic;
|
|
|
|
|
|
|
|
|
|
if (data->dup && !g_task_had_error (task))
|
|
|
|
|
{
|
|
|
|
|
pixbuf = g_task_propagate_pointer (task, NULL);
|
|
|
|
|
|
|
|
|
|
g_assert (pixbuf != NULL); /* we checked for !had_error above */
|
|
|
|
|
}
|
2019-08-30 19:26:21 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pixbuf = g_task_propagate_pointer (task, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
texture = gdk_texture_new_for_pixbuf (pixbuf);
|
|
|
|
|
g_object_unref (pixbuf);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
2019-08-30 19:26:21 +00:00
|
|
|
|
return GDK_PAINTABLE (texture);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-02-15 10:07:51 +00:00
|
|
|
|
* gtk_icon_info_load_symbolic_for_context_async:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
|
* @context: a #GtkStyleContext
|
|
|
|
|
* @cancellable: (allow-none): optional #GCancellable object,
|
|
|
|
|
* %NULL to ignore
|
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
|
* request is satisfied
|
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Asynchronously load, render and scale a symbolic icon previously
|
|
|
|
|
* looked up from the icon theme using gtk_icon_theme_lookup_icon().
|
2013-02-14 15:01:04 +00:00
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* For more details, see gtk_icon_info_load_symbolic_for_context()
|
|
|
|
|
* which is the synchronous version of this call.
|
|
|
|
|
*/
|
2013-02-14 15:01:04 +00:00
|
|
|
|
void
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info,
|
|
|
|
|
GtkStyleContext *context,
|
|
|
|
|
GCancellable *cancellable,
|
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
|
gpointer user_data)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
GdkRGBA fg;
|
|
|
|
|
GdkRGBA success_color;
|
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
|
GdkRGBA error_color;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
|
2015-12-07 03:44:39 +00:00
|
|
|
|
gtk_icon_theme_lookup_symbolic_colors (gtk_style_context_lookup_style (context),
|
|
|
|
|
&fg, &success_color,
|
|
|
|
|
&warning_color, &error_color);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
|
|
|
|
gtk_icon_info_load_symbolic_async (icon_info,
|
2015-12-02 23:33:51 +00:00
|
|
|
|
&fg, &success_color,
|
|
|
|
|
&warning_color, &error_color,
|
2014-06-19 23:42:53 +00:00
|
|
|
|
cancellable, callback, user_data);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_info_load_symbolic_for_context_finish:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
|
* @res: a #GAsyncResult
|
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
|
* applied to it.
|
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
|
* or %NULL.
|
|
|
|
|
*
|
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_symbolic_for_context_async().
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer full): the rendered icon; this may be a newly
|
2013-02-14 15:01:04 +00:00
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
|
* to the icon.
|
2014-06-19 23:42:53 +00:00
|
|
|
|
*/
|
2019-08-30 19:26:21 +00:00
|
|
|
|
GdkPaintable *
|
2014-06-19 23:42:53 +00:00
|
|
|
|
gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
|
GError **error)
|
2013-02-14 15:01:04 +00:00
|
|
|
|
{
|
|
|
|
|
return gtk_icon_info_load_symbolic_finish (icon_info, result, was_symbolic, error);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_lookup_by_gicon:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2008-05-29 14:33:49 +00:00
|
|
|
|
* @icon: the #GIcon to look up
|
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Looks up an icon and returns a #GtkIconInfo containing information
|
|
|
|
|
* such as the filename of the icon. The icon can then be rendered
|
|
|
|
|
* into a pixbuf using gtk_icon_info_load_icon().
|
2008-05-29 14:33:49 +00:00
|
|
|
|
*
|
2015-11-04 11:50:37 +00:00
|
|
|
|
* When rendering on displays with high pixel densities you should not
|
|
|
|
|
* use a @size multiplied by the scaling factor returned by functions
|
2018-03-20 10:40:08 +00:00
|
|
|
|
* like gdk_surface_get_scale_factor(). Instead, you should use
|
2015-11-04 11:50:37 +00:00
|
|
|
|
* gtk_icon_theme_lookup_by_gicon_for_scale(), as the assets loaded
|
|
|
|
|
* for a given scaling factor may be different.
|
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo containing
|
|
|
|
|
* information about the icon, or %NULL if the icon wasn’t
|
|
|
|
|
* found. Unref with g_object_unref()
|
2008-05-29 14:33:49 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_lookup_by_gicon (GtkIconTheme *self,
|
2008-05-29 14:33:49 +00:00
|
|
|
|
GIcon *icon,
|
|
|
|
|
gint size,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2013-05-10 16:06:00 +00:00
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
return gtk_icon_theme_lookup_by_gicon_for_scale (self, icon,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
size, 1, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 15:31:09 +00:00
|
|
|
|
static GtkIconInfo *
|
|
|
|
|
gtk_icon_info_new_for_file (GFile *file,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale)
|
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
|
|
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
|
|
|
|
info->loadable = G_LOADABLE_ICON (g_file_icon_new (file));
|
|
|
|
|
info->is_resource = g_file_has_uri_scheme (file, "resource");
|
|
|
|
|
|
|
|
|
|
if (info->is_resource)
|
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
|
|
|
|
|
|
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
|
info->filename = g_strdup (uri + 11); /* resource:// */
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
info->filename = g_file_get_path (file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info->is_svg = suffix_from_name (info->filename) == ICON_SUFFIX_SVG;
|
|
|
|
|
|
|
|
|
|
info->desired_size = size;
|
|
|
|
|
info->desired_scale = scale;
|
|
|
|
|
info->forced_size = FALSE;
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
2019-10-18 13:47:07 +00:00
|
|
|
|
static GtkIconInfo *
|
|
|
|
|
gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme,
|
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
|
|
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, 0, 1);
|
|
|
|
|
info->texture = gdk_texture_new_for_pixbuf (pixbuf);
|
|
|
|
|
info->scale = 1.0;
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_icon_theme_lookup_by_gicon_for_scale:
|
2019-09-08 12:57:40 +00:00
|
|
|
|
* @self: a #GtkIconTheme
|
2013-05-10 16:06:00 +00:00
|
|
|
|
* @icon: the #GIcon to look up
|
|
|
|
|
* @size: desired icon size
|
|
|
|
|
* @scale: the desired scale
|
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
|
*
|
2014-06-19 23:42:53 +00:00
|
|
|
|
* Looks up an icon and returns a #GtkIconInfo containing information
|
|
|
|
|
* such as the filename of the icon. The icon can then be rendered into
|
|
|
|
|
* a pixbuf using gtk_icon_info_load_icon().
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*
|
2014-05-26 16:13:02 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GtkIconInfo containing
|
|
|
|
|
* information about the icon, or %NULL if the icon wasn’t
|
|
|
|
|
* found. Unref with g_object_unref()
|
2013-05-10 16:06:00 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkIconInfo *
|
2019-09-08 12:57:40 +00:00
|
|
|
|
gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *self,
|
2013-05-10 16:06:00 +00:00
|
|
|
|
GIcon *icon,
|
|
|
|
|
gint size,
|
|
|
|
|
gint scale,
|
|
|
|
|
GtkIconLookupFlags flags)
|
2008-05-29 14:33:49 +00:00
|
|
|
|
{
|
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (self), NULL);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
g_return_val_if_fail (G_IS_ICON (icon), NULL);
|
2015-10-09 13:41:00 +00:00
|
|
|
|
g_warn_if_fail ((flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK) == 0);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
|
2013-08-01 21:06:00 +00:00
|
|
|
|
if (GDK_IS_PIXBUF (icon))
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
|
|
pixbuf = GDK_PIXBUF (icon);
|
|
|
|
|
|
|
|
|
|
if ((flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0)
|
|
|
|
|
{
|
|
|
|
|
gint width, height, max;
|
|
|
|
|
gdouble pixbuf_scale;
|
|
|
|
|
|
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
|
max = MAX (width, height);
|
|
|
|
|
pixbuf_scale = (gdouble) size * scale / (gdouble) max;
|
|
|
|
|
|
2019-08-30 12:23:56 +00:00
|
|
|
|
if (pixbuf_scale != 1.0)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbuf *scaled;
|
|
|
|
|
scaled = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
|
0.5 + width * pixbuf_scale,
|
|
|
|
|
0.5 + height * pixbuf_scale,
|
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = gtk_icon_info_new_for_pixbuf (self, scaled);
|
2019-08-30 12:23:56 +00:00
|
|
|
|
g_object_unref (scaled);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = gtk_icon_info_new_for_pixbuf (self, pixbuf);
|
2019-08-30 12:23:56 +00:00
|
|
|
|
}
|
2013-08-01 21:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = gtk_icon_info_new_for_pixbuf (self, pixbuf);
|
2013-08-01 21:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-14 17:53:50 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
else if (G_IS_FILE_ICON (icon))
|
|
|
|
|
{
|
|
|
|
|
GFile *file = g_file_icon_get_file (G_FILE_ICON (icon));
|
|
|
|
|
|
|
|
|
|
info = gtk_icon_info_new_for_file (file, size, scale);
|
|
|
|
|
info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
|
|
|
|
|
|
2013-08-01 21:06:00 +00:00
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
else if (G_IS_LOADABLE_ICON (icon))
|
2008-05-29 14:33:49 +00:00
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
|
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
info->loadable = G_LOADABLE_ICON (g_object_ref (icon));
|
2014-06-17 16:05:22 +00:00
|
|
|
|
info->is_svg = FALSE;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
info->desired_size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
info->desired_scale = scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
else if (G_IS_THEMED_ICON (icon))
|
|
|
|
|
{
|
|
|
|
|
const gchar **names;
|
|
|
|
|
|
|
|
|
|
names = (const gchar **)g_themed_icon_get_names (G_THEMED_ICON (icon));
|
2019-09-08 12:57:40 +00:00
|
|
|
|
info = gtk_icon_theme_choose_icon_for_scale (self, names, size, scale, flags);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|