1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 01:03:02 +01:00

Use enum to identify window types instead of bool variables

This commit is contained in:
jfreegman 2020-11-09 17:01:22 -05:00
parent 4188b392cc
commit 71d7d355a6
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
11 changed files with 30 additions and 25 deletions

View File

@ -1395,7 +1395,7 @@ ToxWindow *new_chat(Tox *m, uint32_t friendnum)
exit_toxic_err("failed in new_chat", FATALERR_MEMORY); exit_toxic_err("failed in new_chat", FATALERR_MEMORY);
} }
ret->is_chat = true; ret->type = WINDOW_TYPE_CHAT;
ret->onKey = &chat_onKey; ret->onKey = &chat_onKey;
ret->onDraw = &chat_onDraw; ret->onDraw = &chat_onDraw;

View File

@ -734,7 +734,7 @@ static ToxWindow *new_conference_chat(uint32_t conferencenum)
exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY); exit_toxic_err("failed in new_conference_chat", FATALERR_MEMORY);
} }
ret->is_conference = true; ret->type = WINDOW_TYPE_CONFERENCE;
ret->onKey = &conference_onKey; ret->onKey = &conference_onKey;
ret->onDraw = &conference_onDraw; ret->onDraw = &conference_onDraw;

View File

@ -1323,7 +1323,7 @@ ToxWindow *new_friendlist(void)
exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY); exit_toxic_err("failed in new_friendlist", FATALERR_MEMORY);
} }
ret->is_friendlist = true; ret->type = WINDOW_TYPE_FRIEND_LIST;
ret->onKey = &friendlist_onKey; ret->onKey = &friendlist_onKey;
ret->onDraw = &friendlist_onDraw; ret->onDraw = &friendlist_onDraw;

View File

@ -410,12 +410,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
int log_ret = -1; int log_ret = -1;
if (self->is_chat) { if (self->type == WINDOW_TYPE_CHAT) {
Friends.list[self->num].logging_on = true; Friends.list[self->num].logging_on = true;
log_ret = log_enable(self->name, myid, Friends.list[self->num].pub_key, log, LOG_CHAT); 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); 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); 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); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return; return;
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) { } 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; Friends.list[self->num].logging_on = false;
} }

View File

