From: Greg L. <gre...@gm...> - 2012-05-06 08:32:30
|
Cleaned up some echo code and then made the inputbar hide automatically when empty. It is toggled on/off by a define in config.h. Works correctly for both ENABLE_GTK_PROGRESS_BAR and not. Greg Lutostanski (2): Refactor echo and clearing of inputbar to make it easier to follow. Allow autohiding of inputbar when empty. config.h | 1 + main.c | 117 +++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 79 insertions(+), 39 deletions(-) -- 1.7.5.4 |
From: Greg L. <gre...@gm...> - 2012-05-06 08:32:35
|
--- config.h | 1 + main.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/config.h b/config.h index 6e712ed..e5b629b 100644 --- a/config.h +++ b/config.h @@ -42,6 +42,7 @@ static const char statusfont[] = "monospace bold 8"; /* font for stat #define ENABLE_INCREMENTAL_SEARCH #define ENABLE_GTK_PROGRESS_BAR #define ENABLE_WGET_PROGRESS_BAR +#define ENABLE_AUTOHIDE_INPUTBAR static const int progressbartick = 20; static const char progressborderleft = '['; static const char progressbartickchar = '='; diff --git a/main.c b/main.c index 1b3d133..e57abbf 100644 --- a/main.c +++ b/main.c @@ -163,6 +163,11 @@ static void new_generic_request(SoupSession *soup_ses, SoupMessage *soup_msg, gp static void update_cookie_jar(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new); static void handle_cookie_request(SoupMessage *soup_msg, gpointer unused); #endif +#ifdef ENABLE_GTK_PROGRESS_BAR +#ifdef ENABLE_AUTOHIDE_INPUTBAR +static gboolean gtk_progress_visible = FALSE; +#endif +#endif /* callbacks */ void window_destroyed_cb(GtkWidget *window, gpointer func_data) { @@ -178,6 +183,16 @@ void webview_progress_changed_cb(WebKitWebView *webview, int progress, gpointer user_data) { #ifdef ENABLE_GTK_PROGRESS_BAR gtk_entry_set_progress_fraction(GTK_ENTRY(inputbox), progress == 100 ? 0 : (double)progress/100); +#ifdef ENABLE_AUTOHIDE_INPUTBAR + if(progress == 100) + gtk_progress_visible = False; + else + gtk_progress_visible = True; + if(!gtk_progress_visible && !echo_active && !gtk_widget_has_focus(inputbox)) + gtk_widget_hide(inputbox); + else + gtk_widget_show(inputbox); +#endif #endif update_state(); } @@ -377,14 +392,14 @@ webview_keypress_cb(WebKitWebView *webview, GdkEventKey *event) { } case ModePassThrough: if (IS_ESCAPE(event)) { - clear_echo(); set(&a); + clear_echo(); return TRUE; } break; case ModeSendKey: - clear_echo(); set(&a); + clear_echo(); break; } return FALSE; @@ -515,9 +530,9 @@ inputbox_activate_cb(GtkEntry *entry, gpointer user_data) { update_state(); } else return; + gtk_widget_grab_focus(GTK_WIDGET(webview)); if (!echo_active) clear_echo(); - gtk_widget_grab_focus(GTK_WIDGET(webview)); } gboolean @@ -1021,6 +1036,9 @@ echo(const Arg *arg) { /* TA: Always free arg->s here, rather than relying on the caller to do * this. */ +#ifdef ENABLE_AUTOHIDE_INPUTBAR + gtk_widget_show(inputbox); +#endif if (arg->s) g_free(arg->s); return TRUE; @@ -1043,7 +1061,15 @@ clear_echo() { 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), ""); - + +#ifdef ENABLE_AUTOHIDE_INPUTBAR +#ifdef ENABLE_GTK_PROGRESS_BAR + if(!gtk_progress_visible && !echo_active && !gtk_widget_has_focus(inputbox)) + gtk_widget_hide(inputbox); +#else + gtk_widget_hide(inputbox); +#endif +#endif return TRUE; } @@ -1058,6 +1084,9 @@ input(const Arg *arg) { /* to avoid things like :open URL :open URL2 or :open :open URL */ clear_echo(); +#ifdef ENABLE_AUTOHIDE_INPUTBAR + gtk_widget_show(inputbox); +#endif 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); @@ -1426,8 +1455,8 @@ set(const Arg *arg) { search_handle = NULL; webkit_web_view_unmark_text_matches(webview); } - clear_echo(); gtk_widget_grab_focus(GTK_WIDGET(webview)); + clear_echo(); break; case ModePassThrough: a.s = g_strdup("-- PASS THROUGH --"); -- 1.7.5.4 |
From: Greg L. <gre...@gm...> - 2012-05-06 08:32:35
|
--- 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 |
From: Hannes S. <ha...@yl...> - 2012-05-06 14:02:52
Attachments:
signature.asc
|
Hello Greg, I find it strange that in your patch, you never actually check whether the inputbar is empty. Unless I'm misinterpreting something, you simply force it to always be empty by setting echo_active = false and then hide it. Last year, I made a similar patch which you can still find in the archives here: http://sourceforge.net/mailarchive/forum.php?thread_name=20111209082411.GA15480%40ubuntu.dotsource.local&forum_name=vimprobable-users (for some reason the frontend claims the initial message, which includes the patch, is in HTML format; which it isn't). It had some issues, though (as pointed out by Daniel in the thread). Maybe this can give you some inspiration? Hannes |
From: Greg L. <gre...@gm...> - 2012-05-07 06:51:50
|
On Sun, May 06, 2012 at 04:01:22PM +0200, Hannes Sch??ller wrote: > Hello Greg, > Hi Hannes, Thanks for taking a look at this. And as this is my first time posting anything in this mailing list, let me say thanks for the work you and everyone else here have done making a great program. > I find it strange that in your patch, you never actually check whether > the inputbar is empty. Unless I'm misinterpreting something, you simply > force it to always be empty by setting echo_active = false and then > hide it. Your right, I don't explicitly check as to whether the inputbar is empty. Instead I am using the boolean echo_active to check if something is in the inputbar that should be seen. Basically whenever echo(* Arg) is used, it is set to show the inputbar and prevent automatic clearing. On the other hand when the inputbar has user input in it -- it pops up and stays visbile as long as it is in line-edit mode. (When it is activated [Enter] it goes away immediately. > > Last year, I made a similar patch which you can still find in the > archives here: > http://sourceforge.net/mailarchive/forum.php?thread_name=20111209082411.GA15480%40ubuntu.dotsource.local&forum_name=vimprobable-users > (for some reason the frontend claims the initial message, which > includes the patch, is in HTML format; which it isn't). It had some > issues, though (as pointed out by Daniel in the thread). Maybe this can > give you some inspiration? > > Hannes I think I have made it so that whenever there is some text in the inputbar -- no matter what it is, it is visible. The issues you refer to are not apparent in this patchset. Unfourtunately this is my first time submitting patches using git so the way it split into two different patches makes the changes less apparent. I have tested it pretty extensively and there are only two hiccups as far as I can tell. 1. When using the GTK_PROGRESS_BAR the inputbar goes away then pops back up to show the progress -- it hides/unhides fast. 2. The inputbar starts shown -- which is in my opinion incorrect behavior. Please note that the above hiccups are easily fixable with two small changes -- I just notice them until after I sent this patchset in. Thanks, Greg |
From: Hannes S. <ha...@yl...> - 2012-05-27 09:40:17
Attachments:
signature.asc
|
Hi, sorry about the late reply. Greg Lutostanski <gre...@gm...> wrote: > On Sun, May 06, 2012 at 04:01:22PM +0200, Hannes Sch??ller wrote: > > I find it strange that in your patch, you never actually check > > whether the inputbar is empty. Unless I'm misinterpreting > > something, you simply force it to always be empty by setting > > echo_active = false and then hide it. > > Your right, I don't explicitly check as to whether the inputbar is > empty. Instead I am using the boolean echo_active to check if > something is in the inputbar that should be seen. Basically whenever > echo(* Arg) is used, it is set to show the inputbar and prevent > automatic clearing. What if some function calls echo()? This has nothing to do with the state of echo_active, but nevertheless, it will populate the bar. Hannes |
From: <gre...@gm...> - 2012-05-29 03:28:28
|
On Sun May 27 2012 04:40:14 AM CDT, Hannes Schüller <ha...@yl...> wrote: > Hi, > > sorry about the late reply. > > Greg Lutostanski <gre...@gm...> wrote: > > On Sun, May 06, 2012 at 04:01:22PM +0200, Hannes Sch??ller wrote: > > > I find it strange that in your patch, you never actually check > > > whether the inputbar is empty. Unless I'm misinterpreting > > > something, you simply force it to always be empty by setting > > > echo_active = false and then hide it. > > > > Your right, I don't explicitly check as to whether the inputbar is > > empty. Instead I am using the boolean echo_active to check if > > something is in the inputbar that should be seen. Basically whenever > > echo(* Arg) is used, it is set to show the inputbar and prevent > > automatic clearing. > > What if some function calls echo()? This has nothing to do with the > state of echo_active, but nevertheless, it will populate the bar. Well echo_active wasn't ever used in the codebase for vimprobable1 --except for one if statement, so I changed it so that echo_active switches on/off whenever echo() or clear_echo() is used. Patch 1/2 has all these changes, the second patch builds on top to do the hiding of the bar. -- Greg |
From: Hannes S. <ha...@yl...> - 2012-05-29 06:08:45
|
gre...@gm... wrote: > On Sun May 27 2012 04:40:14 AM CDT, Hannes Sch__ller <ha...@yl...> > wrote: > > Greg Lutostanski <gre...@gm...> wrote: > > > On Sun, May 06, 2012 at 04:01:22PM +0200, Hannes Sch??ller wrote: > > > > I find it strange that in your patch, you never actually check > > > > whether the inputbar is empty. Unless I'm misinterpreting > > > > something, you simply force it to always be empty by setting > > > > echo_active = false and then hide it. > > > > > > Your right, I don't explicitly check as to whether the inputbar is > > > empty. Instead I am using the boolean echo_active to check if > > > something is in the inputbar that should be seen. Basically > > > whenever echo(* Arg) is used, it is set to show the inputbar and > > > prevent automatic clearing. > > > > What if some function calls echo()? This has nothing to do with the > > state of echo_active, but nevertheless, it will populate the bar. > > Well echo_active wasn't ever used in the codebase for vimprobable1 > --except for one if statement, so I changed it so that echo_active > switches on/off whenever echo() or clear_echo() is used. Patch 1/2 > has all these changes, the second patch builds on top to do the > hiding of the bar. Yes, that was exactly my initial point: You're not just hiding the bar when it is not used, but *you're also changing the way feedback works* at the same time. I.e. the "forcing the bar to be empty". My feeling is that these are distinct changes, not one. With your patch, there is no way to hide the bar automatically, but still get feedback messages from the browser. Maybe it is only really useful in this combination, but personally, I'm not convinced. Since there is grave silence otherwise, it is hard for me to gauge whether I'm off in my judgement. Hannes |