mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
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
This commit is contained in:
parent
0d0ed9b7ca
commit
c7ff3255b8
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
#endif
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user