Skip to content

Commit

Permalink
audgui: Make drag and drop work on Wayland. Closes: #1423
Browse files Browse the repository at this point in the history
Calling both gtk_drag_get_data() and gtk_drag_finish()
leads to drag and drop not working on Wayland and this error:
"error reading selection buffer: Operation was cancelled"

Move the gtk_drag_finish() call to the "drag-data-received"
handler which gets triggered by calling gtk_drag_get_data()
to fix this.

See also:
- https://gitlab.gnome.org/GNOME/gimp/-/merge_requests/927
- https://docs.gtk.org/gtk3/signal.Widget.drag-drop.html

Co-authored-by: John Lindgren <john@jlindgren.net>
  • Loading branch information
radioactiveman and jlindgren90 committed Jul 8, 2024
1 parent 465c12c commit 5dbba6b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/libaudgui/list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,28 +487,31 @@ static gboolean drag_drop (GtkWidget * widget, GdkDragContext * context, int x,
{
g_signal_stop_emission_by_name (widget, "drag-drop");

gboolean success = true;
int row = audgui_list_row_at_point_rounded (widget, x, y);

if (model->dragging && MODEL_HAS_CB (model, shift_rows))
{
/* dragging within same list */
if (model->clicked_row >= 0 && model->clicked_row < model->rows)
gboolean valid = (model->clicked_row >= 0 && model->clicked_row < model->rows);
if (valid)
model->cbs->shift_rows (model->user, model->clicked_row, row);
else
success = false;

gtk_drag_finish (context, valid, false, time);
}
else if (MODEL_HAS_CB (model, data_type) && MODEL_HAS_CB (model, receive_data))
{
/* cross-widget dragging */
model->receive_row = row;
gtk_drag_get_data (widget, context, gdk_atom_intern
(model->cbs->data_type, false), time);
/* gtk_drag_finish() is called from drag_data_received() */
}
else
success = false;
{
/* invalid */
gtk_drag_finish (context, false, false, time);
}

gtk_drag_finish (context, success, false, time);
gtk_tree_view_set_drag_dest_row ((GtkTreeView *) widget, nullptr, (GtkTreeViewDropPosition) 0);
stop_autoscroll (model, widget);
return true;
Expand All @@ -524,10 +527,12 @@ static void drag_data_received (GtkWidget * widget, GdkDragContext * context, in

auto data = (const char *) gtk_selection_data_get_data (sel);
int length = gtk_selection_data_get_length (sel);
gboolean valid = (data && length);

if (data && length)
if (valid)
model->cbs->receive_data (model->user, model->receive_row, data, length);

gtk_drag_finish (context, valid, false, time);
model->receive_row = -1;
}

Expand Down

0 comments on commit 5dbba6b

Please sign in to comment.