[gtk/matthiasc/for-master: 1/2] textview: Fix dnd
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 1/2] textview: Fix dnd
- Date: Sun, 6 Sep 2020 16:20:52 +0000 (UTC)
commit 9b8c175f234ce4eb071199ab29137adb6ef6c9b0
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Sep 6 11:48:10 2020 -0400
textview: Fix dnd
When we start a dnd of the selection in the drag-update handler,
set the gesture state to denied. Otherwise, we get more drag-update
signals, and things get really confused, leading to no dnd and
sadness.
gtk/gtktextview.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 5b0715befd..dc8d3c9682 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -7188,11 +7188,11 @@ selection_data_free (SelectionData *data)
static gboolean
drag_gesture_get_text_surface_coords (GtkGestureDrag *gesture,
- GtkTextView *text_view,
- int *start_x,
- int *start_y,
- int *x,
- int *y)
+ GtkTextView *text_view,
+ int *start_x,
+ int *start_y,
+ int *x,
+ int *y)
{
double sx, sy, ox, oy;
@@ -7262,6 +7262,10 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
gtk_text_view_start_selection_dnd (text_view, &iter, event,
start_x, start_y);
+
+ /* Deny the gesture so we don't get further updates */
+ gtk_gesture_set_state (text_view->priv->drag_gesture,
+ GTK_EVENT_SEQUENCE_DENIED);
return;
}
else
@@ -7275,6 +7279,8 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
return;
}
+ g_assert (data != NULL);
+
/* Text selection */
if (data->granularity == SELECT_CHARACTERS)
{
@@ -7782,6 +7788,14 @@ dnd_finished_cb (GdkDrag *drag,
self->priv->drag = NULL;
}
+static void
+dnd_cancel_cb (GdkDrag *drag,
+ GdkDragCancelReason reason,
+ GtkTextView *self)
+{
+ self->priv->drag = NULL;
+}
+
static void
gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
@@ -7808,9 +7822,11 @@ gtk_text_view_start_selection_dnd (GtkTextView *text_view,
surface = gdk_event_get_surface (event);
device = gdk_event_get_device (event);
drag = gdk_drag_begin (surface, device, content, actions, x, y);
+
g_object_unref (content);
g_signal_connect (drag, "dnd-finished", G_CALLBACK (dnd_finished_cb), text_view);
+ g_signal_connect (drag, "cancel", G_CALLBACK (dnd_cancel_cb), text_view);
if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]