mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 00:13:01 +01:00
Allow ncurses refresh rate to be set dynamically
This allows us to have a higher refresh rate only when necessary (e.g. games)
This commit is contained in:
parent
1803da85c1
commit
b7002ef3f0
@ -174,6 +174,10 @@ void game_kill(ToxWindow *self)
|
|||||||
|
|
||||||
kill_notifs(self->active_box);
|
kill_notifs(self->active_box);
|
||||||
del_window(self);
|
del_window(self);
|
||||||
|
|
||||||
|
if (get_num_active_windows_type(WINDOW_TYPE_GAME) == 0) {
|
||||||
|
set_window_refresh_rate(NCURSES_DEFAULT_REFRESH_RATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_init_abort(const ToxWindow *parent, ToxWindow *self)
|
static void game_init_abort(const ToxWindow *parent, ToxWindow *self)
|
||||||
@ -300,6 +304,8 @@ int game_initialize(const ToxWindow *parent, Tox *m, GameType type, uint32_t id,
|
|||||||
|
|
||||||
set_active_window_index(window_id);
|
set_active_window_index(window_id);
|
||||||
|
|
||||||
|
set_window_refresh_rate(NCURSES_GAME_REFRESH_RATE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
19
src/toxic.c
19
src/toxic.c
@ -239,6 +239,12 @@ void cb_toxcore_logger(Tox *m, TOX_LOG_LEVEL level, const char *file, uint32_t l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sets ncurses refresh rate. Lower values make it refresh more often. */
|
||||||
|
void set_window_refresh_rate(size_t refresh_rate)
|
||||||
|
{
|
||||||
|
timeout(refresh_rate);
|
||||||
|
}
|
||||||
|
|
||||||
static void init_term(void)
|
static void init_term(void)
|
||||||
{
|
{
|
||||||
#if HAVE_WIDECHAR
|
#if HAVE_WIDECHAR
|
||||||
@ -256,7 +262,7 @@ static void init_term(void)
|
|||||||
keypad(stdscr, 1);
|
keypad(stdscr, 1);
|
||||||
noecho();
|
noecho();
|
||||||
nonl();
|
nonl();
|
||||||
timeout(30);
|
set_window_refresh_rate(NCURSES_DEFAULT_REFRESH_RATE);
|
||||||
|
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
short bg_color = COLOR_BLACK;
|
short bg_color = COLOR_BLACK;
|
||||||
@ -435,9 +441,7 @@ static void cleanup_init_messages(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i;
|
for (int i = 0; i < init_messages.num; ++i) {
|
||||||
|
|
||||||
for (i = 0; i < init_messages.num; ++i) {
|
|
||||||
free(init_messages.msgs[i]);
|
free(init_messages.msgs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,19 +450,16 @@ static void cleanup_init_messages(void)
|
|||||||
|
|
||||||
static void print_init_messages(ToxWindow *toxwin)
|
static void print_init_messages(ToxWindow *toxwin)
|
||||||
{
|
{
|
||||||
int i;
|
for (int i = 0; i < init_messages.num; ++i) {
|
||||||
|
|
||||||
for (i = 0; i < init_messages.num; ++i) {
|
|
||||||
line_info_add(toxwin, NULL, NULL, NULL, SYS_MSG, 0, 0, init_messages.msgs[i]);
|
line_info_add(toxwin, NULL, NULL, NULL, SYS_MSG, 0, 0, init_messages.msgs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_friendlist(Tox *m)
|
static void load_friendlist(Tox *m)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
size_t numfriends = tox_self_get_friend_list_size(m);
|
size_t numfriends = tox_self_get_friend_list_size(m);
|
||||||
|
|
||||||
for (i = 0; i < numfriends; ++i) {
|
for (size_t i = 0; i < numfriends; ++i) {
|
||||||
friendlist_onFriendAdded(NULL, m, i, false);
|
friendlist_onFriendAdded(NULL, m, i, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@
|
|||||||
#define TIME_STR_SIZE 32
|
#define TIME_STR_SIZE 32
|
||||||
#define COLOR_STR_SIZE 10 /* should fit every color option */
|
#define COLOR_STR_SIZE 10 /* should fit every color option */
|
||||||
|
|
||||||
|
#define NCURSES_DEFAULT_REFRESH_RATE 100
|
||||||
|
#define NCURSES_GAME_REFRESH_RATE 25
|
||||||
|
|
||||||
#ifndef MAX_PORT_RANGE
|
#ifndef MAX_PORT_RANGE
|
||||||
#define MAX_PORT_RANGE 65535
|
#define MAX_PORT_RANGE 65535
|
||||||
#endif
|
#endif
|
||||||
@ -104,6 +107,9 @@ void unlock_status(void);
|
|||||||
|
|
||||||
void flag_interface_refresh(void);
|
void flag_interface_refresh(void);
|
||||||
|
|
||||||
|
/* Sets ncurses refresh rate. Lower values make it refresh more often. */
|
||||||
|
void set_window_refresh_rate(size_t refresh_rate);
|
||||||
|
|
||||||
void exit_toxic_success(Tox *m);
|
void exit_toxic_success(Tox *m);
|
||||||
void exit_toxic_err(const char *errmsg, int errcode);
|
void exit_toxic_err(const char *errmsg, int errcode);
|
||||||
|
|
||||||
|
@ -934,6 +934,26 @@ int get_num_active_windows(void)
|
|||||||
return num_active_windows;
|
return num_active_windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the number of active windows of given type. */
|
||||||
|
size_t get_num_active_windows_type(WINDOW_TYPE type)
|
||||||
|
{
|
||||||
|
size_t count = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
|
ToxWindow *w = windows[i];
|
||||||
|
|
||||||
|
if (w == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (w->type == type) {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
/* destroys all chat and conference windows (should only be called on shutdown) */
|
/* destroys all chat and conference windows (should only be called on shutdown) */
|
||||||
void kill_all_windows(Tox *m)
|
void kill_all_windows(Tox *m)
|
||||||
{
|
{
|
||||||
|
@ -309,6 +309,9 @@ ToxWindow *get_window_ptr(size_t i);
|
|||||||
ToxWindow *get_active_window(void);
|
ToxWindow *get_active_window(void);
|
||||||
void draw_window_bar(ToxWindow *self);
|
void draw_window_bar(ToxWindow *self);
|
||||||
|
|
||||||
|
/* Returns the number of active windows of given type. */
|
||||||
|
size_t get_num_active_windows_type(WINDOW_TYPE type);
|
||||||
|
|
||||||
/* refresh inactive windows to prevent scrolling bugs.
|
/* refresh inactive windows to prevent scrolling bugs.
|
||||||
call at least once per second */
|
call at least once per second */
|
||||||
void refresh_inactive_windows(void);
|
void refresh_inactive_windows(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user