@ -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? */ maybe convert entire function to if/else and make them all customizable keys? */
if (!match) { if (!match) {
if (key == user_settings->key_toggle_peerlist) { if (key == user_settings->key_toggle_peerlist) {
if (self->is_conference) { if (self->type == WINDOW_TYPE_CONFERENCE) {
self->show_peerlist ^= 1; self->show_peerlist ^= 1;
redraw_conference_win(self); redraw_conference_win(self);
} }

View File

@ -62,7 +62,7 @@ void line_info_reset_start(ToxWindow *self, struct history *hst)
getmaxyx(self->window, y2, x2); getmaxyx(self->window, y2, x2);
int side_offst = self->show_peerlist ? SIDEBAR_WIDTH : 0; 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 max_y = (y2 - CHATBOX_HEIGHT - top_offst);
int curlines = 0; int curlines = 0;
@ -318,7 +318,7 @@ void line_info_print(ToxWindow *self)
return; return;
} }
if (self->is_conference) { if (self->type == WINDOW_TYPE_CONFERENCE) {
wmove(win, 0, 0); wmove(win, 0, 0);
} else { } else {
wmove(win, 2, 0); wmove(win, 2, 0);

View File

@ -565,7 +565,7 @@ void set_window_title(ToxWindow *self, const char *title, int len)
char cpy[TOXIC_MAX_NAME_LENGTH + 1]; 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); snprintf(cpy, sizeof(cpy), "%u %s", self->num, title);
} else { } else {
snprintf(cpy, sizeof(cpy), "%s", title); snprintf(cpy, sizeof(cpy), "%s", title);

View File

@ -603,7 +603,7 @@ ToxWindow *new_prompt(void)
} }
ret->num = -1; ret->num = -1;
ret->is_prompt = true; ret->type = WINDOW_TYPE_PROMPT;
ret->onKey = &prompt_onKey; ret->onKey = &prompt_onKey;
ret->onDraw = &prompt_onDraw; ret->onDraw = &prompt_onDraw;

View File

@ -987,8 +987,8 @@ void *thread_cqueue(void *data)
for (i = 2; i < MAX_WINDOWS_NUM; ++i) { for (i = 2; i < MAX_WINDOWS_NUM; ++i) {
ToxWindow *toxwin = get_window_ptr(i); ToxWindow *toxwin = get_window_ptr(i);
if (toxwin != NULL && toxwin->is_chat if ((toxwin != NULL) && (toxwin->type == WINDOW_TYPE_CHAT)
&& get_friend_connection_status(toxwin->num) != TOX_CONNECTION_NONE) { && (get_friend_connection_status(toxwin->num) != TOX_CONNECTION_NONE)) {
cqueue_try_send(toxwin, m); cqueue_try_send(toxwin, m);
} }
} }

View File

@ -444,7 +444,7 @@ void on_window_resize(void)
ToxWindow *w = windows[i]; ToxWindow *w = windows[i];
if (windows[i]->is_friendlist) { if (windows[i]->type == WINDOW_TYPE_FRIEND_LIST) {
delwin(w->window); delwin(w->window);
w->window = newwin(y2, x2, 0, 0); w->window = newwin(y2, x2, 0, 0);
continue; continue;
@ -454,7 +454,7 @@ void on_window_resize(void)
wclear(w->help->win); wclear(w->help->win);
} }
if (w->is_conference) { if (w->type == WINDOW_TYPE_CONFERENCE) {
delwin(w->chatwin->sidebar); delwin(w->chatwin->sidebar);
w->chatwin->sidebar = NULL; w->chatwin->sidebar = NULL;
} else { } else {
@ -474,7 +474,7 @@ void on_window_resize(void)
} else { } else {
w->chatwin->history = subwin(w->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0); 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); 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)) { if (printable == 0 && (ch == user_settings->key_next_tab || ch == user_settings->key_prev_tab)) {
set_next_window((int) ch); set_next_window((int) ch);
return; return;
} else if (printable == 0 && !a->is_friendlist) { } else if ((printable == 0) && (a->type != WINDOW_TYPE_FRIEND_LIST)) {
pthread_mutex_lock(&Winthread.lock); pthread_mutex_lock(&Winthread.lock);
bool input_ret = a->onKey(a, m, ch, (bool) printable); bool input_ret = a->onKey(a, m, ch, (bool) printable);
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
@ -716,7 +716,7 @@ void refresh_inactive_windows(void)
continue; 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); pthread_mutex_lock(&Winthread.lock);
line_info_print(toxwin); line_info_print(toxwin);
pthread_mutex_unlock(&Winthread.lock); pthread_mutex_unlock(&Winthread.lock);
@ -762,9 +762,9 @@ void kill_all_windows(Tox *m)
continue; continue;
} }
if (windows[i]->is_chat) { if (windows[i]->type == WINDOW_TYPE_CHAT) {
kill_chat_window(windows[i], m); 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); free_conference(windows[i], windows[i]->num);
} }
} }

View File

@ -61,6 +61,13 @@ typedef enum {
WINDOW_ALERT_2 = MAGENTA, WINDOW_ALERT_2 = MAGENTA,
} WINDOW_ALERTS; } 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. /* Fixes text color problem on some terminals.
Uncomment if necessary */ Uncomment if necessary */
/* #define URXVT_FIX */ /* #define URXVT_FIX */
@ -169,10 +176,8 @@ struct ToxWindow {
uint8_t index; /* This window's index in the windows array */ uint8_t index; /* This window's index in the windows array */
int x; int x;
bool is_chat; WINDOW_TYPE type;
bool is_prompt;
bool is_friendlist;
bool is_conference;
int show_peerlist; /* used to toggle conference peerlist */ int show_peerlist; /* used to toggle conference peerlist */
WINDOW_ALERTS alert; WINDOW_ALERTS alert;