Compare commits

...

14 Commits

Author SHA1 Message Date
R. Tyler Croy 19b3f78cbf Removed compile time warning about count_buf not being used. 2011-05-02 20:49:41 -07:00
Albert Kim afd14130bd Fixed bug with not being able to press enter to follow single digit hints. 2011-05-02 20:47:32 -07:00
Albert Kim 4ea34a1e6d Used numval instead of keyval to calculate new count. 2011-05-02 20:47:32 -07:00
Albert Kim 5f8e971378 Made check for whether keyval is digit shorter. 2011-05-02 20:47:32 -07:00
Albert Kim e73125854a Removed code dealing with old hintmode. 2011-05-02 20:47:32 -07:00
Albert Kim 83e9ab7058 Made script() free arg->s where applicatable. 2011-05-02 20:47:29 -07:00
Albert Kim 19a4d1127e Changed to reset count when quitting hintmode.
Also calls update_state after count is reset.
2011-05-02 20:20:04 -07:00
Albert Kim 1445f02d7c Changed 'f' and 'F' keys to use new hinting mode. 2011-05-02 20:20:04 -07:00
Albert Kim 29d4351dc7 Added proper handling of numbers into new hinting system. 2011-05-02 20:20:04 -07:00
Albert Kim 98649ddacc Pressing ~ now sets up so that hints open up in background. 2011-05-02 20:20:04 -07:00
Albert Kim 5858ee6708 Make hints go away if input is cleared.
Basically, now the existence of followTarget is what sets hint mode on or off.
If followTarget is either ("current" or "new"), when inputbox's length becomes
0, vimprobable_clear is called. followTarget is set once the user sets inputbox
to have '`' as the first character.
2011-05-02 20:20:03 -07:00
Albert Kim e992eabd7e Specified "current" for following hints.
Also, made sure all hints are highlighted if nothing has been typed yet.
2011-05-02 20:20:03 -07:00
Albert Kim c3ca9c458a Uses inputbox_keypress_cb to find hints.
When, '`' is the first character of the inputbox, vimiprobable now uses the
inputbox to find hints. This allows for a cleaner way to handle international
characters and also allows for users to use their IM to type international
characters.
2011-05-02 20:20:03 -07:00
Albert Kim e2543909bb Added backquote as a synonym to start following hints. 2011-05-02 20:20:03 -07:00
2 changed files with 64 additions and 147 deletions

View File

