[Xfce4-commits] [xfce/xfce4-settings] 04/05: display: Right-align the display ratio

noreply at xfce.org noreply at xfce.org
Thu Jan 2 22:54:27 CET 2020


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-settings.

commit f709a3b4b6a2ff3fc47841ba4e6b3d9981358ac5
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Wed Dec 25 23:44:46 2019 +0100

    display: Right-align the display ratio
    
    Also, mark all imprecise ratios in italic font and use
    ≈ as indicator.
---
 dialogs/display-settings/main.c | 102 +++++++++++++++++++++++++---------------
 1 file changed, 64 insertions(+), 38 deletions(-)

diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index fe1a0cb..69cbaa6 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -73,6 +73,14 @@ enum
 
 enum
 {
+    RESOLUTION_COLUMN_COMBO_NAME,
+    RESOLUTION_COLUMN_COMBO_MARKUP,
+    RESOLUTION_COLUMN_COMBO_VALUE,
+    N_RESOLUTION_COMBO_COLUMNS
+};
+
+enum
+{
     COLUMN_COMBO_NAME,
     COLUMN_COMBO_VALUE,
     N_COMBO_COLUMNS
@@ -181,17 +189,17 @@ static GHashTable *display_ratio = NULL;
 /* most prominent ratios */
 /* adding in least exact order to find most precise */
 static XfceRatio ratio_table[] = {
-    { FALSE, _ONE_DIGIT_PRECISION(16.0/9.0), "~16:9" },
-    { FALSE, _TWO_DIGIT_PRECISION(16.0/9.0), "~16:9" },
+    { FALSE, _ONE_DIGIT_PRECISION(16.0/9.0), "<span font_style='italic'>≈16:9</span>" },
+    { FALSE, _TWO_DIGIT_PRECISION(16.0/9.0), "<span font_style='italic'>≈16:9</span>" },
     { TRUE, 16.0/9.0, "16:9" },
-    { FALSE, _ONE_DIGIT_PRECISION(16.0/10.0), "~16:10" },
-    { FALSE, _TWO_DIGIT_PRECISION(16.0/10.0), "~16:10" },
+    { FALSE, _ONE_DIGIT_PRECISION(16.0/10.0), "<span font_style='italic'>≈16:10</span>" },
+    { FALSE, _TWO_DIGIT_PRECISION(16.0/10.0), "<span font_style='italic'>≈16:10</span>" },
     { TRUE, 16.0/10.0, "16:10" },
     /* _ONE_DIGIT_PRECISION(4.0/3.0) would be mixed up with 5/4 */
-    { FALSE, _TWO_DIGIT_PRECISION(4.0/3.0), "~4:3" },
+    { FALSE, _TWO_DIGIT_PRECISION(4.0/3.0), "<span font_style='italic'>≈4:3</span>" },
     { TRUE, 4.0/3.0, "4:3" },
-    { FALSE, _ONE_DIGIT_PRECISION(21.0/9.0), "~21:9" },
-    { FALSE, _TWO_DIGIT_PRECISION(21.0/9.0), "~21:9" },
+    { FALSE, _ONE_DIGIT_PRECISION(21.0/9.0), "<span font_style='italic'>≈21:9</span>" },
+    { FALSE, _TWO_DIGIT_PRECISION(21.0/9.0), "<span font_style='italic'>≈21:9</span>" },
     { TRUE, 21.0/9.0, "21:9" },
     { FALSE, 0.0 , NULL }
 };
@@ -268,7 +276,8 @@ display_settings_get_n_active_outputs (void)
 
 static gboolean
 display_setting_combo_box_get_value (GtkComboBox *combobox,
-                                     gint        *value)
+                                     gint        *value,
+                                     gboolean     resolution)
 {
     GtkTreeModel *model;
     GtkTreeIter   iter;
@@ -276,7 +285,10 @@ display_setting_combo_box_get_value (GtkComboBox *combobox,
     if (gtk_combo_box_get_active_iter (combobox, &iter))
     {
         model = gtk_combo_box_get_model (combobox);
-        gtk_tree_model_get (model, &iter, COLUMN_COMBO_VALUE, value, -1);
+        if (resolution)
+            gtk_tree_model_get (model, &iter, RESOLUTION_COLUMN_COMBO_VALUE, value, -1);
+        else
+            gtk_tree_model_get (model, &iter, COLUMN_COMBO_VALUE, value, -1);
 
         return TRUE;
     }
@@ -372,7 +384,7 @@ display_setting_reflections_changed (GtkComboBox *combobox,
 {
     gint value;
 
-    if (!display_setting_combo_box_get_value (combobox, &value))
+    if (!display_setting_combo_box_get_value (combobox, &value, FALSE))
         return;
 
     /* Remove existing reflection */
@@ -455,7 +467,7 @@ display_setting_rotations_changed (GtkComboBox *combobox,
     XfceOutputInfo *output;
     gint value;
 
-    if (!display_setting_combo_box_get_value (combobox, &value))
+    if (!display_setting_combo_box_get_value (combobox, &value, FALSE))
         return;
 
     /* Set new rotation */
@@ -534,7 +546,7 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
 {
     gint value;
 
-    if (!display_setting_combo_box_get_value (combobox, &value))
+    if (!display_setting_combo_box_get_value (combobox, &value, FALSE))
         return;
 
     /* Set new mode */
@@ -581,7 +593,7 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
 
     /* Fetch the selected resolution */
     res_combobox = gtk_builder_get_object (builder, "randr-resolution");
-    if (!display_setting_combo_box_get_value (GTK_COMBO_BOX (res_combobox), &n))
+    if (!display_setting_combo_box_get_value (GTK_COMBO_BOX (res_combobox), &n, TRUE))
         return;
 
     current_mode = xfce_randr_find_mode_by_id (xfce_randr, active_output, n);
@@ -630,7 +642,7 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
     const XfceRRMode *mode;
     gint value;
 
-    if (!display_setting_combo_box_get_value (combobox, &value))
+    if (!display_setting_combo_box_get_value (combobox, &value, TRUE))
         return;
 
     /* Set new resolution */
@@ -669,6 +681,7 @@ display_setting_resolutions_populate (GtkBuilder *builder)
     GtkCellRenderer  *renderer;
     gint              nmode, n;
     gchar            *name;
+    gchar            *rratio;
     GtkTreeIter       iter;
     const XfceRRMode *modes;
 
@@ -677,13 +690,6 @@ display_setting_resolutions_populate (GtkBuilder *builder)
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
     gtk_list_store_clear (GTK_LIST_STORE (model));
 
-    /* Replace the standard text renderer of the combobox with markup */
-    renderer = gtk_cell_renderer_text_new ();
-    gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
-    gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, FALSE);
-    gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer,
-                                   "markup", 0);
-
     label = gtk_builder_get_object (builder, "label-resolution");
 
     /* Disable it if no mode is selected */
@@ -728,7 +734,7 @@ display_setting_resolutions_populate (GtkBuilder *builder)
                      * although we did round the current ratio
                      * we also mark this as not precise */
                     if (ratio_info->precise)
-                        ratio_text = g_strdup_printf ("~%s", ratio_info->desc);
+                        ratio_text = g_strdup_printf ("<span font_style='italic'>≈%s</span>", ratio_info->desc);
                     else
                         ratio_text = g_strdup (ratio_info->desc);
                 }
@@ -741,7 +747,7 @@ display_setting_resolutions_populate (GtkBuilder *builder)
                 if (ratio_info)
                 {
                     if (ratio_info->precise)
-                        ratio_text = g_strdup_printf ("~%s", ratio_info->desc);
+                        ratio_text = g_strdup_printf ("<span font_style='italic'>≈%s</span>", ratio_info->desc);
                     else
                         ratio_text = g_strdup (ratio_info->desc);
                 }
@@ -752,21 +758,25 @@ display_setting_resolutions_populate (GtkBuilder *builder)
                 guint gcd_tmp = gcd (modes[n].width, modes[n].height);
                 guint format_x = modes[n].width / gcd_tmp;
                 guint format_y = modes[n].height / gcd_tmp;
-                name = g_strdup_printf ("%dx%d <span fgalpha='50%%'>%d:%d</span>", modes[n].width,
-                                        modes[n].height, format_x, format_y);
+                name = g_strdup_printf ("%dx%d", modes[n].width,
+                                        modes[n].height);
+                rratio = g_strdup_printf ("<span fgalpha='50%%'>%d:%d</span>", format_x, format_y);
             }
             else
             {
-                name = g_strdup_printf ("%dx%d <span fgalpha='50%%'>%s</span>", modes[n].width,
-                                        modes[n].height, ratio_text);
+                name = g_strdup_printf ("%dx%d", modes[n].width,
+                                        modes[n].height);
+                rratio = g_strdup_printf ("<span fgalpha='50%%'>%s</span>", ratio_text);
             }
-            g_free(ratio_text);
+            g_free (ratio_text);
 
             gtk_list_store_append (GTK_LIST_STORE (model), &iter);
             gtk_list_store_set (GTK_LIST_STORE (model), &iter,
-                                COLUMN_COMBO_NAME, name,
-                                COLUMN_COMBO_VALUE, modes[n].id, -1);
+                                RESOLUTION_COLUMN_COMBO_NAME, name,
+                                RESOLUTION_COLUMN_COMBO_MARKUP, rratio,
+                                RESOLUTION_COLUMN_COMBO_VALUE, modes[n].id, -1);
             g_free (name);
+            g_free (rratio);
         }
 
         /* Select the active mode */
