From bb6862df1beddeaa4802af58b94332ba48afbb4f Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Sat, 3 Oct 2020 20:09:07 +0900 Subject: [PATCH] Fix crash on drag and drop * src/pgtkterm.c (pgtk_select): Move dispatch before g_main_context_query. (drag_drop): Remove drag_drop. (drag_data_received): Rename arg. (pgtk_set_event_handler): Remove drag-drop callback. --- src/pgtkterm.c | 51 ++++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/src/pgtkterm.c b/src/pgtkterm.c index a5cf0a8159d..c66379e6e4b 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -3841,6 +3841,20 @@ pgtk_select (int fds_lim, fd_set * rfds, fd_set * wfds, fd_set * efds, Note that, as implemented, this failure is completely silent: there is no feedback to the caller. */ + /* Before sleep, dispatch draw events. + * Don't do this after g_main_context_query(), because fd may be closed + * in dispatch. + */ + if (context_acquired) + { + int pselect_errno = errno; + block_input (); + while (g_main_context_pending (context)) + g_main_context_dispatch (context); + unblock_input (); + errno = pselect_errno; + } + if (rfds) all_rfds = *rfds; else @@ -3895,17 +3909,6 @@ pgtk_select (int fds_lim, fd_set * rfds, fd_set * wfds, fd_set * efds, tmop = &tmo; } - /* Before sleep, dispatch draw events. */ - if (context_acquired) - { - int pselect_errno = errno; - block_input (); - while (g_main_context_pending (context)) - g_main_context_dispatch (context); - unblock_input (); - errno = pselect_errno; - } - fds_lim = max_fds + 1; nfds = thread_select (pselect, fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL, efds, @@ -6509,31 +6512,11 @@ scroll_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data) return TRUE; } -static gboolean -drag_drop (GtkWidget * widget, - GdkDragContext * context, - gint x, gint y, guint time_, gpointer user_data) -{ - PGTK_TRACE ("drag_drop"); - GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); - PGTK_TRACE ("drag_drop: target: %p", (void *) target); - - if (target == GDK_NONE) - { - gtk_drag_finish (context, TRUE, FALSE, time_); - return FALSE; - } - - gtk_drag_get_data (widget, context, target, time_); - - return TRUE; -} - static void drag_data_received (GtkWidget * widget, GdkDragContext * context, gint x, gint y, GtkSelectionData * data, - guint info, guint time_, gpointer user_data) + guint info, guint time, gpointer user_data) { PGTK_TRACE ("drag_data_received:"); struct frame *f = pgtk_any_window_to_frame (gtk_widget_get_window (widget)); @@ -6567,7 +6550,7 @@ drag_data_received (GtkWidget * widget, GdkDragContext * context, } PGTK_TRACE ("drag_data_received: that's all."); - gtk_drag_finish (context, TRUE, FALSE, time_); + gtk_drag_finish (context, TRUE, FALSE, time); } void @@ -6622,8 +6605,6 @@ pgtk_set_event_handler (struct frame *f) G_CALLBACK (pgtk_selection_lost), NULL); g_signal_connect (G_OBJECT (FRAME_GTK_WIDGET (f)), "configure-event", G_CALLBACK (configure_event), NULL); - g_signal_connect (G_OBJECT (FRAME_GTK_WIDGET (f)), "drag-drop", - G_CALLBACK (drag_drop), NULL); g_signal_connect (G_OBJECT (FRAME_GTK_WIDGET (f)), "drag-data-received", G_CALLBACK (drag_data_received), NULL); g_signal_connect (G_OBJECT (FRAME_GTK_WIDGET (f)), "draw", -- 2.39.5