[gnome-photos] application: Implement get_scale_factor
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] application: Implement get_scale_factor
- Date: Tue, 15 Apr 2014 09:43:29 +0000 (UTC)
commit 1bdf3b148c4f71ec7a2f0584165a772f4d645335
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 | 2 ++
src/photos-embed.c | 11 +++--------
src/photos-main-window.c | 29 ++++++++++++++++++++++++++---
4 files changed, 48 insertions(+), 11 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index ea6a75f..52e3218 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -1000,3 +1000,20 @@ photos_application_get_miners_running (PhotosApplication *self)
{
return self->priv->miners_running;
}
+
+
+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 f75f94e..ddac3b2 100644
--- a/src/photos-application.h
+++ b/src/photos-application.h
@@ -75,6 +75,8 @@ GtkApplication *photos_application_new (void);
GList *photos_application_get_miners_running (PhotosApplication *self);
+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 bf595d3..a61502e 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -669,17 +669,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;
@@ -693,7 +687,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));
@@ -713,6 +706,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]