[gnome-control-center/wip/jsparber/background: 3/15] background: resize preview based on window size



commit 3027e41ec378839c51f155786040aaf3d9dc0485
Author: Julian Sparber <julian sparber net>
Date:   Tue Nov 7 16:00:00 2017 +0100

    background: resize preview based on window size
    
    Preview:
    - resize preview when window is higher then 700px
    - set margins for preview to 16px
    
    Gallery:
    - move gallery item code to grid-item class
    - add slide icon to time changing wallpapers
    - expand thumbnails to fill a gallery row
    - change gallery thumbnails size
    - use same margin everywhere around the flowbox
    - add white space around gallery and min/max item per line
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/background.ui                  | 330 ++++++------
 panels/background/cc-background-chooser-dialog.c | 616 -----------------------
 panels/background/cc-background-chooser-dialog.h |  38 --
 panels/background/cc-background-grid-item.c      | 143 +++++-
 panels/background/cc-background-grid-item.h      |   3 +-
 panels/background/cc-background-panel.c          |  81 ++-
 panels/background/data/background.css            |   2 +-
 panels/background/test-chooser-dialog.c          |  37 --
 8 files changed, 353 insertions(+), 897 deletions(-)
---
diff --git a/panels/background/background.ui b/panels/background/background.ui
index 147b567f4..d188dd449 100644
--- a/panels/background/background.ui
+++ b/panels/background/background.ui
@@ -5,219 +5,259 @@
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="hexpand">True</property>
-    <property name="orientation">vertical</property>
     <child>
-      <object class="GtkBox" id="background-preview">
+      <object class="GtkBox" id="content">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="margin">16</property>
-        <property name="halign">center</property>
         <property name="orientation">vertical</property>
-        <property name="expand">False</property>
         <child>
-          <object class="GtkBox" id="background-preview-top">
+          <object class="GtkBox" id="background-preview">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="margin">6</property>
-            <property name="spacing">6</property>
+            <property name="margin">16</property>
+            <property name="halign">fill</property>
             <property name="orientation">vertical</property>
-            <style>
-              <class name="black-border"/>
-            </style>
-            <child>
-              <object class="GtkDrawingArea" id="background-desktop-drawingarea">
-                <property name="width_request">310</property>
-                <property name="height_request">170</property>
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="valign">center</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkBox" id="bottom-hbox">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="spacing">12</property>
+            <property name="expand">False</property>
+            <property name="height_request">150</property>
             <child>
-              <object class="GtkBox" id="hbox2">
+              <object class="GtkAspectFrame">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="halign">center</property>
-                <property name="margin_top">12</property>
-                <property name="spacing">2</property>
-                <child>
-                  <object class="GtkImage" id="slide_image">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="icon_name">slideshow-symbolic</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
+                <property name="shadow_type">GTK_SHADOW_NONE</property>
+                <property name="expand">True</property>
+                <property name="obey-child">False</property>
+                <property name="ratio">1.7777</property>
                 <child>
-                  <object class="GtkLabel" id="strut">
+                  <object class="GtkBox" id="background-preview-top">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="label"> </property>
+                    <property name="orientation">vertical</property>
+                    <style>
+                      <class name="black-border"/>
+                    </style>
+                    <child>
+                      <object class="GtkDrawingArea" id="background-desktop-drawingarea">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="expand">True</property>
+                      </object>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkRevealer" id="wallpaper-info">
+                <property name="visible">True</property>
+                <property name="reveal-child">True</property>
                 <child>
-                  <object class="GtkLabel" id="slide-label">
+                  <object class="GtkBox" id="slide-box">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="xalign">0</property>
-                    <property name="label" translatable="yes" comments="This refers to a slideshow 
background">Changes throughout the day</property>
+                    <property name="margin_top">10</property>
+                    <child>
+                      <object class="GtkBox" id="hbox2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">center</property>
+                        <child>
+                          <object class="GtkImage" id="slide_image">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="icon_name">slideshow-symbolic</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="strut">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label"> </property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="slide-label">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes" comments="This refers to a slideshow 
background">Changes throughout the day</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">True</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
             <property name="fill">True</property>
-            <property name="position">2</property>
+            <property name="position">0</property>
           </packing>
         </child>
-      </object>
-      <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
-        <property name="position">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkBox" id="backgroud-gallery-box">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <style>
-          <class name="background-gallery"/>
-        </style>
         <child>
