From 3102bc0cb9d84676ed400935883687d8a738c835 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sat, 24 Jul 2021 10:36:14 +0200 Subject: LdCategorySymbolView: work around a mysterious bug We sometimes get a deselecting event when toying around with menus and then dragging. There might be a simpler reproducer. --- liblogdiag/ld-category-symbol-view.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/liblogdiag/ld-category-symbol-view.c b/liblogdiag/ld-category-symbol-view.c index e4f7e81..2f4e2d9 100644 --- a/liblogdiag/ld-category-symbol-view.c +++ b/liblogdiag/ld-category-symbol-view.c @@ -47,6 +47,7 @@ SymbolData; * @path: path to the category within the library. * @layout: (element-type SymbolData *): current layout of symbols. * @preselected: currently preselected symbol. + * @dragged: currently dragged symbol. */ struct _LdCategorySymbolViewPrivate { @@ -54,6 +55,7 @@ struct _LdCategorySymbolViewPrivate gchar *path; GSList *layout; SymbolData *preselected; + SymbolData *dragged; }; enum @@ -180,6 +182,7 @@ layout_destroy (LdCategorySymbolView *self) g_slist_free (self->priv->layout); self->priv->layout = NULL; self->priv->preselected = NULL; + self->priv->dragged = NULL; } static GSList * @@ -457,12 +460,12 @@ on_drag_data_get LdCategorySymbolView *self; self = LD_CATEGORY_SYMBOL_VIEW (widget); - g_return_if_fail (self->priv->preselected != NULL); + g_return_if_fail (self->priv->dragged != NULL); gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data), - 8, (guchar *) self->priv->preselected->path, - strlen (self->priv->preselected->path)); + 8, (guchar *) self->priv->dragged->path, + strlen (self->priv->dragged->path)); } static void @@ -474,6 +477,9 @@ on_drag_begin (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data) self = LD_CATEGORY_SYMBOL_VIEW (widget); g_return_if_fail (self->priv->preselected != NULL); + /* Working around a mysterious bug where we /sometimes/ get deselected. */ + self->priv->dragged = self->priv->preselected; + /* Some of the larger previews didn't work, and we have to get rid of * the icon later when we're hovering above LdDiagramView anyway. */ pbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 1, 1); @@ -485,7 +491,11 @@ on_drag_begin (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data) static void on_drag_end (GtkWidget *widget, GdkDragContext *ctx, gpointer user_data) { - symbol_deselect (LD_CATEGORY_SYMBOL_VIEW (widget)); + LdCategorySymbolView *self; + + self = LD_CATEGORY_SYMBOL_VIEW (widget); + symbol_deselect (self); + self->priv->dragged = NULL; } static void -- cgit v1.2.3-70-g09d2