[Xfce4-commits] <xfce4-panel:andrzejr/deskbar-github> pager-wnck: correct resizing, removing the aspect ratio hack from pager.c.

Andrzej noreply at xfce.org
Mon Dec 12 11:40:43 CET 2011


Updating branch refs/heads/andrzejr/deskbar-github
         to 22fc12a21d322975a7c37554f0b2e9c4de3248c0 (commit)
       from f518a6c5145fa784fd94a6a66e0d71cb0e07ad58 (commit)

commit 22fc12a21d322975a7c37554f0b2e9c4de3248c0
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Tue Nov 29 02:36:03 2011 +0900

    pager-wnck: correct resizing, removing the aspect ratio hack from pager.c.

 plugins/pager/pager-wnck.c |   72 +++++++++++++++++++++++++++++++++++----
 plugins/pager/pager-wnck.h |    2 +
 plugins/pager/pager.c      |   80 +++++++++++--------------------------------
 plugins/pager/pager.h      |    7 ++++
 4 files changed, 94 insertions(+), 67 deletions(-)

diff --git a/plugins/pager/pager-wnck.c b/plugins/pager/pager-wnck.c
index 56c4e52..b5daa33 100644
--- a/plugins/pager/pager-wnck.c
+++ b/plugins/pager/pager-wnck.c
@@ -32,6 +32,7 @@
 #include <gdk/gdkx.h>
 #include <libwnck/libwnck.h>
 
+#include "pager.h"
 #include "pager-wnck.h"
 
 #define PAGER_WNCK_NO_MANAGER_TOKEN 0 /* from wnck xutils.h */
@@ -68,6 +69,7 @@ struct _PagerWnckPrivate
   
   int n_rows; /* really columns for vertical orientation */
   PagerWnckDisplayMode display_mode;
+  PagerLayoutPolicy layout_policy;
   gboolean show_all_workspaces;
   GtkShadowType shadow_type;
   
@@ -225,6 +227,7 @@ pager_wnck_init (PagerWnck *pager)
   pager->priv->shadow_type = GTK_SHADOW_NONE;
 
   pager->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+  pager->priv->layout_policy = PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT;
   pager->priv->workspace_size = 48;
 
   for (i = 0; i < N_SCREEN_CONNECTIONS; i++)
