Skip to content

Commit

Permalink
Show uri of hinted element in statusbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglingsu committed Mar 30, 2019
1 parent f7e5465 commit 6b07416
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
40 changes: 35 additions & 5 deletions src/hints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@fanglingsu

fanglingsu Apr 18, 2019

Author Owner

@andrejlevkovitch May be this goto error is wrong here. Because the information about current focused hint without url is not a real 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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/scripts/hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ var hints = Object.freeze((function(){
idx = 0;
}
}
focusHint(idx);
return focusHint(idx);
}

function fire() {
Expand Down Expand Up @@ -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);

This comment has been minimized.

Copy link
@andrejlevkovitch

andrejlevkovitch Apr 9, 2019

here I have problem with command ';o2'.

This comment has been minimized.

Copy link
@fanglingsu

fanglingsu Apr 18, 2019

Author Owner

Does it work when you remove the return?

}
}

Expand Down

0 comments on commit 6b07416

Please sign in to comment.