[PATCH] Display the background gradient image from a map signal handler.

Chris Lumens clumens at redhat.com
Tue Jan 15 20:41:53 UTC 2013


Doing it from the init method means we need to call gtk_widget_realize so all
the gdk and cairo stuff has something to operate on.  However, that realize
call screws up glade so that the window gets displayed separately and widgets
cannot be clicked upon.

This reorganization moves the gradient setup to after the widget has been
realized.
---
 widgets/src/SpokeWindow.c | 53 +++++++++++++++++++++++++++--------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/widgets/src/SpokeWindow.c b/widgets/src/SpokeWindow.c
index 16ce3f8..2874e58 100644
--- a/widgets/src/SpokeWindow.c
+++ b/widgets/src/SpokeWindow.c
@@ -61,6 +61,7 @@ G_DEFINE_TYPE(AnacondaSpokeWindow, anaconda_spoke_window, ANACONDA_TYPE_BASE_WIN
 static void anaconda_spoke_window_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 static void anaconda_spoke_window_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 
+static void anaconda_spoke_window_realize(GtkWidget *widget, gpointer user_data);
 static void anaconda_spoke_window_button_clicked(GtkButton *button,
                                                  AnacondaSpokeWindow *win);
 
@@ -124,16 +125,40 @@ GtkWidget *anaconda_spoke_window_new() {
 }
 
 static void anaconda_spoke_window_init(AnacondaSpokeWindow *win) {
+    GtkWidget *nav_area;
+
+    win->priv = G_TYPE_INSTANCE_GET_PRIVATE(win,
+                                            ANACONDA_TYPE_SPOKE_WINDOW,
+                                            AnacondaSpokeWindowPrivate);
+
+    g_signal_connect(win, "map", G_CALLBACK(anaconda_spoke_window_realize), NULL);
+
+    /* Set some default properties. */
+    gtk_window_set_modal(GTK_WINDOW(win), TRUE);
+
+    /* Create the buttons. */
+    win->priv->button = gtk_button_new_with_mnemonic(DEFAULT_BUTTON_LABEL);
+    gtk_widget_set_halign(win->priv->button, GTK_ALIGN_START);
+
+    /* Hook up some signals for that button.  The signal handlers here will
+     * just raise our own custom signals for the whole window.
+     */
+    g_signal_connect(win->priv->button, "clicked",
+                     G_CALLBACK(anaconda_spoke_window_button_clicked), win);
+
+    /* And then put the button into the navigation area. */
+    nav_area = anaconda_base_window_get_nav_area(ANACONDA_BASE_WINDOW(win));
+    gtk_grid_attach(GTK_GRID(nav_area), win->priv->button, 0, 1, 1, 1);
+}
+
+static void anaconda_spoke_window_realize(GtkWidget *widget, gpointer user_data) {
     GError *error;
-    GtkWidget *nav_area, *nav_box;
     GdkPixbuf *pixbuf;
     cairo_pattern_t *pattern;
     cairo_surface_t *surface;
     cairo_t *cr;
 
-    win->priv = G_TYPE_INSTANCE_GET_PRIVATE(win,
-                                            ANACONDA_TYPE_SPOKE_WINDOW,
-                                            AnacondaSpokeWindowPrivate);
+    AnacondaSpokeWindow *window = ANACONDA_SPOKE_WINDOW(widget);
 
     /* Set the background gradient in the header.  If we fail to load the
      * background for any reason, just print an error message and display the
@@ -145,9 +170,8 @@ static void anaconda_spoke_window_init(AnacondaSpokeWindow *win) {
         fprintf(stderr, "could not load header background: %s\n", error->message);
         g_error_free(error);
     } else {
-        nav_box = anaconda_base_window_get_nav_area_background_window(ANACONDA_BASE_WINDOW(win));
+        GtkWidget *nav_box = anaconda_base_window_get_nav_area_background_window(ANACONDA_BASE_WINDOW(window));
         gtk_widget_set_size_request(nav_box, -1, gdk_pixbuf_get_height (pixbuf));
-        gtk_widget_realize(nav_box);
 
         surface = gdk_window_create_similar_surface(gtk_widget_get_window(nav_box), CAIRO_CONTENT_COLOR_ALPHA,
                                                     gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf));
@@ -162,23 +186,6 @@ static void anaconda_spoke_window_init(AnacondaSpokeWindow *win) {
         cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
         gdk_window_set_background_pattern(gtk_widget_get_window(nav_box), pattern);
     }
-
-    /* Set some default properties. */
-    gtk_window_set_modal(GTK_WINDOW(win), TRUE);
-
-    /* Create the buttons. */
-    win->priv->button = gtk_button_new_with_mnemonic(DEFAULT_BUTTON_LABEL);
-    gtk_widget_set_halign(win->priv->button, GTK_ALIGN_START);
-
-    /* Hook up some signals for that button.  The signal handlers here will
-     * just raise our own custom signals for the whole window.
-     */
-    g_signal_connect(win->priv->button, "clicked",
-                     G_CALLBACK(anaconda_spoke_window_button_clicked), win);
-
-    /* And then put the button into the navigation area. */
-    nav_area = anaconda_base_window_get_nav_area(ANACONDA_BASE_WINDOW(win));
-    gtk_grid_attach(GTK_GRID(nav_area), win->priv->button, 0, 1, 1, 1);
 }
 
 static void anaconda_spoke_window_button_clicked(GtkButton *button,
-- 
1.7.11.2



More information about the anaconda-patches mailing list