[Xfce4-commits] [panel-plugins/xfce4-xkb-plugin] 01/02: Bug 11681: Allow adjusting flag sizes

noreply at xfce.org noreply at xfce.org
Tue Jun 30 20:30:16 CEST 2015


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

igor pushed a commit to branch master
in repository panel-plugins/xfce4-xkb-plugin.

commit df86d1490a4491fe29056a5a1ee10093d5a9e146
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Tue Mar 31 18:40:12 2015 -0400

    Bug 11681: Allow adjusting flag sizes
    
    While at it, use a slider for adjusting text sizes too.
---
 panel-plugin/xfce4-xkb-plugin.c    |   37 +++++++++++++--
 panel-plugin/xfce4-xkb-plugin.h    |    3 +-
 panel-plugin/xkb-cairo.c           |   89 +++++++++++++++++++++++++++---------
 panel-plugin/xkb-cairo.h           |    6 ++-
 panel-plugin/xkb-callbacks.c       |    6 ++-
 panel-plugin/xkb-config.c          |    6 ++-
 panel-plugin/xkb-config.h          |    1 +
 panel-plugin/xkb-settings-dialog.c |   42 ++++++++++++-----
 8 files changed, 146 insertions(+), 44 deletions(-)

diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 52a1e96..2d24f4e 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -42,6 +42,9 @@
 #include "xkb-cairo.h"
 #include "xkb-callbacks.h"
 
+#define DISPLAY_TEXTSCALE_LARGE 100
+#define DISPLAY_IMGSCALE_LARGE  100
+
 /* ------------------------------------------------------------------ *
  *                     Panel Plugin Interface                         *
  * ------------------------------------------------------------------ */
@@ -288,7 +291,8 @@ xfce_xkb_save_config (XfcePanelPlugin *plugin, t_xkb *xkb)
     xfce_rc_set_group (rcfile, NULL);
 
     xfce_rc_write_int_entry (rcfile, "display_type", xkb->display_type);
-    xfce_rc_write_int_entry (rcfile, "display_textsize", xkb->display_textsize);
+    xfce_rc_write_int_entry (rcfile, "display_textscale", xkb->display_text_scale);
+    xfce_rc_write_int_entry (rcfile, "display_imgscale", xkb->display_img_scale);
     xfce_rc_write_int_entry (rcfile, "group_policy", xkb->group_policy);
 
     xfce_rc_close (rcfile);
