commit fbd6f0feee8d6345dc98c754812555a9e364cf93
Author: Andrzej <ndrwrdck@gmail.com>
Date:   Sun Nov 27 03:05:24 2011 +0900

    pager: added support for changing starting corner.
    
    Conflicts:
    
    	libwnck/pager.c
    	libwnck/pager.h

diff --git a/libwnck/pager.c b/libwnck/pager.c
index 9474d1a..1410645 100644
--- a/libwnck/pager.c
+++ b/libwnck/pager.c
@@ -73,6 +73,7 @@ struct _WnckPagerPrivate
   GtkShadowType shadow_type;
   
   GtkOrientation orientation;
+  _WnckLayoutCorner starting_corner;
   int workspace_size;
   guint screen_connections[N_SCREEN_CONNECTIONS];
   int prelight; /* workspace mouse is hovering over */
@@ -210,6 +211,8 @@ wnck_pager_init (WnckPager *pager)
   pager->priv->shadow_type = GTK_SHADOW_NONE;
 
   pager->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+  pager->priv->starting_corner = WNCK_LAYOUT_CORNER_TOPLEFT;
+  pager->priv->layout_policy = WNCK_PAGER_LAYOUT_POLICY_AUTOMATIC;
   pager->priv->workspace_size = 48;
 
   for (i = 0; i < N_SCREEN_CONNECTIONS; i++)
@@ -308,7 +311,7 @@ _wnck_pager_set_screen (WnckPager *pager)
       _wnck_screen_get_workspace_layout (pager->priv->screen,
                                          &orientation,
                                          &pager->priv->n_rows,
-                                         NULL, NULL);
+                                         NULL, &pager->priv->starting_corner);
 
       /* test in this order to default to horizontal in case there was in issue
        * when fetching the layout */
