diff options
author | Daniel Carl <danielcarl@gmx.de> | 2017-05-07 02:03:19 +0200 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2017-05-07 02:03:19 +0200 |
commit | c55a758634321161b2b0c1c8e1b77b2595730cf7 (patch) | |
tree | 7b1f9e4e378418cfcde947f3b562b71752a79711 | |
parent | cb3af64b6cc851537f32615f3a1f8cb734605fcf (diff) |
Run hint script syncron #349.
When we run the hinting asyn over dbus we can't use the return value
of the hinting to check if the action was done or not. So it was not
possible to undo last number filter on pressing backspace.
-rw-r--r-- | src/ext-proxy.c | 30 | ||||
-rw-r--r-- | src/ext-proxy.h | 1 | ||||
-rw-r--r-- | src/hints.c | 43 |
3 files changed, 50 insertions, 24 deletions
diff --git a/src/ext-proxy.c b/src/ext-proxy.c index 6957f97..4bee71c 100644 --- a/src/ext-proxy.c +++ b/src/ext-proxy.c @@ -32,6 +32,8 @@ static void on_proxy_created (GDBusProxy *proxy, GAsyncResult *result, gpointer data); static void dbus_call(Client *c, const char *method, GVariant *param, GAsyncReadyCallback callback); +static GVariant *dbus_call_sync(Client *c, const char *method, GVariant + *param); static void on_web_extension_page_created(GDBusConnection *connection, const char *sender_name, const char *object_path, const char *interface_name, const char *signal_name, @@ -162,6 +164,11 @@ void ext_proxy_eval_script(Client *c, char *js, GAsyncReadyCallback callback) } } +GVariant *ext_proxy_eval_script_sync(Client *c, char *js) +{ + return dbus_call_sync(c, "EvalJs", g_variant_new("(s)", js)); +} + /** * Request the web extension to focus first editable element. * Returns whether an focusable element was found or not. @@ -194,6 +201,29 @@ static void dbus_call(Client *c, const char *method, GVariant *param, } /** + * Call a dbus method syncron. + */ +static GVariant *dbus_call_sync(Client *c, const char *method, GVariant *param) +{ + GVariant *result = NULL; + GError *error = NULL; + + if (!c->dbusproxy) { + return NULL; + } + + result = g_dbus_proxy_call_sync(c->dbusproxy, method, param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + + if (error) { + g_warning("Failed dbus method %s: %s", method, error->message); + g_error_free(error); + } + + return result; +} + +/** * Called when the web context created the page. * * Find the right client to the page id returned from the webextension. diff --git a/src/ext-proxy.h b/src/ext-proxy.h index 7c70c72..82e706e 100644 --- a/src/ext-proxy.h +++ b/src/ext-proxy.h @@ -24,6 +24,7 @@ const char *ext_proxy_init(void); void ext_proxy_eval_script(Client *c, char *js, GAsyncReadyCallback callback); +GVariant *ext_proxy_eval_script_sync(Client *c, char *js); void ext_proxy_focus_input(Client *c); void ext_proxy_set_header(Client *c, const char *headers); diff --git a/src/hints.c b/src/hints.c index b24b313..43a7834 100644 --- a/src/hints.c +++ b/src/hints.c @@ -44,7 +44,7 @@ static struct { extern struct Vimb vb; -static void call_hints_function(Client *c, const char *func, const char* args); +static gboolean call_hints_function(Client *c, const char *func, const char* args); static void fire_timeout(Client *c, gboolean on); static gboolean fire_cb(gpointer data); @@ -55,10 +55,11 @@ VbResult hints_keypress(Client *c, int key) hints_fire(c); return RESULT_COMPLETE; - } else if (key == CTRL('H')) { + } else if (key == CTRL('H')) { /* backspace */ fire_timeout(c, false); - call_hints_function(c, "update", "null"); - return RESULT_MORE; // continue handling the backspace + if (call_hints_function(c, "update", "null")) { + return RESULT_COMPLETE; + } } else if (key == KEY_TAB) { fire_timeout(c, false); hints_focus_next(c, false); @@ -72,8 +73,9 @@ VbResult hints_keypress(Client *c, int key) } else { fire_timeout(c, true); /* try to handle the key by the javascript */ - call_hints_function(c, "update", (char[]){'"', key, '"', '\0'}); - return RESULT_ERROR; + if (call_hints_function(c, "update", (char[]){'"', key, '"', '\0'})) { + return RESULT_COMPLETE; + } } fire_timeout(c, false); @@ -247,23 +249,23 @@ gboolean hints_parse_prompt(const char *prompt, char *mode, gboolean *is_gmode) return res; } -static void hints_function_callback(GDBusProxy *proxy, GAsyncResult *result, Client *c) +static gboolean call_hints_function(Client *c, const char *func, const char* args) { + GVariant *return_value; + char *jscode, *value = NULL; gboolean success = FALSE; - char *value = NULL; - GVariant *return_value = g_dbus_proxy_call_finish(proxy, result, NULL); + jscode = g_strdup_printf("hints.%s(%s);", func, args); + return_value = ext_proxy_eval_script_sync(c, jscode); + g_free(jscode); + if (!return_value) { - return; + return FALSE; } g_variant_get(return_value, "(bs)", &success, &value); - if (!success) { - return; - } - - if (!strncmp(value, "ERROR:", 6)) { - return; + if (!success || !strncmp(value, "ERROR:", 6)) { + return FALSE; } /* following return values mark fired hints */ @@ -338,15 +340,8 @@ static void hints_function_callback(GDBusProxy *proxy, GAsyncResult *result, Cli #endif } } -} -static void call_hints_function(Client *c, const char *func, const char* args) -{ - char *jscode; - - jscode = g_strdup_printf("hints.%s(%s);", func, args); - ext_proxy_eval_script(c, jscode, (GAsyncReadyCallback)hints_function_callback); - g_free(jscode); + return TRUE; } static void fire_timeout(Client *c, gboolean on) |