mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 07:03:25 +01:00
Use enum to identify window types instead of bool variables
This commit is contained in:
parent
4188b392cc
commit
71d7d355a6
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user