From 0c6ca060eef33bae6c2de50ce9918c43f17172f8 Mon Sep 17 00:00:00 2001 From: Premysl 'Anydot' Hruby Date: Thu, 30 Apr 2009 23:31:02 +0200 Subject: multiple character bindings --- examples/configs/sampleconfig | 2 +- examples/configs/sampleconfig-dev | 2 +- uzbl.c | 32 ++++++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/examples/configs/sampleconfig b/examples/configs/sampleconfig index f6e8688..b5d598a 100644 --- a/examples/configs/sampleconfig +++ b/examples/configs/sampleconfig @@ -26,7 +26,7 @@ m = forward s = stop r = refresh R = reload -h = uri http://www.uzbl.org +gh = uri http://www.uzbl.org f = follow_link_here F = follow_link_new_tab w = follow_link_new_window diff --git a/examples/configs/sampleconfig-dev b/examples/configs/sampleconfig-dev index f6390b8..3953d79 100644 --- a/examples/configs/sampleconfig-dev +++ b/examples/configs/sampleconfig-dev @@ -26,7 +26,7 @@ m = forward s = stop r = refresh R = reload -h = uri http://www.uzbl.org +gh = uri http://www.uzbl.org f = follow_link_here F = follow_link_new_tab w = follow_link_new_window diff --git a/uzbl.c b/uzbl.c index a48849c..ec16590 100644 --- a/uzbl.c +++ b/uzbl.c @@ -61,6 +61,7 @@ static gint load_progress; static Window xwin = 0; static char fifo_path[64]; static char socket_path[108]; +static GString *keycmd; /* state variables (initial values coming from command line arguments but may be changed later) */ static gchar* uri = NULL; @@ -522,6 +523,8 @@ static void update_title (GtkWindow* window) { GString* string_long = g_string_new (""); GString* string_short = g_string_new (""); + + g_string_append_printf(string_long, "%s ", keycmd->str); if (!always_insert_mode) g_string_append (string_long, (insert_mode ? "[I] " : "[C] ")); if (main_title) { @@ -564,18 +567,35 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event) return FALSE; //TURN OFF/ON INSERT MODE - if ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i'))) { + if ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i') && !keycmd->len)) { insert_mode = !insert_mode || always_insert_mode; update_title (GTK_WINDOW (main_window)); return TRUE; } - if ((!insert_mode || (event->state == modmask)) && (action = g_hash_table_lookup(bindings, event->string))) { - parse_command(action->name, action->param); + if (insert_mode && event->state != modmask) + return FALSE; + + + if (event->keyval == GDK_Escape) { + g_string_truncate(keycmd, 0); + + update_title (GTK_WINDOW (main_window)); + return TRUE; } - return !insert_mode; + g_string_append(keycmd, event->string); + + if ((action = g_hash_table_lookup(bindings, keycmd->str))) { + g_string_truncate(keycmd, 0); + + parse_command(action->name, action->param); + } + + update_title (GTK_WINDOW (main_window)); + + return TRUE; } static GtkWidget* @@ -765,6 +785,8 @@ main (int argc, char* argv[]) { /* initialize hash table */ bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action); + keycmd = g_string_new(""); + settings_init (); commands_hash (); @@ -797,6 +819,8 @@ main (int argc, char* argv[]) { gtk_main (); + g_string_free(keycmd, TRUE); + unlink (socket_path); unlink (fifo_path); -- cgit v1.2.3