From d21bdb01f4f21037840f8482458a8ca05b2ea4c3 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 9 Feb 2004 18:55:54 +0000 Subject: Fix the fix for the epiphany equivalent of bug #133633. Don't convert the 2004-02-09 Christian Persch * src/ephy-tab.c: (clipboard_text_received_cb), (ephy_tab_dom_mouse_click_cb): Fix the fix for the epiphany equivalent of bug #133633. Don't convert the clipboard contents directly as the souurce may not offer UTF-8 text. Instead request the contents, and gtk+ will convert it for us. --- src/ephy-tab.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ephy-tab.c b/src/ephy-tab.c index 260d58828..d05b882fa 100644 --- a/src/ephy-tab.c +++ b/src/ephy-tab.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #define EPHY_TAB_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB, EphyTabPrivate)) @@ -1008,6 +1009,27 @@ save_property_url (EphyEmbed *embed, g_object_unref (G_OBJECT(persist)); } +static void +clipboard_text_received_cb (GtkClipboard *clipboard, + const char *text, + gpointer *weak_ptr) +{ + if (*weak_ptr != NULL && text != NULL) + { + EphyTab *tab = (EphyTab *) *weak_ptr; + EphyEmbed *embed = ephy_tab_get_embed (tab); + + ephy_embed_load_url (embed, text); + } + + if (*weak_ptr != NULL) + { + g_object_remove_weak_pointer (G_OBJECT (*weak_ptr), weak_ptr); + } + + g_free (weak_ptr); +} + static gboolean ephy_tab_dom_mouse_click_cb (EphyEmbed *embed, EphyEmbedEvent *event, @@ -1076,11 +1098,22 @@ ephy_tab_dom_mouse_click_cb (EphyEmbed *embed, /* middle click opens the selection url */ else if (is_middle_clickable && is_middle_click && middle_click_opens) { - gtk_selection_convert (GTK_WIDGET (window), - GDK_SELECTION_PRIMARY, - /* See bug #133633 */ - gdk_atom_intern ("UTF8_STRING", FALSE), - GDK_CURRENT_TIME); + /* See bug #133633 for why we do it this way */ + + /* We need to make sure we know if the tab is destroyed between + * requesting the clipboard contents, and receiving them. + */ + gpointer *weak_ptr; + + weak_ptr = g_new (gpointer, 1); + *weak_ptr = tab; + g_object_add_weak_pointer (G_OBJECT (tab), weak_ptr); + + gtk_clipboard_request_text + (gtk_widget_get_clipboard (GTK_WIDGET (tab->priv->embed), + GDK_SELECTION_PRIMARY), + (GtkClipboardTextReceivedFunc) clipboard_text_received_cb, + weak_ptr); } /* we didn't handle the event */ else -- cgit v1.2.3