[gnome-control-center/wip/jsparber/background: 27/58] [refactor] use a Widget to figure out scale factor instate of Window



commit 2549473cdb0d38f24c76e6c2dc082d4f4f4630a0
Author: Julian Sparber <julian sparber net>
Date:   Sun Nov 5 18:19:51 2017 +0100

    [refactor] use a Widget to figure out scale factor instate of Window

 panels/background/bg-source.c                    |   12 +++++-------
 panels/background/bg-wallpapers-source.c         |    4 ++--
 panels/background/bg-wallpapers-source.h         |    2 +-
 panels/background/cc-background-chooser-dialog.c |    2 +-
 panels/background/cc-background-panel.c          |   13 +++++++------
 5 files changed, 16 insertions(+), 17 deletions(-)
---
diff --git a/panels/background/bg-source.c b/panels/background/bg-source.c
index 7d08dbd..f1fac84 100644
--- a/panels/background/bg-source.c
+++ b/panels/background/bg-source.c
@@ -52,12 +52,12 @@ bg_source_calculate_thumbnail_dimensions (BgSource *source)
   priv->thumbnail_height = THUMBNAIL_HEIGHT;
   priv->thumbnail_width = THUMBNAIL_WIDTH;
 
-  //if (priv->window == NULL)
-  //  return;
+  if (priv->window == NULL)
+    return;
 
 
-  //scale_factor = gtk_widget_get_scale_factor (priv->window);
-  scale_factor = 1;
+  scale_factor = gtk_widget_get_scale_factor (priv->window);
+
   if (scale_factor > 1)
     {
       priv->thumbnail_height *= scale_factor;
@@ -144,7 +144,7 @@ bg_source_class_init (BgSourceClass *klass)
   pspec = g_param_spec_object ("window",
                                "Window",
                                "Toplevel window used to view the source",
-                               GTK_TYPE_WINDOW,
+                               GTK_TYPE_WIDGET,
                                G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_WINDOW, pspec);
 }
@@ -176,8 +176,6 @@ bg_source_get_scale_factor (BgSource *source)
 
   priv = bg_source_get_instance_private (source);
 
-  return 1;
-  g_print("Error Here 2\n");
   return gtk_widget_get_scale_factor (priv->window);
 }
 
diff --git a/panels/background/bg-wallpapers-source.c b/panels/background/bg-wallpapers-source.c
index b94282c..661bdef 100644
--- a/panels/background/bg-wallpapers-source.c
+++ b/panels/background/bg-wallpapers-source.c
@@ -56,7 +56,7 @@ load_wallpapers (gchar              *key,
   if (deleted)
     return;
 
-//  gtk_list_store_append (store, &iter);
+  //gtk_list_store_append (store, &iter);
 
   scale_factor = bg_source_get_scale_factor (BG_SOURCE (source));
   thumbnail_height = bg_source_get_thumbnail_height (BG_SOURCE (source));
@@ -172,7 +172,7 @@ bg_wallpapers_source_class_init (BgWallpapersSourceClass *klass)
 }
 
 BgWallpapersSource *
-bg_wallpapers_source_new (GtkWindow *window)
+bg_wallpapers_source_new (GtkWidget *window)
 {
   return g_object_new (BG_TYPE_WALLPAPERS_SOURCE, "window", window, NULL);
 }
diff --git a/panels/background/bg-wallpapers-source.h b/panels/background/bg-wallpapers-source.h
index 7292669..3d0d2e0 100644
--- a/panels/background/bg-wallpapers-source.h
+++ b/panels/background/bg-wallpapers-source.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
 #define BG_TYPE_WALLPAPERS_SOURCE (bg_wallpapers_source_get_type ())
 G_DECLARE_FINAL_TYPE (BgWallpapersSource, bg_wallpapers_source, BG, WALLPAPERS_SOURCE, BgSource)
 
-BgWallpapersSource *bg_wallpapers_source_new (GtkWindow *);
+BgWallpapersSource *bg_wallpapers_source_new (GtkWidget *);
 
 G_END_DECLS
 
diff --git a/panels/background/cc-background-chooser-dialog.c 
b/panels/background/cc-background-chooser-dialog.c
index da4a057..28ef616 100644
--- a/panels/background/cc-background-chooser-dialog.c
+++ b/panels/background/cc-background-chooser-dialog.c
@@ -458,7 +458,7 @@ cc_background_chooser_dialog_init (CcBackgroundChooserDialog *chooser)
   gchar *pictures_dir_uri;
   GtkTargetList *target_list;
 
-  chooser->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (chooser));
+  chooser->wallpapers_source = bg_wallpapers_source_new (GTK_WIDGET (chooser));
   chooser->pictures_source = bg_pictures_source_new (GTK_WINDOW (chooser));
   chooser->colors_source = bg_colors_source_new (GTK_WINDOW (chooser));
 
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 1499dd8..84e31cc 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -856,9 +856,10 @@ load_wallpapers (CcBackgroundPanel *panel,
   /*gint scale_factor;
 
   scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (panel));
-  */
+  g_print ("Scale factor %d\n", scale_factor);*/
 
-  panel->wallpapers_source = bg_wallpapers_source_new (GTK_WINDOW (NULL));
+  /* FIXME: get the right window to pass it to bg_wallpapers_source_new */
+  panel->wallpapers_source = bg_wallpapers_source_new (GTK_WIDGET (panel));
   model = bg_source_get_liststore (BG_SOURCE (panel->wallpapers_source));
 
   gtk_tree_model_foreach (GTK_TREE_MODEL (model), do_foreach_background_item, panel);
@@ -873,7 +874,7 @@ cc_background_panel_init (CcBackgroundPanel *panel)
 {
   gchar *objects[] = {"background-panel", NULL };
   GError *err = NULL;
-  GtkStyleProvider *provider;
+  GtkCssProvider *provider;
   GtkWidget *widget;
 
   panel->connection = g_application_get_dbus_connection (g_application_get_default ());
@@ -902,11 +903,11 @@ cc_background_panel_init (CcBackgroundPanel *panel)
 
   /* add style */
   widget = WID ("background-preview-top");
-  provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
-  gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (provider),
+  provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_resource (provider,
                                        "org/gnome/control-center/background/background.css");
   gtk_style_context_add_provider_for_screen (gdk_screen_get_default(),
-                                             provider,
+                                             GTK_STYLE_PROVIDER (provider),
                                              GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
   g_object_unref (provider);
 


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