-          <object class="GtkScrolledWindow">
+          <object class="GtkBox" id="background-gallery-box">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="hscrollbar_policy">never</property>
+            <property name="expand">True</property>
+            <!--<property name="height_request">150</property>-->
+            <style>
+              <class name="background-gallery"/>
+            </style>
             <child>
-              <object class="GtkBox" id="box4">
+              <object class="GtkScrolledWindow">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="GtkFlowBox" id="background-gallery">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="homogeneous">True</property>
-                    <property name="orientation">horizontal</property>
-                    <property name="min-children-per-line">2</property>
-                    <property name="row_spacing">5</property>
-                    <property name="column_spacing">5</property>
-                    <property name="halign">center</property>
-                    <property name="valign">center</property>
-                    <property name="margin">25</property>
-                    <property name="margin_top">50</property>
-                    <property name="margin_bottom">32</property>
-                  </object>
-                </child>
+                <property name="hscrollbar_policy">never</property>
                 <child>
                   <object class="GtkBox">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="valign">end</property>
-                    <property name="margin">32</property>
-                    <property name="margin_top">0</property>
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">16</property>
+                    <property name="expand">True</property>
                     <child>
-                      <object class="GtkLabel">
+                      <object class="GtkBox" id="left_space">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="label" translatable="yes">Photos or Files can be used to set any 
image as the background</property>
+                        <property name="expand">True</property>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">0</property>
-                      </packing>
                     </child>
                     <child>
-                      <object class="GtkBox">
+                      <object class="GtkBox" id="box4">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="halign">center</property>
-                        <property name="spacing">16</property>
+                        <property name="orientation">vertical</property>
                         <child>
-                          <object class="GtkButton" id="open-gnome-photos">
-                            <property name="label" translatable="yes">Open Photos app</property>
+                          <object class="GtkFlowBox" id="background-gallery">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="hexpand">True</property>
+                            <property name="vexpand">False</property>
+                            <property name="homogeneous">True</property>
+                            <property name="orientation">horizontal</property>
+                            <property name="min-children-per-line">2</property>
+                            <property name="max-children-per-line">5</property>
+                            <property name="row_spacing">5</property>
+                            <property name="column_spacing">5</property>
+                            <property name="halign">fill</property>
+                            <property name="valign">fill</property>
+                            <property name="margin">25</property>
                           </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
                         </child>
                         <child>
-                          <object class="GtkButton" id="open-picture-folder">
-                            <property name="label" translatable="yes">Open Pictures folder</property>
+                          <object class="GtkBox">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="halign">center</property>
+                            <property name="valign">end</property>
+                            <property name="margin">32</property>
+                            <property name="margin_top">7</property>
+                            <property name="orientation">vertical</property>
+                            <property name="spacing">16</property>
+                            <child>
+                              <object class="GtkLabel">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">Photos or Files can be used to set 
any image as the background</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkBox">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="halign">center</property>
+                                <property name="spacing">16</property>
+                                <child>
+                                  <object class="GtkButton" id="open-gnome-photos">
+                                    <property name="label" translatable="yes">Open Photos app</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkButton" id="open-picture-folder">
+                                    <property name="label" translatable="yes">Open Pictures folder</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">True</property>
-                            <property name="position">1</property>
-                          </packing>
                         </child>
                       </object>
-                      <packing>
-                        <property name="expand">False</property>
-                        <property name="fill">True</property>
-                        <property name="position">1</property>
-                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkBox" id="right_space">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="expand">True</property>
+                      </object>
+
                     </child>
                   </object>
                 </child>
               </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
             </child>
           </object>
           <packing>
             <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="position">0</property>
+            <property name="position">1</property>
           </packing>
         </child>
       </object>
-      <packing>
-        <property name="expand">True</property>
-        <property name="fill">True</property>
-        <property name="position">1</property>
-      </packing>
     </child>
   </object>
   <object class="GtkListStore" id="sources-liststore">
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
index c2341cc76..5d8350253 100644
--- a/panels/background/cc-background-grid-item.c
+++ b/panels/background/cc-background-grid-item.c
@@ -24,11 +24,9 @@ struct _CcBackgroundGridItem
 {
   GtkFlowBoxChild            parent;
 
-  GtkImage                  *image;
-
   /* data */
   CcBackgroundItem      *item;
-
+  GdkPixbuf *cached_pixbuf;
 };
 
 