@ -101,12 +101,15 @@ Key keys[] = {
{ 0, 0, GDK_KP_Divide, input, {.s = "/"} },
{ GDK_SHIFT_MASK, 0, GDK_question, input, {.s = "?"} },
{ 0, 0, GDK_quoteleft, input, {.s = "`"} },
{ GDK_SHIFT_MASK, 0, GDK_asciitilde, input, {.s = "~"} },
{ 0, GDK_VoidSymbol, GDK_Escape, set, {ModeNormal} },
{ GDK_CONTROL_MASK, GDK_VoidSymbol, GDK_bracketleft,set, {ModeNormal} },
{ GDK_CONTROL_MASK, 0, GDK_z, set, {ModePassThrough} },
{ GDK_CONTROL_MASK, 0, GDK_v, set, {ModeSendKey} },
{ 0, 0, GDK_f, set, { .i = ModeHints, .s = "current" } },
{ GDK_SHIFT_MASK, 0, GDK_F, set, { .i = ModeHints, .s = "new" } },
{ 0, 0, GDK_f, input, {.s = "`"} },
{ GDK_SHIFT_MASK, 0, GDK_F, input, {.s = "~"} },
{ 0, GDK_g, GDK_i, focus_input,{} },
{ 0, 0, GDK_u, revive, {} },

204
main.c
View File

@ -132,9 +132,6 @@ static char *configfile = NULL;
static char *winid = NULL;
static char rememberedURI[1024] = "";
static char inputKey[5];
static char inputBuffer[65] = "";
static char chars[65] = "0000000000000000000000000000000000000000000000000000000000000000\n";
static char followTarget[8] = "";
char *error_msg = NULL;
@ -197,7 +194,7 @@ ascii_bar(int total, int state, char *string) {
void
webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) {
Arg a = { .i = Silent, .s = JS_SETUP_HINTS };
Arg a = { .i = Silent, .s = g_strdup(JS_SETUP_HINTS) };
const char *uri = webkit_web_view_get_uri(webview);
update_url(uri);
@ -206,7 +203,7 @@ webview_load_committed_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointe
void
webview_load_finished_cb(WebKitWebView *webview, WebKitWebFrame *frame, gpointer user_data) {
Arg a = { .i = Silent, .s = JS_SETUP_INPUT_FOCUS };
Arg a = { .i = Silent, .s = g_strdup(JS_SETUP_INPUT_FOCUS) };
if (HISTORY_MAX_ENTRIES > 0)
history();
@ -345,7 +342,6 @@ webview_keypress_cb(WebKitWebView *webview, GdkEventKey *event) {
switch (mode) {
case ModeNormal:
if (CLEAN(event->state) == 0) {
memset(inputBuffer, 0, 65);
if (IS_ESCAPE(event)) {
a.i = Info;
a.s = g_strdup("");
@ -384,127 +380,6 @@ webview_keypress_cb(WebKitWebView *webview, GdkEventKey *event) {
echo(&a);
set(&a);
break;
case ModeHints:
if (IS_ESCAPE(event)) {
a.i = Silent;
a.s = "vimprobable_clear()";
script(&a);
a.i = ModeNormal;
count = 0;
strncpy(chars, "0000000000000000000000000000000000000000000000000000000000000000\0", 65);
return set(&a);
} else if (CLEAN(event->state) == 0 && ((event->keyval >= GDK_1 && event->keyval <= GDK_9)
|| (event->keyval >= GDK_KP_1 && event->keyval <= GDK_KP_9)
|| ((event->keyval == GDK_0 || event->keyval == GDK_KP_0) && count))) {
/* allow a zero as non-first number */
if (event->keyval >= GDK_KP_0 && event->keyval <= GDK_KP_9)
count = (count ? count * 10 : 0) + (event->keyval - GDK_KP_0);
else
count = (count ? count * 10 : 0) + (event->keyval - GDK_0);
memset(inputBuffer, 0, 65);
sprintf(inputBuffer, "%d", count);
a.s = g_strconcat("vimprobable_update_hints(", inputBuffer, ")", NULL);
a.i = Silent;
memset(inputBuffer, 0, 65);
strncpy(chars, "0000000000000000000000000000000000000000000000000000000000000000\0", 65);
script(&a);
update_state();
return TRUE;
} else if ((CLEAN(event->state) == 0 && (event->keyval >= GDK_a && event->keyval <= GDK_z))
|| (CLEAN(event->state) == GDK_SHIFT_MASK && (event->keyval >= GDK_A && event->keyval <= GDK_Z))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_space && event->keyval <= GDK_slash))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_colon && event->keyval <= GDK_at))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_braceleft && event->keyval <= GDK_umacron))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Babovedot && event->keyval <= GDK_ycircumflex))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_OE && event->keyval <= GDK_Ydiaeresis))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_overline && event->keyval <= GDK_semivoicedsound))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Farsi_0 && event->keyval <= GDK_Arabic_9))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Arabic_semicolon && event->keyval <= GDK_Arabic_sukun))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Arabic_madda_above && event->keyval <= GDK_Arabic_heh_goal))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Cyrillic_GHE_bar && event->keyval <= GDK_Cyrillic_u_macron))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Serbian_dje && event->keyval <= GDK_Korean_Won))
|| ((CLEAN(event->state) == 0 || CLEAN(event->state) == GDK_SHIFT_MASK) && (event->keyval >= GDK_Armenian_ligature_ew && event->keyval <= GDK_braille_dots_12345678))) {
/* update hints by link text */
if (strlen(inputBuffer) < 65) {
memset(inputKey, 0, 5);
/* support multibyte characters */
sprintf(inputKey, "%C", event->keyval);
strncat(inputBuffer, inputKey, 64 - strlen(inputBuffer));
/* remember the number of bytes of each character */
for (count = 0; count < 64; count++) {
if (strncmp((chars + count), "0", 1) == 0) {
sprintf(inputKey, "%d", (int)strlen(inputKey));
strncpy((chars + count), inputKey, 1);
break;
}
}
memset(inputKey, 0, 5);
count = 0;
a.i = Silent;
a.s = "vimprobable_cleanup()";
script(&a);
a.s = g_strconcat("vimprobable_show_hints('", inputBuffer, "')", NULL);
a.i = Silent;
script(&a);
update_state();
}
return TRUE;
} else if (CLEAN(event->state) == 0 && (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) && count) {
memset(inputBuffer, 0, 65);
sprintf(inputBuffer, "%d", count);
a.s = g_strconcat("vimprobable_fire(", inputBuffer, ")", NULL);
a.i = Silent;
script(&a);
memset(inputBuffer, 0, 65);
count = 0;
strncpy(chars, "0000000000000000000000000000000000000000000000000000000000000000\0", 65);
update_state();
return TRUE;
} else if (CLEAN(event->state) == 0 && event->keyval == GDK_BackSpace) {
if (count > 9) {
count /= 10;
memset(inputBuffer, 0, 65);
sprintf(inputBuffer, "%d", count);
a.s = g_strconcat("vimprobable_update_hints(", inputBuffer, ")", NULL);
a.i = Silent;
memset(inputBuffer, 0, 65);
script(&a);
update_state();
} else if (count > 0) {
count = 0;
memset(inputBuffer, 0, 65);
a.i = Silent;
a.s = "vimprobable_cleanup()";
script(&a);
a.s = g_strconcat("vimprobable_show_hints()", NULL);
a.i = Silent;
script(&a);
update_state();
} else if (strlen(inputBuffer) > 0) {
a.i = Silent;
a.s = "vimprobable_cleanup()";
script(&a);
/* check how many bytes the last character uses */
for (count = 0; count < 64; count++) {
if (strncmp((chars + count), "0", 1) == 0) {
break;
}
}
memset(inputKey, 0, 5);
strncpy(inputKey, (chars + count - 1), 1);
strncpy((chars + count - 1), "0", 1);
count = atoi(inputKey);
/* remove the appropriate number of bytes from the string */
strncpy((inputBuffer + strlen(inputBuffer) - count), "\0", 1);
count = 0;
a.s = g_strconcat("vimprobable_show_hints('", inputBuffer, "')", NULL);
a.i = Silent;
script(&a);
update_state();
}
return TRUE;
}
break;
}
return FALSE;
}
@ -571,10 +446,10 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
a.i = HideCompletion;
complete(&a);
if (length < 2)
if (length == 0)
return;
text = (char*)gtk_entry_get_text(entry);
if (text[0] == ':') {
if (length > 1 && text[0] == ':') {
for (i = 0; i < LENGTH(commands); i++) {
if (commands[i].cmd == NULL)
break;
@ -605,7 +480,7 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
}
echo(&a);
}
} else if ((forward = text[0] == '/') || text[0] == '?') {
} else if (length > 1 && ((forward = text[0] == '/') || text[0] == '?')) {
webkit_web_view_unmark_text_matches(webview);
#ifdef ENABLE_MATCH_HIGHLITING
webkit_web_view_mark_text_matches(webview, &text[1], FALSE, 0);
@ -620,6 +495,11 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
search_direction = forward;
search_handle = g_strdup(&text[1]);
#endif
} else if (count && (text[0] == '`' || text[0] == '~')) {
a.i = Silent;
a.s = g_strdup_printf("vimprobable_fire(%d)", count);
script(&a);
update_state();
} else
return;
if (!echo_active)
@ -630,6 +510,7 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
gboolean
inputbox_keypress_cb(GtkEntry *entry, GdkEventKey *event) {
Arg a;
int numval;
switch (event->keyval) {
case GDK_bracketleft:
@ -657,6 +538,18 @@ inputbox_keypress_cb(GtkEntry *entry, GdkEventKey *event) {
return complete(&a);
break;
}
numval = g_unichar_digit_value((gunichar) gdk_keyval_to_unicode(event->keyval));
if (followTarget[0] && ((numval >= 1 && numval <= 9) || (numval == 0 && count))) {
/* allow a zero as non-first number */
count = (count ? count * 10 : 0) + numval;
a.i = Silent;
a.s = g_strdup_printf("vimprobable_update_hints(%d)", count);
script(&a);
update_state();
return TRUE;
}
return FALSE;
}
@ -697,6 +590,7 @@ static gboolean inputbox_keyrelease_cb(GtkEntry *entry, GdkEventKey *event) {
}
static gboolean inputbox_changed_cb(GtkEditable *entry, gpointer user_data) {
Arg a;
char *text = (char*)gtk_entry_get_text(GTK_ENTRY(entry));
guint16 length = gtk_entry_get_text_length(GTK_ENTRY(entry));
gboolean forward = FALSE;
@ -713,6 +607,24 @@ static gboolean inputbox_changed_cb(GtkEditable *entry, gpointer user_data) {
webkit_web_view_unmark_text_matches(webview);
webkit_web_view_search_text(webview, &text[1], searchoptions & CaseSensitive, forward, searchoptions & Wrapping);
return TRUE;
} else if (gtk_widget_is_focus(GTK_WIDGET(entry)) && length >= 1 &&
(text[0] == '`' || text[0] == '~')) {
a.i = Silent;
a.s = g_strdup("vimprobable_cleanup()");
script(&a);
a.i = Silent;
a.s = g_strconcat("vimprobable_show_hints('", text + 1, "')", NULL);
script(&a);
return TRUE;
} else if (length == 0 && followTarget[0]) {
memset(followTarget, 0, 8);
a.i = Silent;
a.s = g_strdup("vimprobable_clear()");
script(&a);
count = 0;
update_state();
}
return FALSE;
@ -1015,6 +927,7 @@ input(const Arg *arg) {
count = 0;
const char *url;
int index = Info;
Arg a;
update_state();
@ -1024,6 +937,14 @@ input(const Arg *arg) {
*/
set_widget_font_and_color(inputbox, urlboxfont[index], urlboxbgcolor[index], urlboxcolor[index]);
if (arg->s[0] == '`' || arg->s[0] == '~') {
memset(followTarget, 0, 0);
strncpy(followTarget, arg->s[0] == '`' ? "current" : "new", 8);
a.i = Silent;
a.s = g_strdup("vimprobable_show_hints()");
script(&a);
}
/* to avoid things like :open URL :open URL2 or :open :open URL */
gtk_entry_set_text(GTK_ENTRY(inputbox), "");
gtk_editable_insert_text(GTK_EDITABLE(inputbox), arg->s, -1, &pos);
@ -1031,6 +952,7 @@ input(const Arg *arg) {
gtk_editable_insert_text(GTK_EDITABLE(inputbox), url, -1, &pos);
gtk_widget_grab_focus(inputbox);
gtk_editable_set_position(GTK_EDITABLE(inputbox), -1);
return TRUE;
}
@ -1293,13 +1215,6 @@ set(const Arg *arg) {
a.s = g_strdup("-- INSERT --");
echo(&a);
break;
case ModeHints:
memset(followTarget, 0, 8);
strncpy(followTarget, arg->s, 8);
a.i = Silent;
a.s = "vimprobable_show_hints()";
script(&a);
break;
default:
return TRUE;
}
@ -1380,6 +1295,8 @@ script(const Arg *arg) {
jsapi_evaluate_script(arg->s, &value, &message);
if (message) {
set_error(message);
if (arg->s)
g_free(arg->s);
return FALSE;
}
if (arg->i != Silent && value) {
@ -1390,15 +1307,11 @@ script(const Arg *arg) {
if (value) {
if (strncmp(value, "fire;", 5) == 0) {
count = 0;
strncpy(chars, "0000000000000000000000000000000000000000000000000000000000000000", 64);
memset(inputBuffer, 0, 65);
a.s = g_strconcat("vimprobable_fire(", (value + 5), ")", NULL);
a.i = Silent;
script(&a);
} else if (strncmp(value, "open;", 5) == 0) {
count = 0;
strncpy(chars, "0000000000000000000000000000000000000000000000000000000000000000", 64);
memset(inputBuffer, 0, 65);
a.i = ModeNormal;
set(&a);
if (strncmp(followTarget, "new", 3) == 0)
@ -1410,6 +1323,8 @@ script(const Arg *arg) {
open_arg(&a);
}
}
if (arg->s)
g_free(arg->s);
g_free(value);
return TRUE;
}
@ -1482,13 +1397,13 @@ fake_key_event(const Arg *a) {
echo(&err);
return FALSE;
}
if( (xk.keycode = XKeysymToKeycode(xdpy, keysym)) == NoSymbol ) {
err.s = g_strdup("Couldn't translate keysym to keycode");
echo(&err);
return FALSE;
}
xk.type = KeyPress;
if( !XSendEvent(xdpy, embed, True, KeyPressMask, (XEvent *)&xk) ) {
err.s = g_strdup("XSendEvent failed");
@ -1548,7 +1463,7 @@ bookmark(const Arg *arg) {
give_feedback( "Bookmark saved" );
return TRUE;
} else {
set_error("Bookmarks file not found.");
set_error("Bookmarks file not found.");
return FALSE;
}
}
@ -1960,7 +1875,6 @@ update_state() {
/* count, modkey and input buffer */
g_string_append_printf(status, "%.0d", count);
if (current_modkey) g_string_append_c(status, current_modkey);
if (inputBuffer[0]) g_string_append_printf(status, " %s", inputBuffer);
/* the number of active downloads */
if (activeDownloads) {