@@ -1008,11 +1018,11 @@ static void
 display_setting_identity_popups_populate (void)
 {
     guint n;
+    XfceRatio *i;
 
     g_assert (xfce_randr);
 
     display_ratio = g_hash_table_new (g_double_hash, g_double_equal);
-    XfceRatio *i;
     for (i = ratio_table; i->ratio != 0.0; i++)
     {
         g_hash_table_insert (display_ratio, &i->ratio, (gpointer) i);
@@ -1593,13 +1603,17 @@ display_settings_combobox_populate (GtkBuilder *builder)
 }
 
 static void
-display_settings_combo_box_create (GtkComboBox *combobox)
+display_settings_combo_box_create (GtkComboBox *combobox,
+                                   gboolean     resolution)
 {
     GtkCellRenderer *renderer;
     GtkListStore    *store;
 
     /* Create and set the combobox model */
-    store = gtk_list_store_new (N_COMBO_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
+    if (resolution)
+        store = gtk_list_store_new (N_RESOLUTION_COMBO_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
+    else
+        store = gtk_list_store_new (N_COMBO_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
     gtk_combo_box_set_model (combobox, GTK_TREE_MODEL (store));
     g_object_unref (G_OBJECT (store));
 
@@ -1607,7 +1621,19 @@ display_settings_combo_box_create (GtkComboBox *combobox)
     renderer = gtk_cell_renderer_text_new ();
     gtk_cell_layout_clear (GTK_CELL_LAYOUT (combobox));
     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
-    gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, "text", COLUMN_COMBO_NAME);
+    if (resolution)
+        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, "text", RESOLUTION_COLUMN_COMBO_NAME);
+    else
+        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, "text", COLUMN_COMBO_NAME);
+
+    /* Add another column for the resolution combobox to display the ratio */
+    if (resolution)
+    {
+        renderer = gtk_cell_renderer_text_new ();
+        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
+        gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, "markup", RESOLUTION_COLUMN_COMBO_MARKUP);
+        gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
+    }
 }
 
 static void
@@ -2131,20 +2157,20 @@ display_settings_dialog_new (GtkBuilder *builder)
     gtk_widget_show (GTK_WIDGET (label));
 
     combobox = gtk_builder_get_object (builder, "randr-reflection");
-    display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
+    display_settings_combo_box_create (GTK_COMBO_BOX (combobox), FALSE);
     gtk_widget_show (GTK_WIDGET (combobox));
     g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_reflections_changed), builder);
 
     combobox = gtk_builder_get_object (builder, "randr-resolution");
-    display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
+    display_settings_combo_box_create (GTK_COMBO_BOX (combobox), TRUE);
     g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_resolutions_changed), builder);
 
     combobox = gtk_builder_get_object (builder, "randr-refresh-rate");
-    display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
+    display_settings_combo_box_create (GTK_COMBO_BOX (combobox), FALSE);
     g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_refresh_rates_changed), builder);
 
     combobox = gtk_builder_get_object (builder, "randr-rotation");
-    display_settings_combo_box_create (GTK_COMBO_BOX (combobox));
+    display_settings_combo_box_create (GTK_COMBO_BOX (combobox), FALSE);
     g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_rotations_changed), builder);
 
     combobox = gtk_builder_get_object (builder, "randr-profile");

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list