@@ -443,7 +446,7 @@ pager_wnck_size_request  (GtkWidget      *widget,
   spaces_per_row = (n_spaces + pager->priv->n_rows - 1) / pager->priv->n_rows;
   space = wnck_screen_get_workspace (pager->priv->screen, 0);
   
-  if (pager->priv->orientation == GTK_ORIENTATION_VERTICAL)
+  if (pager->priv->layout_policy == PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH)
     {
       if (space) {
         screen_aspect =
@@ -471,8 +474,16 @@ pager_wnck_size_request  (GtkWidget      *widget,
       
       other_dimension_size = screen_aspect * size;
       
-      requisition->width = size * n_rows + (n_rows - 1);
-      requisition->height = other_dimension_size * spaces_per_row  + (spaces_per_row - 1);
+      if (pager->priv->orientation == GTK_ORIENTATION_VERTICAL)
+	{
+	  requisition->width = size * n_rows + (n_rows - 1);
+	  requisition->height = other_dimension_size * spaces_per_row  + (spaces_per_row - 1);
+	}
+      else
+	{
+	  requisition->width = size * spaces_per_row + (spaces_per_row - 1);
+	  requisition->height = other_dimension_size * n_rows  + (n_rows - 1);
+	}
     }
   else
     {
@@ -527,8 +538,16 @@ pager_wnck_size_request  (GtkWidget      *widget,
 	  other_dimension_size += 2;
 	}
       
-      requisition->width = other_dimension_size * spaces_per_row + (spaces_per_row - 1);
-      requisition->height = size * n_rows + (n_rows - 1);
+      if (pager->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+	{
+	  requisition->width = other_dimension_size * spaces_per_row + (spaces_per_row - 1);
+	  requisition->height = size * n_rows + (n_rows - 1);
+	}
+      else
+	{
+	  requisition->width = other_dimension_size * n_rows + (n_rows - 1);
+	  requisition->height = size * spaces_per_row + (spaces_per_row - 1);
+	}
     }
 
   if (pager->priv->shadow_type != GTK_SHADOW_NONE)
@@ -558,6 +577,8 @@ pager_wnck_size_allocate (GtkWidget      *widget,
   int focus_width;
   int width;
   int height;
+  int n_spaces;
+  int spaces_per_row;
 
   pager = XFCE_PAGER_WNCK (widget);
 
@@ -580,17 +601,32 @@ pager_wnck_size_allocate (GtkWidget      *widget,
 
   g_assert (pager->priv->n_rows > 0);
 
-  if (pager->priv->orientation == GTK_ORIENTATION_VERTICAL)
+  n_spaces = wnck_screen_get_workspace_count (pager->priv->screen);
+  spaces_per_row = (n_spaces + pager->priv->n_rows - 1) / pager->priv->n_rows;
+  if (spaces_per_row == 0)
+    spaces_per_row = 1;
+
+  if (pager->priv->layout_policy == PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH)
     {
       if (pager->priv->show_all_workspaces)
-	workspace_size = (width - (pager->priv->n_rows - 1))  / pager->priv->n_rows;
+	{
+	  if (pager->priv->orientation == GTK_ORIENTATION_VERTICAL)
+	    workspace_size = (width - (pager->priv->n_rows - 1))  / pager->priv->n_rows;
+	  else
+	    workspace_size = (width - (spaces_per_row - 1)) / spaces_per_row;
+	}
       else
 	workspace_size = width;
     }
   else
     {
       if (pager->priv->show_all_workspaces)
-	workspace_size = (height - (pager->priv->n_rows - 1))/ pager->priv->n_rows;
+	{
+	  if (pager->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+	    workspace_size = (height - (pager->priv->n_rows - 1))/ pager->priv->n_rows;
+	  else
+	    workspace_size = (height - (spaces_per_row - 1)) / spaces_per_row;
+	}
       else
 	workspace_size = height;
     }
@@ -2151,6 +2187,26 @@ pager_wnck_set_display_mode (PagerWnck            *pager,
 }
 
 /**
+ * wnck_pager_set_layout_policy:
+ * @pager: a #WnckPager.
+ * @policy: a layout policy.
+ *
+ * Sets the layout policy for @pager to @policy.
+ */
+void
+pager_wnck_set_layout_policy (PagerWnck         *pager,
+			      PagerLayoutPolicy  policy)
+{
+  g_return_if_fail (XFCE_IS_PAGER_WNCK (pager));
+
+  if (pager->priv->layout_policy == policy)
+    return;
+
+  pager->priv->layout_policy = policy;
+  gtk_widget_queue_resize (GTK_WIDGET (pager));
+}
+
+/**
  * pager_wnck_set_show_all:
  * @pager: a #PagerWnck.
  * @show_all_workspaces: whether to display all #WnckWorkspace in @pager.
diff --git a/plugins/pager/pager-wnck.h b/plugins/pager/pager-wnck.h
index fab670e..3124a1c 100644
--- a/plugins/pager/pager-wnck.h
+++ b/plugins/pager/pager-wnck.h
@@ -90,6 +90,8 @@ gboolean pager_wnck_set_n_rows   (PagerWnck            *pager,
 				  int                   n_rows);
 void pager_wnck_set_display_mode (PagerWnck            *pager,
 				  PagerWnckDisplayMode  mode);
+void pager_wnck_set_layout_policy (PagerWnck           *pager,
+				   PagerLayoutPolicy    layout_policy);
 void pager_wnck_set_show_all     (PagerWnck            *pager,
 				  gboolean              show_all_workspaces);
 void pager_wnck_set_shadow_type  (PagerWnck	       *pager,
diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
index 463a620..f13a8d7 100644
--- a/plugins/pager/pager.c
+++ b/plugins/pager/pager.c
@@ -67,8 +67,6 @@ static void     pager_plugin_configure_plugin             (XfcePanelPlugin   *pa
 static void     pager_plugin_screen_layout_changed        (PagerPlugin       *plugin);
 static void     pager_plugin_size_request                 (GtkWidget         *widget,
                                                            GtkRequisition    *requisition);
-static void     pager_plugin_size_allocate                (GtkWidget         *widget,
-                                                           GtkAllocation     *allocation);
 
 
 
@@ -89,8 +87,6 @@ struct _PagerPlugin
   guint          scrolling : 1;
   guint          miniature_view : 1;
   gint           rows;
-
-  double         aspect;
 };
 
 enum
@@ -123,7 +119,6 @@ pager_plugin_class_init (PagerPluginClass *klass)
   widget_class = GTK_WIDGET_CLASS (klass);
   widget_class->scroll_event = pager_plugin_scroll_event;
   widget_class->size_request = pager_plugin_size_request;
-  widget_class->size_allocate = pager_plugin_size_allocate;
 
   plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
   plugin_class->construct = pager_plugin_construct;
@@ -165,7 +160,6 @@ pager_plugin_init (PagerPlugin *plugin)
   plugin->miniature_view = TRUE;
   plugin->rows = 1;
   plugin->pager = NULL;
-  plugin->aspect = 1.0;
 }
 
 
@@ -288,7 +282,8 @@ pager_plugin_scroll_event (GtkWidget      *widget,
 static void
 pager_plugin_screen_layout_changed (PagerPlugin *plugin)
 {
-  GtkOrientation orientation;
+  GtkOrientation panel_orientation;
+  GtkOrientation plugin_orientation;
 
   panel_return_if_fail (XFCE_IS_PAGER_PLUGIN (plugin));
   panel_return_if_fail (WNCK_IS_SCREEN (plugin->wnck_screen));
@@ -299,23 +294,28 @@ pager_plugin_screen_layout_changed (PagerPlugin *plugin)
       wnck_screen_force_update (plugin->wnck_screen);
     }
 
-  orientation = xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin));
+  panel_orientation = xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin));
+  plugin_orientation = panel_orientation;
   if (xfce_panel_plugin_get_deskbar_mode (XFCE_PANEL_PLUGIN (plugin)))
-    orientation = GTK_ORIENTATION_HORIZONTAL;
+    plugin_orientation = GTK_ORIENTATION_HORIZONTAL;
 
   if (plugin->miniature_view)
     {
       plugin->pager = pager_wnck_new (plugin->wnck_screen);
-      pager_wnck_set_display_mode (PAGER_WNCK (plugin->pager), PAGER_WNCK_DISPLAY_CONTENT);
-      if (!pager_wnck_set_n_rows (PAGER_WNCK (plugin->pager), plugin->rows))
+      pager_wnck_set_display_mode (XFCE_PAGER_WNCK (plugin->pager), PAGER_WNCK_DISPLAY_CONTENT);
+      if (!pager_wnck_set_n_rows (XFCE_PAGER_WNCK (plugin->pager), plugin->rows))
         g_message ("Setting the pager rows returned false. Maybe the setting is not applied.");
-      pager_wnck_set_orientation (PAGER_WNCK (plugin->pager), orientation);
+      if (panel_orientation == GTK_ORIENTATION_HORIZONTAL)
+        pager_wnck_set_layout_policy (XFCE_PAGER_WNCK (plugin->pager), PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT);
+      else
+        pager_wnck_set_layout_policy (XFCE_PAGER_WNCK (plugin->pager), PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH);
+      pager_wnck_set_orientation (XFCE_PAGER_WNCK (plugin->pager), plugin_orientation);
     }
   else
     {
       plugin->pager = pager_buttons_new (plugin->wnck_screen);
       pager_buttons_set_n_rows (XFCE_PAGER_BUTTONS (plugin->pager), plugin->rows);
-      pager_buttons_set_orientation (XFCE_PAGER_BUTTONS (plugin->pager), orientation);
+      pager_buttons_set_orientation (XFCE_PAGER_BUTTONS (plugin->pager), plugin_orientation);
     }
 
   gtk_container_add (GTK_CONTAINER (plugin), plugin->pager);
@@ -402,56 +402,10 @@ pager_plugin_size_request (GtkWidget      *widget,
                            GtkRequisition *requisition)
 {
   PagerPlugin        *plugin;
-  XfcePanelPlugin    *panel_plugin;
-  gboolean            deskbar_mode;
-  GtkOrientation      orientation;
 
   plugin = XFCE_PAGER_PLUGIN (widget);
-  panel_plugin = XFCE_PANEL_PLUGIN (widget);
-  deskbar_mode = xfce_panel_plugin_get_deskbar_mode (panel_plugin);
-  orientation = xfce_panel_plugin_get_orientation (panel_plugin);
 
   gtk_widget_size_request (plugin->pager, requisition);
-  if (plugin->miniature_view && deskbar_mode && orientation == GTK_ORIENTATION_VERTICAL)
-    {
-      /* Working around limitations of the wnck applet. */
-      /* Wnck assumes that a horizontal applet is always used in a horizontal panel. */
-      /* Ignoring a special case of requisition size == 1 */
-      if (requisition->width > 1)
-        plugin->aspect = (double) requisition->height / (double) requisition->width;
-    }
-}
-
-
-
-static void
-pager_plugin_size_allocate (GtkWidget      *widget,
-                            GtkAllocation  *allocation)
-{
-  PagerPlugin        *plugin;
-  XfcePanelPlugin    *panel_plugin;
-  gboolean            deskbar_mode;
-  GtkOrientation      orientation;
-  gint                error;
-
-  plugin = XFCE_PAGER_PLUGIN (widget);
-  panel_plugin = XFCE_PANEL_PLUGIN (widget);
-  deskbar_mode = xfce_panel_plugin_get_deskbar_mode (panel_plugin);
-  orientation = xfce_panel_plugin_get_orientation (panel_plugin);
-
-  if (plugin->miniature_view && deskbar_mode && orientation == GTK_ORIENTATION_VERTICAL)
-    {
-      /* Working around limitations of the wnck applet.*/
-      /* Wnck assumes that a horizontal applet is always used in a horizontal panel. */
-      /* It would be better to fix the WNCK pager instead.*/
-      error = allocation->height - plugin->aspect * allocation->width;
-      /* Adding a vertical size error allowance of +/-3px to avoid infinite looping. */
-      if (error > 3 || error < -3)
-        {
-          allocation->height = allocation->width * plugin->aspect;
-        }
-    }
-  gtk_widget_size_allocate (plugin->pager, allocation);
 }
 
 
@@ -472,6 +426,14 @@ pager_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
 {
   PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
 
+  if (plugin->miniature_view)
+    {
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
+        pager_wnck_set_layout_policy (XFCE_PAGER_WNCK (plugin->pager), PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT);
+      else
+        pager_wnck_set_layout_policy (XFCE_PAGER_WNCK (plugin->pager), PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH);
+    }
+
   if (xfce_panel_plugin_get_deskbar_mode (panel_plugin))
     orientation = GTK_ORIENTATION_HORIZONTAL;
 
diff --git a/plugins/pager/pager.h b/plugins/pager/pager.h
index 1d65f59..0a16287 100644
--- a/plugins/pager/pager.h
+++ b/plugins/pager/pager.h
@@ -20,6 +20,7 @@
 #define __PAGER_H__
 
 #include <gtk/gtk.h>
+#include <libxfce4panel/libxfce4panel.h>
 
 G_BEGIN_DECLS
 
@@ -37,6 +38,12 @@ GType pager_plugin_get_type      (void) G_GNUC_CONST;
 
 void  pager_plugin_register_type (XfcePanelTypeModule *type_module);
 
+typedef enum {
+  PAGER_LAYOUT_POLICY_WIDTH_FOR_HEIGHT,
+  PAGER_LAYOUT_POLICY_HEIGHT_FOR_WIDTH
+} PagerLayoutPolicy;
+
+
 G_END_DECLS
 
 #endif /* !__PAGER_H__ */


More information about the Xfce4-commits mailing list