@@ -36,15 +34,116 @@ G_DEFINE_TYPE (CcBackgroundGridItem, cc_background_grid_item, GTK_TYPE_FLOW_BOX_
 
     enum {
       PROP_0,
-      PROP_ITEM
+      PROP_ITEM,
+      PROP_PIXBUF_CACHE
     };
 
+static void
+add_slideshow_emblem (GdkPixbuf *pixbuf,
+                      gint w,
+                      gint h,
+                      gint scale_factor)
+{
+  GdkPixbuf *slideshow_emblem;
+  GIcon *icon = NULL;
+  GtkIconInfo *icon_info = NULL;
+  GError *error = NULL;
+  GtkIconTheme *theme;
+
+  int eh;
+  int ew;
+  //int h;
+  //int w;
+  int x;
+  int y;
+
+  icon = g_themed_icon_new ("slideshow-emblem");
+  theme = gtk_icon_theme_get_default ();
+  icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
+                                                        icon,
+                                                        16,
+                                                        scale_factor,
+                                                        GTK_ICON_LOOKUP_FORCE_SIZE |
+                                                        GTK_ICON_LOOKUP_USE_BUILTIN);
+  if (icon_info == NULL) {
+    g_warning ("Your icon theme is missing the slideshow-emblem icon, "
+               "please file a bug against it");
+  }
+  else {
+
+    slideshow_emblem = gtk_icon_info_load_icon (icon_info, &error);
+    if (slideshow_emblem == NULL) {
+      g_warning ("Failed to load slideshow emblem: %s", error->message);
+      g_error_free (error);
+    }
+    else {
+      eh = gdk_pixbuf_get_height (slideshow_emblem);
+      ew = gdk_pixbuf_get_width (slideshow_emblem);
+      //h = gdk_pixbuf_get_height (pixbuf);
+      //w = gdk_pixbuf_get_width (pixbuf);
+      x = w - ew - 5;
+      y = h - eh - 5;
+
+      gdk_pixbuf_composite (slideshow_emblem, pixbuf, x, y, ew, eh, x, y, 1.0, 1.0, GDK_INTERP_BILINEAR, 
255);
+    }
+  }
+
+  g_clear_object (&icon_info);
+  g_clear_object (&icon);
+}
+
+static gboolean
+on_gallery_item_draw (GtkWidget         *widget,
+                      cairo_t           *cr,
+                      CcBackgroundGridItem *item)
+{
+  GdkPixbuf *pixbuf = item->cached_pixbuf;
+  GdkPixbuf *new_pixbuf;
+  const gint space_width = gtk_widget_get_allocated_width (widget);
+  const gint space_height = gtk_widget_get_allocated_height ( (widget));
+  //const gint pixbuf_width = gdk_pixbuf_get_width (pixbuf);
+  //const gint pixbuf_height = gdk_pixbuf_get_height (pixbuf);
+  const gint scale_factor = gtk_widget_get_scale_factor (widget);
+  gint new_width;
+  gint new_height;
+
+  if (space_width * 9/16 > space_height) {
+    new_width = space_width;
+    new_height = space_width * 9/16;
+  }
+  else {
+    new_width = space_height * 16/9;
+    new_height = space_height;
+  }
+
+  new_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+                                        new_width,
+                                        new_height,
+                                        GDK_INTERP_BILINEAR);
+
+  if (cc_background_item_changes_with_time (cc_background_grid_item_get_ref 
(gtk_widget_get_parent(widget)))) {
+    add_slideshow_emblem (new_pixbuf, (space_width + new_width) / 2, (space_height + new_height)/2, 
scale_factor);
+  }
+
+
+  gdk_cairo_set_source_pixbuf (cr,
+                               new_pixbuf,
+                               (space_width - new_width) / 2,
+                               (space_height - new_height) / 2);
+
+  g_object_unref (new_pixbuf);
+  cairo_paint (cr);
+
+  return TRUE;
+}
+
 GtkWidget*
-cc_background_grid_item_new (CcBackgroundItem *item)
+cc_background_grid_item_new (CcBackgroundItem *item, GdkPixbuf *pixbuf)
 {
 
   return g_object_new (CC_TYPE_BACKGROUND_GRID_ITEM,
                        "item", item,
+                       "cached_pixbuf", pixbuf,
                        NULL);
 }
 
