From 74bdc3ed21d74d464cd94c5ca461b9ba7d10616b Mon Sep 17 00:00:00 2001 From: Peter Hofmann Date: Sun, 16 Aug 2020 07:53:37 +0200 Subject: [PATCH] Fix opening links in new tabs (partially) Also, no NULL guard needed for g_free(). --- BUGS | 15 +++++++++++++++ CHANGES | 6 ++++++ browser.c | 33 ++++++++++++++------------------- 3 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 BUGS diff --git a/BUGS b/BUGS new file mode 100644 index 0000000..2be5ead --- /dev/null +++ b/BUGS @@ -0,0 +1,15 @@ +Links sometimes do not open in a new tab +======================================== + +We select for "mouse-target-changed" events: When the pointer is being +moved, WebKit tells us if it's now being positioned over a link or not. + +However, when a new link pops into existence right below the mouse +pointer (without the pointer being moved), we don't get this event. When +the user now issues a middle-click, we open the link in the same tab. +This is wrong. + +Ideally, we could access a hit test result while processing the click +event, but that doesn't appear to be possible? + +This bug is also present in suckless surf and GNOME Epiphany. diff --git a/CHANGES b/CHANGES index 42bb1c5..538ad11 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,11 @@ Release history for lariza +next + [Fixed] + - Middle-click to open in a new tab has been improved. In certain + conditions, the user's intention to open a new tab has been ignored + and URLs haven been opened in the current tab. + v20.07 2020-07-19 [Fixed] - Build no longer depends on GNU sed. diff --git a/browser.c b/browser.c index 8df0e33..3e0a4a7 100644 --- a/browser.c +++ b/browser.c @@ -767,28 +767,23 @@ hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers gpointer data) { struct Client *c = (struct Client *)data; + const char *to_show; - if (!gtk_widget_is_focus(c->location)) - { - if (webkit_hit_test_result_context_is_link(ht)) - { - gtk_entry_set_text(GTK_ENTRY(c->location), - webkit_hit_test_result_get_link_uri(ht)); - - if (c->hover_uri != NULL) - g_free(c->hover_uri); - c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht)); - } - else - { - gtk_entry_set_text(GTK_ENTRY(c->location), - webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view))); + g_free(c->hover_uri); - if (c->hover_uri != NULL) - g_free(c->hover_uri); - c->hover_uri = NULL; - } + if (webkit_hit_test_result_context_is_link(ht)) + { + to_show = webkit_hit_test_result_get_link_uri(ht); + c->hover_uri = g_strdup(to_show); } + else + { + to_show = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)); + c->hover_uri = NULL; + } + + if (!gtk_widget_is_focus(c->location)) + gtk_entry_set_text(GTK_ENTRY(c->location), to_show); } void -- 2.39.2