+
+
+
+\f
+
+struct splash_source
+{
+ GSource parent;
+ cairo_surface_t *sfc;
+};
+
+void
+fill_splash_window (GdkWindow *win, cairo_surface_t *sfce)
+{
+ cairo_t *cr = gdk_cairo_create (win);
+
+ cairo_set_source_surface (cr, sfce, 0, 0);
+
+ cairo_paint (cr);
+ cairo_destroy (cr);
+}
+
+gboolean
+splash_prepare (GSource *source,
+ gint *timeout_)
+{
+ GdkEvent *e = gdk_event_peek ();
+ if (!e)
+ return FALSE;
+
+ gdk_event_free (e);
+ return TRUE;
+}
+
+gboolean
+splash_check (GSource *source)
+{
+ GdkEvent *e = gdk_event_peek ();
+ if (!e)
+ return FALSE;
+
+ gdk_event_free (e);
+ return TRUE;
+}
+
+
+gboolean
+splash_dispatch (GSource *ss,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ struct splash_source *source = (struct splash_source *) ss;
+ GdkEvent *e = gdk_event_get ();
+ if (!e)
+ return TRUE;
+
+ GdkWindow *w = ((GdkEventAny *)e)->window;
+
+ if (!w)
+ {
+ gdk_event_free (e);
+ return TRUE;
+ }
+
+ fill_splash_window (w, source->sfc);
+ gdk_display_flush (gdk_window_get_display (w));
+
+ gdk_event_free (e);
+
+ return TRUE;
+}
+
+
+gboolean
+destroy_splash_window (gpointer ud)
+{
+ GdkWindow *win = GDK_WINDOW (ud);
+ gdk_window_withdraw (win);
+ gdk_display_flush (gdk_window_get_display (win));
+ gdk_window_destroy (win);
+
+ return FALSE;
+}
+
+GSourceFuncs splash_funcs = {splash_prepare, splash_check, splash_dispatch, NULL};
+
+
+GdkWindow *
+create_splash_window (GMainContext *context)
+{
+ const gchar *filename = PKGDATADIR "/splash.png";
+
+ const char *relocated_filename = relocate (filename);
+ cairo_surface_t *the_surface =
+ cairo_image_surface_create_from_png (relocated_filename);
+
+ if (filename != relocated_filename)
+ free (CONST_CAST (char *, relocated_filename));
+
+
+ g_return_val_if_fail (the_surface, NULL);
+
+ int attr_mask = GDK_WA_TYPE_HINT;
+ GdkWindowAttr attr;
+
+ attr.width = cairo_image_surface_get_width (the_surface);
+ attr.height = cairo_image_surface_get_height (the_surface);
+ attr.wclass = GDK_INPUT_OUTPUT;
+ attr.window_type = GDK_WINDOW_TOPLEVEL;
+
+ attr.type_hint = GDK_WINDOW_TYPE_HINT_SPLASHSCREEN;
+
+ GdkWindow *win = gdk_window_new (NULL, &attr, attr_mask);
+
+ gdk_window_set_events (win, GDK_EXPOSURE_MASK);
+ gdk_window_set_keep_above (win, TRUE);
+ gdk_window_show (win);
+
+
+ GSource *ss = g_source_new (&splash_funcs,
+ sizeof (struct splash_source));
+
+ ((struct splash_source *) ss)->sfc = the_surface;
+ g_source_set_priority (ss, G_PRIORITY_HIGH);
+
+ g_source_attach (ss, context);
+
+ g_source_unref (ss);
+
+ return win;
+}
+
+