[PATCH 2/2] Add a sidebar to the standalone and hub windows (#1045250)

Máirín Duffy duffy at redhat.com
Tue Feb 4 20:21:29 UTC 2014


This adds a sidebar to the left of the standalone and hub windows. The
reason for this is to visually reinforce the left-to-right linear nature
of the standalone windows. There is a variable (sidebar_width_percentage)
you can set to control the percentage width of the screen that the
sidebar occupies - I've set it to 18% which seems reasonable. It auto-
centers the logo on top of the sidebar as well. The sidebar is controlled
by the 'sidebar' class in the css and the 'logo' class in the css. In
this patch, the sidebar is set to have a grey background with a
partially-transparent image texture layered on top, and a logo layered
on top of that, centered horizontally 20px down from the top of the
sidebar. To restyle the sidebar, you only have to change the
relevant section in the anaconda-gtk.css file.
---
 data/anaconda-gtk.css          | 34 +++++++++++++++++++++++
 widgets/src/HubWindow.c        | 62 +++++++++++++++++++++++++++++++++++++++++-
 widgets/src/StandaloneWindow.c | 56 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+), 1 deletion(-)

diff --git a/data/anaconda-gtk.css b/data/anaconda-gtk.css
index 92669ba..71d443e 100644
--- a/data/anaconda-gtk.css
+++ b/data/anaconda-gtk.css
@@ -60,3 +60,37 @@
     background-image: none;
     border-color: alpha(#000000, 0.1);
 }
+
+
+/* vendor-specific colors/images */
+
+ at define-color sidebar_redhat #41413e;
+ at define-color sidebar_fedora #006eb4;
+
+/* logo and sidebar classes for RHEL */
+.logo {
+    background-image: url('/usr/share/anaconda/pixmaps/redhat-logo.png');
+    background-position: 50% 20px;
+    background-repeat: no-repeat;
+    background-color: transparent;
+}
+
+.sidebar {
+    background-image: url('/usr/share/anaconda/pixmaps/redhat-bg.png');
+    background-color: @sidebar_redhat;
+}
+
+/* swap these into logo & sidebar classes for Fedora */
+/*
+.logo-fedora {
+    background-image: url('/usr/share/anaconda/pixmaps/fedora-logo.png');
+    background-position: 50% 20px;
+    background-repeat: no-repeat;
+    background-color: transparent;
+}
+
+.sidebar-fedora {
+    background-image: url('/usr/share/anaconda/pixmaps/noise-texture.png');
+    background-color: @sidebar_fedora;
+}
+*/
diff --git a/widgets/src/HubWindow.c b/widgets/src/HubWindow.c
index 7f118dd..dfaee1f 100644
--- a/widgets/src/HubWindow.c
+++ b/widgets/src/HubWindow.c
@@ -82,9 +82,65 @@ static void anaconda_hub_window_buildable_init(GtkBuildableIface *iface);
 G_DEFINE_TYPE_WITH_CODE(AnacondaHubWindow, anaconda_hub_window, ANACONDA_TYPE_BASE_WINDOW,
                         G_IMPLEMENT_INTERFACE(GTK_TYPE_BUILDABLE, anaconda_hub_window_buildable_init))
 
+static int get_sidebar_width(GtkWidget *window) {
+    GtkAllocation allocation;
+    /* change value below to make sidebar bigger / smaller */
+    float sidebar_width_percentage = .18;
+    gtk_widget_get_allocation(window, &allocation);
+    return allocation.width * sidebar_width_percentage;
+}
+
+static int get_sidebar_height(GtkWidget *window) {
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(window, &allocation);
+    return allocation.height;
+}
+
+/* function to override default drawing to insert sidebar image */
+gboolean anaconda_hub_window_on_draw(GtkWidget *win, cairo_t *cr) {
+
+    /* calls parent class' draw handler */
+    GTK_WIDGET_CLASS(anaconda_hub_window_parent_class)->draw(win,cr);
+
+    GtkStyleContext * context = gtk_widget_get_style_context(win);
+    gtk_style_context_save (context);
+
+    gtk_style_context_add_class(context, "sidebar");
+    gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
+    gtk_style_context_remove_class(context, "sidebar");
+
+    gtk_style_context_add_class(context, "logo");
+    gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
+    gtk_style_context_remove_class(context, "logo");
+
+    gtk_style_context_restore (context);
+
+
+    return TRUE; /* TRUE to avoid default draw handler */
+}
+
+/* Move base window content appropriate amount of space to the right to make room for sidebar */
+static void anaconda_hub_window_size_allocate (GtkWidget *window, GtkAllocation *allocation) {
+    GtkAllocation child_allocation;
+    GtkWidget *child;
+
+    gtk_widget_set_allocation(window, allocation);
+    int sidebar_width = get_sidebar_width(window);
+    child_allocation.x = allocation->x+sidebar_width;
+    child_allocation.y = allocation->y;
+    child_allocation.width = allocation->width-sidebar_width;
+    child_allocation.height = allocation->height;
+
+    child = gtk_bin_get_child (GTK_BIN (window));
+    if (child && gtk_widget_get_visible (child))
+    gtk_widget_size_allocate (child, &child_allocation);
+}
+
 static void anaconda_hub_window_class_init(AnacondaHubWindowClass *klass) {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+    widget_class->draw=anaconda_hub_window_on_draw;
+    widget_class->size_allocate=anaconda_hub_window_size_allocate;
     g_type_class_add_private(object_class, sizeof(AnacondaHubWindowPrivate));
 }
 
