[Xfce4-commits] [panel-plugins/xfce4-xkb-plugin] 02/17: Introduce new plugin style

noreply at xfce.org noreply at xfce.org
Sat Jun 10 14:31:35 CEST 2017


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

n   i   n   e   t   l   s       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 panel-plugins/xfce4-xkb-plugin.

commit d1689c7acb6dca933952c362d197020b37b07d33
Author: Viktor Odintsev <zakhams at gmail.com>
Date:   Wed Mar 15 17:09:39 2017 +0300

    Introduce new plugin style
---
 panel-plugin/xfce4-xkb-plugin-private.h |  2 +
 panel-plugin/xfce4-xkb-plugin.c         | 17 +++++++--
 panel-plugin/xfce4-xkb-plugin.h         |  3 +-
 panel-plugin/xkb-cairo.c                | 68 ++++++++++++++++++++++++++++++++-
 panel-plugin/xkb-cairo.h                | 40 +++++++++++--------
 panel-plugin/xkb-callbacks.c            | 12 +++++-
 panel-plugin/xkb-settings-dialog.c      |  3 +-
 panel-plugin/xkb-util.c                 | 29 +++++++++-----
 panel-plugin/xkb-util.h                 |  3 +-
 9 files changed, 143 insertions(+), 34 deletions(-)

diff --git a/panel-plugin/xfce4-xkb-plugin-private.h b/panel-plugin/xfce4-xkb-plugin-private.h
index c97bd03..98468dc 100644
--- a/panel-plugin/xfce4-xkb-plugin-private.h
+++ b/panel-plugin/xfce4-xkb-plugin-private.h
@@ -31,5 +31,7 @@ void            xfce_xkb_save_config        (XfcePanelPlugin *plugin,
 
 void            xkb_refresh_gui             (t_xkb *xkb);
 
+void            xkb_refresh_gui_and_size    (t_xkb *xkb);
+
 #endif
 
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 0486ab1..f3670de 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -356,16 +356,18 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
 {
     guint nrows;
     gint hsize, vsize;
+    gboolean proportional;
 
     nrows       = xfce_panel_plugin_get_nrows (xkb->plugin);
     panel_size /= nrows;
+    proportional = nrows > 1 || xkb->display_type == DISPLAY_TYPE_SYSTEM;
     TRACE ("calculate_sizes(%p: %d,%d)", xkb, panel_size, nrows);
 
     switch (orientation)
     {
         case GTK_ORIENTATION_HORIZONTAL:
             vsize = panel_size;
-            if (nrows > 1)
+            if (proportional)
             {
                 hsize = panel_size;
             }
@@ -378,7 +380,7 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
             break;
         case GTK_ORIENTATION_VERTICAL:
             hsize = panel_size;
-            if (nrows > 1)
+            if (proportional)
             {
                 vsize = panel_size;
             }
@@ -394,7 +396,8 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
             break;
     }
 
-    DBG ("size requested: h/v (%p: %d/%d)", xkb, hsize, vsize);
+    DBG ("size requested: h/v (%p: %d/%d), proportional: %d",
+            xkb, hsize, vsize, proportional);
 
     xkb_refresh_gui (xkb);
     return TRUE;
@@ -488,6 +491,14 @@ xkb_refresh_gui (t_xkb *xkb)
     }
 }
 
+void
+xkb_refresh_gui_and_size (t_xkb *xkb)
+{
+    xkb_calculate_sizes (xkb,
+            xfce_panel_plugin_get_orientation (xkb->plugin),
+            xfce_panel_plugin_get_size (xkb->plugin));
+}
+
 static void
 xfce_xkb_configure_layout (GtkWidget *widget,
                            gpointer user_data)
diff --git a/panel-plugin/xfce4-xkb-plugin.h b/panel-plugin/xfce4-xkb-plugin.h
index 2b1f778..2b1ecbb 100644
--- a/panel-plugin/xfce4-xkb-plugin.h
+++ b/panel-plugin/xfce4-xkb-plugin.h
@@ -39,7 +39,8 @@
 typedef enum
 {
     DISPLAY_TYPE_IMAGE = 0,
-    DISPLAY_TYPE_TEXT = 1
+    DISPLAY_TYPE_TEXT = 1,
+    DISPLAY_TYPE_SYSTEM = 2
 } t_display_type;
 
 typedef enum
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index ce79214..21deea5 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -184,7 +184,7 @@ xkb_cairo_draw_label (cairo_t *cr,
          actual_width, actual_height, variant_markers_count);
 
     layout = pango_cairo_create_layout (cr);
