1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-26 20:37:46 +02:00

add ability to toggle groupchat peerlist with ctrl-b

This commit is contained in:
Jfreegman 2014-10-08 02:45:08 -04:00
parent cc0145d561
commit e6b18231c0
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
6 changed files with 80 additions and 26 deletions

View File

@ -128,6 +128,42 @@ static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
kill_groupchat_window(self); 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, static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum,
const char *msg, uint16_t len) 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]); mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
wclear(ctx->sidebar); wclear(ctx->sidebar);
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2); 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); int num_peers = groupchats[self->num].num_peers;
wattron(ctx->sidebar, A_BOLD);
wprintw(ctx->sidebar, "Peers: %d\n", num_peers);
wattroff(ctx->sidebar, A_BOLD);
mvwaddch(ctx->sidebar, 1, 0, ACS_LTEE); wmove(ctx->sidebar, 0, 1);
mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH - 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; mvwaddch(ctx->sidebar, 1, 0, ACS_LTEE);
int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT; mvwhline(ctx->sidebar, 1, 1, ACS_HLINE, SIDEBAR_WIDTH - 1);
int i;
for (i = 0; i < num_peers && i < maxlines; ++i) { int N = TOX_MAX_NAME_LENGTH;
wmove(ctx->sidebar, i + 2, 1); int maxlines = y2 - SDBAR_OFST - CHATBOX_HEIGHT;
int peer = i + groupchats[self->num].side_pos; int i;
/* truncate nick to fit in side panel without modifying list */ for (i = 0; i < num_peers && i < maxlines; ++i) {
char tmpnck[TOX_MAX_NAME_LENGTH]; wmove(ctx->sidebar, i + 2, 1);
int maxlen = SIDEBAR_WIDTH - 2; int peer = i + groupchats[self->num].side_pos;
memcpy(tmpnck, &groupchats[self->num].peer_names[peer * N], maxlen);
tmpnck[maxlen] = '\0';
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; int y, x;
@ -560,6 +598,7 @@ ToxWindow new_group_chat(Tox *m, int groupnum)
ret.help = help; ret.help = help;
ret.num = groupnum; ret.num = groupnum;
ret.show_peerlist = true;
ret.active_box = -1; ret.active_box = -1;
return ret; return ret;

View File

@ -43,6 +43,10 @@ typedef struct {
void kill_groupchat_window(ToxWindow *self); void kill_groupchat_window(ToxWindow *self);
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum); 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); ToxWindow new_group_chat(Tox *m, int groupnum);
#endif /* #define GROUPCHAT_H */ #endif /* #define GROUPCHAT_H */

View File

@ -32,6 +32,7 @@
#include "toxic_strings.h" #include "toxic_strings.h"
#include "line_info.h" #include "line_info.h"
#include "notify.h" #include "notify.h"
#include "groupchat.h"
/* add a char to input field and buffer */ /* 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) 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); force_refresh(self->chatwin->history);
break; break;
case T_KEY_C_B:
if (self->is_groupchat) {
self->show_peerlist ^= 1;
redraw_groupchat_win(self);
}
break;
default: default:
match = false; match = false;
break; break;

View File

@ -59,7 +59,7 @@ void line_info_reset_start(ToxWindow *self, struct history *hst)
int y2, x2; int y2, x2;
getmaxyx(self->window, 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 top_offst = self->is_chat || self->is_prompt ? 2 : 0;
int max_y = (y2 - CHATBOX_HEIGHT - top_offst); int max_y = (y2 - CHATBOX_HEIGHT - top_offst);
@ -246,7 +246,7 @@ static void line_info_check_queue(ToxWindow *self)
if (x2 <= SIDEBAR_WIDTH) if (x2 <= SIDEBAR_WIDTH)
return; 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 lines = 1 + line->newlines + (line->len / (x2 - offst));
int max_y = y2 - CHATBOX_HEIGHT; int max_y = y2 - CHATBOX_HEIGHT;

View File

@ -24,7 +24,7 @@
#define TOXIC_H #define TOXIC_H
#ifndef TOXICVER #ifndef TOXICVER
#define TOXICVER "NOVER_" /* Use the -D flag to set this */ #define TOXICVER "NOVERS" /* Use the -D flag to set this */
#endif #endif
#ifndef SIGWINCH #ifndef SIGWINCH
@ -64,6 +64,7 @@
#define T_KEY_C_Y 0x19 /* ctrl-y */ #define T_KEY_C_Y 0x19 /* ctrl-y */
#define T_KEY_C_L 0x0C /* ctrl-l */ #define T_KEY_C_L 0x0C /* ctrl-l */
#define T_KEY_C_W 0x17 /* ctrl-w */ #define T_KEY_C_W 0x17 /* ctrl-w */
#define T_KEY_C_B 0x02 /* ctrl-b */
#define T_KEY_TAB 0x09 /* TAB key */ #define T_KEY_TAB 0x09 /* TAB key */
#define ONLINE_CHAR "*" #define ONLINE_CHAR "*"

View File

@ -152,9 +152,10 @@ struct ToxWindow {
int x; int x;
bool is_chat; bool is_chat;
bool is_groupchat;
bool is_prompt; bool is_prompt;
bool is_friendlist; bool is_friendlist;
bool is_groupchat;
int show_peerlist; /* used to toggle groupchat peerlist */
WINDOW_ALERTS alert; WINDOW_ALERTS alert;