gtk-demo: Load icon from resource
This commit is contained in:
@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gresources>
|
<gresources>
|
||||||
|
<gresource prefix="/">
|
||||||
|
<file>cssview.css</file>
|
||||||
|
<file>gtk-logo-rgb.gif</file>
|
||||||
|
<file>reset.css</file>
|
||||||
|
</gresource>
|
||||||
<gresource prefix="/application">
|
<gresource prefix="/application">
|
||||||
<file preprocess="to-pixdata">gtk-logo-24.png</file>
|
<file preprocess="to-pixdata">gtk-logo-24.png</file>
|
||||||
<file preprocess="to-pixdata">gtk-logo-48.png</file>
|
<file preprocess="to-pixdata">gtk-logo-48.png</file>
|
||||||
@ -9,10 +14,6 @@
|
|||||||
<gresource prefix="/appwindow">
|
<gresource prefix="/appwindow">
|
||||||
<file preprocess="to-pixdata">gtk-logo-rgb.gif</file>
|
<file preprocess="to-pixdata">gtk-logo-rgb.gif</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
<gresource prefix="/">
|
|
||||||
<file>cssview.css</file>
|
|
||||||
<file>reset.css</file>
|
|
||||||
</gresource>
|
|
||||||
<gresource prefix="/builder">
|
<gresource prefix="/builder">
|
||||||
<file>demo.ui</file>
|
<file>demo.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
|
@ -877,54 +877,19 @@ create_tree (void)
|
|||||||
static void
|
static void
|
||||||
setup_default_icon (void)
|
setup_default_icon (void)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf, *transparent;
|
||||||
char *filename;
|
|
||||||
GError *err;
|
|
||||||
|
|
||||||
err = NULL;
|
pixbuf = gdk_pixbuf_new_from_resource ("/gtk-logo-rgb.gif", NULL);
|
||||||
|
/* We load a resource, so we can guarantee that loading it is successful */
|
||||||
|
g_assert (pixbuf);
|
||||||
|
|
||||||
pixbuf = NULL;
|
/* The gtk-logo-rgb icon has a white background, make it transparent */
|
||||||
filename = demo_find_file ("gtk-logo-rgb.gif", &err);
|
transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
|
||||||
if (filename)
|
|
||||||
{
|
|
||||||
pixbuf = gdk_pixbuf_new_from_file (filename, &err);
|
|
||||||
g_free (filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ignoring this error (passing NULL instead of &err above)
|
gtk_window_set_default_icon (transparent);
|
||||||
* would probably be reasonable for most apps. We're just
|
|
||||||
* showing off.
|
g_object_unref (pixbuf);
|
||||||
*/
|
g_object_unref (transparent);
|
||||||
if (err)
|
|
||||||
{
|
|
||||||
GtkWidget *dialog;
|
|
||||||
|
|
||||||
dialog = gtk_message_dialog_new (NULL, 0,
|
|
||||||
GTK_MESSAGE_ERROR,
|
|
||||||
GTK_BUTTONS_CLOSE,
|
|
||||||
"Failed to read icon file: %s",
|
|
||||||
err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
|
|
||||||
g_signal_connect (dialog, "response",
|
|
||||||
G_CALLBACK (gtk_widget_destroy), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pixbuf)
|
|
||||||
{
|
|
||||||
GList *list;
|
|
||||||
GdkPixbuf *transparent;
|
|
||||||
|
|
||||||
/* The gtk-logo-rgb icon has a white background, make it transparent */
|
|
||||||
transparent = gdk_pixbuf_add_alpha (pixbuf, TRUE, 0xff, 0xff, 0xff);
|
|
||||||
|
|
||||||
list = NULL;
|
|
||||||
list = g_list_append (list, transparent);
|
|
||||||
gtk_window_set_default_icon_list (list);
|
|
||||||
g_list_free (list);
|
|
||||||
g_object_unref (pixbuf);
|
|
||||||
g_object_unref (transparent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Reference in New Issue
Block a user