Bug 759904: Some icons can't be set from the icon theme

make it possible to use themed standard named icons
so to have also gtk dialogs show icons in the same style
as GIMP ui.
This commit is contained in:
Massimo Valentini 2016-09-02 12:30:49 +02:00
parent 12ac114f71
commit 3cc77b03bf
12 changed files with 211 additions and 114 deletions

View File

@ -1945,12 +1945,16 @@ prefs_dialog_new (Gimp *gimp,
{
GtkTreeIter iter;
GFile *icon_theme_dir = icon_themes_get_theme_dir (gimp, icon_themes[i]);
GFile *icon_theme_search_path = g_file_get_parent (icon_theme_dir);
GtkIconTheme *theme;
gchar *example;
GdkPixbuf *pixbuf;
theme = gtk_icon_theme_new ();
gtk_icon_theme_prepend_search_path (theme, gimp_file_get_utf8_name(icon_theme_dir));
gtk_icon_theme_prepend_search_path (theme, gimp_file_get_utf8_name(icon_theme_search_path));
g_object_unref (icon_theme_search_path);
gtk_icon_theme_set_custom_theme (theme, icon_themes[i]);
example = gtk_icon_theme_get_example_icon_name (theme);
if (! example)
{

View File

@ -101,14 +101,12 @@ icon_themes_init (Gimp *gimp)
g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
{
GFile *file;
GFile *hicolor;
GFile *index_theme;
file = g_file_enumerator_get_child (enumerator, info);
/* make sure there is a hicolor/index.theme file */
hicolor = g_file_get_child (file, "hicolor");
index_theme = g_file_get_child (hicolor, "index.theme");
index_theme = g_file_get_child (file, "index.theme");
if (g_file_query_exists (index_theme, NULL))
{
@ -118,16 +116,22 @@ icon_themes_init (Gimp *gimp)
name = gimp_file_get_utf8_name (file);
basename = g_path_get_basename (name);
if (gimp->be_verbose)
g_print ("Adding icon theme '%s' (%s)\n",
basename, name);
if (strcmp ("hicolor", basename))
{
if (gimp->be_verbose)
g_print ("Adding icon theme '%s' (%s)\n",
basename, name);
g_hash_table_insert (icon_themes_hash, basename,
g_object_ref (file));
g_hash_table_insert (icon_themes_hash, basename,
g_object_ref (file));
}
else
{
g_free (basename);
}
}
g_object_unref (index_theme);
g_object_unref (hicolor);
g_object_unref (file);
}

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
iconsdir = $(gimpdatadir)/icons/Color/hicolor
iconsdir = $(gimpdatadir)/icons/Color
icons_DATA = \
index.theme

View File

@ -1,24 +1,24 @@
## Process this file with automake to produce Makefile.in
iconsdir = $(gimpdatadir)/icons/Legacy/hicolor
icons12dir = $(gimpdatadir)/icons/Legacy/hicolor/12x12/apps
icons16dir = $(gimpdatadir)/icons/Legacy/hicolor/16x16/apps
icons18dir = $(gimpdatadir)/icons/Legacy/hicolor/18x18/apps
icons20dir = $(gimpdatadir)/icons/Legacy/hicolor/20x20/apps
icons22dir = $(gimpdatadir)/icons/Legacy/hicolor/22x22/apps
iconsdir = $(gimpdatadir)/icons/Legacy/
icons12dir = $(gimpdatadir)/icons/Legacy/12x12/apps
icons16dir = $(gimpdatadir)/icons/Legacy/16x16/apps
icons18dir = $(gimpdatadir)/icons/Legacy/18x18/apps
icons20dir = $(gimpdatadir)/icons/Legacy/20x20/apps
icons22dir = $(gimpdatadir)/icons/Legacy/22x22/apps
# 22x22 tool icons will go in their own directory and we tell GTK+
# that this directory contains icons for 24x24 requests.
# This is a special trick to let the theme override the default
# 24x24 size request.
tools22dir = $(gimpdatadir)/icons/Legacy/hicolor/22x22/tools
icons24dir = $(gimpdatadir)/icons/Legacy/hicolor/24x24/apps
icons32dir = $(gimpdatadir)/icons/Legacy/hicolor/32x32/apps
icons48dir = $(gimpdatadir)/icons/Legacy/hicolor/48x48/apps
icons64dir = $(gimpdatadir)/icons/Legacy/hicolor/64x64/apps
icons96dir = $(gimpdatadir)/icons/Legacy/hicolor/96x96/apps
icons128dir = $(gimpdatadir)/icons/Legacy/hicolor/128x128/apps
icons192dir = $(gimpdatadir)/icons/Legacy/hicolor/192x192/apps
icons256dir = $(gimpdatadir)/icons/Legacy/hicolor/256x256/apps
tools22dir = $(gimpdatadir)/icons/Legacy/22x22/tools
icons24dir = $(gimpdatadir)/icons/Legacy/24x24/apps
icons32dir = $(gimpdatadir)/icons/Legacy/32x32/apps
icons48dir = $(gimpdatadir)/icons/Legacy/48x48/apps
icons64dir = $(gimpdatadir)/icons/Legacy/64x64/apps
icons96dir = $(gimpdatadir)/icons/Legacy/96x96/apps
icons128dir = $(gimpdatadir)/icons/Legacy/128x128/apps
icons192dir = $(gimpdatadir)/icons/Legacy/192x192/apps
icons256dir = $(gimpdatadir)/icons/Legacy/256x256/apps
## The icon theme images

File diff suppressed because one or more lines are too long

View File

@ -3,3 +3,11 @@ SUBDIRS = \
Legacy \
Symbolic \
Symbolic-Inverted
iconsdir = $(gimpdatadir)/icons/hicolor
icons_DATA = \
index.theme
EXTRA_DIST = \
$(icons_DATA)

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
iconsdir = $(gimpdatadir)/icons/Symbolic-Inverted/hicolor
iconsdir = $(gimpdatadir)/icons/Symbolic-Inverted
icons_DATA = \
index.theme

View File

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
iconsdir = $(gimpdatadir)/icons/Symbolic/hicolor
iconsdir = $(gimpdatadir)/icons/Symbolic
icons_DATA = \
index.theme

6
icons/index.theme Normal file
View File

@ -0,0 +1,6 @@
[Icon Theme]
Name=Hicolor
Comment=Fallback icon theme
Hidden=true
Directories=

View File

@ -382,47 +382,47 @@ register_bidi_stock_icon (GtkIconFactory *factory,
}
static GFile *icon_theme_path = NULL;
static GFile *default_icon_theme_path = NULL;
static GFile *icon_theme_path = NULL;
static GFile *default_search_path = NULL;
static void
gimp_icons_change_icon_theme (GFile *path)
gimp_icons_change_icon_theme (GFile *new_search_path)
{
if (! default_icon_theme_path)
default_icon_theme_path = gimp_data_directory_file ("icons",
GIMP_DEFAULT_ICON_THEME,
NULL);
GFile *old_search_path = g_file_get_parent (icon_theme_path);
if (! g_file_equal (path, icon_theme_path))
if (! default_search_path)
default_search_path = gimp_data_directory_file ("icons", NULL);
if (! g_file_equal (new_search_path, old_search_path))
{
GtkIconTheme *icon_theme = gtk_icon_theme_get_default ();
if (g_file_equal (icon_theme_path, default_icon_theme_path))
if (g_file_equal (old_search_path, default_search_path))
{
/* if the current icon theme is the default theme, simply
* prepend the new theme's path
/* if the old icon theme is in the default search path,
* simply prepend the new theme's path
*/
gchar *path_str = g_file_get_path (path);
gchar *path_str = g_file_get_path (new_search_path);
gtk_icon_theme_prepend_search_path (icon_theme, path_str);
g_free (path_str);
}
else
{
/* if the current theme is not the default theme, we need
* to deal with the search path's first element
/* if the old theme is not in the default search path,
* we need to deal with the search path's first element
*/
gchar **paths;
gint n_paths;
gtk_icon_theme_get_search_path (icon_theme, &paths, &n_paths);
if (g_file_equal (path, default_icon_theme_path))
if (g_file_equal (new_search_path, default_search_path))
{
/* when switching to the default theme, remove the
* first search path element, the default theme will
* still be in the search path as fallback
/* when switching to a theme in the default path, remove
* the first search path element, the default search path
* is still in the search path
*/
gtk_icon_theme_set_search_path (icon_theme,
(const gchar **) paths + 1,
@ -430,12 +430,12 @@ gimp_icons_change_icon_theme (GFile *path)
}
else
{
/* when switching between two non-default themes, replace
/* when switching between two non-default search paths, replace
* the first element of the search path with the new
* theme's path
*/
g_free (paths[0]);
paths[0] = g_file_get_path (path);
paths[0] = g_file_get_path (new_search_path);
gtk_icon_theme_set_search_path (icon_theme,
(const gchar **) paths, n_paths);
@ -443,69 +443,115 @@ gimp_icons_change_icon_theme (GFile *path)
g_strfreev (paths);
}
g_object_unref (icon_theme_path);
icon_theme_path = g_object_ref (path);
}
g_object_unref (old_search_path);
}
static void
gimp_icons_notify_system_icon_theme (GObject *settings,
GParamSpec *param,
gpointer unused)
{
GdkScreen *screen = gdk_screen_get_default ();
GValue value = G_VALUE_INIT;
g_value_init (&value, G_TYPE_STRING);
if (gdk_screen_get_setting (screen, "gtk-icon-theme-name", &value))
{
const gchar *new_system_icon_theme = g_value_get_string (&value);
gchar *cur_system_icon_theme = NULL;
g_object_get (settings,
"gtk-fallback-icon-theme", &cur_system_icon_theme,
NULL);
if (g_strcmp0 (cur_system_icon_theme, new_system_icon_theme))
{
g_object_set (settings,
"gtk-fallback-icon-theme", new_system_icon_theme,
NULL);
g_object_notify (settings, "gtk-icon-theme-name");
}
g_free (cur_system_icon_theme);
}
g_value_unset (&value);
}
static gboolean
gimp_icons_sanity_check (GFile *path,
const gchar *theme_name)
{
gboolean exists = FALSE;
GFile *child = g_file_get_child (path, theme_name);
if (g_file_query_exists (child, NULL))
{
GFile *index = g_file_get_child (child, "index.theme");
if (g_file_query_exists (index, NULL))
exists = TRUE;
else
g_printerr ("%s: Icon theme path has no '%s/index.theme': %s\n",
G_STRFUNC, theme_name, gimp_file_get_utf8_name (path));
g_object_unref (index);
}
else
g_printerr ("%s: Icon theme path has no '%s' subdirectory: %s\n",
G_STRFUNC, theme_name, gimp_file_get_utf8_name (path));
g_object_unref (child);
return exists;
}
void
gimp_icons_set_icon_theme (GFile *path)
{
gchar *icon_theme_name;
GFile *search_path;
g_return_if_fail (path == NULL || G_IS_FILE (path));
if (path)
path = g_object_ref (path);
else
path = gimp_data_directory_file (gimp_data_directory (),
"icons", GIMP_DEFAULT_ICON_THEME,
NULL);
path = gimp_data_directory_file ("icons", GIMP_DEFAULT_ICON_THEME, NULL);
if (! g_file_query_exists (path, NULL))
{
g_printerr ("%s: Icon theme path does not exist: %s\n",
G_STRFUNC, gimp_file_get_utf8_name (path));
}
else
{
GFile *hicolor = g_file_get_child (path, "hicolor");
search_path = g_file_get_parent (path);
icon_theme_name = g_file_get_basename (path);
if (! g_file_query_exists (hicolor, NULL))
if (gimp_icons_sanity_check (search_path, "hicolor") &&
gimp_icons_sanity_check (search_path, icon_theme_name))
{
if (icon_theme_path)
{
g_printerr ("%s: Icon theme path has no 'hicolor' subdirectory: %s\n",
G_STRFUNC, gimp_file_get_utf8_name (path));
/* this is an icon theme change */
gimp_icons_change_icon_theme (search_path);
if (! g_file_equal (icon_theme_path, path))
{
g_object_unref (icon_theme_path);
icon_theme_path = g_object_ref (path);
}
g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()),
"gtk-icon-theme-name", icon_theme_name,
NULL);
}
else
{
GFile *index = g_file_get_child (hicolor, "index.theme");
if (! g_file_query_exists (index, NULL))
{
g_printerr ("%s: Icon theme path has no 'hicolor/index.theme': %s\n",
G_STRFUNC, gimp_file_get_utf8_name (path));
}
else
{
/* the path points to what looks like a valid icon theme */
if (icon_theme_path)
{
/* this is an icon theme change */
gimp_icons_change_icon_theme (path);
}
else
{
/* this is the first call upon initialization */
icon_theme_path = g_object_ref (path);
}
}
g_object_unref (index);
/* this is the first call upon initialization */
icon_theme_path = g_object_ref (path);
}
g_object_unref (hicolor);
}
g_free (icon_theme_name);
g_object_unref (search_path);
g_object_unref (path);
}
@ -538,10 +584,13 @@ gimp_icons_init (void)
{
static gboolean initialized = FALSE;
GdkPixbuf *pixbuf;
GError *error = NULL;
gchar *icons_dir;
gint i;
GtkSettings *settings;
GdkPixbuf *pixbuf;
GError *error = NULL;
gchar *icons_dir;
gchar *system_icon_theme;
gchar *gimp_icon_theme;
gint i;
if (initialized)
return;
@ -580,26 +629,51 @@ gimp_icons_init (void)
* the path again and acts as fallback for missing icons in other
* themes.
*/
if (! default_icon_theme_path)
default_icon_theme_path = gimp_data_directory_file ("icons",
GIMP_DEFAULT_ICON_THEME,
NULL);
if (! default_search_path)
default_search_path = gimp_data_directory_file ("icons",
NULL);
icons_dir = g_file_get_path (default_icon_theme_path);
icons_dir = g_file_get_path (default_search_path);
gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
icons_dir);
g_free (icons_dir);
/* if an icon theme was chosen before init(), change to it */
if (icon_theme_path &&
! g_file_equal (icon_theme_path, default_icon_theme_path))
if (icon_theme_path)
{
icons_dir = g_file_get_path (icon_theme_path);
gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
icons_dir);
g_free (icons_dir);
GFile *search_path = g_file_get_parent (icon_theme_path);
if (!g_file_equal (search_path, default_search_path))
{
gchar *icon_dir = g_file_get_path (search_path);
gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
icon_dir);
g_free (icon_dir);
}
g_object_unref (search_path);
gimp_icon_theme = g_file_get_basename (icon_theme_path);
}
else
{
gimp_icon_theme = g_strdup (GIMP_DEFAULT_ICON_THEME);
}
settings = gtk_settings_get_for_screen (gdk_screen_get_default ());
g_object_get (settings, "gtk-icon-theme-name", &system_icon_theme, NULL);
g_object_set (settings,
"gtk-fallback-icon-theme", system_icon_theme,
"gtk-icon-theme-name", gimp_icon_theme,
NULL);
g_free (gimp_icon_theme);
g_free (system_icon_theme);
g_signal_connect (settings, "notify::gtk-icon-theme-name",
G_CALLBACK (gimp_icons_notify_system_icon_theme), NULL);
pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/icons/64/gimp-wilber-eek.png",
&error);

View File

@ -15,19 +15,19 @@ style "gimp-default-style"
{
stock["gtk-dialog-error"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-error.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-error.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-info"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-info.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-info.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-question"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-question.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-question.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-warning"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-warning.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-warning.png", *, *, "gtk-dialog" }
}
# Uncommenting this line allows to set a different (smaller) font for GIMP.

View File

@ -21,19 +21,19 @@ style "gimp-default-style"
{
stock["gtk-dialog-error"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-error.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-error.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-info"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-info.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-info.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-question"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-question.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-question.png", *, *, "gtk-dialog" }
}
stock["gtk-dialog-warning"] =
{
{ "../../icons/Color/hicolor/64x64/apps/gimp-warning.png", *, *, "gtk-dialog" }
{ "../../icons/Color/64x64/apps/gimp-warning.png", *, *, "gtk-dialog" }
}
GtkPaned::handle-size = 6