[Xfce4-commits] <xfce4-weather-plugin:master> Better handling of vertical and deskbar modes (bug #8560).
Harald Judt
noreply at xfce.org
Tue Jul 3 00:06:01 CEST 2012
Updating branch refs/heads/master
to 09c4ffec8b218d6851772dfcbeedf9804631e179 (commit)
from eacbc3436a817351760fecdc2e4e57295954c0f6 (commit)
commit 09c4ffec8b218d6851772dfcbeedf9804631e179
Author: Harald Judt <h.judt at gmx.at>
Date: Mon Jul 2 14:58:08 2012 +0200
Better handling of vertical and deskbar modes (bug #8560).
This introduces support for the new deskbar mode in panel >= 4.9
and handles orientation in vertical mode to conform with the
panel plugin HIG. Many thanks to Andrzej for his initial patch.
I've adapted it with the following changes:
* Make it apply after migration work.
* Fix label orientation in vertical mode for panel < 4.9 (not
amended in original patch).
* In conformance with the panel plugin HIG, the 'small'
property of the plugin will not be set when in deskbar mode.
* Icon size in deskbar mode will be 2 times a column size, and
not bigger, preventing it from taking too much valuable
vertical space.
panel-plugin/weather-scrollbox.c | 40 ++++++++++++++--
panel-plugin/weather-scrollbox.h | 3 +
panel-plugin/weather.c | 97 ++++++++++++++++++++++++++++++++++----
panel-plugin/weather.h | 2 +
4 files changed, 129 insertions(+), 13 deletions(-)
diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index 1ed0c36..a883e34 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -62,6 +62,7 @@ gtk_scrollbox_init (GtkScrollbox *self)
self->timeout_id = 0;
self->offset = 0;
self->active = NULL;
+ self->orientation = GTK_ORIENTATION_HORIZONTAL;
}
@@ -101,8 +102,16 @@ gtk_scrollbox_size_request (GtkWidget *widget,
{
layout = PANGO_LAYOUT (li->data);
pango_layout_get_extents (layout, NULL, &logical_rect);
- width = PANGO_PIXELS (logical_rect.width);
- height = PANGO_PIXELS (logical_rect.height);
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ width = PANGO_PIXELS (logical_rect.width);
+ height = PANGO_PIXELS (logical_rect.height);
+ }
+ else
+ {
+ height = PANGO_PIXELS (logical_rect.width);
+ width = PANGO_PIXELS (logical_rect.height);
+ }
requisition->width = MAX (width, requisition->width);
requisition->height = MAX (height, requisition->height);
@@ -119,6 +128,7 @@ gtk_scrollbox_expose_event (GtkWidget *widget,
gint width, height;
PangoRectangle logical_rect;
gboolean result = FALSE;
+ PangoMatrix matrix = PANGO_MATRIX_INIT;
if (GTK_WIDGET_CLASS (gtk_scrollbox_parent_class)->expose_event != NULL)
result = GTK_WIDGET_CLASS (gtk_scrollbox_parent_class)->expose_event (widget, event);
@@ -126,9 +136,19 @@ gtk_scrollbox_expose_event (GtkWidget *widget,
if (self->active != NULL)
{
layout = PANGO_LAYOUT (self->active->data);
+ pango_matrix_rotate(&matrix, (self->orientation == GTK_ORIENTATION_HORIZONTAL) ? 0.0 : -90.0);
+ pango_context_set_matrix(pango_layout_get_context (layout), &matrix);
pango_layout_get_extents (layout, NULL, &logical_rect);
- width = PANGO_PIXELS (logical_rect.width);
- height = PANGO_PIXELS (logical_rect.height);
+ if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ width = PANGO_PIXELS (logical_rect.width);
+ height = PANGO_PIXELS (logical_rect.height);
+ }
+ else
+ {
+ height = PANGO_PIXELS (logical_rect.width);
+ width = PANGO_PIXELS (logical_rect.height);
+ }
gtk_paint_layout (widget->style,
widget->window,
@@ -252,6 +272,18 @@ gtk_scrollbox_set_label (GtkScrollbox *self,
+void
+gtk_scrollbox_set_orientation (GtkScrollbox *self,
+ GtkOrientation orientation)
+{
+ g_return_if_fail (GTK_IS_SCROLLBOX (self));
+
+ self->orientation = orientation;
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+
+
GtkWidget *
gtk_scrollbox_new (void)
{
diff --git a/panel-plugin/weather-scrollbox.h b/panel-plugin/weather-scrollbox.h
index cfacfd1..d37755f 100644
--- a/panel-plugin/weather-scrollbox.h
+++ b/panel-plugin/weather-scrollbox.h
@@ -41,6 +41,7 @@ struct _GtkScrollbox
gint offset;
GSList *active;
gboolean animate;
+ GtkOrientation orientation;
};
struct _GtkScrollboxClass
@@ -50,6 +51,8 @@ struct _GtkScrollboxClass
void gtk_scrollbox_set_label (GtkScrollbox * self, gint position, gchar *markup);
+void gtk_scrollbox_set_orientation (GtkScrollbox *self, GtkOrientation orientation);
+
GtkWidget *gtk_scrollbox_new (void);
void gtk_scrollbox_clear (GtkScrollbox * self);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 23fcd12..81ebfd7 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -215,7 +215,7 @@ set_icon_error (xfceweather_data *data)
gchar *str;
const gchar *txtsize;
- size = data->size;
+ size = data->panel_size;
if (data->weatherdata)
{
@@ -225,7 +225,7 @@ set_icon_error (xfceweather_data *data)
/* arbitrary, choose something that works */
- if (data->orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (data->panel_orientation == GTK_ORIENTATION_HORIZONTAL)
txtsize = "medium";
else if (size > 36)
txtsize = "medium";
@@ -242,10 +242,19 @@ set_icon_error (xfceweather_data *data)
gtk_widget_get_size_request (data->scrollbox, NULL, &height);
- if (data->orientation == GTK_ORIENTATION_VERTICAL)
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+ /* make icon double-size in deskbar mode */
+ if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR
+ && data->size != data->panel_size)
+ icon = get_icon ("99", data->size * 2, FALSE);
+ else
+ icon = get_icon ("99", data->size, FALSE);
+#else
+ if (data->panel_orientation == GTK_ORIENTATION_VERTICAL)
icon = get_icon ("99", data->size - height - 2, FALSE);
else
icon = get_icon ("99", data->size, FALSE);
+#endif
gtk_image_set_from_pixbuf (GTK_IMAGE (data->iconimage), icon);
@@ -275,7 +284,7 @@ set_icon_current (xfceweather_data *data)
{
opt = g_array_index (data->labels, datas, i);
- str = make_label (data->weatherdata, opt, data->unit, data->size, data->orientation, (data->labels->len > 1));
+ str = make_label (data->weatherdata, opt, data->unit, data->panel_size, data->panel_orientation, (data->labels->len > 1));
gtk_scrollbox_set_label (GTK_SCROLLBOX (data->scrollbox), -1, str);
@@ -289,10 +298,19 @@ set_icon_current (xfceweather_data *data)
else
{
gtk_widget_get_size_request (data->scrollbox, NULL, &height);
- if (data->orientation == GTK_ORIENTATION_VERTICAL)
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+ /* make icon double-size in deskbar mode */
+ if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR
+ && data->size != data->panel_size)
+ size = data->size * 2;
+ else
+ size = data->size;
+#else
+ if (data->panel_orientation == GTK_ORIENTATION_VERTICAL)
size = data->size - height - 2;
else
size = data->size;
+#endif
}
/* get data from current timeslice */
@@ -821,6 +839,7 @@ xfceweather_create_control (XfcePanelPlugin *plugin)
#endif
data->scrollbox = gtk_scrollbox_new ();
+ data->size = xfce_panel_plugin_get_size (plugin);
icon = get_icon ("99", 16, FALSE);
data->iconimage = gtk_image_new_from_pixbuf (icon);
@@ -944,6 +963,12 @@ xfceweather_set_size (XfcePanelPlugin *panel,
gint size,
xfceweather_data *data)
{
+ data->panel_size = size;
+
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+ size /= xfce_panel_plugin_get_nrows (panel);
+#endif
+
data->size = size;
gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
@@ -957,6 +982,48 @@ xfceweather_set_size (XfcePanelPlugin *panel,
return TRUE;
}
+
+
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+static gboolean
+xfceweather_set_mode (XfcePanelPlugin *panel,
+ XfcePanelPluginMode mode,
+ xfceweather_data *data)
+{
+ GtkWidget *parent = gtk_widget_get_parent(data->vbox_center_scrollbox);
+
+ data->panel_orientation = xfce_panel_plugin_get_mode(panel);
+ data->orientation = (mode != XFCE_PANEL_PLUGIN_MODE_VERTICAL) ?
+ GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
+
+ g_object_ref(G_OBJECT(data->vbox_center_scrollbox));
+ gtk_container_remove(GTK_CONTAINER(parent), data->vbox_center_scrollbox);
+
+ if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+ gtk_box_pack_start (GTK_BOX (data->top_hbox), data->vbox_center_scrollbox, TRUE, FALSE, 0);
+ else
+ gtk_box_pack_start (GTK_BOX (data->top_vbox), data->vbox_center_scrollbox, TRUE, FALSE, 0);
+ g_object_unref(G_OBJECT(data->vbox_center_scrollbox));
+
+ if (data->panel_orientation == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
+ xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (panel), FALSE);
+ else
+ xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (panel), TRUE);
+
+ gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
+ gtk_scrollbox_set_orientation (GTK_SCROLLBOX (data->scrollbox), data->orientation);
+
+ if (data->weatherdata)
+ set_icon_current (data);
+ else
+ set_icon_error (data);
+
+ /* we handled the orientation */
+ return TRUE;
+}
+
+
+#else
static gboolean
xfceweather_set_orientation (XfcePanelPlugin *panel,
GtkOrientation orientation,
@@ -964,12 +1031,13 @@ xfceweather_set_orientation (XfcePanelPlugin *panel,
{
GtkWidget *parent = gtk_widget_get_parent(data->vbox_center_scrollbox);
- data->orientation = orientation;
+ data->orientation = GTK_ORIENTATION_HORIZONTAL;
+ data->panel_orientation = orientation;
g_object_ref(G_OBJECT(data->vbox_center_scrollbox));
gtk_container_remove(GTK_CONTAINER(parent), data->vbox_center_scrollbox);
- if (data->orientation == GTK_ORIENTATION_HORIZONTAL) {
+ if (data->panel_orientation == GTK_ORIENTATION_HORIZONTAL) {
gtk_box_pack_start (GTK_BOX (data->top_hbox), data->vbox_center_scrollbox, TRUE, FALSE, 0);
} else {
gtk_box_pack_start (GTK_BOX (data->top_vbox), data->vbox_center_scrollbox, TRUE, FALSE, 0);
@@ -977,6 +1045,7 @@ xfceweather_set_orientation (XfcePanelPlugin *panel,
g_object_unref(G_OBJECT(data->vbox_center_scrollbox));
gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
+ gtk_scrollbox_set_orientation (GTK_SCROLLBOX (data->scrollbox), data->panel_orientation);
if (data->weatherdata)
set_icon_current (data);
@@ -986,7 +1055,7 @@ xfceweather_set_orientation (XfcePanelPlugin *panel,
/* we handled the orientation */
return TRUE;
}
-
+#endif
static void
@@ -1002,8 +1071,13 @@ weather_construct (XfcePanelPlugin *plugin)
xfceweather_set_visibility (data);
- xfceweather_set_size (plugin, xfce_panel_plugin_get_size (plugin), data);
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+ xfceweather_set_mode (plugin, xfce_panel_plugin_get_mode(plugin), data);
+#else
xfceweather_set_orientation (plugin, xfce_panel_plugin_get_orientation(plugin), data);
+#endif
+
+ xfceweather_set_size (plugin, xfce_panel_plugin_get_size (plugin), data);
gtk_container_add (GTK_CONTAINER (plugin), data->tooltipbox);
@@ -1016,8 +1090,13 @@ weather_construct (XfcePanelPlugin *plugin)
g_signal_connect (G_OBJECT (plugin), "size-changed",
G_CALLBACK (xfceweather_set_size), data);
+#if LIBXFCE4PANEL_CHECK_VERSION (4,9,0)
+ g_signal_connect (G_OBJECT (plugin), "mode-changed",
+ G_CALLBACK (xfceweather_set_mode), data);
+#else
g_signal_connect (G_OBJECT (plugin), "orientation-changed",
G_CALLBACK (xfceweather_set_orientation), data);
+#endif
xfce_panel_plugin_menu_show_configure (plugin);
g_signal_connect (G_OBJECT (plugin), "configure-plugin",
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 147f72f..173b77d 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -45,8 +45,10 @@ typedef struct
GArray *labels;
+ gint panel_size;
gint size;
GtkOrientation orientation;
+ GtkOrientation panel_orientation;
gint updatetimeout;
gchar *lat;
More information about the Xfce4-commits
mailing list