1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Merge remote-tracking branch 'savar/dynamic_input_block'

This commit is contained in:
James Booth 2015-01-12 23:41:15 +00:00
commit a39ac6cd07
12 changed files with 126 additions and 26 deletions

@ -97,6 +97,7 @@ static char * _affiliation_autocomplete(char *input, int *size);
static char * _role_autocomplete(char *input, int *size); static char * _role_autocomplete(char *input, int *size);
static char * _resource_autocomplete(char *input, int *size); static char * _resource_autocomplete(char *input, int *size);
static char * _titlebar_autocomplete(char *input, int *size); static char * _titlebar_autocomplete(char *input, int *size);
static char * _inpblock_autocomplete(char *input, int *size);
GHashTable *commands = NULL; GHashTable *commands = NULL;
@ -623,14 +624,18 @@ static struct cmd_t command_defs[] =
NULL } } }, NULL } } },
{ "/inpblock", { "/inpblock",
cmd_inpblock, parse_args, 1, 1, &cons_inpblock_setting, cmd_inpblock, parse_args, 2, 2, &cons_inpblock_setting,
{ "/inpblock millis", "Input blocking delay.", { "/inpblock timeout|dynamic [millis|on|off]", "Input blocking delay (dynamic or static).",
{ "/inpblock millis", { "/inpblock timeout|dynamic [millis|on|off]",
"----------------", "-----------------------------------------",
"Time to wait in milliseconds before reading input from the terminal buffer, defaults to 20.", "How long to wait for input before checking for new messages or checking for state changes such as 'idle'.",
"Valid values are 1-1000.", "timeout : Time to wait in milliseconds before reading input from the terminal buffer, defaults to 500.",
"A higher value will result in less CPU usage, but a noticable delay for response to input.", " : Valid values are 1-1000.",
"A lower value will result in higher CPU usage, but faster response to input.", "dynamic : Start with a 0 timeout and increase the value dynamically up to the specified 'timeout'.",
" : on|off",
"A higher timeout will result in less CPU usage, but a noticable delay for response to input.",
"A lower timeout will result in higher CPU usage, but faster response to input.",
"Using the dynamic setting, higher CPU usage will occur during activity, but over time the CPU usage will decrease whilst there is no activity.",
NULL } } }, NULL } } },
{ "/notify", { "/notify",
@ -1114,6 +1119,7 @@ static Autocomplete occupants_ac;
static Autocomplete occupants_default_ac; static Autocomplete occupants_default_ac;
static Autocomplete time_ac; static Autocomplete time_ac;
static Autocomplete resource_ac; static Autocomplete resource_ac;
static Autocomplete inpblock_ac;
/* /*
* Initialise command autocompleter and history * Initialise command autocompleter and history
@ -1464,6 +1470,10 @@ cmd_init(void)
autocomplete_add(resource_ac, "title"); autocomplete_add(resource_ac, "title");
autocomplete_add(resource_ac, "message"); autocomplete_add(resource_ac, "message");
inpblock_ac = autocomplete_new();
autocomplete_add(inpblock_ac, "timeout");
autocomplete_add(inpblock_ac, "dynamic");
cmd_history_init(); cmd_history_init();
} }
@ -1520,6 +1530,7 @@ cmd_uninit(void)
autocomplete_free(occupants_default_ac); autocomplete_free(occupants_default_ac);
autocomplete_free(time_ac); autocomplete_free(time_ac);
autocomplete_free(resource_ac); autocomplete_free(resource_ac);
autocomplete_free(inpblock_ac);
} }
gboolean gboolean
@ -1688,6 +1699,7 @@ cmd_reset_autocomplete()
autocomplete_reset(occupants_default_ac); autocomplete_reset(occupants_default_ac);
autocomplete_reset(time_ac); autocomplete_reset(time_ac);
autocomplete_reset(resource_ac); autocomplete_reset(resource_ac);
autocomplete_reset(inpblock_ac);
if (ui_current_win_type() == WIN_CHAT) { if (ui_current_win_type() == WIN_CHAT) {
ProfChatWin *chatwin = wins_get_current_chat(); ProfChatWin *chatwin = wins_get_current_chat();
@ -2008,6 +2020,7 @@ _cmd_complete_parameters(char *input, int *size)
g_hash_table_insert(ac_funcs, "/role", _role_autocomplete); g_hash_table_insert(ac_funcs, "/role", _role_autocomplete);
g_hash_table_insert(ac_funcs, "/resource", _resource_autocomplete); g_hash_table_insert(ac_funcs, "/resource", _resource_autocomplete);
g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete); g_hash_table_insert(ac_funcs, "/titlebar", _titlebar_autocomplete);
g_hash_table_insert(ac_funcs, "/inpblock", _inpblock_autocomplete);
char parsed[*size+1]; char parsed[*size+1];
i = 0; i = 0;
@ -2513,6 +2526,24 @@ _titlebar_autocomplete(char *input, int *size)
return NULL; return NULL;
} }
static char *
_inpblock_autocomplete(char *input, int *size)
{
char *found = NULL;
found = autocomplete_param_with_func(input, size, "/inpblock dynamic", prefs_autocomplete_boolean_choice);
if (found != NULL) {
return found;
}
found = autocomplete_param_with_ac(input, size, "/inpblock", inpblock_ac, FALSE);
if (found != NULL) {
return found;
}
return NULL;
}
static char * static char *
_form_autocomplete(char *input, int *size) _form_autocomplete(char *input, int *size)
{ {

@ -3450,13 +3450,41 @@ cmd_notify(gchar **args, struct cmd_help_t help)
gboolean gboolean
cmd_inpblock(gchar **args, struct cmd_help_t help) cmd_inpblock(gchar **args, struct cmd_help_t help)
{ {
char *value = args[0]; char *subcmd = args[0];
char *value = args[1];
int intval; int intval;
if (_strtoi(value, &intval, 1, 1000) == 0) {
cons_show("Input blocking set to %d milliseconds.", intval); if (g_strcmp0(subcmd, "timeout") == 0) {
prefs_set_inpblock(intval); if (value == NULL) {
ui_input_nonblocking(); 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 (g_strcmp0(subcmd, "dynamic") == 0) {
if (value == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
if (g_strcmp0(value, "on") != 0 && g_strcmp0(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; return TRUE;
} }

@ -531,6 +531,7 @@ _get_group(preference_t pref)
case PREF_ROSTER_BY: case PREF_ROSTER_BY:
case PREF_RESOURCE_TITLE: case PREF_RESOURCE_TITLE:
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
case PREF_INPBLOCK_DYNAMIC:
return PREF_GROUP_UI; return PREF_GROUP_UI;
case PREF_STATES: case PREF_STATES:
case PREF_OUTTYPE: case PREF_OUTTYPE:
@ -672,6 +673,8 @@ _get_key(preference_t pref)
return "resource.title"; return "resource.title";
case PREF_RESOURCE_MESSAGE: case PREF_RESOURCE_MESSAGE:
return "resource.message"; return "resource.message";
case PREF_INPBLOCK_DYNAMIC:
return "inpblock.dynamic";
default: default:
return NULL; return NULL;
} }
@ -696,6 +699,7 @@ _get_default_boolean(preference_t pref)
case PREF_MUC_PRIVILEGES: case PREF_MUC_PRIVILEGES:
case PREF_PRESENCE: case PREF_PRESENCE:
case PREF_WRAP: case PREF_WRAP:
case PREF_INPBLOCK_DYNAMIC:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

@ -100,7 +100,8 @@ typedef enum {
PREF_OTR_WARN, PREF_OTR_WARN,
PREF_OTR_POLICY, PREF_OTR_POLICY,
PREF_RESOURCE_TITLE, PREF_RESOURCE_TITLE,
PREF_RESOURCE_MESSAGE PREF_RESOURCE_MESSAGE,
PREF_INPBLOCK_DYNAMIC
} preference_t; } preference_t;
typedef struct prof_alias_t { typedef struct prof_alias_t {

@ -76,7 +76,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
{ {
_init(disable_tls, log_level); _init(disable_tls, log_level);
log_info("Starting main event loop"); log_info("Starting main event loop");
ui_input_nonblocking(); ui_input_nonblocking(TRUE);
GTimer *timer = g_timer_new(); GTimer *timer = g_timer_new();
gboolean cmd_result = TRUE; gboolean cmd_result = TRUE;
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();

@ -1182,7 +1182,12 @@ cons_show_chat_prefs(void)
void void
cons_inpblock_setting(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("Dynamic timeout (/inpblock) : ON");
} else {
cons_show("Dynamic timeout (/inpblock) : OFF");
}
} }
void void

@ -180,7 +180,11 @@ ui_get_char(char *input, int *size, int *result)
wint_t ch = inp_get_char(input, size, result); wint_t ch = inp_get_char(input, size, result);
if (ch != ERR && *result != ERR) { if (ch != ERR && *result != ERR) {
ui_reset_idle_time(); ui_reset_idle_time();
ui_input_nonblocking(TRUE);
} else {
ui_input_nonblocking(FALSE);
} }
return ch; return ch;
} }
@ -197,9 +201,34 @@ ui_replace_input(char *input, const char * const new_input, int *size)
} }
void void
ui_input_nonblocking(void) ui_input_nonblocking(gboolean reset)
{ {
inp_non_block(); 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;
}
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 void
@ -2218,7 +2247,7 @@ ui_ask_password(void)
status_bar_update_virtual(); status_bar_update_virtual();
inp_block(); inp_block();
inp_get_password(passwd); inp_get_password(passwd);
inp_non_block(); inp_non_block(prefs_get_inpblock());
return passwd; return passwd;
} }

@ -120,9 +120,9 @@ inp_win_resize(void)
} }
void void
inp_non_block(void) inp_non_block(gint timeout)
{ {
wtimeout(inp_win, prefs_get_inpblock()); wtimeout(inp_win, timeout);
} }
void void

@ -40,9 +40,9 @@ wint_t inp_get_char(char *input, int *size, int *result);
void inp_win_reset(void); void inp_win_reset(void);
void inp_win_resize(void); void inp_win_resize(void);
void inp_put_back(void); void inp_put_back(void);
void inp_non_block(void); void inp_non_block(gint);
void inp_block(void); void inp_block(void);
void inp_get_password(char *passwd); void inp_get_password(char *passwd);
void inp_replace_input(char *input, const char * const new_input, int *size); void inp_replace_input(char *input, const char * const new_input, int *size);
#endif #endif

@ -232,7 +232,7 @@ void ui_statusbar_new(const int win);
wint_t ui_get_char(char *input, int *size, int *result); wint_t ui_get_char(char *input, int *size, int *result);
void ui_input_clear(void); 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_replace_input(char *input, const char * const new_input, int *size);
void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)); void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void));

@ -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); buffer_push(window->layout->buffer, show_char, time, flags, theme_item, from, message);
_win_print(window, 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 void
@ -952,4 +954,4 @@ win_printline_nowrap(WINDOW *win, char *msg)
waddnstr(win, msg, maxx); waddnstr(win, msg, maxx);
wmove(win, cury+1, 0); wmove(win, cury+1, 0);
} }

@ -331,7 +331,7 @@ wint_t ui_get_char(char *input, int *size, int *result)
} }
void ui_input_clear(void) {} void ui_input_clear(void) {}
void ui_input_nonblocking(void) {} void ui_input_nonblocking(gboolean reset) {}
void ui_replace_input(char *input, const char * const new_input, int *size) {} 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)) {} void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) {}