@@ -299,12 +303,34 @@ static gboolean
 xkb_load_config (t_xkb *xkb, const gchar *filename)
 {
     XfceRc* rcfile;
+    gint text_scale;
+
     if ((rcfile = xfce_rc_simple_open (filename, TRUE)))
     {
         xfce_rc_set_group (rcfile, NULL);
 
         xkb->display_type = xfce_rc_read_int_entry (rcfile, "display_type", DISPLAY_TYPE_IMAGE);
-        xkb->display_textsize = xfce_rc_read_int_entry (rcfile, "display_textsize", DISPLAY_TEXTSIZE_LARGE);
+        text_scale = xfce_rc_read_int_entry (rcfile, "display_textscale", -1);
+        if (text_scale < 0)
+        {
+            /* Check if the old textsize value is there */
+            text_scale = xfce_rc_read_int_entry (rcfile, "display_textsize", -1);
+            switch (text_scale)
+            {
+            case DISPLAY_TEXTSIZE_SMALL:
+                text_scale = 47;
+                break;
+            case DISPLAY_TEXTSIZE_MEDIUM:
+                text_scale = 70;
+                break;
+            case DISPLAY_TEXTSIZE_LARGE:
+            default:
+                text_scale = DISPLAY_TEXTSCALE_LARGE;
+                break;
+            }
+        }
+        xkb->display_text_scale = text_scale;
+        xkb->display_img_scale = xfce_rc_read_int_entry (rcfile, "display_imgscale", DISPLAY_IMGSCALE_LARGE);
         xkb->group_policy = xfce_rc_read_int_entry (rcfile, "group_policy", GROUP_POLICY_PER_APPLICATION);
 
         xfce_rc_close (rcfile);
@@ -318,9 +344,10 @@ xkb_load_config (t_xkb *xkb, const gchar *filename)
 static void
 xkb_load_default (t_xkb *xkb)
 {
-    xkb->display_type = DISPLAY_TYPE_IMAGE;
-    xkb->display_textsize = DISPLAY_TEXTSIZE_LARGE;
-    xkb->group_policy = GROUP_POLICY_PER_APPLICATION;
+    xkb->display_type       = DISPLAY_TYPE_IMAGE;
+    xkb->display_text_scale = DISPLAY_TEXTSCALE_LARGE;
+    xkb->display_img_scale  = DISPLAY_IMGSCALE_LARGE;
+    xkb->group_policy       = GROUP_POLICY_PER_APPLICATION;
 }
 
 static gboolean
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h
index 68f6c8a..372a27a 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xfce4-xkb-plugin.h
@@ -60,7 +60,8 @@ typedef struct
     gint button_vsize;            /* read allocated button size - see below */
 
     t_display_type display_type;  /* display layout as image ot text */
-    t_display_textsize display_textsize; /* text size for text layout */
+    guint display_text_scale; /* text scale % for text layout */
+    guint display_img_scale;  /* image scale % for flag layout */
     t_group_policy group_policy;     /* per-app/window/global policy */
 
     gint button_state;            /* gtk state of the button */
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index 27ad119..27454f3 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -34,8 +34,7 @@
 #define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold"
 
 #define xkb_cairo_arc_for_flag(cr, x, y, r, a1, a2) \
-    xx = layoutx + width - 12 + x; \
-    yy = layouty + height - 12 + y; \
+    xx = x; yy = y; \
     cairo_device_to_user (cr, &xx, &yy); \
     cairo_arc (cr, xx, yy, r, a1, a2);
 
@@ -59,7 +58,9 @@ xkb_cairo_draw_flag (cairo_t *cr,
                      gint width,
                      gint height,
                      gint variant_markers_count,
-                     gint textsize,
+                     guint max_variant_markers_count,
+                     guint img_scale,
+                     guint text_scale,
                      GdkColor fgcolor)
 {
     gchar *filename;
@@ -68,7 +69,9 @@ xkb_cairo_draw_flag (cairo_t *cr,
     double scalex, scaley;
     double xx, yy;
     gint i;
-    double layoutx, layouty;
+    double layoutx, layouty, img_width, img_height;
+    double radius, diameter;
+    guint spacing;
 
     g_assert (cr != NULL);
 
@@ -86,7 +89,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
                 actual_width, actual_height,
                 width, height,
                 variant_markers_count,
-                textsize,
+                text_scale,
                 fgcolor);
         return;
     }
@@ -96,8 +99,17 @@ xkb_cairo_draw_flag (cairo_t *cr,
     scalex = (double) (width - 4) / dim.width;
     scaley = (double) (height - 4) / dim.height;
 
-    layoutx = (actual_width - width) / 2 + 2;
-    layouty = (actual_height - height) / 2 + 2;
+    scalex *= img_scale / 100.0;
+    scaley *= img_scale / 100.0;
+
+    img_width  = dim.width * scalex;
+    img_height = dim.height * scaley;
+
+    DBG ("scale x/y: %.3f/%.3f, dim w/h: %d/%d, scaled w/h: %.1f/%.1f",
+         scalex, scaley, dim.width, dim.height, scalex*dim.width, scaley*dim.height);
+
+    layoutx = (actual_width - img_width) / 2;
+    layouty = (actual_height - img_height) / 2;
     cairo_translate (cr, layoutx, layouty);
 
     cairo_save (cr);
@@ -107,15 +119,59 @@ xkb_cairo_draw_flag (cairo_t *cr,
 
     cairo_restore (cr);
 
+    DBG ("actual width/height: %d/%d; w/h: %d/%d; img w/h: %.1f/%.1f; markers: %d, max markers: %d",
+         actual_width, actual_height, width, height, img_width, img_height,
+         variant_markers_count, max_variant_markers_count);
+    DBG ("layout x/y: %.1f/%.1f", layoutx, layouty);
+
+    if (variant_markers_count > 0)
+    {
+        diameter = 5.0;
+        spacing = 1;
+
+        /* check if the flag is too small to draw variant markers inside it */
+        if ((diameter + spacing) * (max_variant_markers_count-1) > img_width - 2)
+        {
+            /* draw markers below the flag */
+            diameter = 4;
+            spacing  = 0;
+            layoutx  = actual_width / 2 + (max_variant_markers_count - 2) * diameter / 2;
+            layouty  = (actual_height + img_height) / 2 + diameter + 1;
+            DBG ("small flag");
+        }
+        else
+        {
+            /* draw markers inside the flag */
+            spacing  = 1;
+            layoutx += img_width  - diameter / 2 - 1;
+            layouty += img_height - diameter / 2 - 1;
+            DBG ("large flag");
+        }
+
+        radius = diameter / 2.0;
+
+        if (layouty > actual_height - radius)
+            layouty = actual_height - radius;
+        if (layoutx > actual_width - radius)
+            layoutx = actual_width - radius;
+    }
+
     /* draw variant_markers_count circles */
     for (i = 0; i < variant_markers_count; i++)
     {
+        gint x, y;
+
         cairo_set_source_rgb (cr, 0, 0, 0);
 
         cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
         cairo_set_line_width (cr, 1);
 
-        xkb_cairo_arc_for_flag (cr, -(7 * i) + 4, 4, 2.5, 0, 2 * G_PI);
+        x = layoutx - (diameter + spacing) * i + 0.5;
+        y = layouty;
+
+        DBG ("variant center x/y: %d/%d, diameter: %.1f, spacing: %d",
+             x, y, diameter, spacing);
+        xkb_cairo_arc_for_flag (cr, x, y, radius, 0, 2 * G_PI);
 
         cairo_set_source_rgb (cr, 0, 0, 0);
         cairo_fill_preserve (cr);
@@ -136,7 +192,7 @@ xkb_cairo_draw_label (cairo_t *cr,
                       const gint width,
                       const gint height,
                       const gint variant_markers_count,
-                      const gint textsize,
+                      const guint text_scale,
                       const GdkColor fgcolor)
 {
     gchar *normalized_group_name;
@@ -176,18 +232,7 @@ xkb_cairo_draw_label (cairo_t *cr,
     pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
     DBG ("pango_width/height: %d/%d", pango_width, pango_height);
 
-    switch (textsize){
-        case DISPLAY_TEXTSIZE_SMALL:
-        default:    /* catch misconfiguration */
-            scalex = scaley = 0.475;
-            break;
-        case DISPLAY_TEXTSIZE_MEDIUM:
-            scalex = scaley = 0.7;
-            break;
-        case DISPLAY_TEXTSIZE_LARGE:
-            scalex = scaley = 1;
-            break;
-    }
+    scalex = scaley = text_scale / 100.0;
 
     DBG ("txt size scale x/y: %.2f/%.2f", scalex, scaley);
 
@@ -201,7 +246,7 @@ xkb_cairo_draw_label (cairo_t *cr,
     {
         text_width = actual_width - 3 - (variant_markers_count) * diameter;
     }
-    else if (textsize == DISPLAY_TEXTSIZE_LARGE)
+    else if (text_scale >= 99.5)
     {
         text_width -= 3;
     }
diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h
index 4be2b24..fbac467 100644
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -41,7 +41,9 @@ void        xkb_cairo_draw_flag     (cairo_t *cr,
                                      gint width,
                                      gint height,
                                      gint variant_markers_count,
-                                     gint textsize,
+                                     guint max_variant_markers_count,
+                                     guint img_scale,
+                                     guint text_scale,
                                      GdkColor fgcolor);
 
 void        xkb_cairo_draw_label    (cairo_t *cr,
@@ -52,7 +54,7 @@ void        xkb_cairo_draw_label    (cairo_t *cr,
                                      const gint width,
                                      const gint height,
                                      const gint variant_markers_count,
-                                     const gint textsize,
+                                     const guint text_scale,
                                      const GdkColor fgcolor);
 
 #endif
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index 179276d..3453c62 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -137,7 +137,9 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
                 actual_hsize, actual_vsize,
                 xkb->hsize, vsize,
                 xkb_config_variant_index_for_group (-1),
-                xkb->display_textsize,
+                xkb_config_get_max_group_count (),
+                xkb->display_img_scale,
+                xkb->display_text_scale,
                 fgcolor
         );
     }
@@ -148,7 +150,7 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
                 actual_hsize, actual_vsize,
                 xkb->hsize, vsize,
                 xkb_config_variant_index_for_group (-1),
-                xkb->display_textsize,
+                xkb->display_text_scale,
                 fgcolor
         );
     }
diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c
index 70fc426..b7234d2 100644
--- a/panel-plugin/xkb-config.c
+++ b/panel-plugin/xkb-config.c
@@ -456,7 +456,6 @@ xkb_config_window_closed (guint window_id)
     }
 }
 
-
 gint
 xkb_config_get_group_count (void)
 {
@@ -465,6 +464,11 @@ xkb_config_get_group_count (void)
     return config->group_count;
 }
 
+guint xkb_config_get_max_group_count (void)
+{
+    return xkl_engine_get_max_num_groups(config->engine);
+}
+
 const gchar*
 xkb_config_get_group_name (gint group)
 {
diff --git a/panel-plugin/xkb-config.h b/panel-plugin/xkb-config.h
index 69888d3..072adca 100644
--- a/panel-plugin/xkb-config.h
+++ b/panel-plugin/xkb-config.h
@@ -52,6 +52,7 @@ gboolean          xkb_config_initialize                   (t_group_policy group_
 void              xkb_config_finalize                     (void);
 void              xkb_config_set_group_policy             (t_group_policy group_policy);
 gint              xkb_config_get_group_count              (void);
+guint             xkb_config_get_max_group_count          (void);
 const gchar*      xkb_config_get_group_name               (gint group);
 const gchar*      xkb_config_get_variant                  (gint group);
 gboolean          xkb_config_set_group                    (gint group);
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index d155bdb..2431773 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -86,9 +86,16 @@ on_display_type_changed (GtkComboBox *cb, t_xkb *xkb)
 }
 
 static void
-on_display_textsize_changed (GtkComboBox *cb, t_xkb *xkb)
+on_display_textsize_changed (GtkHScale *scale, t_xkb *xkb)
 {
-    xkb->display_textsize = gtk_combo_box_get_active (cb);
+    xkb->display_text_scale = gtk_range_get_value (GTK_RANGE (scale));
+    xkb_refresh_gui (xkb);
+}
+
+static void
+on_display_imgsize_changed (GtkHScale *scale, t_xkb *xkb)
+{
+    xkb->display_img_scale = gtk_range_get_value (GTK_RANGE (scale));
     xkb_refresh_gui (xkb);
 }
 
@@ -105,7 +112,8 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
 {
     GtkWidget *display_type_optmenu, *group_policy_combo;
     GtkWidget *vbox, *display_type_frame, *group_policy_frame, *bin;
-    GtkWidget *display_textsize_frame, *display_textsize_optmenu;
+    GtkWidget *display_textsize_frame, *display_textsize_scale;
+    GtkWidget *display_imgsize_frame, *display_imgsize_scale;
 
     xfce_panel_plugin_block_menu (plugin);
 
@@ -134,12 +142,22 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
     gtk_widget_show (display_textsize_frame);
     gtk_box_pack_start (GTK_BOX (vbox), display_textsize_frame, TRUE, TRUE, 2);
 
-    display_textsize_optmenu = gtk_combo_box_new_text ();
-    gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("small"));
-    gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("medium"));
-    gtk_combo_box_append_text (GTK_COMBO_BOX (display_textsize_optmenu), _("large"));
-    gtk_widget_set_size_request (display_textsize_optmenu, 230, -1);
-    gtk_container_add (GTK_CONTAINER (bin), display_textsize_optmenu);
+    display_textsize_scale = gtk_hscale_new_with_range (0, 100, 1);
+    gtk_range_set_update_policy (GTK_RANGE (display_textsize_scale), GTK_UPDATE_CONTINUOUS);
+    gtk_scale_set_value_pos (GTK_SCALE (display_textsize_scale), GTK_POS_RIGHT);
+    gtk_widget_set_size_request (display_textsize_scale, 230, -1);
+    gtk_container_add (GTK_CONTAINER (bin), display_textsize_scale);
+
+    /* image size option */
+    display_imgsize_frame = xfce_gtk_frame_box_new (_("Image size:"), &bin);
+    gtk_widget_show (display_imgsize_frame);
+    gtk_box_pack_start (GTK_BOX (vbox), display_imgsize_frame, TRUE, TRUE, 2);
+
+    display_imgsize_scale = gtk_hscale_new_with_range (0, 100, 1);
+    gtk_range_set_update_policy (GTK_RANGE (display_imgsize_scale), GTK_UPDATE_CONTINUOUS);
+    gtk_scale_set_value_pos (GTK_SCALE (display_imgsize_scale), GTK_POS_RIGHT);
+    gtk_widget_set_size_request (display_imgsize_scale, 230, -1);
+    gtk_container_add (GTK_CONTAINER (bin), display_imgsize_scale);
 
     group_policy_frame = xfce_gtk_frame_box_new (_("Manage layout:"), &bin);
     gtk_widget_show (group_policy_frame);
@@ -159,12 +177,14 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
             G_CALLBACK (on_settings_close), xkb);
 
     gtk_combo_box_set_active (GTK_COMBO_BOX (display_type_optmenu), xkb->display_type);
-    gtk_combo_box_set_active (GTK_COMBO_BOX (display_textsize_optmenu), xkb->display_textsize);
+    gtk_range_set_value (GTK_RANGE (display_textsize_scale), xkb->display_text_scale);
+    gtk_range_set_value (GTK_RANGE (display_imgsize_scale), xkb->display_img_scale);
     gtk_combo_box_set_active (GTK_COMBO_BOX (group_policy_combo), xkb->group_policy);
 
     g_signal_connect (display_type_optmenu, "changed", G_CALLBACK (on_display_type_changed), xkb);
     g_signal_connect (group_policy_combo, "changed", G_CALLBACK (on_group_policy_changed), xkb);
-    g_signal_connect (display_textsize_optmenu, "changed", G_CALLBACK (on_display_textsize_changed), xkb);
+    g_signal_connect (display_textsize_scale, "value_changed", G_CALLBACK (on_display_textsize_changed), xkb);
+    g_signal_connect (display_imgsize_scale, "value_changed", G_CALLBACK (on_display_imgsize_changed), xkb);
 
     gtk_widget_show (settings_dialog);
 }

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


More information about the Xfce4-commits mailing list