#include "main.h"
#include "command.h"
+#include "keybind.h"
+#include "setting.h"
+
+extern const char *inputbox_font[2];
+extern const char *inputbox_fg[2];
+extern const char *inputbox_bg[2];
static CommandInfo cmd_list[] = {
- /* command function arg */
- {"normal", vp_set_mode, {VP_MODE_NORMAL, ""}},
- {"open", vp_open, {VP_MODE_NORMAL, ""}},
- {"input", vp_input, {0, ":"}},
- {"inputopen", vp_input, {0, ":open "}},
- {"inputopencurrent", vp_input, {VP_INPUT_CURRENT_URI, ":open "}},
- {"quit", vp_close_browser, {0}},
- {"source", vp_view_source, {0}},
- {"back", vp_navigate, {VP_NAVIG_BACK}},
- {"forward", vp_navigate, {VP_NAVIG_FORWARD}},
- {"reload", vp_navigate, {VP_NAVIG_RELOAD}},
- {"reload!", vp_navigate, {VP_NAVIG_RELOAD_FORCE}},
- {"stop", vp_navigate, {VP_NAVIG_STOP_LOADING}},
- {"jumpleft", vp_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}},
- {"jumpright", vp_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}},
- {"jumptop", vp_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}},
- {"jumpbottom", vp_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}},
- {"pageup", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}},
- {"pagedown", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}},
- {"halfpageup", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}},
- {"halfpagedown", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}},
- {"scrollleft", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}},
- {"scrollright", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}},
- {"scrollup", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}},
- {"scrolldown", vp_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}},
- {"nmap", vp_map, {VP_MODE_NORMAL}},
- {"imap", vp_map, {VP_MODE_INSERT}},
- {"cmap", vp_map, {VP_MODE_COMMAND}},
- {"nunmap", vp_unmap, {VP_MODE_NORMAL}},
- {"iunmap", vp_unmap, {VP_MODE_INSERT}},
- {"cunmap", vp_unmap, {VP_MODE_COMMAND}},
- {"set", vp_set, {0}},
+ /* command function arg */
+ {"open", command_open, {VP_MODE_NORMAL, ""}},
+ {"input", command_input, {0, ":"}},
+ {"inputopen", command_input, {0, ":open "}},
+ {"inputopencurrent", command_input, {VP_INPUT_CURRENT_URI, ":open "}},
+ {"quit", command_close, {0}},
+ {"source", command_view_source, {0}},
+ {"back", command_navigate, {VP_NAVIG_BACK}},
+ {"forward", command_navigate, {VP_NAVIG_FORWARD}},
+ {"reload", command_navigate, {VP_NAVIG_RELOAD}},
+ {"reload!", command_navigate, {VP_NAVIG_RELOAD_FORCE}},
+ {"stop", command_navigate, {VP_NAVIG_STOP_LOADING}},
+ {"jumpleft", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_LEFT}},
+ {"jumpright", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_RIGHT}},
+ {"jumptop", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_TOP}},
+ {"jumpbottom", command_scroll, {VP_SCROLL_TYPE_JUMP | VP_SCROLL_DIRECTION_DOWN}},
+ {"pageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_PAGE}},
+ {"pagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_PAGE}},
+ {"halfpageup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_HALFPAGE}},
+ {"halfpagedown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_HALFPAGE}},
+ {"scrollleft", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_LEFT | VP_SCROLL_UNIT_LINE}},
+ {"scrollright", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_RIGHT | VP_SCROLL_UNIT_LINE}},
+ {"scrollup", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_TOP | VP_SCROLL_UNIT_LINE}},
+ {"scrolldown", command_scroll, {VP_SCROLL_TYPE_SCROLL | VP_SCROLL_DIRECTION_DOWN | VP_SCROLL_UNIT_LINE}},
+ {"nmap", command_map, {VP_MODE_NORMAL}},
+ {"imap", command_map, {VP_MODE_INSERT}},
+ {"cmap", command_map, {VP_MODE_COMMAND}},
+ {"nunmap", command_unmap, {VP_MODE_NORMAL}},
+ {"iunmap", command_unmap, {VP_MODE_INSERT}},
+ {"cunmap", command_unmap, {VP_MODE_COMMAND}},
+ {"set", command_set, {0}},
};
-void command_init()
+void command_init(void)
{
guint i;
vp.behave.commands = g_hash_table_new(g_str_hash, g_str_equal);
}
}
+void command_cleanup(void)
+{
+ if (vp.behave.commands) {
+ g_hash_table_destroy(vp.behave.commands);
+ }
+}
+
gboolean command_exists(const gchar* name)
{
return g_hash_table_contains(vp.behave.commands, name);
return result;
}
+
+gboolean command_open(const Arg* arg)
+{
+ return vp_load_uri(arg);
+}
+
+gboolean command_input(const Arg* arg)
+{
+ gint pos = 0;
+ const gchar* url;
+
+ /* reset the colors and fonts to defalts */
+ vp_set_widget_font(vp.gui.inputbox, inputbox_font[0], inputbox_bg[0], inputbox_fg[0]);
+
+ /* remove content from input box */
+ gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), "");
+
+ /* insert string from arg */
+ gtk_editable_insert_text(GTK_EDITABLE(vp.gui.inputbox), arg->s, -1, &pos);
+
+ /* add current url if requested */
+ if (VP_INPUT_CURRENT_URI == arg->i
+ && (url = webkit_web_view_get_uri(vp.gui.webview))) {
+ gtk_editable_insert_text(GTK_EDITABLE(vp.gui.inputbox), url, -1, &pos);
+ }
+
+ gtk_editable_set_position(GTK_EDITABLE(vp.gui.inputbox), -1);
+
+ Arg a = {VP_MODE_COMMAND};
+ return vp_set_mode(&a);
+}
+
+gboolean command_close(const Arg* arg)
+{
+ vp_clean_up();
+ gtk_main_quit();
+
+ return TRUE;
+}
+
+gboolean command_view_source(const Arg* arg)
+{
+ gboolean mode = webkit_web_view_get_view_source_mode(vp.gui.webview);
+ webkit_web_view_set_view_source_mode(vp.gui.webview, !mode);
+ webkit_web_view_reload(vp.gui.webview);
+
+ return TRUE;
+}
+
+gboolean command_navigate(const Arg* arg)
+{
+ if (arg->i <= VP_NAVIG_FORWARD) {
+ /* TODO allow to set a count for the navigation */
+ webkit_web_view_go_back_or_forward(
+ vp.gui.webview, (arg->i == VP_NAVIG_BACK ? -1 : 1)
+ );
+ } else if (arg->i == VP_NAVIG_RELOAD) {
+ webkit_web_view_reload(vp.gui.webview);
+ } else if (arg->i == VP_NAVIG_RELOAD_FORCE) {
+ webkit_web_view_reload_bypass_cache(vp.gui.webview);
+ } else {
+ webkit_web_view_stop_loading(vp.gui.webview);
+ }
+
+ return TRUE;
+}
+
+gboolean command_scroll(const Arg* arg)
+{
+ GtkAdjustment *adjust = (arg->i & VP_SCROLL_AXIS_H) ? vp.gui.adjust_h : vp.gui.adjust_v;
+
+ gint direction = (arg->i & (1 << 2)) ? 1 : -1;
+
+ /* type scroll */
+ if (arg->i & VP_SCROLL_TYPE_SCROLL) {
+ gdouble value;
+ gint count = vp.state.count ? vp.state.count : 1;
+ if (arg->i & VP_SCROLL_UNIT_LINE) {
+ /* make scroll step configurable */
+ value = 40;
+ } else if (arg->i & VP_SCROLL_UNIT_HALFPAGE) {
+ value = gtk_adjustment_get_page_size(adjust) / 2;
+ } else {
+ value = gtk_adjustment_get_page_size(adjust);
+ }
+ gtk_adjustment_set_value(adjust, gtk_adjustment_get_value(adjust) + direction * value * count);
+ } else if (vp.state.count) {
+ /* jump - if count is set to count% of page */
+ gdouble max = gtk_adjustment_get_upper(adjust) - gtk_adjustment_get_page_size(adjust);
+ gtk_adjustment_set_value(adjust, max * vp.state.count / 100);
+ } else if (direction == 1) {
+ /* jump to top */
+ gtk_adjustment_set_value(adjust, gtk_adjustment_get_upper(adjust));
+ } else {
+ /* jump to bottom */
+ gtk_adjustment_set_value(adjust, gtk_adjustment_get_lower(adjust));
+ }
+
+ return TRUE;
+}
+
+gboolean command_map(const Arg* arg)
+{
+ return keybind_add_from_string(arg->s, arg->i);
+}
+
+gboolean command_unmap(const Arg* arg)
+{
+ return keybind_remove_from_string(arg->s, arg->i);
+}
+
+gboolean command_set(const Arg* arg)
+{
+ gboolean success;
+ gchar* line = NULL;
+ gchar** token;
+
+ if (!arg->s || !strlen(arg->s)) {
+ return FALSE;
+ }
+
+ line = g_strdup(arg->s);
+ g_strstrip(line);
+
+ /* split the input string into paramete and value part */
+ token = g_strsplit(line, "=", 2);
+ g_free(line);
+
+ if (!token[1]) {
+ /* TODO display current value */
+ g_strfreev(token);
+ vp_echo(VP_MSG_ERROR, "No param given");
+ return FALSE;
+ }
+ success = setting_run(token[0], token[1] ? token[1] : NULL);
+ g_strfreev(token);
+
+ return success;
+}
*/
#include "main.h"
-#include "config.h"
#include "util.h"
#include "command.h"
#include "keybind.h"
#include "setting.h"
+#include "config.h"
/* variables */
VpCore vp;
static void vp_read_config(void);
static void vp_init_gui(void);
static void vp_init_files(void);
-static void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color);
static void vp_setup_signals(void);
-static gboolean vp_load_uri(const Arg* arg);
#ifdef FEATURE_COOKIE
static void vp_set_cookie(SoupCookie* cookie);
static const gchar* vp_get_cookies(SoupURI *uri);
#endif
-static void vp_clean_up(void);
static gboolean vp_hide_message(void);
static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gpointer user_data)
static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer user_data)
{
- vp_close_browser(0);
+ command_close(0);
}
static gboolean vp_frame_scrollbar_policy_changed_cb(void)
return success;
}
-static gboolean vp_load_uri(const Arg* arg)
+gboolean vp_load_uri(const Arg* arg)
{
char* uri;
char* line = arg->s;
}
#endif
-gboolean vp_navigate(const Arg* arg)
-{
- if (arg->i <= VP_NAVIG_FORWARD) {
- /* TODO allow to set a count for the navigation */
- webkit_web_view_go_back_or_forward(
- vp.gui.webview, (arg->i == VP_NAVIG_BACK ? -1 : 1)
- );
- } else if (arg->i == VP_NAVIG_RELOAD) {
- webkit_web_view_reload(vp.gui.webview);
- } else if (arg->i == VP_NAVIG_RELOAD_FORCE) {
- webkit_web_view_reload_bypass_cache(vp.gui.webview);
- } else {
- webkit_web_view_stop_loading(vp.gui.webview);
- }
-
- return TRUE;
-}
-
-gboolean vp_scroll(const Arg* arg)
-{
- GtkAdjustment *adjust = (arg->i & VP_SCROLL_AXIS_H) ? vp.gui.adjust_h : vp.gui.adjust_v;
-
- gint direction = (arg->i & (1 << 2)) ? 1 : -1;
-
- /* type scroll */
- if (arg->i & VP_SCROLL_TYPE_SCROLL) {
- gdouble value;
- gint count = vp.state.count ? vp.state.count : 1;
- if (arg->i & VP_SCROLL_UNIT_LINE) {
- value = SCROLLSTEP;
- } else if (arg->i & VP_SCROLL_UNIT_HALFPAGE) {
- value = gtk_adjustment_get_page_size(adjust) / 2;
- } else {
- value = gtk_adjustment_get_page_size(adjust);
- }
- gtk_adjustment_set_value(adjust, gtk_adjustment_get_value(adjust) + direction * value * count);
- } else if (vp.state.count) {
- /* jump - if count is set to count% of page */
- gdouble max = gtk_adjustment_get_upper(adjust) - gtk_adjustment_get_page_size(adjust);
- gtk_adjustment_set_value(adjust, max * vp.state.count / 100);
- } else if (direction == 1) {
- /* jump to top */
- gtk_adjustment_set_value(adjust, gtk_adjustment_get_upper(adjust));
- } else {
- /* jump to bottom */
- gtk_adjustment_set_value(adjust, gtk_adjustment_get_lower(adjust));
- }
-
- return TRUE;
-}
-
-gboolean vp_close_browser(const Arg* arg)
-{
- vp_clean_up();
- gtk_main_quit();
-
- return TRUE;
-}
-
-static void vp_clean_up(void)
+void vp_clean_up(void)
{
if (vp.behave.commands) {
g_hash_table_destroy(vp.behave.commands);
for (int i = FILES_FIRST; i < FILES_LAST; i++) {
g_free(vp.files[i]);
}
+ command_cleanup();
+ setting_cleanup();
+ keybind_cleanup();
}
static gboolean vp_hide_message(void)
return FALSE;
}
-gboolean vp_view_source(const Arg* arg)
-{
- gboolean mode = webkit_web_view_get_view_source_mode(vp.gui.webview);
- webkit_web_view_set_view_source_mode(vp.gui.webview, !mode);
- webkit_web_view_reload(vp.gui.webview);
-
- return TRUE;
-}
-
-gboolean vp_map(const Arg* arg)
-{
- return keybind_add_from_string(arg->s, arg->i);
-}
-
-gboolean vp_unmap(const Arg* arg)
-{
- return keybind_remove_from_string(arg->s, arg->i);
-}
-
gboolean vp_set_mode(const Arg* arg)
{
vp.state.mode = arg->i;
return TRUE;
}
-gboolean vp_input(const Arg* arg)
-{
- gint pos = 0;
- const gchar* url;
-
- /* reset the colors and fonts to defalts */
- vp_set_widget_font(vp.gui.inputbox, inputbox_font[0], inputbox_bg[0], inputbox_fg[0]);
-
- /* remove content from input box */
- gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), "");
-
- /* insert string from arg */
- gtk_editable_insert_text(GTK_EDITABLE(vp.gui.inputbox), arg->s, -1, &pos);
-
- /* add current url if requested */
- if (VP_INPUT_CURRENT_URI == arg->i
- && (url = webkit_web_view_get_uri(vp.gui.webview))) {
- gtk_editable_insert_text(GTK_EDITABLE(vp.gui.inputbox), url, -1, &pos);
- }
-
- gtk_editable_set_position(GTK_EDITABLE(vp.gui.inputbox), -1);
-
- Arg a = {VP_MODE_COMMAND};
- return vp_set_mode(&a);
-}
-
-gboolean vp_open(const Arg* arg)
-{
- return vp_load_uri(arg);
-}
-
-gboolean vp_set(const Arg* arg)
-{
- gboolean success;
- gchar* line = NULL;
- gchar** token;
-
- if (!arg->s || !strlen(arg->s)) {
- return FALSE;
- }
-
- line = g_strdup(arg->s);
- g_strstrip(line);
-
- /* split the input string into paramete and value part */
- token = g_strsplit(line, "=", 2);
- g_free(line);
-
- if (!token[1]) {
- /* TODO display current value */
- g_strfreev(token);
- vp_echo(VP_MSG_ERROR, "No param given");
- return FALSE;
- }
- success = setting_run(token[0], token[1] ? token[1] : NULL);
- g_strfreev(token);
-
- return success;
-}
-
void vp_update_urlbar(const gchar* uri)
{
gchar* markup;
g_free(path);
}
-static void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color)
+void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color)
{
GdkColor fg, bg;
PangoFontDescription *font;