[Xfce4-commits] <xfce4-xkb-plugin:master> Compatibility with 4.10 panel
Igor Slepchin
noreply at xfce.org
Wed Mar 20 18:48:02 CET 2013
Updating branch refs/heads/master
to b8861cade0f00d2443358a43af8826b170673175 (commit)
from 9a4599dfe96247d0b3095aeec085b7c8e669545a (commit)
commit b8861cade0f00d2443358a43af8826b170673175
Author: Igor Slepchin <igor.slepchin at gmail.com>
Date: Fri Mar 15 17:29:23 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
panel-plugin/xfce4-xkb-plugin.c | 29 +++++++++++++-
panel-plugin/xkb-cairo.c | 80 ++++++++++++++++++++++++++++++--------
panel-plugin/xkb-callbacks.c | 25 +++++++++---
3 files changed, 109 insertions(+), 25 deletions(-)
diff --git a/panel-plugin/xfce4-xkb-plugin.c b/panel-plugin/xfce4-xkb-plugin.c
index e9b1233..a485ea5 100644
--- a/panel-plugin/xfce4-xkb-plugin.c
+++ b/panel-plugin/xfce4-xkb-plugin.c
@@ -101,6 +101,8 @@ xfce_xkb_construct (XfcePanelPlugin *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);
@@ -210,6 +212,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);
@@ -322,17 +325,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;
@@ -340,6 +363,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..ff1f5e9 100644
--- a/panel-plugin/xkb-cairo.c
+++ b/panel-plugin/xkb-cairo.c
@@ -27,7 +27,7 @@
#include "xkb-util.h"
#include "xfce4-xkb-plugin.h"
-#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold %d"
+#define XKB_PREFERRED_FONT "Courier New, Courier 10 Pitch, Monospace Bold %dpx"
#define xkb_cairo_arc_for_flag(cr, x, y, r, a1, a2) \
xx = layoutx + width - 12 + x; \
@@ -119,6 +119,7 @@ xkb_cairo_draw_flag (cairo_t *cr,
cairo_stroke (cr);
}
+ rsvg_handle_close (handle, NULL);
g_object_unref (handle);
}
@@ -135,12 +136,13 @@ xkb_cairo_draw_label (cairo_t *cr,
GdkColor fgcolor)
{
gchar *normalized_group_name;
- gchar font_str[80];
+ /* gchar font_str[80]; */
gint pango_width, pango_height;
- gint layoutx, layouty;
+ double layoutx, layouty;
double xx, yy;
+ double scalex, scaley;
gint i;
- gint radius;
+ double radius;
PangoLayout *layout;
PangoFontDescription *desc;
@@ -150,7 +152,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);
@@ -158,39 +161,82 @@ xkb_cairo_draw_label (cairo_t *cr,
}
pango_layout_set_text (layout, normalized_group_name, -1);
+ /* switch (textsize){ */
+ /* case DISPLAY_TEXTSIZE_SMALL: */
+ /* default: /\* catch misconfiguration *\/ */
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.475 * panel_size) ); */
+ /* break; */
+ /* case DISPLAY_TEXTSIZE_MEDIUM: */
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.700 * panel_size) ); */
+ /* break; */
+ /* case DISPLAY_TEXTSIZE_LARGE: */
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(1.000 * panel_size) ); */
+ /* break; */
+ /* } */
+
+ /* DBG ("font: %s", font_str); */
+
+ // desc = pango_font_description_from_string (font_str);
+ desc = pango_font_description_from_string( "Courier New, Courier 10 Pitch, Monospace Bold" );
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+
+ gdk_cairo_set_source_color (cr, &fgcolor);
+ pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
+
+ /* layoutx = (int) (actual_width - (pango_width + variant_markers_count * 7)) / 2; */
+ /* layouty = (int) (actual_height - pango_height) / 2; */
+
+ /* layoutx = layouty = 0; */
+
+
+ scalex = (float)actual_width / (pango_width + variant_markers_count * 7);
+ scaley = (float)actual_height / pango_height;
+
switch (textsize){
case DISPLAY_TEXTSIZE_SMALL:
default: /* catch misconfiguration */
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.375 * panel_size) );
+ scalex *= 0.475;
+ scaley *= 0.475;
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.475 * panel_size) ); */
break;
case DISPLAY_TEXTSIZE_MEDIUM:
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.600 * panel_size) );
+ scalex *= 0.7;
+ scaley *= 0.7;
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.700 * panel_size) ); */
break;
case DISPLAY_TEXTSIZE_LARGE:
- g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(0.900 * panel_size) );
+ /* g_sprintf (font_str, XKB_PREFERRED_FONT, (int)(1.000 * panel_size) ); */
break;
}
- desc = pango_font_description_from_string (font_str);
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
- gdk_cairo_set_source_color (cr, &fgcolor);
- pango_layout_get_pixel_size (layout, &pango_width, &pango_height);
+ pango_width *= scalex;
+ pango_height *= scaley;
+ radius = (pango_height < 32) ? 1.5 : 2.5;
+ layoutx = (actual_width - (pango_width + variant_markers_count * 2*radius)) / 2;
+ layouty = (actual_height - pango_height) / 2;
- layoutx = (int) (actual_width - (pango_width + variant_markers_count * 7)) / 2;
- layouty = (int) (actual_height - pango_height) / 2;
+ DBG ("scaled pango_width/height: %d/%d", pango_width, pango_height);
+ DBG ("layout x/y: %.2f/%.2f scale x/y: %.2f/%.2f, radius: %.2f",
+ layoutx, layouty, scalex, scaley, radius);
xkb_cairo_move_to (cr, layoutx, layouty);
+ cairo_save (cr);
+ cairo_scale (cr, scalex, scaley);
pango_cairo_show_layout (cr, layout);
+ cairo_restore (cr);
+ /* cairo_scale (cr, 1/scalex, 1/scaley); */
for (i = 0; i < variant_markers_count; i++)
{
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_width (cr, 1);
- radius = (panel_size < 32) ? 1.5 : 2.5;
+ /* radius = (panel_size < 32) ? 1.5 : 2.5; */
+ /* if (scalex < 1.0) */
+ /* radius *= scalex; */
xkb_cairo_arc_for_label (cr,
- layoutx + pango_width + 3 + (7 * i),
+ layoutx + pango_width + 3 + (2*radius * i),
layouty + pango_height - (pango_height / 5),
radius, 0, 2 * G_PI
);
diff --git a/panel-plugin/xkb-callbacks.c b/panel-plugin/xkb-callbacks.c
index ee7c056..179276d 100644
--- a/panel-plugin/xkb-callbacks.c
+++ b/panel-plugin/xkb-callbacks.c
@@ -77,6 +77,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
@@ -106,23 +109,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
@@ -131,9 +144,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
More information about the Xfce4-commits
mailing list