From 13f73a30e73f0349968f827e4003b3b4c84ebbf3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 21 Dec 2014 18:15:29 +0000 Subject: [PATCH] Added /inpblock command --- src/command/command.c | 11 +++++++++++ src/command/commands.c | 13 +++++++++++++ src/command/commands.h | 1 + src/config/preferences.c | 18 ++++++++++++++++++ src/config/preferences.h | 2 ++ src/ui/console.c | 8 ++++++++ src/ui/inputwin.c | 2 +- src/ui/ui.h | 1 + 8 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/command/command.c b/src/command/command.c index 776dd533..d00b1896 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -617,6 +617,17 @@ static struct cmd_t command_defs[] = "Configure time precision for the main window.", NULL } } }, + { "/inpblock", + cmd_inpblock, parse_args, 1, 1, &cons_inpblock_setting, + { "/inpblock millis", "Input blocking delay.", + { "/inpblock millis", + "----------------", + "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.", + NULL } } }, + { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, { "/notify [type value]|[type setting value]", "Control various desktop noficiations.", diff --git a/src/command/commands.c b/src/command/commands.c index 39bcf287..cc914c1f 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3395,6 +3395,19 @@ cmd_notify(gchar **args, struct cmd_help_t help) return TRUE; } +gboolean +cmd_inpblock(gchar **args, struct cmd_help_t help) +{ + char *value = args[0]; + 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(); + } + return TRUE; +} + gboolean cmd_log(gchar **args, struct cmd_help_t help) { diff --git a/src/command/commands.h b/src/command/commands.h index 5245b2c7..48a11e24 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -136,6 +136,7 @@ gboolean cmd_presence(gchar **args, struct cmd_help_t help); gboolean cmd_wrap(gchar **args, struct cmd_help_t help); gboolean cmd_time(gchar **args, struct cmd_help_t help); gboolean cmd_resource(gchar **args, struct cmd_help_t help); +gboolean cmd_inpblock(gchar **args, struct cmd_help_t help); gboolean cmd_form_field(char *tag, gchar **args); diff --git a/src/config/preferences.c b/src/config/preferences.c index baf3e853..7bc56999 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -61,6 +61,8 @@ #define PREF_GROUP_ALIAS "alias" #define PREF_GROUP_OTR "otr" +#define INPBLOCK_DEFAULT 20 + static gchar *prefs_loc; static GKeyFile *prefs; gint log_maxsize = 0; @@ -261,6 +263,22 @@ prefs_set_max_log_size(gint value) _save_prefs(); } +gint prefs_get_inpblock(void) +{ + int val = g_key_file_get_integer(prefs, PREF_GROUP_UI, "inpblock", NULL); + if (val == 0) { + return INPBLOCK_DEFAULT; + } else { + return val; + } +} + +void prefs_set_inpblock(gint value) +{ + g_key_file_set_integer(prefs, PREF_GROUP_UI, "inpblock", value); + _save_prefs(); +} + gint prefs_get_priority(void) { diff --git a/src/config/preferences.h b/src/config/preferences.h index d2a3fafd..cc95c6e9 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -123,6 +123,8 @@ void prefs_set_reconnect(gint value); gint prefs_get_reconnect(void); void prefs_set_autoping(gint value); gint prefs_get_autoping(void); +gint prefs_get_inpblock(void); +void prefs_set_inpblock(gint value); void prefs_set_occupants_size(gint value); gint prefs_get_occupants_size(void); diff --git a/src/ui/console.c b/src/ui/console.c index 3a280eb5..2bfc12ef 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -999,6 +999,7 @@ _cons_show_ui_prefs(void) cons_privileges_setting(); cons_titlebar_setting(); cons_presence_setting(); + cons_inpblock_setting(); cons_alert(); } @@ -1159,6 +1160,12 @@ _cons_show_chat_prefs(void) cons_alert(); } +static void +_cons_inpblock_setting(void) +{ + cons_show("Input block (/inpblock) : %d milliseconds", prefs_get_inpblock()); +} + static void _cons_log_setting(void) { @@ -1677,6 +1684,7 @@ console_init_module(void) cons_reconnect_setting = _cons_reconnect_setting; cons_autoping_setting = _cons_autoping_setting; cons_priority_setting = _cons_priority_setting; + cons_inpblock_setting = _cons_inpblock_setting; cons_show_connection_prefs = _cons_show_connection_prefs; cons_show_themes = _cons_show_themes; cons_prefs = _cons_prefs; diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 4c9845a4..4ed47601 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -112,7 +112,7 @@ inp_win_resize(void) void inp_non_block(void) { - wtimeout(inp_win, 20); + wtimeout(inp_win, prefs_get_inpblock()); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 159f7f18..3271d25b 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -322,6 +322,7 @@ void (*cons_reconnect_setting)(void); void (*cons_autoping_setting)(void); void (*cons_priority_setting)(void); void (*cons_autoconnect_setting)(void); +void (*cons_inpblock_setting)(void); void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime *last_activity); void (*cons_show_contact_offline)(PContact contact, char *resource, char *status); void (*cons_theme_colours)(void);