--- pager.c	2009-03-16 23:26:49.000000000 +0100
+++ /home/marcus/temp/svn/libwnck-2.26.0/libwnck/pager.c	2009-05-16 00:53:56.000000000 +0200
@@ -76,6 +77,8 @@
   int workspace_size;
   guint screen_connections[N_SCREEN_CONNECTIONS];
   int prelight; /* workspace mouse is hovering over */
+  int prelight_viewport_x;
+  int prelight_viewport_y;
   gboolean prelight_dnd; /* is dnd happening? */
 
   guint dragging :1;
@@ -1025,7 +1028,11 @@
   WnckWorkspace *space;
   GtkWidget *widget;
   GtkStateType state;
-  
+  double width_ratio, height_ratio;
+  int workspace_width, workspace_height;
+  double vx, vy, vw, vh; /* viewport */
+  int screen_width, screen_height;
+
   space = wnck_screen_get_workspace (pager->priv->screen, workspace);
   if (!space)
     return;
@@ -1068,12 +1075,6 @@
         }
       else
         {
-          //FIXME prelight for dnd in the viewport?
-          int workspace_width, workspace_height;
-          int screen_width, screen_height;
-          double width_ratio, height_ratio;
-          double vx, vy, vw, vh; /* viewport */
-
           workspace_width = wnck_workspace_get_width (space);
           workspace_height = wnck_workspace_get_height (space);
           screen_width = wnck_screen_get_width (pager->priv->screen);
@@ -1223,19 +1224,34 @@
 
   if (workspace == pager->priv->prelight && pager->priv->prelight_dnd)
     {
+      workspace_width = wnck_workspace_get_width (space);
+      workspace_height = wnck_workspace_get_height (space);
+      screen_width = wnck_screen_get_width (pager->priv->screen);
+      screen_height = wnck_screen_get_height (pager->priv->screen);
+
+      width_ratio = rect->width / (double) workspace_width;
+      height_ratio = rect->height / (double) workspace_height;
+
       /* stolen directly from gtk source so it matches nicely */
-      cairo_t *cr;
+      vx = rect->x + width_ratio * pager->priv->prelight_viewport_x;
+      vy = rect->y + height_ratio * pager->priv->prelight_viewport_y;
+
+      vw = width_ratio * screen_width;
+      vh = height_ratio * screen_height;
+
       gtk_paint_shadow (widget->style, widget->window,
-		        GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-		        NULL, widget, "dnd",
-			rect->x, rect->y, rect->width, rect->height);
+            GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+            NULL, widget, "dnd",
+            vx, vy, vw, vh);
 
+      cairo_t *cr;
       cr = gdk_cairo_create (widget->window);
       cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
       cairo_set_line_width (cr, 1.0);
       cairo_rectangle (cr,
-		       rect->x + 0.5, rect->y + 0.5,
-		       MAX (0, rect->width - 1), MAX (0, rect->height - 1));
+            vx + 0.5, vy + 0.5,
+            MAX (0, vw - 1), MAX (0, vh - 1));
+
       cairo_stroke (cr);
       cairo_destroy (cr);
     }
@@ -1417,15 +1433,25 @@
                            gboolean   prelight_dnd)
 {
   gint id;
+  int viewport_x;
+  int viewport_y;
 
   if (x < 0 || y < 0)
     id = -1;
   else
-    id = workspace_at_point (pager, x, y, NULL, NULL);
-  
+    id = workspace_at_point (pager, x, y, &viewport_x, &viewport_y);
+
+  int screen_width  = wnck_screen_get_width  (pager->priv->screen);
+  int screen_height = wnck_screen_get_height (pager->priv->screen);
+
+  viewport_x = (viewport_x / screen_width)  * screen_width;
+  viewport_y = (viewport_y / screen_height) * screen_height;
+
   if (id != pager->priv->prelight)
     {
       wnck_pager_queue_draw_workspace (pager, pager->priv->prelight);
+      pager->priv->prelight_viewport_x = viewport_x;
+      pager->priv->prelight_viewport_y = viewport_y;
       wnck_pager_queue_draw_workspace (pager, id);
       pager->priv->prelight = id;
       pager->priv->prelight_dnd = prelight_dnd;
@@ -1435,6 +1461,15 @@
       wnck_pager_queue_draw_workspace (pager, pager->priv->prelight);
       pager->priv->prelight_dnd = prelight_dnd;
     }
+  else if (pager->priv->prelight_viewport_x != viewport_x || pager->priv->prelight_viewport_y != viewport_y)
+    {
+      pager->priv->prelight_viewport_x = viewport_x;
+      pager->priv->prelight_viewport_y = viewport_y;
+      wnck_pager_queue_draw_workspace (pager, id);
+    }  
+
+
+
 }
 
 static gboolean 
