[evolution] Bug 785178 - Message preview pane size gets reset every time on HiDPI



commit d5201031e9b9659abd64a47f1936122e641cb12b
Author: Milan Crha <mcrha redhat com>
Date:   Fri Sep 15 11:14:23 2017 +0200

    Bug 785178 - Message preview pane size gets reset every time on HiDPI

 src/e-util/e-paned.c         |   21 +++++++--
 src/mail/e-mail-paned-view.c |  101 +++++++++++++++++++++++++++++++-----------
 2 files changed, 91 insertions(+), 31 deletions(-)
---
diff --git a/src/e-util/e-paned.c b/src/e-util/e-paned.c
index 59c459e..520c0f1 100644
--- a/src/e-util/e-paned.c
+++ b/src/e-util/e-paned.c
@@ -276,7 +276,7 @@ paned_size_allocate (GtkWidget *widget,
        gdouble proportion, old_proportion = -1.0;
        gint allocated;
        gint position, min_position = -1, max_position = -1, clamp_position;
-       gboolean corrected_portion = FALSE;
+       gboolean corrected_portion = FALSE, notify_proportion_change = FALSE;
 
        if (!e_paned_get_fixed_resize (paned))
                old_proportion = e_paned_get_proportion (paned);
@@ -287,16 +287,23 @@ paned_size_allocate (GtkWidget *widget,
        if (paned->priv->sync_request == SYNC_REQUEST_PROPORTION &&
            old_proportion != e_paned_get_proportion (paned) && old_proportion > 0.0) {
                paned->priv->proportion = old_proportion;
-               g_object_notify (G_OBJECT (paned), "proportion");
-
+               notify_proportion_change = TRUE;
                corrected_portion = TRUE;
        }
 
-       if (!paned->priv->toplevel_ready)
+       if (!paned->priv->toplevel_ready) {
+               if (notify_proportion_change)
+                       g_object_notify (G_OBJECT (paned), "proportion");
+
                return;
+       }
 
        if (paned->priv->sync_request == SYNC_REQUEST_NONE) {
                paned_recalc_positions (paned, FALSE);
+
+               if (notify_proportion_change)
+                       g_object_notify (G_OBJECT (paned), "proportion");
+
                return;
        }
 
@@ -319,7 +326,7 @@ paned_size_allocate (GtkWidget *widget,
                if (!e_paned_get_fixed_resize (paned) && allocated > 0) {
                        proportion = 1.0 - ((gdouble) position / allocated);
                        paned->priv->proportion = proportion;
-                       g_object_notify (G_OBJECT (paned), "proportion");
+                       notify_proportion_change = TRUE;
                }
        } else {
                position = (1.0 - proportion) * allocated;
@@ -338,6 +345,7 @@ paned_size_allocate (GtkWidget *widget,
        if (clamp_position != position && allocated > 0) {
                proportion = 1.0 - ((gdouble) clamp_position / allocated);
                paned->priv->proportion = proportion;
+               notify_proportion_change = TRUE;
 
                corrected_portion = TRUE;
        }
@@ -356,6 +364,9 @@ paned_size_allocate (GtkWidget *widget,
                }
        }
 
+       if (notify_proportion_change)
+               g_object_notify (G_OBJECT (paned), "proportion");
+
        paned->priv->sync_request = SYNC_REQUEST_NONE;
 
        /* gtk_paned_set_position() calls queue_resize, which cannot
diff --git a/src/mail/e-mail-paned-view.c b/src/mail/e-mail-paned-view.c
index acc66e1..7918adf 100644
--- a/src/mail/e-mail-paned-view.c
+++ b/src/mail/e-mail-paned-view.c
@@ -218,46 +218,95 @@ mail_paned_view_message_selected_cb (EMailView *view,
        g_object_unref (folder);
 }
 
+/* To recognize old values from new values */
+#define PROPORTION_LOWER_LIMIT 1000000
+
+static gboolean
+mail_paned_view_map_setting_to_proportion_cb (GValue *value,
+                                             GVariant *variant,
+                                             gpointer user_data)
+{
+       gint stored;
+       gdouble proportion = 0.5;
+
+       stored = g_variant_get_int32 (variant);
+
+       if (stored >= PROPORTION_LOWER_LIMIT)
+               proportion = (stored - PROPORTION_LOWER_LIMIT) / ((gdouble) PROPORTION_LOWER_LIMIT);
+
+       g_value_set_double (value, proportion);
+
+       return TRUE;
+}
+
+static GVariant *
+mail_paned_view_map_proportion_to_setting_cb (const GValue *value,
+                                             const GVariantType *expected_type,
+                                             gpointer user_data)
+{
+       gdouble proportion;
+
+       proportion = g_value_get_double (value);
+
+       return g_variant_new_int32 (PROPORTION_LOWER_LIMIT + (gint32) (proportion * PROPORTION_LOWER_LIMIT));
+}
+
 static void
-mail_paned_view_restore_state_cb (EShellWindow *shell_window,
-                                  EShellView *shell_view,
-                                  EMailPanedView *view)
+mail_paned_view_notify_orientation_cb (GtkWidget *paned,
+                                      GParamSpec *param,
+                                      EShellWindow *shell_window)
 {
-       EMailPanedViewPrivate *priv;
        GSettings *settings;
+       const gchar *settings_key;
+       guint32 add_flags = 0;
 
-       priv = E_MAIL_PANED_VIEW (view)->priv;
+       g_return_if_fail (E_IS_PANED (paned));
+       g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
 
-       settings = e_util_ref_settings ("org.gnome.evolution.mail");
+       g_settings_unbind (paned, "proportion");
 
        if (e_shell_window_is_main_instance (shell_window)) {
-               g_settings_bind (
-                       settings, "hpaned-size",
-                       priv->paned, "hposition",
-                       G_SETTINGS_BIND_DEFAULT);
-
-               g_settings_bind (
-                       settings, "paned-size",
-                       priv->paned, "vposition",
-                       G_SETTINGS_BIND_DEFAULT);
+               if (gtk_orientable_get_orientation (GTK_ORIENTABLE (paned)) == GTK_ORIENTATION_HORIZONTAL)
+                       settings_key = "hpaned-size";
+               else
+                       settings_key = "paned-size";
        } else {
-               g_settings_bind (
-                       settings, "hpaned-size-sub",
-                       priv->paned, "hposition",
-                       G_SETTINGS_BIND_DEFAULT |
-                       G_SETTINGS_BIND_GET_NO_CHANGES);
-
-               g_settings_bind (
-                       settings, "paned-size-sub",
-                       priv->paned, "vposition",
-                       G_SETTINGS_BIND_DEFAULT |
-                       G_SETTINGS_BIND_GET_NO_CHANGES);
+               if (gtk_orientable_get_orientation (GTK_ORIENTABLE (paned)) == GTK_ORIENTATION_HORIZONTAL)
+                       settings_key = "hpaned-size-sub";
+               else
+                       settings_key = "paned-size-sub";
+
+               add_flags = G_SETTINGS_BIND_GET_NO_CHANGES;
        }
 
+       settings = e_util_ref_settings ("org.gnome.evolution.mail");
+
+       g_settings_bind_with_mapping (settings, settings_key,
+               paned, "proportion",
+               G_SETTINGS_BIND_DEFAULT | add_flags,
+               mail_paned_view_map_setting_to_proportion_cb,
+               mail_paned_view_map_proportion_to_setting_cb,
+               NULL, NULL);
+
        g_object_unref (settings);
 }
 
 static void
+mail_paned_view_restore_state_cb (EShellWindow *shell_window,
+                                  EShellView *shell_view,
+                                  EMailPanedView *view)
+{
+       EMailPanedViewPrivate *priv;
+
+       priv = E_MAIL_PANED_VIEW (view)->priv;
+
+       g_signal_connect (priv->paned, "notify::orientation",
+               G_CALLBACK (mail_paned_view_notify_orientation_cb), shell_window);
+
+       mail_paned_view_notify_orientation_cb (priv->paned, NULL, shell_window);
+}
+
+static void
 mail_paned_display_view_cb (GalViewInstance *view_instance,
                             GalView *gal_view,
                             EMailView *view)


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