[gnome-photos/gnome-3-12] application: Implement get_scale_factor



commit 5bcda2dcb425a3d10ce1d1fdd27fdb9c5d257370
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Mar 22 22:41:50 2014 +0100

    application: Implement get_scale_factor
    
    We'll use it to render HiDpi icons.
    
    Original patch from Cosimo Cecchi for gnome-documents.
    
    Fixes: https://bugzilla.gnome.org/726903

 src/photos-application.c |   17 +++++++++++++++++
 src/photos-application.h |    4 +++-
 src/photos-embed.c       |   11 +++--------
 src/photos-main-window.c |   29 ++++++++++++++++++++++++++---
 4 files changed, 49 insertions(+), 12 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 3826fb3..1357a5c 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -976,3 +976,20 @@ photos_application_new (void)
                        "flags", G_APPLICATION_IS_SERVICE,
                        NULL);
 }
+
+
+gint
+photos_application_get_scale_factor (PhotosApplication *self)
+{
+  GList *windows;
+  gint scale_factor;
+
+  /* We do not use priv->main_window to allow widgets to use this
+   * method while they are being constructed. The widget hierarchy is
+   * created in PhotosMainWindow:constructed and at that point
+   * priv->main_window is NULL.
+   */
+  windows = gtk_application_get_windows (GTK_APPLICATION (self));
+  scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (windows->data));
+  return scale_factor;
+}
diff --git a/src/photos-application.h b/src/photos-application.h
index 6b0c30e..e45f4aa 100644
--- a/src/photos-application.h
+++ b/src/photos-application.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2014 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -70,6 +70,8 @@ GType                  photos_application_get_type               (void) G_GNUC_C
 
 GtkApplication        *photos_application_new                    (void);
 
+gint                   photos_application_get_scale_factor       (PhotosApplication *self);
+
 G_END_DECLS
 
 #endif /* PHOTOS_APPLICATION_H */
diff --git a/src/photos-embed.c b/src/photos-embed.c
index d54bfa2..a1f6347 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -672,17 +672,11 @@ photos_embed_dispose (GObject *object)
 
 
 static void
-photos_embed_window_added (PhotosEmbed *self, GtkWindow *window)
-{
-  gtk_window_set_titlebar (window, self->priv->toolbar);
-}
-
-
-static void
 photos_embed_init (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv;
   GApplication *app;
+  GList *windows;
   GtkListStore *model;
   PhotosSearchbar *searchbar;
   PhotosSearchContextState *state;
@@ -695,7 +689,6 @@ photos_embed_init (PhotosEmbed *self)
   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
 
   priv->search_action = g_action_map_lookup_action (G_ACTION_MAP (app), "search");
-  g_signal_connect_swapped (app, "window-added", G_CALLBACK (photos_embed_window_added), self);
 
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
   gtk_widget_show (GTK_WIDGET (self));
@@ -715,6 +708,8 @@ photos_embed_init (PhotosEmbed *self)
 
   priv->toolbar = photos_main_toolbar_new (GTK_OVERLAY (priv->stack_overlay));
   photos_main_toolbar_set_stack (PHOTOS_MAIN_TOOLBAR (priv->toolbar), GTK_STACK (priv->stack));
+  windows = gtk_application_get_windows (GTK_APPLICATION (app));
+  gtk_window_set_titlebar (GTK_WINDOW (windows->data), priv->toolbar);
   searchbar = photos_main_toolbar_get_searchbar (PHOTOS_MAIN_TOOLBAR (priv->toolbar));
   g_signal_connect_swapped (searchbar, "activate-result", G_CALLBACK (photos_embed_activate_result), self);
 
diff --git a/src/photos-main-window.c b/src/photos-main-window.c
index 21bcaa9..9b0d2b8 100644
--- a/src/photos-main-window.c
+++ b/src/photos-main-window.c
@@ -25,6 +25,7 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 
@@ -315,6 +316,30 @@ photos_main_window_window_state_event (GtkWidget *widget, GdkEventWindowState *e
 
 
 static void
+photos_main_window_constructed (GObject *object)
+{
+  PhotosMainWindow *self = PHOTOS_MAIN_WINDOW (object);
+  PhotosMainWindowPrivate *priv = self->priv;
+  GApplication *app;
+
+  G_OBJECT_CLASS (photos_main_window_parent_class)->constructed (object);
+
+  /* HACK: Since GtkWindow:application is a non-construct property it
+   * will be set after constructed has finished. We explicitly add
+   * the window to the application here before creating the rest of
+   * the widget hierarchy. This ensures that we can use
+   * photos_application_get_scale_factor while constructing the
+   * widgets.
+   */
+  app = g_application_get_default ();
+  gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (self));
+
+  priv->embed = photos_embed_new ();
+  gtk_container_add (GTK_CONTAINER (self), priv->embed);
+}
+
+
+static void
 photos_main_window_dispose (GObject *object)
 {
   PhotosMainWindow *self = PHOTOS_MAIN_WINDOW (object);
@@ -382,9 +407,6 @@ photos_main_window_init (PhotosMainWindow *self)
                             self);
 
   priv->sel_cntrlr = photos_selection_controller_dup_singleton ();
-
-  priv->embed = photos_embed_new ();
-  gtk_container_add (GTK_CONTAINER (self), priv->embed);
 }
 
 
@@ -394,6 +416,7 @@ photos_main_window_class_init (PhotosMainWindowClass *class)
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
+  object_class->constructed = photos_main_window_constructed;
   object_class->dispose = photos_main_window_dispose;
   widget_class->configure_event = photos_main_window_configure_event;
   widget_class->delete_event = photos_main_window_delete_event;


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