@@ -1518,6 +1553,18 @@
   GList *tmp;
   gint i;
   gulong xid;
+  int viewport_x;
+  int viewport_y;
+  int wx;
+  int wy;
+  int wh;
+  int ww;
+  int win_viewport_x;
+  int win_viewport_y;
+  int delta_x;
+  int delta_y;
+  int screen_width;
+  int screen_height;
 
   if ((selection_data->length != sizeof (gulong)) ||
       (selection_data->format != 8))
@@ -1526,7 +1573,7 @@
       return;
     }
   
-  i = workspace_at_point (pager, x, y, NULL, NULL);
+  i = workspace_at_point (pager, x, y, &viewport_x, &viewport_y);
   space = wnck_screen_get_workspace (pager->priv->screen, i);
   if (!space)
     {
@@ -1535,20 +1582,52 @@
     }
   
   xid = *((gulong *)selection_data->data);
-	      
+  
   for (tmp = wnck_screen_get_windows_stacked (pager->priv->screen); tmp != NULL; tmp = tmp->next)
     {
       if (wnck_window_get_xid (tmp->data) == xid)
 	{
 	  WnckWindow *win = tmp->data;
-	  wnck_window_move_to_workspace (win, space);
-	  if (space == wnck_screen_get_active_workspace (pager->priv->screen))
-	    wnck_window_activate (win, time);
+          WnckWorkspace *win_space = wnck_window_get_workspace(win);
+          WnckWorkspace *active_space = wnck_screen_get_active_workspace (pager->priv->screen);
+          //First move window to correct workspace	  
+          wnck_window_move_to_workspace (win, space);
+
+          if (space == win_space) 
+            {
+              //Second, move to right viewport (compiz)
+              screen_width  = wnck_screen_get_width  (pager->priv->screen);
+              screen_height = wnck_screen_get_height (pager->priv->screen);
+
+              wnck_window_get_geometry(win, &wx, &wy, &ww, &wh);
+
+              workspace_at_point(pager, pager->priv->drag_start_x, pager->priv->drag_start_y, &win_viewport_x, &win_viewport_y);
+
+              viewport_x = (viewport_x / screen_width)  * screen_width;
+              viewport_y = (viewport_y / screen_height) * screen_height;
+
+              win_viewport_x = (win_viewport_x / screen_width)  * screen_width;
+              win_viewport_y = (win_viewport_y / screen_height) * screen_height;
+
+              delta_x = viewport_x - win_viewport_x;
+              delta_y = viewport_y - win_viewport_y;
+
+              wnck_window_set_geometry(win, 0, WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y, wx + delta_x, wy + delta_y, ww, wh);
+
+              //Third, if window is moved to the current viewport - activate it
+              if (wnck_workspace_get_viewport_x(active_space) == viewport_x && wnck_workspace_get_viewport_y(active_space) == viewport_y)
+                wnck_window_activate (win, time);
+          }
+            else 
+          {
+            if (space == wnck_screen_get_active_workspace (pager->priv->screen))
+              wnck_window_activate (win, time);
+
+          }
 	  gtk_drag_finish (context, TRUE, FALSE, time);
 	  return;
 	}
     }
-
   gtk_drag_finish (context, FALSE, FALSE, time);
 }			       
 