-    normalized_group_name = xkb_util_normalize_group_name (group_name);
+    normalized_group_name = xkb_util_normalize_group_name (group_name, FALSE);
 
     if (!normalized_group_name ||
         !g_utf8_validate (normalized_group_name, -1, NULL))
@@ -256,3 +256,69 @@ xkb_cairo_draw_label (cairo_t *cr,
     g_object_unref (layout);
 }
 
+void
+xkb_cairo_draw_label_system (cairo_t *cr,
+                             const gchar *group_name,
+                             const gint actual_width,
+                             const gint actual_height,
+                             const gint variant_markers_count,
+                             const PangoFontDescription *desc,
+                             const GdkRGBA rgba)
+{
+    gchar *normalized_group_name;
+    gint pango_width, pango_height;
+    double layoutx, layouty;
+    gint i;
+    double radius, diameter;
+    PangoLayout *layout;
+
+    g_assert (cr != NULL);
+
+    DBG ("actual width/height: %d/%d; markers: %d",
+         actual_width, actual_height, variant_markers_count);
+
+    layout = pango_cairo_create_layout (cr);
+    normalized_group_name = xkb_util_normalize_group_name (group_name, TRUE);
+
+    if (!normalized_group_name ||
+        !g_utf8_validate (normalized_group_name, -1, NULL))
+    {
+        g_object_unref (layout);
+        g_free (normalized_group_name);
+        return;
+    }
+
+    pango_layout_set_text (layout, normalized_group_name, -1);
+    pango_layout_set_font_description (layout, desc);
+
+    gdk_cairo_set_source_rgba (cr, &rgba);
+    pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
+    DBG ("pango_width/height: %d/%d", pango_width, pango_height);
+
+    layoutx = (double) (actual_width - pango_width) / 2;
+    layouty = (actual_height - pango_height) / 2;
+    radius = pango_height / 10;
+    diameter = 2 * radius;
+
+    DBG ("layout x/y: %.2f/%.2f, radius: %.2f", layoutx, layouty, radius);
+
+    cairo_move_to (cr, layoutx, layouty);
+    pango_cairo_show_layout (cr, layout);
+
+    for (i = 0; i < variant_markers_count; i++)
+    {
+        cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+        cairo_set_line_width (cr, 1);
+        cairo_arc (cr,
+                layoutx + (pango_width - (2 * variant_markers_count - 2) * diameter) / 2
+                    + 2 * diameter * i,
+                layouty + pango_height + radius,
+                radius, 0, 2 * G_PI
+        );
+        cairo_fill (cr);
+    }
+
+    g_free (normalized_group_name);
+    g_object_unref (layout);
+}
+
diff --git a/panel-plugin/xkb-cairo.h b/panel-plugin/xkb-cairo.h
index ec06b93..e9c77b9 100644
--- a/panel-plugin/xkb-cairo.h
+++ b/panel-plugin/xkb-cairo.h
@@ -32,23 +32,31 @@
 #include <cairo/cairo.h>
 #include <pango/pangocairo.h>
 
-void        xkb_cairo_draw_flag     (cairo_t *cr,
-                                     const gchar *flag_name,
-                                     gint actual_width,
-                                     gint actual_height,
-                                     gint variant_markers_count,
-                                     guint max_variant_markers_count,
-                                     guint img_scale,
-                                     guint text_scale,
-                                     GdkRGBA rgba);
+void        xkb_cairo_draw_flag         (cairo_t *cr,
+                                         const gchar *flag_name,
+                                         gint actual_width,
+                                         gint actual_height,
+                                         gint variant_markers_count,
+                                         guint max_variant_markers_count,
+                                         guint img_scale,
+                                         guint text_scale,
+                                         GdkRGBA rgba);
 
-void        xkb_cairo_draw_label    (cairo_t *cr,
-                                     const gchar *group_name,
-                                     const gint actual_width,
-                                     const gint actual_height,
-                                     const gint variant_markers_count,
-                                     const guint text_scale,
-                                     const GdkRGBA rgba);
+void        xkb_cairo_draw_label        (cairo_t *cr,
+                                         const gchar *group_name,
+                                         const gint actual_width,
+                                         const gint actual_height,
+                                         const gint variant_markers_count,
+                                         const guint text_scale,
+                                         const GdkRGBA rgba);
+
+void        xkb_cairo_draw_label_system (cairo_t *cr,
+                                         const gchar *group_name,
+                                         const gint actual_width,
+                                         const gint actual_height,
+                                         const gint variant_markers_count,
+                                         const PangoFontDescription *desc,
+                                         GdkRGBA rgba);
 
 #endif
 
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index 049ba20..0071dd3 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -79,6 +79,7 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
     GtkAllocation allocation;
     GtkStyleContext *style_ctx;
     GtkStateFlags state;
