static VbResult normal_mark(Client *c, const NormalCmdInfo *info) { glong current; char *js, *mark; int idx; /* check if the second char is a valid mark char */ if (!(mark = strchr(MARK_CHARS, info->key2))) { return RESULT_ERROR; } /* get the index of the mark char */ idx = mark - MARK_CHARS; if ('m' == info->key) { c->state.marks[idx] = c->state.scroll_top; } else { /* check if the mark was set */ if ((int)(c->state.marks[idx] - .5) < 0) { return RESULT_ERROR; } current = c->state.scroll_top; /* jump to the location */ js = g_strdup_printf("window.scroll(window.screenLeft,%ld);", c->state.marks[idx]); ext_proxy_eval_script(c, js, NULL); g_free(js); /* save previous adjust as last position */ c->state.marks[MARK_TICK] = current; } return RESULT_COMPLETE; }
/** * Function called when vimb enters the input mode. */ void input_enter(Client *c) { /* switch focus first to make sure we can write to the inputbox without * disturbing the user */ gtk_widget_grab_focus(GTK_WIDGET(c->webview)); vb_modelabel_update(c, "-- INPUT --"); ext_proxy_eval_script(c, "var vimb_input_mode_element = document.activeElement;", NULL); }
static VbResult normal_scroll(Client *c, const NormalCmdInfo *info) { char *js; js = g_strdup_printf("vbscroll('%c',%d,%d);", info->key, c->config.scrollstep, info->count); ext_proxy_eval_script(c, js, NULL); g_free(js); return RESULT_COMPLETE; }
static VbResult normal_increment_decrement(Client *c, const NormalCmdInfo *info) { char *js; int count = info->count ? info->count : 1; js = g_strdup_printf(JS_INCREMENT_URI_NUMBER, info->key == CTRL('A') ? count : -count); ext_proxy_eval_script(c, js, NULL); g_free(js); return RESULT_COMPLETE; }
static VbResult normal_fire(Client *c, const NormalCmdInfo *info) { /* If searching is currently active - click link containing current search * highlight. We use the search_matches as indicator that the searching is * active. */ if (c->state.search.active) { ext_proxy_eval_script(c, "getSelection().anchorNode.parentNode.click();", NULL); return RESULT_COMPLETE; } return RESULT_ERROR; }
/** * Called when the input mode is left. */ void input_leave(Client *c) { ext_proxy_eval_script(c, "vimb_input_mode_element.blur();", NULL); vb_modelabel_update(c, ""); }
static void resume_editor(GPid pid, int status, EditorData *data) { char *text, *tmp; char *jscode; g_assert(pid); g_assert(data); g_assert(data->c); g_assert(data->file); if (status == 0) { /* get the text the editor stored */ text = util_get_file_contents(data->file, NULL); if (text) { /* escape the text to form a valid JS string */ /* TODO: could go into util.c maybe */ struct search_replace { const char* search; const char* replace; } escapes[] = { {"\x01", ""}, {"\x02", ""}, {"\x03", ""}, {"\x04", ""}, {"\x05", ""}, {"\x06", ""}, {"\a", ""}, {"\b", ""}, {"\t", "\\t"}, {"\n", "\\n"}, {"\v", ""}, {"\f", ""}, {"\r", ""}, {"\x0E", ""}, {"\x0F", ""}, {"\x10", ""}, {"\x11", ""}, {"\x12", ""}, {"\x13", ""}, {"\x14", ""}, {"\x15", ""}, {"\x16", ""}, {"\x17", ""}, {"\x18", ""}, {"\x19", ""}, {"\x1A", ""}, {"\x1B", ""}, {"\x1C", ""}, {"\x1D", ""}, {"\x1E", ""}, {"\x1F", ""}, {"\"", "\\\""}, {"\x7F", ""}, {NULL, NULL}, }; for(struct search_replace *i = escapes; i->search; i++) { tmp = util_str_replace(i->search, i->replace, text); g_free(text); text = tmp; } /* put the text back into the element */ jscode = g_strdup_printf("vimb_input_mode_element.value=\"%s\"", text); ext_proxy_eval_script(data->c, jscode, NULL); g_free(jscode); g_free(text); } } ext_proxy_eval_script(data->c, "vimb_input_mode_element.disabled=false;" "vimb_input_mode_element.focus()", NULL); g_unlink(data->file); g_free(data->file); g_slice_free(EditorData, data); g_spawn_close_pid(pid); }
VbResult input_open_editor(Client *c) { char **argv, *file_path = NULL; const char *text = NULL, *editor_command; int argc; GPid pid; gboolean success; GVariant *jsreturn; g_assert(c); /* get the editor command */ editor_command = GET_CHAR(c, "editor-command"); if (!editor_command || !*editor_command) { vb_echo(c, MSG_ERROR, TRUE, "No editor-command configured"); return RESULT_ERROR; } /* get the selected input element */ jsreturn = ext_proxy_eval_script_sync(c, "vimb_input_mode_element.value"); g_variant_get(jsreturn, "(bs)", &success, &text); if (!success || !text) { return RESULT_ERROR; } /* create a temp file to pass text to and from editor */ if (!util_create_tmp_file(text, &file_path)) { return RESULT_ERROR; } /* spawn editor */ char* command = g_strdup_printf(editor_command, file_path); if (!g_shell_parse_argv(command, &argc, &argv, NULL)) { g_critical("Could not parse editor-command '%s'", command); g_free(command); return RESULT_ERROR; } g_free(command); success = g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL ); g_strfreev(argv); if (!success) { unlink(file_path); g_free(file_path); g_warning("Could not spawn editor-command"); return RESULT_ERROR; } /* disable the active element */ ext_proxy_eval_script(c, "vimb_input_mode_element.disabled=true", NULL); /* watch the editor process */ EditorData *data = g_slice_new0(EditorData); data->file = file_path; data->c = c; g_child_watch_add(pid, (GChildWatchFunc)resume_editor, data); return RESULT_COMPLETE; }
/** * Called when passthrough mode is left. */ void pass_leave(Client *c) { ext_proxy_eval_script(c, "document.activeElement.blur();", NULL); vb_modelabel_update(c, ""); }