[gnome-software] Add gs_plugin_loader_set_scale() to be able to support HiDPI in the future



commit 4ab22c1f52629b8cae2c0ddf7011c4806252094a
Author: Richard Hughes <richard hughsie com>
Date:   Fri Sep 26 16:28:18 2014 +0100

    Add gs_plugin_loader_set_scale() to be able to support HiDPI in the future

 src/gs-plugin-loader.c |   29 +++++++++++++++++++++++++++++
 src/gs-plugin-loader.h |    3 +++
 src/gs-plugin.h        |    1 +
 src/gs-shell.c         |   13 +++++++++++++
 4 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index a1808f7..44e0b74 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -44,6 +44,7 @@ struct GsPluginLoaderPrivate
        GSettings               *settings;
 
        gchar                   **compatible_projects;
+       gint                     scale;
 
        GList                   *queued_installs;
        gboolean                 online; 
@@ -2589,6 +2590,7 @@ gs_plugin_loader_open_plugin (GsPluginLoader *plugin_loader,
        plugin->updates_changed_fn = gs_plugin_loader_updates_changed_cb;
        plugin->updates_changed_user_data = plugin_loader;
        plugin->profile = g_object_ref (plugin_loader->priv->profile);
+       plugin->scale = gs_plugin_loader_get_scale (plugin_loader);
        g_debug ("opened plugin %s: %s", filename, plugin->name);
 
        /* add to array */
@@ -2598,6 +2600,32 @@ out:
 }
 
 /**
+ * gs_plugin_loader_set_scale:
+ */
+void
+gs_plugin_loader_set_scale (GsPluginLoader *plugin_loader, gint scale)
+{
+       GsPlugin *plugin;
+       guint i;
+
+       /* save globally, and update each plugin */
+       plugin_loader->priv->scale = scale;
+       for (i = 0; i < plugin_loader->priv->plugins->len; i++) {
+               plugin = g_ptr_array_index (plugin_loader->priv->plugins, i);
+               plugin->scale = scale;
+       }
+}
+
+/**
+ * gs_plugin_loader_get_scale:
+ */
+gint
+gs_plugin_loader_get_scale (GsPluginLoader *plugin_loader)
+{
+       return plugin_loader->priv->scale;
+}
+
+/**
  * gs_plugin_loader_set_location:
  */
 void
@@ -2828,6 +2856,7 @@ gs_plugin_loader_init (GsPluginLoader *plugin_loader)
        guint i;
 
        plugin_loader->priv = gs_plugin_loader_get_instance_private (plugin_loader);
+       plugin_loader->priv->scale = 1;
        plugin_loader->priv->plugins = g_ptr_array_new_with_free_func ((GDestroyNotify) 
gs_plugin_loader_plugin_free);
        plugin_loader->priv->status_last = GS_PLUGIN_STATUS_LAST;
        plugin_loader->priv->pending_apps = g_ptr_array_new_with_free_func ((GFreeFunc) g_object_unref);
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 98ce88f..474de8a 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -163,6 +163,9 @@ gboolean     gs_plugin_loader_set_enabled           (GsPluginLoader *plugin_loader,
                                                         gboolean        enabled);
 void            gs_plugin_loader_set_location          (GsPluginLoader *plugin_loader,
                                                         const gchar    *location);
+gint            gs_plugin_loader_get_scale             (GsPluginLoader *plugin_loader);
+void            gs_plugin_loader_set_scale             (GsPluginLoader *plugin_loader,
+                                                        gint            scale);
 void            gs_plugin_loader_app_refine_async      (GsPluginLoader *plugin_loader,
                                                         GsApp          *app,
                                                         GsPluginRefineFlags flags,
diff --git a/src/gs-plugin.h b/src/gs-plugin.h
index ee37426..5c9399e 100644
--- a/src/gs-plugin.h
+++ b/src/gs-plugin.h
@@ -67,6 +67,7 @@ struct GsPlugin {
        gchar                   *name;
        GsPluginPrivate         *priv;
        guint                    pixbuf_size;
+       gint                     scale;
        GsPluginStatusUpdate     status_update_fn;
        gpointer                 status_update_user_data;
        GsPluginUpdatesChanged   updates_changed_fn;
diff --git a/src/gs-shell.c b/src/gs-shell.c
index fb8ec72..43f87e9 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -488,6 +488,17 @@ gs_shell_updates_changed_cb (GsPluginLoader *plugin_loader, GsShell *shell)
 }
 
 /**
+ * gs_shell_main_window_mapped_cb:
+ */
+static void
+gs_shell_main_window_mapped_cb (GtkWidget *widget, GsShell *shell)
+{
+       GsShellPrivate *priv = shell->priv;
+       gs_plugin_loader_set_scale (priv->plugin_loader,
+                                   gtk_widget_get_scale_factor (widget));
+}
+
+/**
  * gs_shell_setup:
  */
 void
@@ -506,6 +517,8 @@ gs_shell_setup (GsShell *shell, GsPluginLoader *plugin_loader, GCancellable *can
        /* get UI */
        priv->builder = gtk_builder_new_from_resource ("/org/gnome/Software/gnome-software.ui");
        priv->main_window = GTK_WINDOW (gtk_builder_get_object (priv->builder, "window_software"));
+       g_signal_connect (priv->main_window, "map",
+                         G_CALLBACK (gs_shell_main_window_mapped_cb), shell);
 
        /* add application specific icons to search path */
        gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),


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