1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-18 15:07:47 +02:00

remove scroll mode, scroll windows via PageUp/PageDown

This commit is contained in:
Jfreegman 2014-06-13 01:42:20 -04:00
parent f10ce94f38
commit 24a85df15f
12 changed files with 63 additions and 130 deletions

View File

@ -548,17 +548,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
getmaxyx(self->window, y2, x2);
int cur_len = 0;
if (!ltr && (key == T_KEY_ESC)) { /* ESC key: Toggle history scroll mode */
bool scroll = ctx->hst->scroll_mode ? false : true;
line_info_toggle_scroll(self, scroll);
}
/* If we're in scroll mode ignore rest of function */
if (ctx->hst->scroll_mode) {
line_info_onKey(self, key);
return;
}
if (ltr) {
/* 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)) ) {
@ -574,6 +563,8 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
set_typingstatus(self, m, 1);
} else { /* if (!ltr) */
if (line_info_onKey(self, key))
return;
if (key == 0x107 || key == 0x8 || key == 0x7f) { /* BACKSPACE key */
if (ctx->pos > 0) {
@ -746,21 +737,17 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
line_info_print(self);
wclear(ctx->linewin);
if (ctx->hst->scroll_mode) {
line_info_onDraw(self);
} else {
curs_set(1);
scrollok(ctx->history, 1);
curs_set(1);
scrollok(ctx->history, 0);
if (ctx->len > 0 && !ctx->hst->scroll_mode) {
uint8_t line[MAX_STR_SIZE];
if (ctx->len> 0) {
uint8_t line[MAX_STR_SIZE];
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
reset_buf(ctx);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
} else {
mvwprintw(ctx->linewin, 1, 0, "%s", line);
}
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
reset_buf(ctx);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
} else {
mvwprintw(ctx->linewin, 1, 0, "%s", line);
}
}

View File

@ -87,7 +87,7 @@ void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
for (i = 0; i < NUMLINES; ++i)
line_info_add(self, NULL, NULL, NULL, lines[i], SYS_MSG, 0, 0);
msg = " * Use ESC key to toggle history scroll mode\n";
msg = " * Use Page Up/Page Down to scroll chat history\n";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
hst->line_start = start;

View File

@ -147,9 +147,9 @@ static void print_groupchat_help(ToxWindow *self)
for (i = 0; i < NUMLINES; ++i)
line_info_add(self, NULL, NULL, NULL, lines[i], SYS_MSG, 0, 0);
msg = " * Use ESC key to toggle history scroll mode";
msg = " * Use Page Up/Page Down to scroll chat history";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
msg = " * Scroll peer list with the Page Up/Page Down keys.\n";
msg = " * Scroll peer list with the < and > keys.\n";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, CYAN);
msg = " * Notice, some friends will be missing names while finding peers\n";
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 1, 0);
@ -383,17 +383,6 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
getmaxyx(self->window, y2, x2);
int cur_len = 0;
if (!ltr && (key == T_KEY_ESC) ) { /* ESC key: Toggle history scroll mode */
bool scroll = ctx->hst->scroll_mode ? false : true;
line_info_toggle_scroll(self, scroll);
}
/* If we're in scroll mode ignore rest of function */
if (ctx->hst->scroll_mode) {
line_info_onKey(self, key);
return;
}
if (ltr) {
if ( (ctx->len < MAX_STR_SIZE - 1) && (ctx->len < (x2 * (CHATBOX_HEIGHT - 1) - 1)) ) {
add_char_to_buf(ctx, key);
@ -405,6 +394,8 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
}
} else { /* if (!ltr) */
if (line_info_onKey(self, key))
return;
if (key == 0x107 || key == 0x8 || key == 0x7f) { /* BACKSPACE key: Remove character behind pos */
if (ctx->pos > 0) {
@ -521,14 +512,14 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
}
/* Scroll peerlist up and down one position if list overflows window */
else if (key == KEY_NPAGE) {
else if (key == T_KEY_C_PRD) {
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
if (groupchats[self->num].side_pos < groupchats[self->num].num_peers - L)
++groupchats[self->num].side_pos;
}
else if (key == KEY_PPAGE) {
else if (key == T_KEY_C_CMA) {
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
}
@ -587,21 +578,17 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
line_info_print(self);
wclear(ctx->linewin);
if (ctx->hst->scroll_mode) {
line_info_onDraw(self);
} else {
scrollok(ctx->history, 1);
curs_set(1);
scrollok(ctx->history, 0);
curs_set(1);
if (ctx->len > 0) {
uint8_t line[MAX_STR_SIZE];
if (ctx->len > 0) {
uint8_t line[MAX_STR_SIZE];
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
reset_buf(ctx);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
} else {
mvwprintw(ctx->linewin, 1, 0, "%s", line);
}
if (wcs_to_mbs_buf(line, ctx->line, MAX_STR_SIZE) == -1) {
reset_buf(ctx);
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
} else {
mvwprintw(ctx->linewin, 1, 0, "%s", line);
}
}

View File

@ -51,7 +51,7 @@ void line_info_init(struct history *hst)
hst->line_end = hst->line_start;
}
/* resets line_start when scroll mode is disabled */
/* resets line_start */
static void line_info_reset_start(struct history *hst)
{
struct line_info *line = hst->line_end;
@ -59,7 +59,7 @@ static void line_info_reset_start(struct history *hst)
while (line) {
if (line->id == start_id) {
hst->line_start = line;
hst->line_start = line->next;
break;
}
@ -67,23 +67,6 @@ static void line_info_reset_start(struct history *hst)
}
}
void line_info_toggle_scroll(ToxWindow *self, bool scroll)
{
WINDOW *win = self->chatwin->history;
struct history *hst = self->chatwin->hst;
if (scroll) {
hst->scroll_mode = true;
scrollok(win, 0);
curs_set(0);
} else {
hst->scroll_mode = false;
scrollok(win, 1);
curs_set(1);
line_info_reset_start(hst);
}
}
void line_info_cleanup(struct history *hst)
{
struct line_info *tmp1 = hst->line_root;
@ -201,7 +184,7 @@ void line_info_add(ToxWindow *self, uint8_t *tmstmp, uint8_t *name1, uint8_t *na
++hst->start_id;
lines -= (1 + hst->line_start->len / (x2 - offst));
if (!hst->scroll_mode && hst->line_start->next)
if (hst->line_start->next)
hst->line_start = hst->line_start->next;
}
}
@ -407,24 +390,26 @@ static void line_info_page_down(ToxWindow *self, struct history *hst)
hst->line_start = hst->line_start->next;
}
void line_info_onKey(ToxWindow *self, wint_t key)
bool line_info_onKey(ToxWindow *self, wint_t key)
{
struct history *hst = self->chatwin->hst;
bool match = true;
switch (key) {
case KEY_PPAGE:
/* TODO: Find good key bindings for page up/page down scroll behaviour */
/* case KEY_SPREVIOUS:
line_info_page_up(self, hst);
break;
case KEY_NPAGE:
case KEY_SNEXT:
line_info_page_down(self, hst);
break;
break; */
case KEY_UP:
case KEY_PPAGE:
line_info_scroll_up(hst);
break;
case KEY_DOWN:
case KEY_NPAGE:
line_info_scroll_down(hst);
break;
@ -435,18 +420,13 @@ void line_info_onKey(ToxWindow *self, wint_t key)
case KEY_END:
line_info_reset_start(hst);
break;
default:
match = false;
break;
}
}
void line_info_onDraw(ToxWindow *self)
{
ChatContext *ctx = self->chatwin;
wattron(ctx->linewin, A_BOLD | COLOR_PAIR(BLUE));
mvwprintw(ctx->linewin, 1, 0, "Scroll mode:\n");
wattroff(ctx->linewin, A_BOLD | COLOR_PAIR(BLUE));
mvwprintw(ctx->linewin, 1, 13, "Use up/down arrows, page up/page down, and home/end to navigate.\n"
" ESC to exit.\n");
return match;
}
void line_info_clear(struct history *hst)

View File

@ -61,7 +61,6 @@ struct history {
struct line_info *line_end;
uint32_t start_id; /* keeps track of where line_start should be when at bottom of history */
uint32_t line_items;
bool scroll_mode;
/* keeps track of lines added between window refreshes */
uint32_t queue;
@ -78,9 +77,6 @@ void line_info_print(ToxWindow *self);
/* frees all history lines */
void line_info_cleanup(struct history *hst);
/* Toggles scroll mode for current window */
void line_info_toggle_scroll(ToxWindow *self, bool scroll);
/* clears the screen (does not delete anything) */
void line_info_clear(struct history *hst);
@ -88,7 +84,6 @@ void line_info_clear(struct history *hst);
void line_info_set(ToxWindow *self, uint32_t id, uint8_t *msg);
void line_info_init(struct history *hst);
void line_info_onKey(ToxWindow *self, wint_t key);
void line_info_onDraw(ToxWindow *self);
bool line_info_onKey(ToxWindow *self, wint_t key); /* returns true if key is a match */
#endif /* #define _line_info_h */

View File

@ -64,11 +64,10 @@ void get_time_str(uint8_t *buf)
strftime(buf, TIME_STR_SIZE, t, get_time());
}
/* XXX: FIX */
unsigned char *hex_string_to_bin(char hex_string[])
char *hex_string_to_bin(const char *hex_string)
{
size_t len = strlen(hex_string);
unsigned char *val = malloc(len);
char *val = malloc(len);
if (val == NULL) {
endwin();
@ -76,11 +75,10 @@ unsigned char *hex_string_to_bin(char hex_string[])
exit(EXIT_FAILURE);
}
char *pos = hex_string;
size_t i;
for (i = 0; i < len; ++i, pos += 2)
sscanf(pos, "%2hhx", &val[i]);
for (i = 0; i < len; ++i, hex_string += 2)
sscanf(hex_string, "%2hhx", &val[i]);
return val;
}

View File

@ -29,7 +29,7 @@
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
/* convert a hex string to binary */
unsigned char *hex_string_to_bin(char hex_string[]);
char *hex_string_to_bin(const char *hex_string);
/* get the current unix time */
uint64_t get_unix_time(void);

View File

@ -131,21 +131,6 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
getyx(ctx->history, y, x);
getmaxyx(ctx->history, y2, x2);
/* TODO this is buggy */
/* ESC key: Toggle history scroll mode */
/*
if (key == T_KEY_ESC) {
bool scroll = ctx->hst->scroll_mode ? false : true;
line_info_toggle_scroll(self, scroll);
}
*/
/* If we're in scroll mode ignore rest of function */
if (ctx->hst->scroll_mode) {
line_info_onKey(self, key);
return;
}
if (ltr) {
if (ctx->len < (MAX_STR_SIZE - 1)) {
add_char_to_buf(ctx, key);
@ -273,10 +258,8 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
getyx(ctx->history, y, x);
getmaxyx(ctx->history, y2, x2);
if (!ctx->hst->scroll_mode) {
curs_set(1);
scrollok(ctx->history, 1);
}
curs_set(1);
scrollok(ctx->history, 1);
line_info_print(self);

View File

@ -84,12 +84,6 @@ struct arg_opts {
struct _Winthread Winthread;
struct user_settings *user_settings = NULL;
void on_window_resize(int sig)
{
refresh();
clear();
}
static void init_term(void)
{
signal(SIGWINCH, on_window_resize);
@ -208,9 +202,9 @@ static int nodelist_load(char *filename)
while (fgets(line, sizeof(line), fp) && linecnt < MAXNODES) {
if (strlen(line) > MINLINE) {
char *name = strtok(line, " ");
char *port = strtok(NULL, " ");
char *key_ascii = strtok(NULL, " ");
const char *name = strtok(line, " ");
const char *port = strtok(NULL, " ");
const char *key_ascii = strtok(NULL, " ");
/* invalid line */
if (name == NULL || port == NULL || key_ascii == NULL)

View File

@ -52,6 +52,8 @@
#define T_KEY_C_E 0x05 /* ctrl-e */
#define T_KEY_C_A 0x01 /* ctrl-a */
#define T_KEY_ESC 0x1B /* ESC key */
#define T_KEY_C_CMA 0x2C /* ctrl-comma */
#define T_KEY_C_PRD 0x2E /* ctrl-period */
enum {
MOVE_UP,

View File

@ -316,6 +316,12 @@ ToxWindow *init_windows(Tox *m)
return prompt;
}
void on_window_resize(int sig)
{
refresh();
clear();
}
static void draw_window_tab(ToxWindow toxwin)
{
/* alert0 takes priority */

View File

@ -176,5 +176,6 @@ void del_window(ToxWindow *w);
void set_active_window(int ch);
int get_num_active_windows(void);
void kill_all_windows(void); /* should only be called on shutdown */
void on_window_resize(int sig);
#endif /* #define _windows_h */