From: Daniel Carl Date: Sat, 30 Mar 2019 01:18:51 +0000 (+0100) Subject: Show uri of hinted element in statusbar. X-Git-Url: https://git.owens.tech/dummy.html/dummy.html/git?a=commitdiff_plain;h=6b07416d773e2b48c6904c3590222e01f0a66725;p=vimb.git Show uri of hinted element in statusbar. --- diff --git a/src/hints.c b/src/hints.c index c5be1d8..d14db78 100644 --- a/src/hints.c +++ b/src/hints.c @@ -306,18 +306,40 @@ static gboolean hint_function_check_result(Client *c, GVariant *return_value) { gboolean success = FALSE; char *value = NULL; + WebKitHitTestResult *hitresult; if (!return_value) { - return FALSE; + goto error; } g_variant_get(return_value, "(bs)", &success, &value); if (!success || !strncmp(value, "ERROR:", 6)) { - return FALSE; + goto error; } - - /* following return values mark fired hints */ - if (!strncmp(value, "DONE:", 5)) { + if (!strncmp(value, "OVER:", 5)) { + /* If focused elements src is given fire mouse-target-changed signal + * to show its uri in the statusbar. */ + if (*(value + 7)) { + /* We get OVER:{I,A}:element-url so we use byte 6 to check for the + * hinted element type image I or link A. */ + if (*(value + 5) == 'I') { + hitresult = g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT, + "context", WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE, + "image-uri", value + 7, + NULL); + } else { + hitresult = g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT, + "context", WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK, + "link-uri", value + 7, + NULL); + } + g_signal_emit_by_name(c->webview, "mouse-target-changed", + WEBKIT_HIT_TEST_RESULT(hitresult), 0); + g_object_unref(hitresult); + } else { + goto error; + } + } else if (!strncmp(value, "DONE:", 5)) { fire_timeout(c, FALSE); /* Change to normal mode only if we are currently in command mode and * we are not in g-mode hinting. This is required to not switch to @@ -397,6 +419,14 @@ static gboolean hint_function_check_result(Client *c, GVariant *return_value) } return TRUE; + +error: + hitresult = g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT, + "context", WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT, + NULL); + g_signal_emit_by_name(c->webview, "mouse-target-changed", WEBKIT_HIT_TEST_RESULT(hitresult), 0); + g_object_unref(hitresult); + return FALSE; } static void fire_timeout(Client *c, gboolean on) diff --git a/src/scripts/hints.js b/src/scripts/hints.js index 6efee48..fab48de 100644 --- a/src/scripts/hints.js +++ b/src/scripts/hints.js @@ -348,7 +348,7 @@ var hints = Object.freeze((function(){ idx = 0; } } - focusHint(idx); + return focusHint(idx); } function fire() { @@ -423,8 +423,11 @@ var hints = Object.freeze((function(){ } /* get the new active hint */ if ((activeHint = validHints[newIdx])) { + var e = activeHint.e; activeHint.focus(); - mouseEvent(activeHint.e, "mouseover"); + mouseEvent(e, "mouseover"); + + return "OVER:" + (e instanceof HTMLImageElement ? "I:" : "A:") + getSrc(e); } }