From c7ff3255b8bd4bed2f825255a4fe28940db533b2 Mon Sep 17 00:00:00 2001 From: Simon Effenberg Date: Thu, 8 Jan 2015 23:43:11 +0100 Subject: [PATCH] trying to block (and save cpu power) more dynamically instead of blocking too long if inpblock is set to something like 500ms the input timeout is not set directly to inpblock but is increasing dynamically from 0 to inpblock by a little algorithm FIXME: the call from the win_* method to the ui_input_* method looks wrong.. this causes a cross reference which shouldn't be --- src/command/commands.c | 2 +- src/profanity.c | 2 +- src/ui/core.c | 30 +++++++++++++++++++++++++++--- src/ui/inputwin.c | 4 ++-- src/ui/inputwin.h | 4 ++-- src/ui/ui.h | 2 +- src/ui/window.c | 4 +++- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index fba32b8b..5aae8fe5 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3455,7 +3455,7 @@ cmd_inpblock(gchar **args, struct cmd_help_t help) if (_strtoi(value, &intval, 1, 1000) == 0) { cons_show("Input blocking set to %d milliseconds.", intval); prefs_set_inpblock(intval); - ui_input_nonblocking(); + ui_input_nonblocking(FALSE); } return TRUE; } diff --git a/src/profanity.c b/src/profanity.c index 18bcc5f9..b28eae20 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -76,7 +76,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name) { _init(disable_tls, log_level); log_info("Starting main event loop"); - ui_input_nonblocking(); + ui_input_nonblocking(TRUE); GTimer *timer = g_timer_new(); gboolean cmd_result = TRUE; jabber_conn_status_t conn_status = jabber_get_connection_status(); diff --git a/src/ui/core.c b/src/ui/core.c index be16dfad..3b53b4ed 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -180,7 +180,11 @@ ui_get_char(char *input, int *size, int *result) wint_t ch = inp_get_char(input, size, result); if (ch != ERR && *result != ERR) { ui_reset_idle_time(); + ui_input_nonblocking(TRUE); + } else { + ui_input_nonblocking(FALSE); } + return ch; } @@ -197,9 +201,29 @@ ui_replace_input(char *input, const char * const new_input, int *size) } void -ui_input_nonblocking(void) +ui_input_nonblocking(gboolean reset) { - inp_non_block(); + static gint timeout = 0; + static gint no_input_count = 0; + + if (reset) { + timeout = 0; + no_input_count = 0; + } + + if (timeout < prefs_get_inpblock()) { + no_input_count++; + + if (no_input_count % 10 == 0) { + timeout += no_input_count; + + if (timeout > prefs_get_inpblock()) { + timeout = prefs_get_inpblock(); + } + } + } + + inp_non_block(timeout); } void @@ -2218,7 +2242,7 @@ ui_ask_password(void) status_bar_update_virtual(); inp_block(); inp_get_password(passwd); - inp_non_block(); + inp_non_block(prefs_get_inpblock()); return passwd; } diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 19318745..a6877a86 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -120,9 +120,9 @@ inp_win_resize(void) } void -inp_non_block(void) +inp_non_block(gint timeout) { - wtimeout(inp_win, prefs_get_inpblock()); + wtimeout(inp_win, timeout); } void diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h index eae20a51..b5a26c10 100644 --- a/src/ui/inputwin.h +++ b/src/ui/inputwin.h @@ -40,9 +40,9 @@ wint_t inp_get_char(char *input, int *size, int *result); void inp_win_reset(void); void inp_win_resize(void); void inp_put_back(void); -void inp_non_block(void); +void inp_non_block(gint); void inp_block(void); void inp_get_password(char *passwd); void inp_replace_input(char *input, const char * const new_input, int *size); -#endif \ No newline at end of file +#endif diff --git a/src/ui/ui.h b/src/ui/ui.h index 32484b9e..e28914ff 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -232,7 +232,7 @@ void ui_statusbar_new(const int win); wint_t ui_get_char(char *input, int *size, int *result); void ui_input_clear(void); -void ui_input_nonblocking(void); +void ui_input_nonblocking(gboolean); void ui_replace_input(char *input, const char * const new_input, int *size); void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)); diff --git a/src/ui/window.c b/src/ui/window.c index caef36df..3a45ab01 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -740,6 +740,8 @@ win_save_print(ProfWin *window, const char show_char, GTimeVal *tstamp, buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message); _win_print(window, show_char, time, flags, theme_item, from, message); + // TODO: cross-reference.. this should be replaced by a real event-based system + ui_input_nonblocking(TRUE); } void @@ -952,4 +954,4 @@ win_printline_nowrap(WINDOW *win, char *msg) waddnstr(win, msg, maxx); wmove(win, cury+1, 0); -} \ No newline at end of file +}