@@ -88,8 +187,10 @@ cc_background_grid_item_set_property (GObject *object,
     {
 
     case PROP_ITEM:
-      self->item = g_value_dup_object (value);
-      g_debug ("Every set %p -> %p", value, self->item);
+      g_set_object (&self->item, g_value_get_object (value));
+      break;
+    case PROP_PIXBUF_CACHE:
+      g_set_object (&self->cached_pixbuf, g_value_get_object (value));
       break;
 
     default:
@@ -111,6 +212,10 @@ cc_background_grid_item_get_property (GObject    *object,
       g_value_set_object (value, self->item);
       break;
 
+    case PROP_PIXBUF_CACHE:
+      g_value_set_object (value, self->cached_pixbuf);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -128,10 +233,6 @@ cc_background_grid_item_class_init (CcBackgroundGridItemClass *klass)
   object_class->get_property = cc_background_grid_item_get_property;
   object_class->set_property = cc_background_grid_item_set_property;
 
-  /*g_object_class_override_property (object_class,
-                                    PROP_ITEM,
-                                    "item");
-                                    */
   g_object_class_install_property (object_class,
                                    PROP_ITEM,
                                    g_param_spec_object ("item",
@@ -139,12 +240,28 @@ cc_background_grid_item_class_init (CcBackgroundGridItemClass *klass)
                                                         "The reference to this background item",
                                                         CC_TYPE_BACKGROUND_ITEM,
                                                         G_PARAM_READWRITE));
+  g_object_class_install_property (object_class,
+                                   PROP_PIXBUF_CACHE,
+                                   g_param_spec_object ("cached_pixbuf",
+                                                        "Cached Pixbuf for preview",
+                                                        "The pixbuf for caching the preview in gallery",
+                                                        GDK_TYPE_PIXBUF,
+                                                        G_PARAM_READWRITE));
 
 }
 
 static void
 cc_background_grid_item_init (CcBackgroundGridItem *self)
 {
-  g_debug ("Item ref: %p", self->item);
-  //gtk_widget_init_template (GTK_WIDGET (self));
+  GtkWidget *drawing;
+
+  drawing = gtk_drawing_area_new ();
+  gtk_widget_set_hexpand(drawing, TRUE);
+  gtk_widget_set_vexpand(drawing, TRUE);
+  g_signal_connect (G_OBJECT (drawing), "draw",
+                    G_CALLBACK (on_gallery_item_draw), self);
+
+  gtk_widget_set_size_request (self, 250, 200);
+  gtk_widget_show (drawing);
+  gtk_container_add (GTK_CONTAINER (self), drawing);
 }
diff --git a/panels/background/cc-background-grid-item.h b/panels/background/cc-background-grid-item.h
index 2c0a19772..1e90a7fba 100644
--- a/panels/background/cc-background-grid-item.h
+++ b/panels/background/cc-background-grid-item.h
@@ -28,7 +28,8 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (CcBackgroundGridItem, cc_background_grid_item, CC, BACKGROUND_GRID_LIST, 
GtkFlowBoxChild)
 
-GtkWidget *             cc_background_grid_item_new             (CcBackgroundItem             *);
+GtkWidget *             cc_background_grid_item_new             (CcBackgroundItem             *,
+                                                                 GdkPixbuf                    *);
 void                    cc_background_grid_item_set_ref         (GtkWidget                    *,
                                                                  CcBackgroundItem             *);
 CcBackgroundItem *      cc_background_grid_item_get_ref         (GtkWidget                    *);
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index c8a8d7fe3..3206401ce 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -146,8 +146,8 @@ update_preview (CcBackgroundPanel *panel,
       changes_with_time = cc_background_item_changes_with_time (current_background);
     }
 
-  gtk_widget_set_visible (WID ("slide_image"), changes_with_time);
-  gtk_widget_set_visible (WID ("slide-label"), changes_with_time);
+  gtk_revealer_set_reveal_child (GTK_REVEALER (WID ("wallpaper-info")),
+                                 changes_with_time);
 
   gtk_widget_queue_draw (WID ("background-desktop-drawingarea"));
 }
@@ -167,28 +167,24 @@ get_or_create_cached_pixbuf (CcBackgroundPanel *panel,
                              GtkWidget         *widget,
                              CcBackgroundItem  *background)
 {
-  GtkAllocation allocation;
-
-  //const gint preview_width;// = 310; //309
-  //const gint preview_height;// = 174; //168
   gint scale_factor;
   GdkPixbuf *pixbuf;
   const gint preview_width = gtk_widget_get_allocated_width (widget);
   const gint preview_height = gtk_widget_get_allocated_height (widget);
 
   pixbuf = g_object_get_data (G_OBJECT (background), "pixbuf");
-  if (pixbuf == NULL)
-    {
-      gtk_widget_get_allocation (widget, &allocation);
-      scale_factor = gtk_widget_get_scale_factor (widget);
-      pixbuf = cc_background_item_get_frame_thumbnail (background,
-                                                       panel->thumb_factory,
-                                                       preview_width,
-                                                       preview_height,
-                                                       scale_factor,
-                                                       -2, TRUE);
-      g_object_set_data_full (G_OBJECT (background), "pixbuf", pixbuf, g_object_unref);
-    }
+  if (pixbuf == NULL ||
+      gdk_pixbuf_get_width (pixbuf) != preview_width ||
+      gdk_pixbuf_get_height (pixbuf) != preview_height) {
+    scale_factor = gtk_widget_get_scale_factor (widget);
+    pixbuf = cc_background_item_get_frame_thumbnail (background,
+                                                     panel->thumb_factory,
+                                                     preview_width,
+                                                     preview_height,
+                                                     scale_factor,
+                                                     -2, TRUE);
+    g_object_set_data_full (G_OBJECT (background), "pixbuf", pixbuf, g_object_unref);
+  }
 
   return pixbuf;
 }
@@ -207,19 +203,26 @@ on_preview_draw (GtkWidget         *widget,
                                pixbuf,
                                0, 0);
   cairo_paint (cr);
-
   return TRUE;
 }
 
