diff --git a/src/chat.c b/src/chat.c index 9359095..2dd6950 100644 --- a/src/chat.c +++ b/src/chat.c @@ -212,10 +212,18 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) wclear(ctx->linewin); wmove(self->window, y2 - CURS_Y_OFFSET, 0); wclrtobot(self->window); + bool close_win = false; - if (line[0] == '/') - execute(self, ctx, m, line); - else { + if (line[0] == '/') { + if (close_win = !strncmp(line, "/close", strlen("/close"))) { + int f_num = ctx->friendnum; + delwin(ctx->linewin); + del_window(self); + disable_chatwin(f_num); + } else { + execute(self, ctx, m, line); + } + } else { /* make sure the string has at least non-space character */ if (!string_is_empty(line)) { uint8_t selfname[TOX_MAX_NAME_LENGTH]; @@ -237,8 +245,13 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) } } - ctx->line[0] = L'\0'; - ctx->pos = 0; + if (close_win) + free(ctx); + else { + ctx->line[0] = L'\0'; + ctx->pos = 0; + } + free(line); } } @@ -368,13 +381,6 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd) wprintw(ctx->history, "%s\n", id); } - else if (strcmp(cmd, "/close") == 0) { - int f_num = ctx->friendnum; - delwin(ctx->linewin); - del_window(self); - disable_chatwin(f_num); - } - else wprintw(ctx->history, "Invalid command.\n"); } @@ -439,7 +445,7 @@ ToxWindow new_chat(Tox *m, int friendnum) snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); ChatContext *x = calloc(1, sizeof(ChatContext)); + ret.x = x; x->friendnum = friendnum; - ret.x = (void *) x; return ret; } diff --git a/src/windows.c b/src/windows.c index 4319c00..e477928 100644 --- a/src/windows.c +++ b/src/windows.c @@ -120,9 +120,10 @@ int add_window(Tox *m, ToxWindow w) void del_window(ToxWindow *w) { active_window = windows; // Go to prompt screen + delwin(w->window); - w->window = NULL; memset(w, 0, sizeof(ToxWindow)); + clear(); refresh(); }