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; GtkTreeIter iter;
GFile *icon_theme_dir = icon_themes_get_theme_dir (gimp, icon_themes[i]); 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; GtkIconTheme *theme;
gchar *example; gchar *example;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
theme = gtk_icon_theme_new (); 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); example = gtk_icon_theme_get_example_icon_name (theme);
if (! example) if (! example)
{ {

View file

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

View file

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

View file

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

File diff suppressed because one or more lines are too long

View file

@ -3,3 +3,11 @@ SUBDIRS = \
Legacy \ Legacy \
Symbolic \ Symbolic \
Symbolic-Inverted 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 ## Process this file with automake to produce Makefile.in
iconsdir = $(gimpdatadir)/icons/Symbolic-Inverted/hicolor iconsdir = $(gimpdatadir)/icons/Symbolic-Inverted
icons_DATA = \ icons_DATA = \
index.theme index.theme

View file

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

@ -383,46 +383,46 @@ register_bidi_stock_icon (GtkIconFactory *factory,
static GFile *icon_theme_path = NULL; static GFile *icon_theme_path = NULL;
static GFile *default_icon_theme_path = NULL; static GFile *default_search_path = NULL;
static void static void
gimp_icons_change_icon_theme (GFile *path) gimp_icons_change_icon_theme (GFile *new_search_path)
{ {
if (! default_icon_theme_path) GFile *old_search_path = g_file_get_parent (icon_theme_path);
default_icon_theme_path = gimp_data_directory_file ("icons",
GIMP_DEFAULT_ICON_THEME,
NULL);
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 (); 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 /* if the old icon theme is in the default search path,
* prepend the new theme's 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); gtk_icon_theme_prepend_search_path (icon_theme, path_str);
g_free (path_str); g_free (path_str);
} }
else else
{ {
/* if the current theme is not the default theme, we need /* if the old theme is not in the default search path,
* to deal with the search path's first element * we need to deal with the search path's first element
*/ */
gchar **paths; gchar **paths;
gint n_paths; gint n_paths;
gtk_icon_theme_get_search_path (icon_theme, &paths, &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 /* when switching to a theme in the default path, remove
* first search path element, the default theme will * the first search path element, the default search path
* still be in the search path as fallback * is still in the search path
*/ */
gtk_icon_theme_set_search_path (icon_theme, gtk_icon_theme_set_search_path (icon_theme,
(const gchar **) paths + 1, (const gchar **) paths + 1,
@ -430,12 +430,12 @@ gimp_icons_change_icon_theme (GFile *path)
} }
else 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 * the first element of the search path with the new
* theme's path * theme's path
*/ */
g_free (paths[0]); 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, gtk_icon_theme_set_search_path (icon_theme,
(const gchar **) paths, n_paths); (const gchar **) paths, n_paths);
@ -443,55 +443,105 @@ gimp_icons_change_icon_theme (GFile *path)
g_strfreev (paths); 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 void
gimp_icons_set_icon_theme (GFile *path) gimp_icons_set_icon_theme (GFile *path)
{ {
gchar *icon_theme_name;
GFile *search_path;
g_return_if_fail (path == NULL || G_IS_FILE (path)); g_return_if_fail (path == NULL || G_IS_FILE (path));
if (path) if (path)
path = g_object_ref (path); path = g_object_ref (path);
else else
path = gimp_data_directory_file (gimp_data_directory (), path = gimp_data_directory_file ("icons", GIMP_DEFAULT_ICON_THEME, NULL);
"icons", GIMP_DEFAULT_ICON_THEME,
NULL);
if (! g_file_query_exists (path, NULL)) search_path = g_file_get_parent (path);
{ icon_theme_name = g_file_get_basename (path);
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");
if (! g_file_query_exists (hicolor, NULL)) if (gimp_icons_sanity_check (search_path, "hicolor") &&
gimp_icons_sanity_check (search_path, icon_theme_name))
{ {
g_printerr ("%s: Icon theme path has no 'hicolor' subdirectory: %s\n",
G_STRFUNC, gimp_file_get_utf8_name (path));
}
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) if (icon_theme_path)
{ {
/* this is an icon theme change */ /* this is an icon theme change */
gimp_icons_change_icon_theme (path); 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 else
{ {
@ -500,12 +550,8 @@ gimp_icons_set_icon_theme (GFile *path)
} }
} }
g_object_unref (index); g_free (icon_theme_name);
} g_object_unref (search_path);
g_object_unref (hicolor);
}
g_object_unref (path); g_object_unref (path);
} }
@ -538,9 +584,12 @@ gimp_icons_init (void)
{ {
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
GtkSettings *settings;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error = NULL; GError *error = NULL;
gchar *icons_dir; gchar *icons_dir;
gchar *system_icon_theme;
gchar *gimp_icon_theme;
gint i; gint i;
if (initialized) if (initialized)
@ -580,26 +629,51 @@ gimp_icons_init (void)
* the path again and acts as fallback for missing icons in other * the path again and acts as fallback for missing icons in other
* themes. * themes.
*/ */
if (! default_icon_theme_path) if (! default_search_path)
default_icon_theme_path = gimp_data_directory_file ("icons", default_search_path = gimp_data_directory_file ("icons",
GIMP_DEFAULT_ICON_THEME,
NULL); 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 (), gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
icons_dir); icons_dir);
g_free (icons_dir); g_free (icons_dir);
/* if an icon theme was chosen before init(), change to it */ /* if an icon theme was chosen before init(), change to it */
if (icon_theme_path && if (icon_theme_path)
! g_file_equal (icon_theme_path, default_icon_theme_path))
{ {
icons_dir = g_file_get_path (icon_theme_path); 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 (), gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (),
icons_dir); icon_dir);
g_free (icons_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", pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/icons/64/gimp-wilber-eek.png",
&error); &error);

View file

@ -15,19 +15,19 @@ style "gimp-default-style"
{ {
stock["gtk-dialog-error"] = 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"] = 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"] = 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"] = 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. # 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"] = 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"] = 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"] = 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"] = 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 GtkPaned::handle-size = 6