[gnome-todo/wip/gbsneto/dnd-fixups] task-list-view: Properly calculate row x offset



commit a670618a663d7a36249467d7c2342b32055d81ae
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Oct 31 17:07:48 2017 -0200

    task-list-view: Properly calculate row x offset

 src/gtd-dnd-row.c        |  2 +-
 src/gtd-task-list-view.c |  6 ++++++
 src/gtd-task-row.c       | 37 +++++++++++++++++++++++--------------
 src/gtd-task-row.h       |  2 ++
 4 files changed, 32 insertions(+), 15 deletions(-)
---
diff --git a/src/gtd-dnd-row.c b/src/gtd-dnd-row.c
index e83af84..bb85055 100644
--- a/src/gtd-dnd-row.c
+++ b/src/gtd-dnd-row.c
@@ -199,7 +199,7 @@ gtd_dnd_row_drag_motion (GtkWidget      *widget,
       gint offset;
 
       task = gtd_task_row_get_task (GTD_TASK_ROW (self->row_above));
-      offset = gtk_widget_get_margin_start (self->box) + gtk_widget_get_allocated_width (self->icon) + 12;
+      offset = gtk_widget_get_margin_start (self->box) + gtk_widget_get_allocated_width (self->icon);
       self->depth = CLAMP (floor ((x - alloc.x - offset) / 32),
                            0,
                            gtd_task_get_depth (task) + 1);
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index 008835b..fcdf7d9 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -1333,13 +1333,19 @@ listbox_drag_motion (GtkListBox      *listbox,
 {
   GtdTaskListViewPrivate *priv;
   GtkListBoxRow *hovered_row;
+  GtkListBoxRow *source_row;
   GtkListBoxRow *task_row;
   GtkListBoxRow *row_above_dnd;
+  GtkWidget *source_widget;
   gint row_x, row_y, row_height;
 
   priv = gtd_task_list_view_get_instance_private (self);
+  source_widget = gtk_drag_get_source_widget (context);
+  source_row = GTK_LIST_BOX_ROW (gtk_widget_get_ancestor (source_widget, GTK_TYPE_LIST_BOX_ROW));
   hovered_row = gtk_list_box_get_row_at_y (listbox, y);
 
+  x -= gtd_task_row_get_x_offset (GTD_TASK_ROW (source_row));
+
   /*
    * When not hovering any row, we still have to make sure that the listbox is a valid
    * drop target. Otherwise, the user can drop at the space after the rows, and the row
diff --git a/src/gtd-task-row.c b/src/gtd-task-row.c
index 80ff5f8..0ddbf1a 100644
--- a/src/gtd-task-row.c
+++ b/src/gtd-task-row.c
@@ -51,8 +51,8 @@ struct _GtdTaskRow
   GtkWidget          *dnd_box;
   GtkWidget          *dnd_event_box;
   GtkWidget          *dnd_icon;
-  gdouble             clicked_x;
-  gdouble             clicked_y;
+  gint                clicked_x;
+  gint                clicked_y;
 
   gboolean            handle_subtasks : 1;
 
@@ -193,8 +193,18 @@ button_press_event (GtkWidget      *widget,
                     GdkEventButton *event,
                     GtdTaskRow     *self)
 {
-  self->clicked_x = event->x;
-  self->clicked_y = event->y;
+  gint real_x;
+  gint real_y;
+
+  gtk_widget_translate_coordinates (widget,
+                                    GTK_WIDGET (self),
+                                    event->x,
+                                    event->y,
+                                    &real_x,
+                                    &real_y);
+
+  self->clicked_x = real_x;
+  self->clicked_y = real_y;
 
   return GDK_EVENT_PROPAGATE;
 }
@@ -205,18 +215,9 @@ drag_begin_cb (GtkWidget      *event_box,
                GtdTaskRow     *self)
 {
   GtkWidget *widget, *new_row;
-  gint real_x;
-  gint real_y;
 
   widget = GTK_WIDGET (self);
 
-  gtk_widget_translate_coordinates (event_box,
-                                    widget,
-                                    self->clicked_x,
-                                    self->clicked_y,
-                                    &real_x,
-                                    &real_y);
-
   set_cursor (widget, "grabbing");
 
   /*
@@ -229,7 +230,7 @@ drag_begin_cb (GtkWidget      *event_box,
                                gtk_widget_get_allocated_width (widget),
                                gtk_widget_get_allocated_height (widget));
 
-  gtk_drag_set_icon_widget (context, new_row, real_x, real_y);
+  gtk_drag_set_icon_widget (context, new_row, self->clicked_x, self->clicked_y);
 
   gtk_widget_hide (widget);
 }
@@ -908,3 +909,11 @@ gtd_task_row_set_sizegroups (GtdTaskRow   *self,
   gtk_size_group_add_widget (name_group, GTK_WIDGET (self->task_list_label));
   gtk_size_group_add_widget (name_group, GTK_WIDGET (self->task_date_label));
 }
+
+gint
+gtd_task_row_get_x_offset (GtdTaskRow *self)
+{
+  g_return_val_if_fail (GTD_IS_TASK_ROW (self), -1);
+
+  return self->clicked_x;
+}
diff --git a/src/gtd-task-row.h b/src/gtd-task-row.h
index 814aa37..40e850d 100644
--- a/src/gtd-task-row.h
+++ b/src/gtd-task-row.h
@@ -61,6 +61,8 @@ void                      gtd_task_row_set_sizegroups           (GtdTaskRow
                                                                  GtkSizeGroup        *name_group,
                                                                  GtkSizeGroup        *date_group);
 
+gint                      gtd_task_row_get_x_offset             (GtdTaskRow          *self);
+
 G_END_DECLS
 
 #endif /* GTD_TASK_ROW_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]