Index: pager.c
===================================================================
RCS file: /cvs/gnome/libwnck/libwnck/pager.c,v
retrieving revision 1.48
diff -u -p -r1.48 pager.c
--- pager.c	22 Jan 2006 21:37:55 -0000	1.48
+++ pager.c	18 Feb 2006 11:08:35 -0000
@@ -1086,24 +1086,32 @@ wnck_pager_button_press (GtkWidget      
                          GdkEventButton *event)
 {
   WnckPager *pager;
-  gboolean handled = FALSE;
   int space_number;
   WnckWorkspace *space = NULL;
   GdkRectangle workspace_rect;
 						    
+  if (event->button != 1)
+    return FALSE;
+
   pager = WNCK_PAGER (widget);
 
   space_number = workspace_at_point (pager, event->x, event->y, NULL, NULL);
 
   if (space_number != -1)
     {
-      if (event->button == 1)
-	handled = TRUE;
-
       get_workspace_rect (pager, space_number, &workspace_rect);
       space = wnck_screen_get_workspace (pager->priv->screen, space_number);
     }
 
+  if (space)
+    {
+      /* always save the start coordinates so we can know if we need to change
+       * workspace when the button is released (ie, start and end coordinates
+       * should be in the same workspace) */
+      pager->priv->drag_start_x = event->x;
+      pager->priv->drag_start_y = event->y;
+    }
+
   if (space && (pager->priv->display_mode != WNCK_PAGER_DISPLAY_NAME))
     {
       GList *windows;
@@ -1126,18 +1134,12 @@ wnck_pager_button_press (GtkWidget      
 	  
 	  if (POINT_IN_RECT (event->x, event->y, winrect))
 	    {
-	      if (event->button == 1)
-		{
-		  /* wnck_window_activate (win); */
-		  pager->priv->drag_window = win;
-		  pager->priv->drag_start_x = event->x;
-		  pager->priv->drag_start_y = event->y;
-		  pager->priv->drag_start_x_workspace_relative =
-		    event->x - workspace_rect.x;
-		  pager->priv->drag_start_y_workspace_relative =
-		    event->y - workspace_rect.y;
-		}
-	      
+              /* wnck_window_activate (win); */
+              pager->priv->drag_window = win;
+              pager->priv->drag_start_x_workspace_relative =
+                event->x - workspace_rect.x;
+              pager->priv->drag_start_y_workspace_relative =
+                event->y - workspace_rect.y;
 	      break;
 	    }
 	  
@@ -1147,7 +1149,7 @@ wnck_pager_button_press (GtkWidget      
       g_list_free (windows);
     }
   
-  return handled;
+  return TRUE;
 }
 
 static gboolean
@@ -1245,13 +1247,16 @@ wnck_pager_button_release (GtkWidget    
   WnckWorkspace *space;
   WnckPager *pager;
   int i;
-  gboolean handled = FALSE;
+  int j;
   int viewport_x;
   int viewport_y;
   
+  if (event->button != 1)
+    return FALSE;
+
   pager = WNCK_PAGER (widget);
 
-  if (event->button == 1 && pager->priv->dragging)
+  if (pager->priv->dragging)
     {
       i = workspace_at_point (pager, event->x, event->y, NULL, NULL);
 
@@ -1268,15 +1273,16 @@ wnck_pager_button_release (GtkWidget    
                 wnck_window_activate (pager->priv->drag_window, event->time);
             }	  
 	}
-      
-      wnck_pager_clear_drag (pager);
-      handled = TRUE;
     }
-  else if (event->button == 1)
+  else
     {
+      j = workspace_at_point (pager,
+                              pager->priv->drag_start_x, pager->priv->drag_start_y,
+                              NULL, NULL);
       i = workspace_at_point (pager, event->x, event->y, &viewport_x, &viewport_y);
 
-      if (i >= 0 && (space = wnck_screen_get_workspace (pager->priv->screen, i)))
+      if (i >= 0 && i == j &&
+          (space = wnck_screen_get_workspace (pager->priv->screen, i)))
 	  {
 	    int screen_width, screen_height;
 
@@ -1302,14 +1308,12 @@ wnck_pager_button_release (GtkWidget    
 		wnck_workspace_get_viewport_y (space) != viewport_y)
 	      wnck_screen_move_viewport (pager->priv->screen, viewport_x, viewport_y);
 	  }
-      
-      if (pager->priv->drag_window)
-        wnck_pager_clear_drag (pager);
-
-      handled = TRUE;
     }
 
-  return FALSE;
+  if (pager->priv->drag_window)
+    wnck_pager_clear_drag (pager);
+
+  return TRUE;
 }
 
 static gboolean
