[Xfce4-commits] <xfce4-xkb-plugin:4.10_panel_support> Compatibility with 4.10 panel

Igor Slepchin noreply at xfce.org
Wed Mar 27 00:12:16 CET 2013


Updating branch refs/heads/4.10_panel_support
         to 71a87726f0cbbad1df2143c7f84d885a1b6df7e9 (commit)
       from 964fcb1cd2aa57c2d92cd6ab0591618eb85643dd (commit)

commit 71a87726f0cbbad1df2143c7f84d885a1b6df7e9
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date:   Mon Mar 25 16:42:19 2013 -0400

    Compatibility with 4.10 panel
    
    The xkb plugin now always occupies one row only (xfce_panel_plugin_set_small).
    If the panel has only one row, the plugin requests a rectangular shape
    (just as it used to); with more than one panel row, the plugin
    will be the "standard" square so as to better blend in with other
    plugins at the expense of having smaller display area.
    
    Bug 8762
    (largely cherry picked from commit b8861cade0f00d2443358a43af8826b170673175)

 panel-plugin/xfce4-xkb-plugin.c |   29 +++++++++++++++++++++++++++--
 panel-plugin/xkb-cairo.c        |    4 +++-
 panel-plugin/xkb-callbacks.c    |   25 +++++++++++++++++++------
 panel-plugin/xkb-config.c       |    9 ++++-----
 4 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index 2afc9bb..879346b 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -90,6 +90,8 @@ xfce_xkb_construct (XfcePanelPlugin *plugin)
     t_xkb *xkb = xkb_new (plugin);
     xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
 
+    xfce_panel_plugin_set_small (plugin, TRUE);
+
     g_signal_connect (plugin, "orientation-changed",
             G_CALLBACK (xfce_xkb_orientation_changed), xkb);
 
@@ -179,6 +181,7 @@ xkb_new (XfcePanelPlugin *plugin)
     gtk_button_set_relief (GTK_BUTTON (xkb->btn), GTK_RELIEF_NONE);
     gtk_container_add (GTK_CONTAINER (xkb->plugin), xkb->btn);
     xfce_panel_plugin_add_action_widget (xkb->plugin, xkb->btn);
+    xkb->button_state = GTK_STATE_NORMAL;
 
     gtk_widget_show (xkb->btn);
     g_signal_connect (xkb->btn, "clicked", G_CALLBACK (xkb_plugin_button_clicked), xkb);
@@ -335,17 +338,37 @@ xkb_load_default (t_xkb *xkb)
 static gboolean
 xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
 {
+    guint nrows;
+
+    nrows       = xfce_panel_plugin_get_nrows (xkb->plugin);
+    panel_size /= nrows;
+    TRACE ("calculate_sizes(%p: %d,%d)", xkb, panel_size, nrows);
 
     switch (orientation)
     {
         case GTK_ORIENTATION_HORIZONTAL:
             xkb->vsize = panel_size;
-            xkb->hsize = (int) (1.33 * panel_size);
+            if (nrows > 1)
+            {
+                xkb->hsize = xkb->vsize;
+            }
+            else
+            {
+                xkb->hsize = (int) (1.33 * panel_size);
+            }
+
             gtk_widget_set_size_request (xkb->btn, xkb->hsize, xkb->vsize);
             break;
         case GTK_ORIENTATION_VERTICAL:
             xkb->hsize = panel_size;
-            xkb->vsize = (int) (0.75 * panel_size);
+            if (nrows > 1)
+            {
+                xkb->vsize = xkb->hsize;
+            }
+            else
+            {
+                xkb->vsize = (int) (0.75 * panel_size);
+            }
             if (xkb->vsize < 10) xkb->vsize = 10;
             gtk_widget_set_size_request (xkb->btn, xkb->hsize, xkb->vsize);
             break;
@@ -353,6 +376,8 @@ xkb_calculate_sizes (t_xkb *xkb, GtkOrientation orientation, gint panel_size)
             break;
     }
 
+    DBG ("size requested: h/v (%p: %d/%d)", xkb, xkb->hsize, xkb->vsize);
+
     xkb_refresh_gui (xkb);
     return TRUE;
 }
diff --git a/panel-plugin/xkb-cairo.c b/panel-plugin/xkb-cairo.c
index 9c80444..8a3a4ef 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -119,6 +119,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
         cairo_stroke (cr);
     }
 
+    rsvg_handle_close (handle, NULL);
     g_object_unref (handle);
 }
 
