#include "command.h"
+#include "main.h"
static CommandInfo cmd_list[] = {
- /* command function arg */
- {"quit", quit, {0}},
- {"source", view_source, {0}},
+ /* command function arg */
+ {"quit", vp_close_browser, {0}},
+ {"source", vp_view_source, {0}},
+ {"back", vp_navigate, {NAVIG_BACK}},
+ {"forward", vp_navigate, {NAVIG_FORWARD}},
+ {"reload", vp_navigate, {NAVIG_RELOAD}},
+ {"reload!", vp_navigate, {NAVIG_RELOAD_FORCE}},
+ {"stop", vp_navigate, {NAVIG_STOP_LOADING}},
};
void command_init()
c->function(&a);
g_free(a.s);
}
-
-void quit(Arg* arg)
-{
- vp_close_browser();
-}
-
-void view_source(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);
-}
VpCore vp;
/* callbacks */
-void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec);
-void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window);
-gboolean vp_frame_scrollbar_policy_changed_cb(void);
+static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gpointer user_data);
+static void vp_webview_load_commited_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data);
+static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer user_data);
+static gboolean vp_frame_scrollbar_policy_changed_cb(void);
/* functions */
static void vp_print_version(void);
static void vp_setup_signals(void);
-void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec)
+static void vp_webview_load_status_cb(WebKitWebView* view, GParamSpec* pspec, gpointer user_data)
{
Gui* gui = &vp.gui;
const char* uri = webkit_web_view_get_uri(gui->webview);
}
}
-void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window)
+static void vp_webview_load_commited_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data)
+{
+ /* unset possible set modkey and counts if loading a new page */
+ vp.state.modkey = vp.state.count = 0;
+ vp_update_statusbar();
+}
+
+static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer user_data)
{
vp_close_browser(0);
}
-gboolean vp_frame_scrollbar_policy_changed_cb(void)
+static gboolean vp_frame_scrollbar_policy_changed_cb(void)
{
return TRUE;
}
return TRUE;
}
-gboolean vp_navigate(const Arg *arg)
+void vp_navigate(const Arg *arg)
{
if (arg->i <= NAVIG_FORWARD) {
/* TODO allow to set a count for the navigation */
} else {
webkit_web_view_stop_loading(vp.gui.webview);
}
-
- return TRUE;
}
-void vp_close_browser()
+void vp_close_browser(const Arg* arg)
{
if (vp.behave.commands) {
g_hash_table_destroy(vp.behave.commands);
gtk_main_quit();
}
+void 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);
+}
+
void vp_update_urlbar(const gchar* uri)
{
gchar* markup;
/* initialize the keybindings */
keybind_init();
- keybind_add(VP_MODE_NORMAL, GDK_g, 0, GDK_f, "source");
- keybind_add(VP_MODE_NORMAL, 0, 0, GDK_d, "quit");
+ keybind_add(VP_MODE_NORMAL, GDK_g, 0, GDK_f, "source");
+ keybind_add(VP_MODE_NORMAL, 0, 0, GDK_d, "quit");
+ keybind_add(VP_MODE_NORMAL, 0, GDK_CONTROL_MASK, GDK_o, "back");
+ keybind_add(VP_MODE_NORMAL, 0, GDK_CONTROL_MASK, GDK_i, "forward");
+ keybind_add(VP_MODE_NORMAL, 0, 0, GDK_r, "reload");
+ keybind_add(VP_MODE_NORMAL, 0, 0, GDK_R, "reload!");
+ keybind_add(VP_MODE_NORMAL, 0, GDK_CONTROL_MASK, GDK_c, "stop");
}
static void vp_init_gui(void)
g_signal_connect(gui->window, "destroy", G_CALLBACK(vp_destroy_window_cb), NULL);
g_signal_connect(G_OBJECT(frame), "scrollbars-policy-changed", G_CALLBACK(vp_frame_scrollbar_policy_changed_cb), NULL);
g_signal_connect(G_OBJECT(gui->webview), "notify::load-status", G_CALLBACK(vp_webview_load_status_cb), NULL);
+ g_signal_connect(G_OBJECT(gui->webview), "load-committed", G_CALLBACK(vp_webview_load_commited_cb), NULL);
}
int main(int argc, char* argv[])