mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:43:02 +01:00
fix resizing bugs
This commit is contained in:
parent
a126f9c1a6
commit
c271622670
@ -50,9 +50,8 @@ for more details.
|
|||||||
.IP __DATADIR__/toxic.conf.example
|
.IP __DATADIR__/toxic.conf.example
|
||||||
Configuration example.
|
Configuration example.
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
Resizing the terminal breaks the layout. We suggest you size your terminal as
|
Unicode characters with a width larger than 1 column may cause
|
||||||
desired prior to starting the client. Unicode characters with a width larger
|
strange behaviour. Expect more bugs and bad
|
||||||
than 1 column may cause strange behaviour. Expect more bugs and bad
|
|
||||||
behaviour: this software is in a pre\-alpha stage.
|
behaviour: this software is in a pre\-alpha stage.
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
JFreegman <JFreegman@gmail.com>
|
JFreegman <JFreegman@gmail.com>
|
||||||
|
16
src/chat.c
16
src/chat.c
@ -116,6 +116,8 @@ void kill_chat_window(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
int f_num = self->num;
|
int f_num = self->num;
|
||||||
delwin(ctx->linewin);
|
delwin(ctx->linewin);
|
||||||
|
delwin(ctx->history);
|
||||||
|
delwin(self->window);
|
||||||
delwin(statusbar->topline);
|
delwin(statusbar->topline);
|
||||||
del_window(self);
|
del_window(self);
|
||||||
disable_chatwin(f_num);
|
disable_chatwin(f_num);
|
||||||
@ -386,9 +388,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
|
|||||||
|
|
||||||
if (fp) {
|
if (fp) {
|
||||||
if (fwrite(data, length, 1, fp) != 1) {
|
if (fwrite(data, length, 1, fp) != 1) {
|
||||||
uint8_t *msg = " * Error writing to file.";
|
line_info_add(self, NULL, NULL, NULL, " * Error writing to file.", SYS_MSG, 0, RED);
|
||||||
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
|
|
||||||
|
|
||||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||||
chat_close_file_receiver(num, filenum);
|
chat_close_file_receiver(num, filenum);
|
||||||
}
|
}
|
||||||
@ -400,10 +400,10 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
|
|||||||
/* refresh line with percentage complete */
|
/* refresh line with percentage complete */
|
||||||
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
|
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
|
||||||
friends[num].file_receiver.last_progress[filenum] = curtime;
|
friends[num].file_receiver.last_progress[filenum] = curtime;
|
||||||
uint8_t msg[MAX_STR_SIZE];
|
|
||||||
uint64_t size = friends[num].file_receiver.size[filenum];
|
uint64_t size = friends[num].file_receiver.size[filenum];
|
||||||
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
|
long double pct_remain = remain ? (1 - (remain / size)) * 100 : 100;
|
||||||
|
|
||||||
|
uint8_t msg[MAX_STR_SIZE];
|
||||||
const uint8_t *name = friends[num].file_receiver.filenames[filenum];
|
const uint8_t *name = friends[num].file_receiver.filenames[filenum];
|
||||||
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
|
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
|
||||||
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
|
line_info_set(self, friends[num].file_receiver.line_id[filenum], msg);
|
||||||
@ -838,7 +838,13 @@ static void chat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
wprintw(statusbar->topline, "%02X", friends[self->num].pub_key[i] & 0xff);
|
wprintw(statusbar->topline, "%02X", friends[self->num].pub_key[i] & 0xff);
|
||||||
|
|
||||||
wprintw(statusbar->topline, "}\n");
|
wprintw(statusbar->topline, "}\n");
|
||||||
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2);
|
|
||||||
|
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2);
|
||||||
|
|
||||||
|
int y, x;
|
||||||
|
getyx(self->window, y, x);
|
||||||
|
int new_x = ctx->start ? x2 - 1 : ctx->pos;
|
||||||
|
wmove(self->window, y + 1, new_x);
|
||||||
|
|
||||||
#ifdef _SUPPORT_AUDIO
|
#ifdef _SUPPORT_AUDIO
|
||||||
wrefresh(self->window);
|
wrefresh(self->window);
|
||||||
|
@ -93,6 +93,9 @@ void kill_groupchat_window(ToxWindow *self)
|
|||||||
log_disable(ctx->log);
|
log_disable(ctx->log);
|
||||||
line_info_cleanup(ctx->hst);
|
line_info_cleanup(ctx->hst);
|
||||||
delwin(ctx->linewin);
|
delwin(ctx->linewin);
|
||||||
|
delwin(ctx->history);
|
||||||
|
delwin(ctx->sidebar);
|
||||||
|
delwin(self->window);
|
||||||
del_window(self);
|
del_window(self);
|
||||||
free(ctx->log);
|
free(ctx->log);
|
||||||
free(ctx->hst);
|
free(ctx->hst);
|
||||||
@ -422,8 +425,12 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
} else {
|
} else {
|
||||||
wmove(self->window, y, x + diff);
|
wmove(self->window, y, x + diff);
|
||||||
}
|
}
|
||||||
} else beep();
|
} else {
|
||||||
} else beep();
|
beep();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
beep();
|
||||||
|
}
|
||||||
} else if (key == T_KEY_C_RB) { /* Scroll peerlist up and down one position */
|
} else if (key == T_KEY_C_RB) { /* Scroll peerlist up and down one position */
|
||||||
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
|
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
|
||||||
|
|
||||||
@ -473,7 +480,6 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
|
|
||||||
static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||||
{
|
{
|
||||||
|
|
||||||
int x2, y2;
|
int x2, y2;
|
||||||
getmaxyx(self->window, y2, x2);
|
getmaxyx(self->window, y2, x2);
|
||||||
|
|
||||||
@ -482,14 +488,14 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
line_info_print(self);
|
line_info_print(self);
|
||||||
wclear(ctx->linewin);
|
wclear(ctx->linewin);
|
||||||
|
|
||||||
scrollok(ctx->history, 0);
|
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
|
|
||||||
if (ctx->len > 0)
|
if (ctx->len > 0)
|
||||||
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(ctx->linewin, 0, 0, ACS_HLINE, x2);
|
|
||||||
|
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2);
|
||||||
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT);
|
mvwvline(ctx->sidebar, 0, 0, ACS_VLINE, y2 - CHATBOX_HEIGHT);
|
||||||
mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE);
|
mvwaddch(ctx->sidebar, y2 - CHATBOX_HEIGHT, 0, ACS_BTEE);
|
||||||
|
|
||||||
@ -518,18 +524,23 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
wprintw(ctx->sidebar, "%s\n", tmpnck);
|
wprintw(ctx->sidebar, "%s\n", tmpnck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int y, x;
|
||||||
|
getyx(self->window, y, x);
|
||||||
|
int new_x = ctx->start ? x2 - 1 : ctx->pos;
|
||||||
|
wmove(self->window, y + 1, new_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupchat_onInit(ToxWindow *self, Tox *m)
|
static void groupchat_onInit(ToxWindow *self, Tox *m)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x2, y2;
|
||||||
getmaxyx(self->window, y, x);
|
getmaxyx(self->window, y2, x2);
|
||||||
|
|
||||||
ChatContext *ctx = self->chatwin;
|
ChatContext *ctx = self->chatwin;
|
||||||
|
|
||||||
ctx->history = subwin(self->window, y - CHATBOX_HEIGHT + 1, x - SIDEBAR_WIDTH - 1, 0, 0);
|
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
||||||
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x, y - CHATBOX_HEIGHT, 0);
|
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
||||||
ctx->sidebar = subwin(self->window, y - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x - SIDEBAR_WIDTH);
|
ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
|
||||||
|
|
||||||
ctx->hst = malloc(sizeof(struct history));
|
ctx->hst = malloc(sizeof(struct history));
|
||||||
ctx->log = malloc(sizeof(struct chatlog));
|
ctx->log = malloc(sizeof(struct chatlog));
|
||||||
@ -548,7 +559,8 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
|||||||
|
|
||||||
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
||||||
|
|
||||||
wmove(self->window, y - CURS_Y_OFFSET, 0);
|
scrollok(ctx->history, 0);
|
||||||
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxWindow new_group_chat(Tox *m, int groupnum)
|
ToxWindow new_group_chat(Tox *m, int groupnum)
|
||||||
|
@ -241,7 +241,12 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
|||||||
if (statusbar->statusmsg[0])
|
if (statusbar->statusmsg[0])
|
||||||
wprintw(statusbar->topline, " - %s", statusbar->statusmsg);
|
wprintw(statusbar->topline, " - %s", statusbar->statusmsg);
|
||||||
|
|
||||||
mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2);
|
mvwhline(self->window, y2 - CHATBOX_HEIGHT, 0, ACS_HLINE, x2);
|
||||||
|
|
||||||
|
int y, x;
|
||||||
|
getyx(self->window, y, x);
|
||||||
|
int new_x = ctx->start ? x2 - 1 : ctx->pos;
|
||||||
|
wmove(self->window, y + 1, new_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
|
static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int32_t friendnum , uint8_t status)
|
||||||
|
18
src/toxic.c
18
src/toxic.c
@ -92,6 +92,11 @@ static void ignore_SIGINT(int sig)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void flag_window_resize(int sig)
|
||||||
|
{
|
||||||
|
Winthread.flag_resize = true;
|
||||||
|
}
|
||||||
|
|
||||||
void exit_toxic_success(Tox *m)
|
void exit_toxic_success(Tox *m)
|
||||||
{
|
{
|
||||||
store_data(m, DATA_FILE);
|
store_data(m, DATA_FILE);
|
||||||
@ -110,7 +115,6 @@ void exit_toxic_success(Tox *m)
|
|||||||
#endif /* _SUPPORT_AUDIO */
|
#endif /* _SUPPORT_AUDIO */
|
||||||
tox_kill(m);
|
tox_kill(m);
|
||||||
endwin();
|
endwin();
|
||||||
fprintf(stderr, "Toxic session ended gracefully.\n");
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,14 +130,14 @@ void exit_toxic_err(const char *errmsg, int errcode)
|
|||||||
|
|
||||||
static void init_term(void)
|
static void init_term(void)
|
||||||
{
|
{
|
||||||
signal(SIGWINCH, on_window_resize);
|
signal(SIGWINCH, flag_window_resize);
|
||||||
|
|
||||||
#if HAVE_WIDECHAR
|
#if HAVE_WIDECHAR
|
||||||
|
|
||||||
if (!arg_opts.default_locale) {
|
if (!arg_opts.default_locale) {
|
||||||
if (setlocale(LC_ALL, "") == NULL)
|
if (setlocale(LC_ALL, "") == NULL)
|
||||||
exit_toxic_err("Could not set your locale, please check your locale settings or "
|
exit_toxic_err("Could not set your locale, please check your locale settings or "
|
||||||
"disable unicode support with the -D flag.", FATALERR_LOCALE_SET);
|
"disable unicode support with the -d flag.", FATALERR_LOCALE_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -476,7 +480,13 @@ void *thread_winref(void *data)
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
draw_active_window(m);
|
draw_active_window(m);
|
||||||
refresh_inactive_windows();
|
|
||||||
|
if (Winthread.flag_resize) {
|
||||||
|
on_window_resize();
|
||||||
|
Winthread.flag_resize = false;
|
||||||
|
} else {
|
||||||
|
refresh_inactive_windows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,11 +309,50 @@ ToxWindow *init_windows(Tox *m)
|
|||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_window_resize(int sig)
|
void on_window_resize(void)
|
||||||
{
|
{
|
||||||
endwin();
|
endwin();
|
||||||
refresh();
|
refresh();
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i == 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
|
if (!windows[i].active || windows[i].is_friendlist)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ToxWindow *w = &windows[i];
|
||||||
|
ChatContext *ctx = w->chatwin;
|
||||||
|
|
||||||
|
if (w->is_groupchat)
|
||||||
|
delwin(ctx->sidebar);
|
||||||
|
else
|
||||||
|
delwin(w->stb->topline);
|
||||||
|
|
||||||
|
delwin(ctx->linewin);
|
||||||
|
delwin(ctx->history);
|
||||||
|
delwin(w->window);
|
||||||
|
|
||||||
|
w->window = newwin(LINES - 2, COLS, 0, 0);
|
||||||
|
|
||||||
|
int x2, y2, x, y;
|
||||||
|
getmaxyx(w->window, y2, x2);
|
||||||
|
getyx(w->window, y, x);
|
||||||
|
w->x = x2;
|
||||||
|
|
||||||
|
ctx = w->chatwin;
|
||||||
|
ctx->linewin = subwin(w->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
||||||
|
|
||||||
|
if (w->is_groupchat) {
|
||||||
|
ctx->history = subwin(w->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
||||||
|
ctx->sidebar = subwin(w->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
|
||||||
|
} else {
|
||||||
|
ctx->history = subwin(w->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
|
||||||
|
w->stb->topline = subwin(w->window, 2, x2, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollok(ctx->history, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_window_tab(ToxWindow toxwin)
|
static void draw_window_tab(ToxWindow toxwin)
|
||||||
|
@ -65,6 +65,7 @@ enum {
|
|||||||
struct _Winthread {
|
struct _Winthread {
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
pthread_mutex_t lock;
|
pthread_mutex_t lock;
|
||||||
|
bool flag_resize;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct ToxWindow ToxWindow;
|
typedef struct ToxWindow ToxWindow;
|
||||||
@ -196,7 +197,7 @@ void del_window(ToxWindow *w);
|
|||||||
void set_active_window(int ch);
|
void set_active_window(int ch);
|
||||||
int get_num_active_windows(void);
|
int get_num_active_windows(void);
|
||||||
void kill_all_windows(void); /* should only be called on shutdown */
|
void kill_all_windows(void); /* should only be called on shutdown */
|
||||||
void on_window_resize(int sig);
|
void on_window_resize(void);
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
Loading…
Reference in New Issue
Block a user