[Xfce4-commits] <xfce4-panel:xfce-4.8> Add a sorting mode for tasklist reordering with dnd (bug #7058).

Nick Schermer noreply at xfce.org
Sun Jun 19 20:40:01 CEST 2011


Updating branch refs/heads/xfce-4.8
         to 2bef165ce1395d9e02a9d4ae2a8fb76133e7e03a (commit)
       from 1805ea4d253cc2c342e928d55dd715c762bbf999 (commit)

commit 2bef165ce1395d9e02a9d4ae2a8fb76133e7e03a
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Jun 19 20:15:04 2011 +0200

    Add a sorting mode for tasklist reordering with dnd (bug #7058).
    
    (cherry picked from commit e316c7f40bb43373629c8e4bd4a19b2960c9f486)

 plugins/tasklist/tasklist-dialog.glade |    3 +
 plugins/tasklist/tasklist-widget.c     |   65 ++++++++++++++++++++++++++++++-
 plugins/tasklist/tasklist-widget.h     |    3 +-
 3 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/plugins/tasklist/tasklist-dialog.glade b/plugins/tasklist/tasklist-dialog.glade
index 86a2be0..835449e 100644
--- a/plugins/tasklist/tasklist-dialog.glade
+++ b/plugins/tasklist/tasklist-dialog.glade
@@ -399,6 +399,9 @@
       <row>
         <col id="0" translatable="yes">Group title and window title</col>
       </row>
+      <row>
+        <col id="0" translatable="yes">None, allow drag-and-drop</col>
+      </row>
     </data>
   </object>
 </interface>
diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c
index 9bae441..a301b65 100644
--- a/plugins/tasklist/tasklist-widget.c
+++ b/plugins/tasklist/tasklist-widget.c
@@ -1751,9 +1751,10 @@ xfce_tasklist_sort (XfceTasklist *tasklist)
 {
   panel_return_if_fail (XFCE_IS_TASKLIST (tasklist));
 
-  tasklist->windows = g_list_sort_with_data (tasklist->windows,
-                                             xfce_tasklist_button_compare,
-                                             tasklist);
+  if (tasklist->sort_order != XFCE_TASKLIST_SORT_ORDER_DND)
+    tasklist->windows = g_list_sort_with_data (tasklist->windows,
+                                               xfce_tasklist_button_compare,
+                                               tasklist);
 
   gtk_widget_queue_resize (GTK_WIDGET (tasklist));
 }
@@ -2215,6 +2216,10 @@ xfce_tasklist_button_compare (gconstpointer child_a,
   panel_return_val_if_fail (b->type == CHILD_TYPE_GROUP
                             || WNCK_IS_WINDOW (b->window), 0);
 
+  /* just append to the list */
+  if (tasklist->sort_order == XFCE_TASKLIST_SORT_ORDER_DND)
+    return a->unique_id - b->unique_id;
+
   if (tasklist->all_workspaces)
     {
       /* get workspace (this is slightly inefficient because the WnckWindow
@@ -2887,6 +2892,55 @@ xfce_tasklist_button_drag_begin (GtkWidget         *button,
 
 
 
+static void
+xfce_tasklist_button_drag_data_received (GtkWidget         *button,
+                                         GdkDragContext    *context,
+                                         gint               x,
+                                         gint               y,
+                                         GtkSelectionData  *selection_data,
+                                         guint              info,
+                                         guint              drag_time,
+                                         XfceTasklistChild *child2)
+{
+  GList             *li, *sibling;
+  gulong             xid;
+  XfceTasklistChild *child;
+  XfceTasklist      *tasklist = XFCE_TASKLIST (child2->tasklist);
+
+  panel_return_if_fail (XFCE_IS_TASKLIST (tasklist));
+
+  if (tasklist->sort_order != XFCE_TASKLIST_SORT_ORDER_DND)
+    return;
+
+  sibling = g_list_find (tasklist->windows, child2);
+  panel_return_if_fail (sibling != NULL);
+
+  if ((tasklist->horizontal && x >= button->allocation.width / 2)
+      || (!tasklist->horizontal && y >= button->allocation.height / 2))
+    sibling = g_list_next (sibling);
+
+  xid = *((gulong *) gtk_selection_data_get_data (selection_data));
+  for (li = tasklist->windows; li != NULL; li = li->next)
+    {
+      child = li->data;
+
+      if (child != child2
+          && child->window != NULL
+          && wnck_window_get_xid (child->window) == xid)
+        {
+          /* swap items */
+          tasklist->windows = g_list_delete_link (tasklist->windows, li);
+          tasklist->windows = g_list_insert_before (tasklist->windows, sibling, child);
+
+          gtk_widget_queue_resize (GTK_WIDGET (tasklist));
+
+          break;
+        }
+    }
+}
+
+
+
 static XfceTasklistChild *
 xfce_tasklist_button_new (WnckWindow   *window,
                           XfceTasklist *tasklist)
@@ -2911,10 +2965,15 @@ xfce_tasklist_button_new (WnckWindow   *window,
   gtk_drag_source_set (child->button, GDK_BUTTON1_MASK,
                        source_targets, G_N_ELEMENTS (source_targets),
                        GDK_ACTION_MOVE);
+  gtk_drag_dest_set (child->button, GTK_DEST_DEFAULT_ALL,
+                     source_targets, G_N_ELEMENTS (source_targets),
+                     GDK_ACTION_MOVE);
   g_signal_connect (G_OBJECT (child->button), "drag-data-get",
       G_CALLBACK (xfce_tasklist_button_drag_data_get), child);
   g_signal_connect (G_OBJECT (child->button), "drag-begin",
       G_CALLBACK (xfce_tasklist_button_drag_begin), child);
+  g_signal_connect (G_OBJECT (child->button), "drag-data-received",
+      G_CALLBACK (xfce_tasklist_button_drag_data_received), child);
 
   /* note that the same signals should be in the proxy menu item too */
   g_signal_connect (G_OBJECT (child->button), "enter-notify-event",
diff --git a/plugins/tasklist/tasklist-widget.h b/plugins/tasklist/tasklist-widget.h
index f1f6b11..3a0eaf4 100644
--- a/plugins/tasklist/tasklist-widget.h
+++ b/plugins/tasklist/tasklist-widget.h
@@ -54,9 +54,10 @@ enum _XfceTasklistSortOrder
   XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP, /* sort by group and then by timestamp */
   XFCE_TASKLIST_SORT_ORDER_TITLE, /* sort by window title */
   XFCE_TASKLIST_SORT_ORDER_GROUP_TITLE, /* sort by group and then by title */
+  XFCE_TASKLIST_SORT_ORDER_DND, /* append and support dnd */
 
   XFCE_TASKLIST_SORT_ORDER_MIN = XFCE_TASKLIST_SORT_ORDER_TIMESTAMP,
-  XFCE_TASKLIST_SORT_ORDER_MAX = XFCE_TASKLIST_SORT_ORDER_GROUP_TITLE,
+  XFCE_TASKLIST_SORT_ORDER_MAX = XFCE_TASKLIST_SORT_ORDER_DND,
   XFCE_TASKLIST_SORT_ORDER_DEFAULT = XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP
 };
 



More information about the Xfce4-commits mailing list