@@ -100,6 +156,8 @@ GtkWidget *anaconda_hub_window_new() {
     return g_object_new(ANACONDA_TYPE_HUB_WINDOW, NULL);
 }
 
+
+
 static void anaconda_hub_window_init(AnacondaHubWindow *win) {
     GtkWidget *action_area = anaconda_base_window_get_action_area(ANACONDA_BASE_WINDOW(win));
 
@@ -115,6 +173,8 @@ static void anaconda_hub_window_init(AnacondaHubWindow *win) {
     /* The hub has different alignment requirements than a spoke. */
     gtk_alignment_set(GTK_ALIGNMENT(anaconda_base_window_get_alignment(ANACONDA_BASE_WINDOW(win))),
                       0.5, 0.0, 0.5, 1.0);
+
+
 }
 
 /**
diff --git a/widgets/src/StandaloneWindow.c b/widgets/src/StandaloneWindow.c
index 2b04c49..219bb96 100644
--- a/widgets/src/StandaloneWindow.c
+++ b/widgets/src/StandaloneWindow.c
@@ -70,8 +70,64 @@ static void anaconda_standalone_window_realize(GtkWidget *widget,
 
 G_DEFINE_TYPE(AnacondaStandaloneWindow, anaconda_standalone_window, ANACONDA_TYPE_BASE_WINDOW)
 
+static int get_sidebar_width(GtkWidget *window) {
+   GtkAllocation allocation;
+    /* change value below to make sidebar bigger / smaller */
+    float sidebar_width_percentage = .18;
+    gtk_widget_get_allocation(window, &allocation);
+    return allocation.width * sidebar_width_percentage;
+}
+
+static int get_sidebar_height(GtkWidget *window) {
+    GtkAllocation allocation;
+    gtk_widget_get_allocation(window, &allocation);
+    return allocation.height;
+}
+
+/* function to override default drawing to insert sidebar image */
+gboolean anaconda_standalone_window_on_draw(GtkWidget *win, cairo_t *cr) {
+
+    /* calls parent class' draw handler */
+    GTK_WIDGET_CLASS(anaconda_standalone_window_parent_class)->draw(win,cr);
+
+    GtkStyleContext * context = gtk_widget_get_style_context(win);
+    gtk_style_context_save (context);
+
+    gtk_style_context_add_class(context, "sidebar");
+    gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
+    gtk_style_context_remove_class(context, "sidebar");
+
+    gtk_style_context_add_class(context, "logo");
+    gtk_render_background(context, cr, 0, 0, get_sidebar_width(win), get_sidebar_height(win));
+    gtk_style_context_remove_class(context, "logo");
+
+    gtk_style_context_restore (context);
+
+    return TRUE; /* TRUE to avoid default draw handler */
+}
+
+/* Move base window content appropriate amount of space to the right to make room for sidebar */
+static void anaconda_standalone_window_size_allocate (GtkWidget *window, GtkAllocation *allocation) {
+    GtkAllocation child_allocation;
+    GtkWidget *child;
+
+    gtk_widget_set_allocation(window, allocation);
+    int sidebar_width = get_sidebar_width(window);
+    child_allocation.x = allocation->x+sidebar_width;
+    child_allocation.y = allocation->y;
+    child_allocation.width = allocation->width-sidebar_width;
+    child_allocation.height = allocation->height;
+
+    child = gtk_bin_get_child (GTK_BIN (window));
+    if (child && gtk_widget_get_visible (child))
+    gtk_widget_size_allocate (child, &child_allocation);
+}
+
 static void anaconda_standalone_window_class_init(AnacondaStandaloneWindowClass *klass) {
     GObjectClass *object_class = G_OBJECT_CLASS(klass);
+    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+    widget_class->draw=anaconda_standalone_window_on_draw;
+    widget_class->size_allocate=anaconda_standalone_window_size_allocate;
 
     klass->quit_clicked = NULL;
     klass->continue_clicked = NULL;
-- 
1.8.4.2



More information about the anaconda-patches mailing list