logo

badwolf

Unnamed repository; edit this file 'description' to name the repository.
commit: 78a41bafb8ea56d72e873e617d1adbc5c3d0e212
parent: a6cc185390f63988860788ab794f2e7cb9028b53
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  8 Jan 2019 21:53:07 +0100

badwolf.c: Add statusbar with link hovering URI, handles mouse-target-changed

Diffstat:

Mbadwolf.c30++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/badwolf.c b/badwolf.c @@ -11,6 +11,7 @@ struct Client GtkWidget *main_window; GtkWidget *box; GtkWidget *location; + GtkWidget *statusbar; WebKitWebView *webView; }; @@ -71,6 +72,25 @@ WebViewCb_notify__title(WebKitWebView *webView, GParamSpec *pspec, gpointer user return TRUE; } +static gboolean WebViewCb_mouse_target_changed(WebKitWebView *webView, + WebKitHitTestResult *hit, + guint modifiers, + gpointer user_data) +{ + struct Client *browser = (struct Client *)user_data; + const gchar *link_uri = webkit_hit_test_result_get_link_uri(hit); + guint context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR(browser->statusbar), "link"); + + gtk_statusbar_remove_all(GTK_STATUSBAR(browser->statusbar), context_id); + + if(link_uri != NULL) + { + gtk_statusbar_push(GTK_STATUSBAR(browser->statusbar), context_id, link_uri); + } + + return TRUE; +} + static gboolean locationCb_activate(GtkEntry *location, gpointer user_data) { const char *target_url; @@ -93,13 +113,15 @@ int main(int argc, char *argv[]) if(argv[1]) target_url = argv[1]; browser->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - browser->location = gtk_entry_new(); browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + browser->location = gtk_entry_new(); + browser->statusbar = gtk_statusbar_new(); browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); gtk_container_add(GTK_CONTAINER(browser->main_window), browser->box); gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->location), FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(browser->box), GTK_WIDGET(browser->webView), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->webView), TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(browser->box), GTK_WIDGET(browser->statusbar), FALSE, FALSE, 0); gtk_entry_set_text(GTK_ENTRY(browser->location), target_url); @@ -112,6 +134,10 @@ int main(int argc, char *argv[]) NULL); g_signal_connect(browser->webView, "notify::uri", G_CALLBACK(WebViewCb_notify__uri), browser); g_signal_connect(browser->webView, "notify::title", G_CALLBACK(WebViewCb_notify__title), browser); + g_signal_connect(browser->webView, + "mouse-target-changed", + G_CALLBACK(WebViewCb_mouse_target_changed), + browser); WebKitSettings *settings = webkit_web_view_get_settings(browser->webView);