From e6b18231c02824a226b978c2383630a8940aa96e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 8 Oct 2014 02:45:08 -0400 Subject: [PATCH] add ability to toggle groupchat peerlist with ctrl-b --- src/groupchat.c | 83 ++++++++++++++++++++++++++++++++++++------------- src/groupchat.h | 4 +++ src/input.c | 9 ++++++ src/line_info.c | 4 +-- src/toxic.h | 3 +- src/windows.h | 3 +- 6 files changed, 80 insertions(+), 26 deletions(-) diff --git a/src/groupchat.c b/src/groupchat.c index 7e32682..2706a7e 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -128,6 +128,42 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum) kill_groupchat_window(self); } +/* destroys and re-creates groupchat window with or without the peerlist */ +void redraw_groupchat_win(ToxWindow *self) +{ + ChatContext *ctx = self->chatwin; + + endwin(); + refresh(); + clear(); + + int x2, y2; + getmaxyx(stdscr, y2, x2); + y2 -= 2; + + if (ctx->sidebar) { + delwin(ctx->sidebar); + ctx->sidebar = NULL; + } + + delwin(ctx->linewin); + delwin(ctx->history); + delwin(self->window); + + self->window = newwin(y2, x2, 0, 0); + ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0); + + if (self->show_peerlist) { + ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0); + ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH); + } else { + ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0); + } + + scrollok(ctx->history, 0); + +} + static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *msg, uint16_t len) { @@ -458,36 +494,38 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m) mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]); wclear(ctx->sidebar); - mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2); - mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT); - mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE); - int num_peers = groupchats[self->num].num_peers; + if (self->show_peerlist) { + mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT); + mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE); - wmove(ctx->sidebar, 0, 1); - wattron(ctx->sidebar, A_BOLD); - wprintw(ctx->sidebar, "Peers: %d\n", num_peers); - wattroff(ctx->sidebar, A_BOLD); + int num_peers = groupchats[self->num].num_peers; - mvwaddch(ctx->sidebar, 1, 0, ACS_LTEE); - mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH - 1); + wmove(ctx->sidebar, 0, 1); + wattron(ctx->sidebar, A_BOLD); + wprintw(ctx->sidebar, "Peers: %d\n", num_peers); + wattroff(ctx->sidebar, A_BOLD); - int N = TOX_MAX_NAME_LENGTH; - int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT; - int i; + mvwaddch(ctx->sidebar, 1, 0, ACS_LTEE); + mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH - 1); - for (i = 0; i < num_peers && i < maxlines; ++i) { - wmove(ctx->sidebar, i + 2, 1); - int peer = i + groupchats[self->num].side_pos; + int N = TOX_MAX_NAME_LENGTH; + int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT; + int i; - /* truncate nick to fit in side panel without modifying list */ - char tmpnck[TOX_MAX_NAME_LENGTH]; - int maxlen = SIDEBAR_WIDTH - 2; - memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], maxlen); - tmpnck[maxlen] = '\0'; + for (i = 0; i < num_peers && i < maxlines; ++i) { + wmove(ctx->sidebar, i + 2, 1); + int peer = i + groupchats[self->num].side_pos; - wprintw(ctx->sidebar, "%s\n", tmpnck); + /* truncate nick to fit in side panel without modifying list */ + char tmpnck[TOX_MAX_NAME_LENGTH]; + int maxlen = SIDEBAR_WIDTH - 2; + memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], maxlen); + tmpnck[maxlen] = '\0'; + + wprintw(ctx->sidebar, "%s\n", tmpnck); + } } int y, x; @@ -560,6 +598,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum) ret.help = help; ret.num = groupnum; + ret.show_peerlist = true; ret.active_box = -1; return ret; diff --git a/src/groupchat.h b/src/groupchat.h index e76df10..7de171d 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -43,6 +43,10 @@ typedef struct { void kill_groupchat_window(ToxWindow *self); int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum); + +/* destroys and re-creates groupchat window with or without the peerlist */ +void redraw_groupchat_win(ToxWindow *self); + ToxWindow new_group_chat(Tox *m, int groupnum); #endif /* #define GROUPCHAT_H */ diff --git a/src/input.c b/src/input.c index 35f03a4..644b010 100644 --- a/src/input.c +++ b/src/input.c @@ -32,6 +32,7 @@ #include "toxic_strings.h" #include "line_info.h" #include "notify.h" +#include "groupchat.h" /* add a char to input field and buffer */ void input_new_char(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_y) @@ -255,6 +256,14 @@ bool input_handle(ToxWindow *self, wint_t key, int x, int y, int mx_x, int mx_y) force_refresh(self->chatwin->history); break; + case T_KEY_C_B: + if (self->is_groupchat) { + self->show_peerlist ^= 1; + redraw_groupchat_win(self); + } + + break; + default: match = false; break; diff --git a/src/line_info.c b/src/line_info.c index 9c942cf..6be471e 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -59,7 +59,7 @@ void line_info_reset_start(ToxWindow *self, struct history *hst) int y2, x2; getmaxyx(self->window, y2, x2); - int side_offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; + int side_offst = self->show_peerlist ? SIDEBAR_WIDTH : 0; int top_offst = self->is_chat || self->is_prompt ? 2 : 0; int max_y = (y2 - CHATBOX_HEIGHT - top_offst); @@ -246,7 +246,7 @@ static void line_info_check_queue(ToxWindow *self) if (x2 <= SIDEBAR_WIDTH) return; - int offst = self->is_groupchat ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */ + int offst = self->show_peerlist ? SIDEBAR_WIDTH : 0; /* offset width of groupchat sidebar */ int lines = 1 + line->newlines + (line->len / (x2 - offst)); int max_y = y2 - CHATBOX_HEIGHT; diff --git a/src/toxic.h b/src/toxic.h index 1f214ea..80374b3 100644 --- a/src/toxic.h +++ b/src/toxic.h @@ -24,7 +24,7 @@ #define TOXIC_H #ifndef TOXICVER -#define TOXICVER "NOVER_" /* Use the -D flag to set this */ +#define TOXICVER "NOVERS" /* Use the -D flag to set this */ #endif #ifndef SIGWINCH @@ -64,6 +64,7 @@ #define T_KEY_C_Y 0x19 /* ctrl-y */ #define T_KEY_C_L 0x0C /* ctrl-l */ #define T_KEY_C_W 0x17 /* ctrl-w */ +#define T_KEY_C_B 0x02 /* ctrl-b */ #define T_KEY_TAB 0x09 /* TAB key */ #define ONLINE_CHAR "*" diff --git a/src/windows.h b/src/windows.h index be3950e..266f363 100644 --- a/src/windows.h +++ b/src/windows.h @@ -152,9 +152,10 @@ struct ToxWindow { int x; bool is_chat; - bool is_groupchat; bool is_prompt; bool is_friendlist; + bool is_groupchat; + int show_peerlist; /* used to toggle groupchat peerlist */ WINDOW_ALERTS alert;