mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 03:53:25 +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
|
||||
Configuration example.
|
||||
.SH BUGS
|
||||
Resizing the terminal breaks the layout. We suggest you size your terminal as
|
||||
desired prior to starting the client. Unicode characters with a width larger
|
||||
than 1 column may cause strange behaviour. Expect more bugs and bad
|
||||
Unicode characters with a width larger than 1 column may cause
|
||||
strange behaviour. Expect more bugs and bad
|
||||
behaviour: this software is in a pre\-alpha stage.
|
||||
.SH AUTHORS
|
||||
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;
|
||||
delwin(ctx->linewin);
|
||||
delwin(ctx->history);
|
||||
delwin(self->window);
|
||||
delwin(statusbar->topline);
|
||||
del_window(self);
|
||||
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 (fwrite(data, length, 1, fp) != 1) {
|
||||
uint8_t *msg = " * Error writing to file.";
|
||||
line_info_add(self, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, " * Error writing to file.", SYS_MSG, 0, RED);
|
||||
tox_file_send_control(m, num, 1, filenum, TOX_FILECONTROL_KILL, 0, 0);
|
||||
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 */
|
||||
if (!remain || timed_out(friends[num].file_receiver.last_progress[filenum], curtime, 1)) {
|
||||
friends[num].file_receiver.last_progress[filenum] = curtime;
|
||||
uint8_t msg[MAX_STR_SIZE];
|
||||
uint64_t size = friends[num].file_receiver.size[filenum];
|
||||
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];
|
||||
snprintf(msg, sizeof(msg), "Saving file as: '%s' (%.1Lf%%)", name, pct_remain);
|
||||
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, "}\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
|
||||
wrefresh(self->window);
|
||||
|
@ -93,6 +93,9 @@ void kill_groupchat_window(ToxWindow *self)
|
||||
log_disable(ctx->log);
|
||||
line_info_cleanup(ctx->hst);
|
||||
delwin(ctx->linewin);
|
||||
delwin(ctx->history);
|
||||
delwin(ctx->sidebar);
|
||||
delwin(self->window);
|
||||
del_window(self);
|
||||
free(ctx->log);
|
||||
free(ctx->hst);
|
||||
@ -422,8 +425,12 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
} else {
|
||||
wmove(self->window, y, x + diff);
|
||||
}
|
||||
} else beep();
|
||||
} else beep();
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
} else {
|
||||
beep();
|
||||
}
|
||||
} else if (key == T_KEY_C_RB) { /* Scroll peerlist up and down one position */
|
||||
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)
|
||||
{
|
||||
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
@ -482,14 +488,14 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
||||
line_info_print(self);
|
||||
wclear(ctx->linewin);
|
||||
|
||||
scrollok(ctx->history, 0);
|
||||
curs_set(1);
|
||||
|
||||
if (ctx->len > 0)
|
||||
mvwprintw(ctx->linewin, 1, 0, "%ls", &ctx->line[ctx->start]);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int x, y;
|
||||
getmaxyx(self->window, y, x);
|
||||
int x2, y2;
|
||||
getmaxyx(self->window, y2, x2);
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
ctx->history = subwin(self->window, y - CHATBOX_HEIGHT + 1, x - SIDEBAR_WIDTH - 1, 0, 0);
|
||||
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x, y - CHATBOX_HEIGHT, 0);
|
||||
ctx->sidebar = subwin(self->window, y - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x - SIDEBAR_WIDTH);
|
||||
ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
|
||||
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
|
||||
ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);
|
||||
|
||||
ctx->hst = malloc(sizeof(struct history));
|
||||
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);
|
||||
|
||||
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)
|
||||
|
@ -241,7 +241,12 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
|
||||
if (statusbar->statusmsg[0])
|
||||
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)
|
||||
|
18
src/toxic.c
18
src/toxic.c
@ -92,6 +92,11 @@ static void ignore_SIGINT(int sig)
|
||||
return;
|
||||
}
|
||||
|
||||
static void flag_window_resize(int sig)
|
||||
{
|
||||
Winthread.flag_resize = true;
|
||||
}
|
||||
|
||||
void exit_toxic_success(Tox *m)
|
||||
{
|
||||
store_data(m, DATA_FILE);
|
||||
@ -110,7 +115,6 @@ void exit_toxic_success(Tox *m)
|
||||
#endif /* _SUPPORT_AUDIO */
|
||||
tox_kill(m);
|
||||
endwin();
|
||||
fprintf(stderr, "Toxic session ended gracefully.\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@ -126,14 +130,14 @@ void exit_toxic_err(const char *errmsg, int errcode)
|
||||
|
||||
static void init_term(void)
|
||||
{
|
||||
signal(SIGWINCH, on_window_resize);
|
||||
signal(SIGWINCH, flag_window_resize);
|
||||
|
||||
#if HAVE_WIDECHAR
|
||||
|
||||
if (!arg_opts.default_locale) {
|
||||
if (setlocale(LC_ALL, "") == NULL)
|
||||
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
|
||||
@ -476,7 +480,13 @@ void *thread_winref(void *data)
|
||||
|
||||
while (true) {
|
||||
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;
|
||||
}
|
||||
|
||||
void on_window_resize(int sig)
|
||||
void on_window_resize(void)
|
||||
{
|
||||
endwin();
|
||||
refresh();
|
||||
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)
|
||||
|
@ -65,6 +65,7 @@ enum {
|
||||
struct _Winthread {
|
||||
pthread_t tid;
|
||||
pthread_mutex_t lock;
|
||||
bool flag_resize;
|
||||
};
|
||||
|
||||
typedef struct ToxWindow ToxWindow;
|
||||
@ -196,7 +197,7 @@ 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);
|
||||
void on_window_resize(void);
|
||||
|
||||
/* refresh inactive windows to prevent scrolling bugs.
|
||||
call at least once per second */
|
||||
|
Loading…
Reference in New Issue
Block a user