-static gboolean
-resize_preview (GtkWidget *widget,
-               GdkEvent  *event,
-               gpointer   user_data)
+static void
+on_panel_resize (GtkWidget *widget,
+                 GdkRectangle *allocation,
+                 gpointer      user_data)
 {
-  g_print ("run me");
-  return TRUE;
+  CcBackgroundPanel *panel = CC_BACKGROUND_PANEL (user_data);
+  GtkWidget *preview = WID ("background-preview");
+
+  if (allocation->height > 700) {
+    gtk_widget_set_size_request (preview, -1, 200);
+  }
+  else {
+    gtk_widget_set_size_request (preview, -1, 150);
+  }
 }
 
+
 static void
 reload_current_bg (CcBackgroundPanel *panel,
                    GSettings *settings)
@@ -583,26 +586,18 @@ is_gnome_photos_installed ()
   return TRUE;
 }
 
-static void
-on_window_resize (GtkWidget    *widget,
-                  GdkRectangle *allocation,
-                  gpointer      user_data)
-{
-  g_print ("New size\n");
-}
 
 static GtkWidget *
 create_gallery_item (gpointer item,
                      gpointer user_data)
 {
   CcBackgroundPanel *panel = user_data;
+  CcBackgroundItem *self = item;
   GtkWidget *flow;
-  GtkWidget *widget;
   GdkPixbuf *pixbuf;
-  CcBackgroundItem *self = item;
   gint scale_factor;
-  const gint preview_width = 309;
-  const gint preview_height = 168;
+  const gint preview_width = 400;
+  const gint preview_height = 400 * 9 / 16;
 
   scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
 
@@ -612,15 +607,7 @@ create_gallery_item (gpointer item,
                                                    preview_height,
                                                    scale_factor,
                                                    -2, TRUE);
-
-  widget = gtk_image_new_from_pixbuf (pixbuf);
-
-  flow = cc_background_grid_item_new(self);
-  cc_background_grid_item_set_ref (flow, self);
-  gtk_widget_show (flow);
-  gtk_widget_show (widget);
-  gtk_container_add (GTK_CONTAINER (flow), widget);
-
+  flow = cc_background_grid_item_new(self, pixbuf);
   return flow;
 }
 
@@ -672,6 +659,9 @@ cc_background_panel_init (CcBackgroundPanel *panel)
   widget = WID ("background-desktop-drawingarea");
   g_signal_connect (widget, "draw", G_CALLBACK (on_preview_draw), panel);
 
+  /* Add handler for resizing the preview */
+  g_signal_connect (panel, "size-allocate", G_CALLBACK (on_panel_resize), panel);
+
   panel->copy_cancellable = g_cancellable_new ();
 
   panel->thumb_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
@@ -708,5 +698,4 @@ cc_background_panel_init (CcBackgroundPanel *panel)
 
   /* Background settings */
   g_signal_connect (panel->settings, "changed", G_CALLBACK (on_settings_changed), panel);
-  g_signal_connect (panel, "configure-event", G_CALLBACK (resize_preview), panel);
 }
diff --git a/panels/background/data/background.css b/panels/background/data/background.css
index 04695ed40..2c7ee12f4 100644
--- a/panels/background/data/background.css
+++ b/panels/background/data/background.css
@@ -1,6 +1,6 @@
 .background-gallery {
   background: #fff;
-  border-top: 1px solid #b6b6b3;
+  border: 1px solid #b6b6b3;
 }
 
 .black-border {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]