@@ -665,8 +668,33 @@ get_workspace_rect (WnckPager    *pager,
       rect->width = (hsize - (pager->priv->n_rows - 1)) / pager->priv->n_rows;
       rect->height = (vsize - (spaces_per_row - 1)) / spaces_per_row;
 
-      col = space / spaces_per_row;
-      row = space % spaces_per_row;
+      switch (pager->priv->starting_corner)
+	{
+	case WNCK_LAYOUT_CORNER_TOPLEFT:
+	  col = space / spaces_per_row;
+	  row = space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_TOPRIGHT:
+	  col = (pager->priv->n_rows - 1) - space / spaces_per_row;
+	  row = space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_BOTTOMLEFT:
+	  col = space / spaces_per_row;
+	  row = (spaces_per_row - 1) - space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_BOTTOMRIGHT:
+	  col = (pager->priv->n_rows - 1) - space / spaces_per_row;
+	  row = (spaces_per_row - 1) - space % spaces_per_row;
+	  break;
+
+	default:
+	  row = 0;
+	  col = 0;
+	  break;
+	}
 
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
         col = pager->priv->n_rows - col - 1;
@@ -685,8 +713,33 @@ get_workspace_rect (WnckPager    *pager,
       rect->width = (hsize - (spaces_per_row - 1)) / spaces_per_row;
       rect->height = (vsize - (pager->priv->n_rows - 1)) / pager->priv->n_rows;
       
-      col = space % spaces_per_row;
-      row = space / spaces_per_row;
+      switch (pager->priv->starting_corner)
+	{
+	case WNCK_LAYOUT_CORNER_TOPLEFT:
+	  row = space / spaces_per_row;
+	  col = space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_TOPRIGHT:
+	  row = (pager->priv->n_rows - 1) - space / spaces_per_row;
+	  col = space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_BOTTOMLEFT:
+	  row = space / spaces_per_row;
+	  col = (spaces_per_row - 1) - space % spaces_per_row;
+	  break;
+
+	case WNCK_LAYOUT_CORNER_BOTTOMRIGHT:
+	  row = (pager->priv->n_rows - 1) - space / spaces_per_row;
+	  col = (spaces_per_row - 1) - space % spaces_per_row;
+	  break;
+
+	default:
+	  row = 0;
+	  col = 0;
+	  break;
+	}
 
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
         col = spaces_per_row - col - 1;
@@ -2006,6 +2059,7 @@ wnck_pager_set_layout_hint (WnckPager *pager)
 {
   int layout_rows;
   int layout_cols;
+  _WnckLayoutOrientation orientation;
 
   /* if we're not realized, we don't know about our screen yet */
   if (pager->priv->screen == NULL)
@@ -2022,16 +2076,8 @@ wnck_pager_set_layout_hint (WnckPager *pager)
   if (!pager->priv->show_all_workspaces)
     return FALSE;
 
-  if (pager->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-    {
-      layout_rows = pager->priv->n_rows;
-      layout_cols = 0;
-    }
-  else
-    {
-      layout_rows = 0;
-      layout_cols = pager->priv->n_rows;
-    }
+  layout_rows = pager->priv->n_rows;
+  layout_cols = 0;
 
   pager->priv->layout_manager_token =
     wnck_screen_try_set_workspace_layout (pager->priv->screen,
@@ -2039,6 +2085,27 @@ wnck_pager_set_layout_hint (WnckPager *pager)
                                           layout_rows,
                                           layout_cols);
 
+  if (pager->priv->layout_manager_token == WNCK_NO_MANAGER_TOKEN)
+    return FALSE;
+
+  if (pager->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    orientation = WNCK_LAYOUT_ORIENTATION_HORIZONTAL;
+  else
+    orientation = WNCK_LAYOUT_ORIENTATION_VERTICAL;
+
+  pager->priv->layout_manager_token =
+    wnck_screen_try_set_workspace_orientation (pager->priv->screen,
+					       pager->priv->layout_manager_token,
+					       orientation);
+
+  if (pager->priv->layout_manager_token == WNCK_NO_MANAGER_TOKEN)
+    return FALSE;
+
+  pager->priv->layout_manager_token =
+    wnck_screen_try_set_workspace_corner (pager->priv->screen,
+                                          pager->priv->layout_manager_token,
+                                          pager->priv->starting_corner);
+
   return (pager->priv->layout_manager_token != WNCK_NO_MANAGER_TOKEN);
 }
 
@@ -2099,6 +2166,53 @@ wnck_pager_set_orientation (WnckPager     *pager,
 }
 
 /**
+ * wnck_pager_set_starting_corner:
+ * @pager: a #WnckPager.
+ * @starting_corner: starting corner to use for the layout of #WnckWorkspace on the
+ * #WnckScreen @pager is watching.
+ *
+ * Tries to change the starting corner of the layout of #WnckWorkspace on the
+ * #WnckScreen @pager is watching. Since no more than one application should
+ * set this property of a #WnckScreen at a time, setting the layout starting corner is not
+ * guaranteed to work. 
+ *
+ * If @pager has not been added to a widget hierarchy, the call will fail
+ * because @pager can't know the screen on which to modify the starting corner.
+ *
+ * Return value: %TRUE if the layout of #WnckWorkspace has been successfully
+ * changed or did not need to be changed, %FALSE otherwise.
+ */
+gboolean
+wnck_pager_set_starting_corner (WnckPager         *pager,
+				_WnckLayoutCorner  starting_corner)
+{
+  int      old_starting_corner;
+  gboolean old_starting_corner_is_valid;
+
+  g_return_val_if_fail (WNCK_IS_PAGER (pager), FALSE);
+
+  if (pager->priv->starting_corner == starting_corner)
+    return TRUE;
+
+  old_starting_corner = pager->priv->starting_corner;
+  old_starting_corner_is_valid = pager->priv->screen != NULL;
+
+  pager->priv->starting_corner = starting_corner;
+
+  if (wnck_pager_set_layout_hint (pager))
+    {
+      gtk_widget_queue_resize (GTK_WIDGET (pager));
+      return TRUE;
+    }
+  else
+    {
+      if (old_starting_corner_is_valid)
+        pager->priv->starting_corner = old_starting_corner;
+      return FALSE;
+    }
+}
+
+/**
  * wnck_pager_set_n_rows:
  * @pager: a #WnckPager.
  * @n_rows: the number of rows to use for the layout of #WnckWorkspace on the
diff --git a/libwnck/pager.h b/libwnck/pager.h
index 9104755..0f9b4d4 100644
--- a/libwnck/pager.h
+++ b/libwnck/pager.h
@@ -92,6 +92,10 @@ void wnck_pager_set_show_all     (WnckPager            *pager,
 				  gboolean              show_all_workspaces);
 void wnck_pager_set_shadow_type  (WnckPager	       *pager,
 				  GtkShadowType		shadow_type);
+void wnck_pager_set_layout_policy (WnckPager            *pager,
+                                   WnckPagerLayoutPolicy policy);
+gboolean wnck_pager_set_starting_corner (WnckPager         *pager,
+                                         _WnckLayoutCorner  starting_corner);
 
 
 #ifndef WNCK_DISABLE_DEPRECATED
diff --git a/libwnck/xutils.c b/libwnck/xutils.c
index 950ed0b..6125a7a 100644
--- a/libwnck/xutils.c
+++ b/libwnck/xutils.c
@@ -2482,7 +2482,7 @@ _wnck_set_desktop_layout_all (Screen                 *xscreen,
   Window   root;
   gulong   data[4];
 
-  g_assert ((rows == 0) || (columns == 0));
+  /* g_assert ((rows == 0) || (columns == 0)); */
 
   display = DisplayOfScreen (xscreen);
   root = RootWindowOfScreen (xscreen);
