diff --git a/src/chat.c b/src/chat.c index cb200de..162d55e 100644 --- a/src/chat.c +++ b/src/chat.c @@ -1395,7 +1395,7 @@ ToxWindow *new_chat(Tox *m, uint32_t friendnum) exit_toxic_err("failed in new_chat", FATALERR_MEMORY); } - ret->is_chat = true; + ret->type = WINDOW_TYPE_CHAT; ret->onKey = &chat_onKey; ret->onDraw = &chat_onDraw; diff --git a/src/conference.c b/src/conference.c index 2847090..09fd1c2 100644 --- a/src/conference.c +++ b/src/conference.c @@ -734,7 +734,7 @@ static ToxWindow *new_conference_chat(uint32_t conferencenum) exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY); } - ret->is_conference = true; + ret->type = WINDOW_TYPE_CONFERENCE; ret->onKey = &conference_onKey; ret->onDraw = &conference_onDraw; diff --git a/src/friendlist.c b/src/friendlist.c index c2d0ba9..8a279e5 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -1323,7 +1323,7 @@ ToxWindow *new_friendlist(void) exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY); } - ret->is_friendlist = true; + ret->type = WINDOW_TYPE_FRIEND_LIST; ret->onKey = &friendlist_onKey; ret->onDraw = &friendlist_onDraw; diff --git a/src/global_commands.c b/src/global_commands.c index 272caa8..6ef2d01 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -410,12 +410,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX int log_ret = -1; - if (self->is_chat) { + if (self->type == WINDOW_TYPE_CHAT) { Friends.list[self->num].logging_on = true; log_ret = log_enable(self->name, myid, Friends.list[self->num].pub_key, log, LOG_CHAT); - } else if (self->is_prompt) { + } else if (self->type == WINDOW_TYPE_PROMPT) { log_ret = log_enable(self->name, myid, NULL, log, LOG_PROMPT); - } else if (self->is_conference) { + } else if (self->type == WINDOW_TYPE_CONFERENCE) { log_ret = log_enable(self->name, myid, NULL, log, LOG_CONFERENCE); } @@ -423,7 +423,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg); return; } else if (!strcmp(swch, "0") || !strcmp(swch, "off")) { - if (self->is_chat) { + if (self->type == WINDOW_TYPE_CHAT) { Friends.list[self->num].logging_on = false; } diff --git a/src/input.c b/src/input.c index e97788d..67e2f13 100644 --- a/src/input.c +++ b/src/input.c @@ -334,7 +334,7 @@ bool input_handle(ToxWindow *self, wint_t key, int x, int mx_x) maybe convert entire function to if/else and make them all customizable keys? */ if (!match) { if (key == user_settings->key_toggle_peerlist) { - if (self->is_conference) { + if (self->type == WINDOW_TYPE_CONFERENCE) { self->show_peerlist ^= 1; redraw_conference_win(self); } diff --git a/src/line_info.c b/src/line_info.c index 7b2680d..6c19a1d 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -62,7 +62,7 @@ void line_info_reset_start(ToxWindow *self, struct history *hst) getmaxyx(self->window, y2, x2); int side_offst = self->show_peerlist ? SIDEBAR_WIDTH : 0; - int top_offst = self->is_chat || self->is_prompt ? 2 : 0; + int top_offst = (self->type == WINDOW_TYPE_CHAT) || (self->type == WINDOW_TYPE_PROMPT) ? 2 : 0; int max_y = (y2 - CHATBOX_HEIGHT - top_offst); int curlines = 0; @@ -318,7 +318,7 @@ void line_info_print(ToxWindow *self) return; } - if (self->is_conference) { + if (self->type == WINDOW_TYPE_CONFERENCE) { wmove(win, 0, 0); } else { wmove(win, 2, 0); diff --git a/src/misc_tools.c b/src/misc_tools.c index 5c9feb9..6f70e07 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -565,7 +565,7 @@ void set_window_title(ToxWindow *self, const char *title, int len) char cpy[TOXIC_MAX_NAME_LENGTH + 1]; - if (self->is_conference) { /* keep conferencenumber in title */ + if (self->type == WINDOW_TYPE_CONFERENCE) { /* keep conferencenumber in title */ snprintf(cpy, sizeof(cpy), "%u %s", self->num, title); } else { snprintf(cpy, sizeof(cpy), "%s", title); diff --git a/src/prompt.c b/src/prompt.c index fda4bac..d3ba0cd 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -603,7 +603,7 @@ ToxWindow *new_prompt(void) } ret->num = -1; - ret->is_prompt = true; + ret->type = WINDOW_TYPE_PROMPT; ret->onKey = &prompt_onKey; ret->onDraw = &prompt_onDraw; diff --git a/src/toxic.c b/src/toxic.c index 90abfe3..6106b1b 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -987,8 +987,8 @@ void *thread_cqueue(void *data) for (i = 2; i < MAX_WINDOWS_NUM; ++i) { ToxWindow *toxwin = get_window_ptr(i); - if (toxwin != NULL && toxwin->is_chat - && get_friend_connection_status(toxwin->num) != TOX_CONNECTION_NONE) { + if ((toxwin != NULL) && (toxwin->type == WINDOW_TYPE_CHAT) + && (get_friend_connection_status(toxwin->num) != TOX_CONNECTION_NONE)) { cqueue_try_send(toxwin, m); } } diff --git a/src/windows.c b/src/windows.c index 2f60d5c..782e990 100644 --- a/src/windows.c +++ b/src/windows.c @@ -444,7 +444,7 @@ void on_window_resize(void) ToxWindow *w = windows[i]; - if (windows[i]->is_friendlist) { + if (windows[i]->type == WINDOW_TYPE_FRIEND_LIST) { delwin(w->window); w->window = newwin(y2, x2, 0, 0); continue; @@ -454,7 +454,7 @@ void on_window_resize(void) wclear(w->help->win); } - if (w->is_conference) { + if (w->type == WINDOW_TYPE_CONFERENCE) { delwin(w->chatwin->sidebar); w->chatwin->sidebar = NULL; } else { @@ -474,7 +474,7 @@ void on_window_resize(void) } else { w->chatwin->history = subwin(w->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0); - if (!w->is_conference) { + if (w->type != WINDOW_TYPE_CONFERENCE) { w->stb->topline = subwin(w->window, 2, x2, 0, 0); } } @@ -682,7 +682,7 @@ void draw_active_window(Tox *m) if (printable == 0 && (ch == user_settings->key_next_tab || ch == user_settings->key_prev_tab)) { set_next_window((int) ch); return; - } else if (printable == 0 && !a->is_friendlist) { + } else if ((printable == 0) && (a->type != WINDOW_TYPE_FRIEND_LIST)) { pthread_mutex_lock(&Winthread.lock); bool input_ret = a->onKey(a, m, ch, (bool) printable); pthread_mutex_unlock(&Winthread.lock); @@ -716,7 +716,7 @@ void refresh_inactive_windows(void) continue; } - if (i != active_window_index && !toxwin->is_friendlist) { + if ((i != active_window_index) && (toxwin->type != WINDOW_TYPE_FRIEND_LIST)) { pthread_mutex_lock(&Winthread.lock); line_info_print(toxwin); pthread_mutex_unlock(&Winthread.lock); @@ -762,9 +762,9 @@ void kill_all_windows(Tox *m) continue; } - if (windows[i]->is_chat) { + if (windows[i]->type == WINDOW_TYPE_CHAT) { kill_chat_window(windows[i], m); - } else if (windows[i]->is_conference) { + } else if (windows[i]->type == WINDOW_TYPE_CONFERENCE) { free_conference(windows[i], windows[i]->num); } } diff --git a/src/windows.h b/src/windows.h index ea11eec..62e47bd 100644 --- a/src/windows.h +++ b/src/windows.h @@ -61,6 +61,13 @@ typedef enum { WINDOW_ALERT_2 = MAGENTA, } WINDOW_ALERTS; +typedef enum { + WINDOW_TYPE_PROMPT, + WINDOW_TYPE_CHAT, + WINDOW_TYPE_CONFERENCE, + WINDOW_TYPE_FRIEND_LIST, +} WINDOW_TYPE; + /* Fixes text color problem on some terminals. Uncomment if necessary */ /* #define URXVT_FIX */ @@ -169,10 +176,8 @@ struct ToxWindow { uint8_t index; /* This window's index in the windows array */ int x; - bool is_chat; - bool is_prompt; - bool is_friendlist; - bool is_conference; + WINDOW_TYPE type; + int show_peerlist; /* used to toggle conference peerlist */ WINDOW_ALERTS alert;