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

Chris Lumens clumens at redhat.com
Tue Feb 4 20:57:39 UTC 2014


> 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;
> +}
> +*/

The -logo files will be coming out of a product.img, I assume?  What are
the odds we can just ensure the file is always the same name and not
have to worry about different classes for different products?

> 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;

Stylistically, I'm picky.  I like whitespace.  I'd like to see a newline
here.

> +    /* change value below to make sidebar bigger / smaller */
> +    float sidebar_width_percentage = .18;

And this as 0.18.  It just looks weird without.

> +    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) {

This function is only used in this file, yeah?  So it could be static.

> +
> +    /* 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);

I know gcc doesn't require it, but I like variables defined before they
start getting used.  Old school, I guess.

> +    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);

Please indent the part under the if.

> +}
> +
>  static void anaconda_hub_window_class_init(AnacondaHubWindowClass *klass) {
>      GObjectClass *object_class = G_OBJECT_CLASS(klass);
> -
> +    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

Please add a newline here.

> +    widget_class->draw=anaconda_hub_window_on_draw;
> +    widget_class->size_allocate=anaconda_hub_window_size_allocate;

And put spaces around the = operators here.

> 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

And then all the same comments apply to this file too.

I assume you've also checked tty1 to make sure there's no relevant
gtk/glib/whatever assertions.  Sometimes those are hiding there.

- Chris


More information about the anaconda-patches mailing list