aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
authorGravatar DuClare <akarinotengoku@gmail.com>2009-05-16 13:53:11 +0300
committerGravatar DuClare <akarinotengoku@gmail.com>2009-05-16 13:53:11 +0300
commitb77997f5eb8dfdc7ce4d0e9dc3b84e11add285d3 (patch)
treebdb56110fb8bb69d394481f26581fe63f27e4ff1 /uzbl.c
parent27c2682dc79399a378c06ea03046319a972b81aa (diff)
parent5b2fc03f96d0f83a8e695c271655ccc10e2ef610 (diff)
Merge branch 'keycmd' into experimental
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c48
1 files changed, 35 insertions, 13 deletions
diff --git a/uzbl.c b/uzbl.c
index 820754a..70850ec 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -767,7 +767,9 @@ setup_regex() {
G_REGEX_OPTIMIZE, 0, &err);
uzbl.comm.bind_regex = g_regex_new("^[Bb][a-zA-Z]*\\s+?(.*[^ ])\\s*?=\\s*([a-z][^\\n].+)$",
G_REGEX_UNGREEDY|G_REGEX_OPTIMIZE, 0, &err);
- uzbl.comm.cmd_regex = g_regex_new("^[Cc][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$",
+ uzbl.comm.act_regex = g_regex_new("^[Aa][a-zA-Z]*\\s+([^ \\n]+)\\s*([^\\n]*)?$",
+ G_REGEX_OPTIMIZE, 0, &err);
+ uzbl.comm.keycmd_regex = g_regex_new("^[Kk][a-zA-Z]*\\s+([^\\n]+)$",
G_REGEX_OPTIMIZE, 0, &err);
}
@@ -960,9 +962,9 @@ parse_cmd_line(const char *ctl_line) {
else
printf("Error in command: %s\n", tokens[0]);
}
- /* CMD command */
- else if(ctl_line[0] == 'C' || ctl_line[0] == 'c') {
- tokens = g_regex_split(uzbl.comm.cmd_regex, ctl_line, 0);
+ /* ACT command */
+ else if(ctl_line[0] == 'A' || ctl_line[0] == 'a') {
+ tokens = g_regex_split(uzbl.comm.act_regex, ctl_line, 0);
if(tokens[0][0] == 0) {
parse_command(tokens[1], tokens[2]);
g_strfreev(tokens);
@@ -970,6 +972,18 @@ parse_cmd_line(const char *ctl_line) {
else
printf("Error in command: %s\n", tokens[0]);
}
+ /* KEYCMD command */
+ else if(ctl_line[0] == 'K' || ctl_line[0] == 'k') {
+ tokens = g_regex_split(uzbl.comm.keycmd_regex, ctl_line, 0);
+ if(tokens[0][0] == 0) {
+ /* should incremental commands want each individual "keystroke"
+ sent in a loop or the whole string in one go like now? */
+ g_string_assign(uzbl.state.keycmd, tokens[1]);
+ run_keycmd(FALSE);
+ update_title();
+ g_strfreev(tokens);
+ }
+ }
/* Comments */
else if( (ctl_line[0] == '#')
|| (ctl_line[0] == ' ')
@@ -1260,7 +1274,6 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
//TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
(void) page;
- Action *action;
if (event->type != GDK_KEY_PRESS || event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down
|| event->keyval == GDK_Up || event->keyval == GDK_Down || event->keyval == GDK_Left || event->keyval == GDK_Right || event->keyval == GDK_Shift_L || event->keyval == GDK_Shift_R)
@@ -1291,7 +1304,7 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
str = gtk_clipboard_wait_for_text (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD));
}
if (str) {
- g_string_append_printf (uzbl.state.keycmd, "%s", str);
+ g_string_append (uzbl.state.keycmd, str);
update_title ();
free (str);
}
@@ -1306,13 +1319,25 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
gboolean key_ret = FALSE;
if ((event->keyval == GDK_Return) || (event->keyval == GDK_KP_Enter))
key_ret = TRUE;
-
if (!key_ret) g_string_append(uzbl.state.keycmd, event->string);
+
+ run_keycmd(key_ret);
+ update_title();
+ if (key_ret) return (!uzbl.behave.insert_mode);
+ return TRUE;
+}
+
+static void
+run_keycmd(const gboolean key_ret) {
+ /* run the keycmd immediately if it isn't incremental and doesn't take args */
+ Action *action;
if ((action = g_hash_table_lookup(uzbl.bindings, uzbl.state.keycmd->str))) {
g_string_truncate(uzbl.state.keycmd, 0);
parse_command(action->name, action->param);
+ return;
}
+ /* try if it's an incremental keycmd or one that takes args, and run it */
GString* short_keys = g_string_new ("");
GString* short_keys_inc = g_string_new ("");
unsigned int i;
@@ -1324,12 +1349,12 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
gboolean exec_now = FALSE;
if ((action = g_hash_table_lookup(uzbl.bindings, short_keys->str))) {
- if (key_ret) exec_now = TRUE; // run normal cmds only if return was pressed
+ if (key_ret) exec_now = TRUE; /* run normal cmds only if return was pressed */
} else if ((action = g_hash_table_lookup(uzbl.bindings, short_keys_inc->str))) {
- if (key_ret) { // just quit the incremental command on return
+ if (key_ret) { /* just quit the incremental command on return */
g_string_truncate(uzbl.state.keycmd, 0);
break;
- } else exec_now = TRUE; // always exec inc. commands on keys other than return
+ } else exec_now = TRUE; /* always exec incr. commands on keys other than return */
}
if (exec_now) {
@@ -1354,9 +1379,6 @@ key_press_cb (WebKitWebView* page, GdkEventKey* event)
}
g_string_free (short_keys, TRUE);
g_string_free (short_keys_inc, TRUE);
- update_title();
- if (key_ret) return (!uzbl.behave.insert_mode);
- return TRUE;
}
static GtkWidget*