+    PangoFontDescription *desc;
     GdkRGBA rgba;
     gint actual_hsize, actual_vsize;
 
@@ -105,7 +106,7 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
                 rgba
         );
     }
-    else
+    else if (xkb->display_type == DISPLAY_TYPE_TEXT)
     {
         xkb_cairo_draw_label (cr, group_name,
                 actual_hsize, actual_vsize,
@@ -114,6 +115,15 @@ xkb_plugin_layout_image_draw (GtkWidget *widget,
                 rgba
         );
     }
+    else
+    {
+        gtk_style_context_get (style_ctx, state, "font", &desc, NULL);
+        xkb_cairo_draw_label_system (cr, group_name,
+                actual_hsize, actual_vsize,
+                xkb_config_variant_index_for_group (-1),
+                desc, rgba
+        );
+    }
 
     return FALSE;
 }
diff --git a/panel-plugin/xkb-settings-dialog.c b/panel-plugin/xkb-settings-dialog.c
index 53f0baa..0c1d5ea 100644
--- a/panel-plugin/xkb-settings-dialog.c
+++ b/panel-plugin/xkb-settings-dialog.c
@@ -82,7 +82,7 @@ static void
 on_display_type_changed (GtkComboBox *cb, t_xkb *xkb)
 {
     xkb->display_type = gtk_combo_box_get_active (cb);
-    xkb_refresh_gui (xkb);
+    xkb_refresh_gui_and_size (xkb);
 }
 
 static void
@@ -138,6 +138,7 @@ xfce_xkb_configure (XfcePanelPlugin *plugin,
     display_type_optmenu = gtk_combo_box_text_new ();
     gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (display_type_optmenu), _("image"));
     gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (display_type_optmenu), _("text"));
+    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (display_type_optmenu), _("system"));
     gtk_widget_set_size_request (display_type_optmenu, 230, -1);
     gtk_container_add (GTK_CONTAINER (bin), display_type_optmenu);
 
diff --git a/panel-plugin/xkb-util.c b/panel-plugin/xkb-util.c
index 3b7d9e1..7ea77e2 100644
--- a/panel-plugin/xkb-util.c
+++ b/panel-plugin/xkb-util.c
@@ -63,7 +63,7 @@ xkb_util_get_layout_string (const gchar *group_name, const gchar *variant)
 }
 
 gchar*
-xkb_util_normalize_group_name (const gchar* group_name)
+xkb_util_normalize_group_name (const gchar* group_name, const gboolean capitalize)
 {
     const gchar *c;
     gchar *result;
@@ -73,21 +73,30 @@ xkb_util_normalize_group_name (const gchar* group_name)
     if (!group_name)
         return NULL;
 
-    if (strlen (group_name) <= 3)
-        return g_strdup (group_name);
+    cut_length = strlen (group_name);
 
-    for (c = group_name; *c; c++)
+    if (cut_length > 3)
     {
-        if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z')))
+        for (c = group_name; *c; c++)
         {
-            index_of_na = c - group_name;
-            break;
+            if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z')))
+            {
+                index_of_na = c - group_name;
+                break;
+            }
         }
-    }
 
-    cut_length = (index_of_na != -1 && index_of_na <= 3) ? index_of_na : 3;
+        cut_length = (index_of_na != -1 && index_of_na <= 3) ? index_of_na : 3;
+    }
 
-    result = g_strndup (group_name, cut_length);
+    if (capitalize)
+    {
+        result = g_ascii_strup (group_name, cut_length);
+    }
+    else
+    {
+        result = g_strndup (group_name, cut_length);
+    }
 
     return result;
 }
diff --git a/panel-plugin/xkb-util.h b/panel-plugin/xkb-util.h
index 92cc9ca..08130aa 100644
--- a/panel-plugin/xkb-util.h
+++ b/panel-plugin/xkb-util.h
@@ -34,7 +34,8 @@ gchar*      xkb_util_get_flag_filename      (const gchar* group_name);
 
 gchar*      xkb_util_get_layout_string      (const gchar* group_name,
                                              const gchar* variant);
-gchar*      xkb_util_normalize_group_name   (const gchar* group_name);
+gchar*      xkb_util_normalize_group_name   (const gchar* group_name,
+                                             const gboolean capitalize);
 
 #endif
 

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


More information about the Xfce4-commits mailing list