[gnome-software: 1/2] gs-app-row: Fix arrow direction for versions in RTL locales




commit 10becd562b177190a66da85c365fe7c361633f0f
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Nov 24 12:49:22 2020 +0000

    gs-app-row: Fix arrow direction for versions in RTL locales
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Fixes: #1100

 src/gs-app-row.c       | 14 ++++++++++++++
 src/gs-update-dialog.c | 26 +++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index a00dfb03..4425f551 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -354,6 +354,20 @@ gs_app_row_actually_refresh (GsAppRow *app_row)
                        gtk_widget_hide (priv->version_arrow_label);
                }
 
+               /* ensure the arrow is the right way round for the text direction,
+                * as arrows are not bidi-mirrored automatically
+                * See section 2 of http://www.unicode.org/L2/L2017/17438-bidi-math-fdbk.html */
+               switch (gtk_widget_get_direction (priv->version_box)) {
+               case GTK_TEXT_DIR_RTL:
+                       gtk_label_set_label (GTK_LABEL (priv->version_arrow_label), "←");
+                       break;
+               case GTK_TEXT_DIR_NONE:
+               case GTK_TEXT_DIR_LTR:
+               default:
+                       gtk_label_set_label (GTK_LABEL (priv->version_arrow_label), "→");
+                       break;
+               }
+
                /* show the box if we have either of the versions */
                if (version_current != NULL || version_update != NULL)
                        gtk_widget_show (priv->version_box);
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 2bc2f136..c64eaa58 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -338,7 +338,7 @@ unset_focus (GtkWidget *widget)
 }
 
 static gchar *
-format_version_update (GsApp *app)
+format_version_update (GsApp *app, GtkTextDirection direction)
 {
        const gchar *tmp;
        const gchar *version_current = NULL;
@@ -357,9 +357,25 @@ format_version_update (GsApp *app)
        /* have both */
        if (version_current != NULL && version_update != NULL &&
            g_strcmp0 (version_current, version_update) != 0) {
-               return g_strdup_printf ("%s → %s",
-                                       version_current,
-                                       version_update);
+               switch (direction) {
+               case GTK_TEXT_DIR_RTL:
+                       /* This might look the wrong way round, but that’s
+                        * because the #GtkLabel this is put in will reverse the
+                        * text order in RTL, but won’t swap ← for → or
+                        * vice-versa (the bidi mirroring property of those two
+                        * arrows is false). So we need to explicitly use ‘←’ in
+                        * RTL locales, but not change the text order.
+                        * See section 2 of http://www.unicode.org/L2/L2017/17438-bidi-math-fdbk.html */
+                       return g_strdup_printf ("%s ← %s",
+                                               version_current,
+                                               version_update);
+               case GTK_TEXT_DIR_NONE:
+               case GTK_TEXT_DIR_LTR:
+               default:
+                       return g_strdup_printf ("%s → %s",
+                                               version_current,
+                                               version_update);
+               }
        }
 
        /* just update */
@@ -395,7 +411,7 @@ create_app_row (GsApp *app)
        gtk_container_add (GTK_CONTAINER (row), label);
        if (gs_app_get_state (app) == AS_APP_STATE_UPDATABLE ||
            gs_app_get_state (app) == AS_APP_STATE_UPDATABLE_LIVE) {
-               g_autofree gchar *verstr = format_version_update (app);
+               g_autofree gchar *verstr = format_version_update (app, gtk_widget_get_direction (row));
                label = gtk_label_new (verstr);
        } else {
                label = gtk_label_new (gs_app_get_version (app));


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