diff --git a/src/chat.c b/src/chat.c index 19e7f3c..0df5257 100644 --- a/src/chat.c +++ b/src/chat.c @@ -335,7 +335,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) #endif { /* prevents buffer overflows and strange behaviour when cursor goes past the window */ if ( (ctx->len < MAX_STR_SIZE-1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1)-1)) ) { - add_char_to_buf(key, ctx->line, &ctx->pos, &ctx->len); + add_char_to_buf(ctx->line, &ctx->pos, &ctx->len, key); if (x == x2-1) wmove(self->window, y+1, 0); diff --git a/src/friendlist.c b/src/friendlist.c index ae50f1f..e30eaab 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -256,14 +256,16 @@ static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) } } +#define FLIST_OFST 3 /* Accounts for the three lines of text at top */ + static void friendlist_onDraw(ToxWindow *self, Tox *m) { curs_set(0); werase(self->window); - int x, y; - getmaxyx(self->window, y, x); + int x2, y2; + getmaxyx(self->window, y2, x2); - bool fix_statuses = x != self->x; /* true if window x axis has changed */ + bool fix_statuses = x2 != self->x; /* true if window x axis has changed */ if (num_friends == 0) { wprintw(self->window, "Empty. Add some friends! :-)\n"); @@ -274,9 +276,14 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) wattroff(self->window, COLOR_PAIR(CYAN) | A_BOLD); } + /* Determine which portion of friendlist to draw based on current position */ + int page = num_selected / (y2 - FLIST_OFST); + int start = (y2 - FLIST_OFST) * page; + int end = y2 - FLIST_OFST + start; + int i; - for (i = 0; i < num_friends && i < y-3; ++i) { + for (i = start; i < num_friends && i < end; ++i) { int f = friendlist_index[i]; bool f_selected = false; @@ -329,7 +336,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) } /* Truncate note if it doesn't fit on one line */ - uint16_t maxlen = x - getcurx(self->window) - 4; + uint16_t maxlen = x2 - getcurx(self->window) - 4; if (friends[f].statusmsg_len > maxlen) { friends[f].statusmsg[maxlen-3] = '\0'; strcat(friends[f].statusmsg, "..."); @@ -352,7 +359,7 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m) } } - self->x = x; + self->x = x2; wrefresh(self->window); } diff --git a/src/groupchat.c b/src/groupchat.c index 0cfe981..fedfc32 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -275,7 +275,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key) #endif { /* prevents buffer overflows and strange behaviour when cursor goes past the window */ if ( (ctx->len < MAX_STR_SIZE-1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1)-1)) ) { - add_char_to_buf(key, ctx->line, &ctx->pos, &ctx->len); + add_char_to_buf(ctx->line, &ctx->pos, &ctx->len, key); if (x == x2-1) wmove(self->window, y+1, 0); diff --git a/src/misc_tools.c b/src/misc_tools.c index 2e2da2e..0f53053 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -166,7 +166,7 @@ bool valid_nick(uint8_t *nick) */ /* Adds char to buffer at pos */ -void add_char_to_buf(wint_t ch, wchar_t *buf, size_t *pos, size_t *len) +void add_char_to_buf(wchar_t *buf, size_t *pos, size_t *len, wint_t ch) { if (*pos < 0 || *len >= MAX_STR_SIZE) return; @@ -197,7 +197,7 @@ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len) --(*len); } -/* Deletes the character at pos */ +/* Deletes the character after pos */ void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len) { if (*pos < 0 || *pos >= *len) diff --git a/src/misc_tools.h b/src/misc_tools.h index cd5fe3b..656e927 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -42,12 +42,12 @@ bool valid_nick(uint8_t *nick); */ /* Adds char to buffer at pos */ -void add_char_to_buf(wint_t ch, wchar_t *buf, size_t *pos, size_t *len); +void add_char_to_buf(wchar_t *buf, size_t *pos, size_t *len, wint_t ch); /* Deletes the character before pos */ void del_char_buf_bck(wchar_t *buf, size_t *pos, size_t *len); -/* Deletes the character at pos */ +/* Deletes the character after pos */ void del_char_buf_frnt(wchar_t *buf, size_t *pos, size_t *len); /* nulls buf and sets pos and len to 0 */