summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-09-17 13:29:14 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-09-17 13:49:26 (EDT)
commit37733b6c3e88ee99b97f944792e23026e524f4dc (patch)
tree2eecfb0a4c04ad3e931feaff6c4359dd69e21e01 /src
parentf64765f2e5663452cab52268abc58b214ea8229e (diff)
downloadmarquee-37733b6c3e88ee99b97f944792e23026e524f4dc.zip
marquee-37733b6c3e88ee99b97f944792e23026e524f4dc.tar.gz
marquee-37733b6c3e88ee99b97f944792e23026e524f4dc.tar.bz2
src/tab-chrome.[ch]: Show hovered link URI in URI bar
And do so only if the URI bar hasn't been manually edited. (Or maybe we can just cache the edited string. Then the cache would have to be updated if the Web view's URI changes while a link is targeted.) This is a cool feature I haven't seen anywhere. It largely obviates a status bar, puts the hovered link URI in arguably a more sensible location, and allows the hovered link URI to be added to the primary selection and/or clipboard quickly and easily from the URI bar.
Diffstat (limited to 'src')
-rw-r--r--src/tab-chrome.c33
-rw-r--r--src/tab-chrome.h1
2 files changed, 34 insertions, 0 deletions
diff --git a/src/tab-chrome.c b/src/tab-chrome.c
index ea168dd..1b07236 100644
--- a/src/tab-chrome.c
+++ b/src/tab-chrome.c
@@ -117,6 +117,11 @@ navigation_toolbar_new(MqTabChrome *chrome, gchar *uri)
gtk_tool_item_set_expand(uri_toolitem, TRUE);
gtk_toolbar_insert(navigation_toolbar, uri_toolitem, -1);
+ /* URI bar hovered link style */
+ chrome->hovered_link_style = pango_attr_list_new();
+ pango_attr_list_insert(chrome->hovered_link_style,
+ pango_attr_style_new(PANGO_STYLE_ITALIC));
+
gtk_widget_set_hexpand(GTK_WIDGET(navigation_toolbar), TRUE);
chrome->load_failed = FALSE;
@@ -203,6 +208,32 @@ load_failed_cb(WebKitWebView __attribute__((unused)) *web_view,
}
static void
+mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view,
+ WebKitHitTestResult *hit_test_result,
+ guint __attribute__((unused)) modifiers,
+ MqTabChrome *chrome)
+{
+ if (webkit_hit_test_result_context_is_link(hit_test_result)) {
+ if (g_strcmp0(gtk_entry_get_text(GTK_ENTRY(chrome->uri_entry)),
+ webkit_web_view_get_uri(web_view)) == 0) {
+ gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry),
+ webkit_hit_test_result_get_link_uri(
+ hit_test_result));
+ gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry),
+ chrome->hovered_link_style);
+ }
+ } else {
+ if (gtk_entry_get_attributes(GTK_ENTRY(chrome->uri_entry)) ==
+ chrome->hovered_link_style) {
+ gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry),
+ webkit_web_view_get_uri(web_view));
+ gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry),
+ NULL);
+ }
+ }
+}
+
+static void
load_progress_cb(WebKitWebView *web_view,
GParamSpec __attribute__((unused)) *paramspec, MqTabChrome *chrome)
{
@@ -276,6 +307,8 @@ connect_web_view(MqTabChrome *chrome)
G_CALLBACK(load_changed_cb), chrome);
g_signal_connect(chrome->web_view, "load-failed",
G_CALLBACK(load_failed_cb), chrome);
+ g_signal_connect(chrome->web_view, "mouse-target-changed",
+ G_CALLBACK(mouse_target_changed_cb), chrome);
g_signal_connect(chrome->web_view, "notify::estimated-load-progress",
G_CALLBACK(load_progress_cb), chrome);
g_signal_connect(chrome->web_view, "notify::uri",
diff --git a/src/tab-chrome.h b/src/tab-chrome.h
index aef59f9..61fc069 100644
--- a/src/tab-chrome.h
+++ b/src/tab-chrome.h
@@ -36,6 +36,7 @@ typedef struct {
GtkWidget *reload_icon;
GtkToolItem *stop_reload_button;
GtkWidget *uri_entry;
+ PangoAttrList *hovered_link_style;
WebKitWebView *web_view;
gboolean load_failed;
} MqTabChrome;