@@ -150,7 +151,8 @@ xkb_cairo_draw_label (cairo_t *cr,
     layout = pango_cairo_create_layout (cr);
     normalized_group_name = xkb_util_normalize_group_name (group_name);
 
-    if (!g_utf8_validate (normalized_group_name, -1, NULL))
+    if (!normalized_group_name ||
+        !g_utf8_validate (normalized_group_name, -1, NULL))
     {
         g_object_unref (layout);
         g_free (normalized_group_name);
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index 36e5375..e8f6d6e 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -74,6 +74,9 @@ xkb_plugin_button_size_allocated (GtkWidget *button,
 {
     xkb->button_hsize = allocation->width;
     xkb->button_vsize = allocation->height;
+
+    DBG ("size_allocated: h/v (%p: %d/%d)",
+         xkb, xkb->button_hsize, xkb->button_vsize);
 }
 
 gboolean
@@ -103,23 +106,33 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
     cairo_t *cr;
     GtkStyle *style;
     GdkColor fgcolor;
-    gint actual_hsize, actual_vsize;
+    gint actual_hsize, actual_vsize, panel_size;
+    gint vsize;
 
     actual_hsize = (xkb->button_hsize > xkb->hsize) ? xkb->button_hsize : xkb->hsize;
     actual_vsize = (xkb->button_vsize > xkb->vsize) ? xkb->button_vsize : xkb->vsize;
 
-    cr = gdk_cairo_create ((GTK_WIDGET (xkb->layout_image))->window);
+    vsize = MIN (xkb->vsize, (int) (xkb->hsize * 0.75));
+
+    panel_size   = xfce_panel_plugin_get_size (xkb->plugin);
+    panel_size  /= xfce_panel_plugin_get_nrows (xkb->plugin);
 
     style = gtk_widget_get_style (GTK_WIDGET (xkb->btn));
     fgcolor = style->fg[xkb->button_state];
     group_name = xkb_config_get_group_name (-1);
 
+    DBG ("img_exposed: actual h/v (%d/%d), xkb h/v (%d/%d), panel sz (%d)",
+         actual_hsize, actual_vsize,
+         xkb->hsize, xkb->vsize, panel_size);
+
+    cr = gdk_cairo_create ((GTK_WIDGET (xkb->layout_image))->window);
+
     if (xkb->display_type == DISPLAY_TYPE_IMAGE)
     {
         xkb_cairo_draw_flag (cr, group_name,
-                xfce_panel_plugin_get_size (xkb->plugin),
+                panel_size,
                 actual_hsize, actual_vsize,
-                xkb->hsize, xkb->vsize,
+                xkb->hsize, vsize,
                 xkb_config_variant_index_for_group (-1),
                 xkb->display_textsize,
                 fgcolor
@@ -128,9 +141,9 @@ xkb_plugin_layout_image_exposed (GtkWidget *widget,
     else
     {
         xkb_cairo_draw_label (cr, group_name,
-                xfce_panel_plugin_get_size (xkb->plugin),
+                panel_size,
                 actual_hsize, actual_vsize,
-                xkb->hsize, xkb->vsize,
+                xkb->hsize, vsize,
                 xkb_config_variant_index_for_group (-1),
                 xkb->display_textsize,
                 fgcolor
diff --git a/panel-plugin/xkb-config.c b/panel-plugin/xkb-config.c
index b2199b7..08ba9c2 100644
--- a/panel-plugin/xkb-config.c
+++ b/panel-plugin/xkb-config.c
@@ -293,6 +293,8 @@ xkb_config_update_settings (t_xkb_settings *settings)
 
     gchar **opt;
     gchar **prefix;
+    gchar *tmp1, *tmp2;
+    int i;
 
     g_assert (config != NULL);
     g_assert (settings != NULL);
@@ -318,9 +320,8 @@ xkb_config_update_settings (t_xkb_settings *settings)
         /* XklConfigRec uses for NULL for empty variant instead of "".
          * So if has skipped variants we can't get proper settings->kbd_config->variants.
          * So I use this hack to get proper kbd_config->variants */
-        gchar *tmp1 = g_strdup("");
-        gchar *tmp2 = NULL;
-        int i;
+        tmp1 = g_strdup("");
+        tmp2 = NULL;
         for (i = 0; config->config_rec->layouts[i]; i++)
         {
             tmp2 = g_strconcat (tmp1, config->config_rec->variants[i] ? config->config_rec->variants[i] : "", NULL);
@@ -407,7 +408,6 @@ xkb_config_window_changed (guint new_window_id, guint application_id)
     gpointer key, value;
     GHashTable *hashtable;
     guint id;
-    gint DEBUG_FOUND = 0;
 
     g_assert (config != NULL);
 
@@ -437,7 +437,6 @@ xkb_config_window_changed (guint new_window_id, guint application_id)
     if (g_hash_table_lookup_extended (hashtable, GINT_TO_POINTER (id), &key, &value))
     {
         group = GPOINTER_TO_INT (value);
-        DEBUG_FOUND = 1;
     }
 
     g_hash_table_insert (


More information about the Xfce4-commits mailing list