From c7ff3255b8bd4bed2f825255a4fe28940db533b2 Mon Sep 17 00:00:00 2001 From: Simon Effenberg Date: Thu, 8 Jan 2015 23:43:11 +0100 Subject: 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/ui/core.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/ui/core.c') 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; } -- cgit 1.4.1-2-gfad0 From 34148e21012289b8ebf4ba5a3e2aa8b65051fd55 Mon Sep 17 00:00:00 2001 From: Simon Effenberg Date: Mon, 12 Jan 2015 11:32:32 +0100 Subject: adding preference option for dynamic input blocking /inpblock is now having subcommands 'timeout' and 'dynamic' with: /inpblock timeout and /inpblock dynamic Defaults are: /inpblock timeout 500 /inpblock dynamic on To get the old behavior specify: /inpblock timeout 20 /inpblock dynamic off The dynamic mode will block incrementally after something should be written to the window or after a key was pressed. So pressing a key would set the timeout to 0ms and after 10 timeouts to the next bigger one. Example (with dynamic mode on): "/inpblock timeout 50" timeout series: 10x 0ms 10x 10ms (0ms + 10 times since last keypress) 10x 30ms (10ms + 20 times since last keypress) *x50ms until next key was pressed or --- src/command/command.c | 20 +++++++++++++------- src/command/commands.c | 37 ++++++++++++++++++++++++++++++++----- src/config/preferences.c | 4 ++++ src/config/preferences.h | 3 ++- src/ui/console.c | 7 ++++++- src/ui/core.c | 5 +++++ 6 files changed, 62 insertions(+), 14 deletions(-) (limited to 'src/ui/core.c') diff --git a/src/command/command.c b/src/command/command.c index f2ceaa82..bfc05f7e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -623,14 +623,20 @@ static struct cmd_t command_defs[] = NULL } } }, { "/inpblock", - cmd_inpblock, parse_args, 1, 1, &cons_inpblock_setting, - { "/inpblock millis", "Input blocking delay.", - { "/inpblock millis", + cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting, + { "/inpblock [timeout|dynamic] [millis|on|off]", "Input blocking delay (dynamic or static).", + { "/inpblock [timeout|dynamic] [millis|on|off]", "----------------", - "Time to wait in milliseconds before reading input from the terminal buffer, defaults to 20.", - "Valid values are 1-1000.", - "A higher value will result in less CPU usage, but a noticable delay for response to input.", - "A lower value will result in higher CPU usage, but faster response to input.", + "Setting for how long to wait for input before checking for new messages or checking for state", + "changes like 'idle'.", + "timeout : Time to wait in milliseconds before reading input from the terminal buffer, defaults to 500.", + " : Valid values are 1-1000.", + "dynamic : Either use the timeout statically or use a dynamic variant which is responsive after an input", + " : and blocks longer (up to the specified 'timeout').", + " : on|off", + "A higher value will result in less CPU usage (irrespective if dynamic is on or off), but a noticable", + "delay for response to input if dynamic is off.", + "A lower value will result in higher CPU usage, but faster response to input if dynamic is off.", NULL } } }, { "/notify", diff --git a/src/command/commands.c b/src/command/commands.c index 5aae8fe5..2126800d 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3450,13 +3450,40 @@ cmd_notify(gchar **args, struct cmd_help_t help) gboolean cmd_inpblock(gchar **args, struct cmd_help_t help) { - char *value = args[0]; + char *subcmd = args[0]; + char *value = args[1]; int intval; - if (_strtoi(value, &intval, 1, 1000) == 0) { - cons_show("Input blocking set to %d milliseconds.", intval); - prefs_set_inpblock(intval); - ui_input_nonblocking(FALSE); + if (strcmp(subcmd, "timeout") == 0) { + if (value == NULL) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + + if (_strtoi(value, &intval, 1, 1000) == 0) { + cons_show("Input blocking set to %d milliseconds.", intval); + prefs_set_inpblock(intval); + ui_input_nonblocking(FALSE); + } + + return TRUE; + } + + if (strcmp(subcmd, "dynamic") == 0) { + if (value == NULL) { + cons_show("Usage: %s", help.usage); + return TRUE; + } + + if (strcmp(value, "on") != 0 && strcmp(value, "off") != 0) { + cons_show("Dynamic must be one of 'on' or 'off'"); + return TRUE; + } + + return _cmd_set_boolean_preference(value, help, "Dynamic input blocking", PREF_INPBLOCK_DYNAMIC); } + + cons_show("Usage: %s", help.usage); + return TRUE; } diff --git a/src/config/preferences.c b/src/config/preferences.c index 6e7ab576..5b683426 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -531,6 +531,7 @@ _get_group(preference_t pref) case PREF_ROSTER_BY: case PREF_RESOURCE_TITLE: case PREF_RESOURCE_MESSAGE: + case PREF_INPBLOCK_DYNAMIC: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -672,6 +673,8 @@ _get_key(preference_t pref) return "resource.title"; case PREF_RESOURCE_MESSAGE: return "resource.message"; + case PREF_INPBLOCK_DYNAMIC: + return "inpblock.dynamic"; default: return NULL; } @@ -696,6 +699,7 @@ _get_default_boolean(preference_t pref) case PREF_MUC_PRIVILEGES: case PREF_PRESENCE: case PREF_WRAP: + case PREF_INPBLOCK_DYNAMIC: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index a0ad2f84..9590eb64 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -100,7 +100,8 @@ typedef enum { PREF_OTR_WARN, PREF_OTR_POLICY, PREF_RESOURCE_TITLE, - PREF_RESOURCE_MESSAGE + PREF_RESOURCE_MESSAGE, + PREF_INPBLOCK_DYNAMIC } preference_t; typedef struct prof_alias_t { diff --git a/src/ui/console.c b/src/ui/console.c index d219a175..69abafef 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1182,7 +1182,12 @@ cons_show_chat_prefs(void) void cons_inpblock_setting(void) { - cons_show("Input block (/inpblock) : %d milliseconds", prefs_get_inpblock()); + cons_show("Input timeout (/inpblock) : %d milliseconds", prefs_get_inpblock()); + if (prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { + cons_show("Input dynamic (/inpblock) : ON"); + } else { + cons_show("Input dynamic (/inpblock) : OFF"); + } } void diff --git a/src/ui/core.c b/src/ui/core.c index 3b53b4ed..20db2010 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -206,6 +206,11 @@ ui_input_nonblocking(gboolean reset) static gint timeout = 0; static gint no_input_count = 0; + if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) { + inp_non_block(prefs_get_inpblock()); + return; + } + if (reset) { timeout = 0; no_input_count = 0; -- cgit 1.4.1-2-gfad0