---
main.c | 86 +++++++++++++++++++++++++++++++++++----------------------------
1 files changed, 48 insertions(+), 38 deletions(-)
diff --git a/main.c b/main.c
index 6d6739a..1b3d133 100644
--- a/main.c
+++ b/main.c
@@ -64,6 +64,7 @@ static gboolean bookmark(const Arg *arg);
static gboolean complete(const Arg *arg);
static gboolean descend(const Arg *arg);
static gboolean echo(const Arg *arg);
+static gboolean clear_echo(void);
static gboolean focus_input(const Arg *arg);
static gboolean input(const Arg *arg);
static gboolean navigate(const Arg *arg);
@@ -134,7 +135,7 @@ static char *modkeys;
static char current_modkey;
static char *search_handle;
static gboolean search_direction;
-static gboolean echo_active = TRUE;
+static gboolean echo_active = False;
static GdkNativeWindow embed = 0;
static char *winid = NULL;
@@ -339,9 +340,7 @@ webview_keypress_cb(WebKitWebView *webview, GdkEventKey *event) {
case ModeNormal:
if ((CLEAN(event->state) & ~irrelevant) == 0) {
if (IS_ESCAPE(event)) {
- a.i = Info;
- a.s = g_strdup("");
- echo(&a);
+ clear_echo();
} else if (current_modkey == 0 && ((event->keyval >= GDK_1 && event->keyval <= GDK_9)
|| (event->keyval == GDK_0 && count))) {
count = (count ? count * 10 : 0) + (event->keyval - GDK_0);
@@ -378,13 +377,13 @@ webview_keypress_cb(WebKitWebView *webview, GdkEventKey *event) {
}
case ModePassThrough:
if (IS_ESCAPE(event)) {
- echo(&a);
+ clear_echo();
set(&a);
return TRUE;
}
break;
case ModeSendKey:
- echo(&a);
+ clear_echo();
set(&a);
break;
}
@@ -505,6 +504,9 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
search_direction = forward;
search_handle = g_strdup(&text[1]);
#endif
+ a.i = Info;
+ a.s = g_strdup(text);
+ echo(&a);
} else if (text[0] == '.' || text[0] == ',' || text[0] == ';') {
a.i = Silent;
a.s = g_strdup_printf("hints.fire();");
@@ -514,7 +516,7 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) {
} else
return;
if (!echo_active)
- gtk_entry_set_text(entry, "");
+ clear_echo();
gtk_widget_grab_focus(GTK_WIDGET(webview));
}
@@ -777,6 +779,7 @@ complete(const Arg *arg) {
static char **suggestions;
static GtkWidget **widgets;
static int n = 0, m, current = -1;
+ Arg a;
str = (char*)gtk_entry_get_text(GTK_ENTRY(inputbox));
len = strlen(str);
@@ -943,10 +946,16 @@ complete(const Arg *arg) {
gdk_color_parse(completionbgcolor[2], &color);
gtk_widget_modify_bg(GTK_WIDGET(widgets[current]), GTK_STATE_NORMAL, &color);
s = g_strconcat(":", suggestions[current], NULL);
- gtk_entry_set_text(GTK_ENTRY(inputbox), s);
+ a.i = Info;
+ a.s = g_strdup(s);
+ echo(&a);
g_free(s);
- } else
- gtk_entry_set_text(GTK_ENTRY(inputbox), prefix);
+ } else{
+ a.i = Info;
+ a.s = g_strdup(prefix);
+ echo(&a);
+ }
+
gtk_editable_set_position(GTK_EDITABLE(inputbox), -1);
return TRUE;
}
@@ -994,6 +1003,11 @@ echo(const Arg *arg) {
if (index < Info || index > Error)
return TRUE;
+ if(!arg->s){
+ clear_echo();
+ return TRUE;
+ }
+ echo_active = True;
font = pango_font_description_from_string(urlboxfont[index]);
gtk_widget_modify_font(inputbox, font);
pango_font_description_free(font);
@@ -1003,7 +1017,7 @@ echo(const Arg *arg) {
if (urlboxbgcolor[index])
gdk_color_parse(urlboxbgcolor[index], &color);
gtk_widget_modify_base(inputbox, GTK_STATE_NORMAL, urlboxbgcolor[index] ? &color : NULL);
- gtk_entry_set_text(GTK_ENTRY(inputbox), !arg->s ? "" : arg->s);
+ gtk_entry_set_text(GTK_ENTRY(inputbox), arg->s);
/* TA: Always free arg->s here, rather than relying on the caller to do
* this.
*/
@@ -1013,6 +1027,27 @@ echo(const Arg *arg) {
}
gboolean
+clear_echo() {
+ PangoFontDescription *font;
+ GdkColor color;
+ int index = 0;
+ echo_active = False;
+
+ font = pango_font_description_from_string(urlboxfont[index]);
+ gtk_widget_modify_font(inputbox, font);
+ pango_font_description_free(font);
+ if (urlboxcolor[index])
+ gdk_color_parse(urlboxcolor[index], &color);
+ gtk_widget_modify_text(inputbox, GTK_STATE_NORMAL, urlboxcolor[index] ? &color : NULL);
+ if (urlboxbgcolor[index])
+ gdk_color_parse(urlboxbgcolor[index], &color);
+ gtk_widget_modify_base(inputbox, GTK_STATE_NORMAL, urlboxbgcolor[index] ? &color : NULL);
+ gtk_entry_set_text(GTK_ENTRY(inputbox), "");
+
+ return TRUE;
+}
+
+gboolean
input(const Arg *arg) {
int pos = 0;
count = 0;
@@ -1021,33 +1056,8 @@ input(const Arg *arg) {
update_state();
- /* Set the colour and font back to the default, so that we don't still
- * maintain a red colour from a warning from an end of search indicator,
- * etc.
- *
- * XXX - unify this with echo() at some point.
- */
- {
- GdkColor ibox_fg_color;
- GdkColor ibox_bg_color;
- PangoFontDescription *font;
- int index = Info;
-
- font = pango_font_description_from_string(urlboxfont[index]);
- gtk_widget_modify_font(inputbox, font);
- pango_font_description_free(font);
-
- if (urlboxcolor[index])
- gdk_color_parse(urlboxcolor[index], &ibox_fg_color);
- if (urlboxbgcolor[index])
- gdk_color_parse(urlboxbgcolor[index], &ibox_bg_color);
-
- gtk_widget_modify_text(inputbox, GTK_STATE_NORMAL, urlboxcolor[index] ? &ibox_fg_color : NULL);
- gtk_widget_modify_base(inputbox, GTK_STATE_NORMAL, urlboxbgcolor[index] ? &ibox_bg_color : NULL);
- }
-
/* to avoid things like :open URL :open URL2 or :open :open URL */
- gtk_entry_set_text(GTK_ENTRY(inputbox), "");
+ clear_echo();
gtk_editable_insert_text(GTK_EDITABLE(inputbox), arg->s, -1, &pos);
if (arg->i & InsertCurrentURL && (url = webkit_web_view_get_uri(webview)))
gtk_editable_insert_text(GTK_EDITABLE(inputbox), url, -1, &pos);
@@ -1416,7 +1426,7 @@ set(const Arg *arg) {
search_handle = NULL;
webkit_web_view_unmark_text_matches(webview);
}
- gtk_entry_set_text(GTK_ENTRY(inputbox), "");
+ clear_echo();
gtk_widget_grab_focus(GTK_WIDGET(webview));
break;
case ModePassThrough:
--
1.7.5.4
|