+void event_button_motion_notify (XEvent *e)
+{
+ Panel * panel = get_panel(e->xany.window);
+ if(!panel || !task_drag)
+ return;
+
+ // Find the taskbar on the event's location
+ Taskbar * event_taskbar = click_taskbar(panel, e->xbutton.x, e->xbutton.y);
+ if(event_taskbar == NULL)
+ return;
+
+ // Find the task on the event's location
+ Task * event_task = click_task(panel, e->xbutton.x, e->xbutton.y);
+
+ // If the event takes place on the same taskbar as the task being dragged
+ if(event_taskbar == task_drag->area.parent) {
+ // Swap the task_drag with the task on the event's location (if they differ)
+ if(event_task && event_task != task_drag) {
+ GSList * drag_iter = g_slist_find(event_taskbar->area.list, task_drag);
+ GSList * task_iter = g_slist_find(event_taskbar->area.list, event_task);
+ if(drag_iter && task_iter) {
+ gpointer temp = task_iter->data;
+ task_iter->data = drag_iter->data;
+ drag_iter->data = temp;
+ event_taskbar->area.resize = 1;
+ panel_refresh = 1;
+ task_dragged = 1;
+ }
+ }
+ }
+ else { // The event is on another taskbar than the task being dragged
+ if(task_drag->desktop == ALLDESKTOP || panel_mode != MULTI_DESKTOP)
+ return;
+
+ Taskbar * drag_taskbar = (Taskbar*)task_drag->area.parent;
+ drag_taskbar->area.list = g_slist_remove(drag_taskbar->area.list, task_drag);
+
+ if(event_taskbar->area.posx > drag_taskbar->area.posx || event_taskbar->area.posy > drag_taskbar->area.posy)
+ event_taskbar->area.list = g_slist_prepend(event_taskbar->area.list, task_drag);
+ else
+ event_taskbar->area.list = g_slist_append(event_taskbar->area.list, task_drag);
+
+ // Move task to other desktop (but avoid the 'Window desktop changed' code in 'event_property_notify')
+ task_drag->area.parent = event_taskbar;
+ task_drag->desktop = event_taskbar->desktop;
+
+ windows_set_desktop(task_drag->win, event_taskbar->desktop);
+
+ event_taskbar->area.resize = 1;
+ drag_taskbar->area.resize = 1;
+ task_dragged = 1;
+ panel_refresh = 1;
+ }
+}