1.1 --- a/plover-gtk/stockicons.c Mon Nov 02 19:01:50 2015 +0000
1.2 +++ b/plover-gtk/stockicons.c Tue Jul 14 13:17:21 2020 +0100
1.3 @@ -34,6 +34,8 @@
1.4 GSList *tmp_list;
1.5 static gint found_svg=-1;
1.6 gchar **mime_types,**mime_type;
1.7 + if (g_getenv("PLOVER_IGNORE_SVG_SUPPORT"))
1.8 + return FALSE;
1.9 if (found_svg!=-1)
1.10 return found_svg;
1.11 formats=gdk_pixbuf_get_formats();
1.12 @@ -55,10 +57,15 @@
1.13 {
1.14 int w,h;
1.15 GdkPixbuf *pixbuf;
1.16 + GtkSettings *settings;
1.17 GtkIconSource *source;
1.18 - if (gtk_icon_size_lookup(size,&w,&h))
1.19 + GError *err=NULL;
1.20 + settings=gtk_settings_get_default();
1.21 + if (!settings)
1.22 + g_warning("plover: Can't add icons without a default screen");
1.23 + else if (gtk_icon_size_lookup_for_settings(settings,size,&w,&h))
1.24 {
1.25 - pixbuf=gdk_pixbuf_new_from_file_at_size(filename,w,h,NULL);
1.26 + pixbuf=gdk_pixbuf_new_from_file_at_size(filename,w,h,&err);
1.27 if (pixbuf)
1.28 {
1.29 source=gtk_icon_source_new();
1.30 @@ -69,6 +76,11 @@
1.31 gtk_icon_source_free(source);
1.32 g_object_unref(pixbuf);
1.33 }
1.34 + else
1.35 + {
1.36 + g_warning("%s: %s",filename,err->message);
1.37 + g_error_free(err);
1.38 + }
1.39 }
1.40 }
1.41
1.42 @@ -87,23 +99,30 @@
1.43 */
1.44 void plover_icons_add_to_stock(const char *type,const char *name)
1.45 {
1.46 - gchar *prefix,*s,*filename;
1.47 + gchar *datadir,*prefix,*s,*filename;
1.48 GtkIconSource *source;
1.49 GtkIconSet *icon_set;
1.50 GtkIconFactory *factory;
1.51 factory=gtk_icon_factory_new();
1.52 icon_set=gtk_icon_set_new();
1.53 + datadir=g_strdup(g_getenv("PLOVER_ICONS_DATADIR"));
1.54 + if (!datadir)
1.55 + {
1.56 #ifdef WIN32
1.57 - prefix=g_win32_get_package_installation_directory_of_module(NULL);
1.58 + prefix=g_win32_get_package_installation_directory_of_module(NULL);
1.59 #else
1.60 - prefix=NULL;
1.61 + prefix=NULL;
1.62 #endif
1.63 + if (!prefix)
1.64 + prefix=g_strdup("/usr");
1.65 + datadir=g_strconcat(prefix,"share",NULL);
1.66 + g_free(prefix);
1.67 + }
1.68 if (plover_pixbuf_supports_svg())
1.69 {
1.70 source=gtk_icon_source_new();
1.71 s=g_strconcat(name,".svg",NULL);
1.72 - filename=g_build_filename(prefix?prefix:"/usr",
1.73 - "share/icons/hicolor/scalable",type,s,NULL);
1.74 + filename=g_build_filename(datadir,"icons/hicolor/scalable",type,s,NULL);
1.75 g_free(s);
1.76 gtk_icon_source_set_filename(source,filename);
1.77 g_free(filename);
1.78 @@ -113,8 +132,7 @@
1.79 else
1.80 {
1.81 s=g_strconcat(name,".png",NULL);
1.82 - filename=g_build_filename(prefix?prefix:"/usr",
1.83 - "share/icons/hicolor/24x24",type,s,NULL);
1.84 + filename=g_build_filename(datadir,"icons/hicolor/24x24",type,s,NULL);
1.85 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_MENU,
1.86 filename);
1.87 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_BUTTON,
1.88 @@ -124,8 +142,7 @@
1.89 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_LARGE_TOOLBAR,
1.90 filename);
1.91 g_free(filename);
1.92 - filename=g_build_filename(prefix?prefix:"/usr",
1.93 - "share/icons/hicolor/48x48",type,s,NULL);
1.94 + filename=g_build_filename(datadir,"icons/hicolor/48x48",type,s,NULL);
1.95 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DND,
1.96 filename);
1.97 plover_install_icon_at_size(name,icon_set,GTK_ICON_SIZE_DIALOG,
1.98 @@ -133,6 +150,7 @@
1.99 g_free(filename);
1.100 g_free(s);
1.101 }
1.102 + g_free(datadir);
1.103 gtk_icon_factory_add(factory,name,icon_set);
1.104 gtk_icon_set_unref(icon_set);
1.105 //icon_set=gtk_icon_factory_lookup(factory,name);