hirc

IRC client
Log | Files | Refs

commit 9dc5bcb1c7559c11645b18217b9551c7afb7e287
parent 3df17ce91e5a37aee0cf9c6485c25e4c2a4dfa7f
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 25 Oct 2021 19:41:23 +0100

Do redraws from main loop using redraw var in struct Window

Diffstat:
Mhandle.c | 20+++++++++-----------
Mhirc.h | 1+
Mhist.c | 2+-
Mmain.c | 27+++++++++++++++++++--------
Mnick.c | 2+-
Mstruct.h | 6++++--
Mui.c | 24++++++++++++++++++------
7 files changed, 53 insertions(+), 29 deletions(-)

diff --git a/handle.c b/handle.c @@ -51,12 +51,10 @@ handle_JOIN(char *msg, char **params, struct Server *server, time_t timestamp) { hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); - if (nick_isself(nick)) { - selected.server = server; - selected.channel = chan; - } else if (selected.channel == chan) { - ui_draw_nicklist(); - } + if (nick_isself(nick)) + ui_select(server, chan); + else if (selected.channel == chan) + windows[Win_nicklist].redraw = 1; nick_free(nick); } @@ -79,11 +77,11 @@ handle_PART(char *msg, char **params, struct Server *server, time_t timestamp) { chan_setold(chan, 1); nick_free_list(&chan->nicks); if (chan == selected.channel) - selected.channel = NULL; + ui_select(selected.server, NULL); } else { nick_remove(&chan->nicks, nick->nick); if (chan == selected.channel) - ui_draw_nicklist(); + windows[Win_nicklist].redraw = 1; } hist_add(server, server->history, nick, msg, params, Activity_status, timestamp, HIST_LOG); @@ -111,7 +109,7 @@ handle_QUIT(char *msg, char **params, struct Server *server, time_t timestamp) { nick_remove(&chan->nicks, nick->nick); hist_add(server, chan->history, nick, msg, params, Activity_status, timestamp, HIST_SHOW); if (chan == selected.channel) - ui_draw_nicklist(); + windows[Win_nicklist].redraw = 1; } } @@ -233,7 +231,7 @@ handle_NAMREPLY(char *msg, char **params, struct Server *server, time_t timestam } if (selected.channel == chan) - ui_draw_nicklist(); + windows[Win_nicklist].redraw = 1; param_free(nicksref); } @@ -279,7 +277,7 @@ handle_NICK(char *msg, char **params, struct Server *server, time_t timestamp) { nick_add(&chan->nicks, prefix, chnick->priv, server); nick_remove(&chan->nicks, nick->nick); if (selected.channel == chan) - ui_draw_nicklist(); + windows[Win_nicklist].redraw = 1; } } } diff --git a/hirc.h b/hirc.h @@ -95,6 +95,7 @@ void ui_read(void); void ui_redraw(void); void ui_draw_input(void); void ui_draw_nicklist(void); +void ui_select(struct Server *server, struct Channel *channel); void ui_error_(char *file, int line, char *format, ...); #define ui_error(format, ...) ui_error_(__FILE__, __LINE__, format, __VA_ARGS__); void ui_perror_(char *file, int line, char *str); diff --git a/hist.c b/hist.c @@ -101,7 +101,7 @@ hist_add(struct Server *server, struct HistInfo *histinfo, struct Nick *from, // XXX if (options & HIST_SHOW) { wprintw(windows[Win_main].window, "!%lld :%s %s\n", (long long)new->timestamp, nick_strprefix(new->from), new->raw); - refresh(); + windows[Win_main].redraw = 1; } if (options & HIST_LOG) { diff --git a/main.c b/main.c @@ -176,8 +176,10 @@ sighandler(int signal) { int main(int argc, char **argv) { + struct Selected oldselected; struct Server *sp; FILE *file; + int i; struct pollfd fds[] = { { .fd = fileno(stdin), .events = POLLIN }, }; @@ -190,7 +192,7 @@ main(int argc, char **argv) { main_buf->history = NULL; ui_init(); - selected.server = serv_add(&servers, "hlircnet", "irc.hhvn.uk", "6667", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0); + ui_select(serv_add(&servers, "hlircnet", "irc.hhvn.uk", "6667", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0), NULL); /* serv_add(&servers, "dataswamp", "127.0.0.1", "6697", "hhvn", "Fanatic", "gopher://hhvn.uk", 1, 0); */ for (sp = servers; sp; sp = sp->next) serv_connect(sp); @@ -226,17 +228,26 @@ main(int argc, char **argv) { } } - if (selected.oldchannel != selected.channel || selected.oldserver != selected.server) { - ui_draw_nicklist(); + if (oldselected.channel != selected.channel || oldselected.server != selected.server) { + windows[Win_nicklist].redraw = 1; + windows[Win_winlist].redraw = 1; } - wrefresh(windows[Win_winlist].window); - wrefresh(windows[Win_main].window); + oldselected.channel = selected.channel; + oldselected.server = selected.server; + oldselected.history = selected.history; + oldselected.name = selected.name; + + for (i=0; i < Win_last; i++) { + if (windows[i].redraw) { + if (windows[i].handler) + windows[i].handler(); + wrefresh(windows[i].window); + windows[i].redraw = 0; + } + } ui_read(); - - selected.oldchannel = selected.channel; - selected.oldserver = selected.server; } return 0; diff --git a/nick.c b/nick.c @@ -291,5 +291,5 @@ nick_sort(struct Nick **head, struct Server *server) { } } } while (swapped); - ui_draw_nicklist(); + windows[Win_nicklist].redraw = 1; } diff --git a/struct.h b/struct.h @@ -139,7 +139,9 @@ enum WindowLocation { struct Window { int x, y; int h, w; + int redraw; enum WindowLocation location; + void (*handler)(void); WINDOW *window; }; @@ -154,8 +156,8 @@ enum { struct Selected { struct Channel *channel; struct Server *server; - struct Channel *oldchannel; - struct Server *oldserver; + struct Histinfo *history; + char *name; }; #endif /* H_STRUCT */ diff --git a/ui.c b/ui.c @@ -10,7 +10,12 @@ #include "hirc.h" struct HistInfo *error_buf; -struct Window windows[Win_last]; +struct Window windows[Win_last] = { + [Win_main] = {.handler = NULL}, + [Win_input] = {.handler = ui_draw_input}, + [Win_nicklist] = {.handler = ui_draw_nicklist}, + [Win_winlist] = {.handler = NULL}, +}; struct Selected selected; struct { @@ -144,9 +149,10 @@ ui_read(void) { strlen(&input.string[input.counter])); input.string[input.counter++] = key; } + break; } - ui_draw_input(); + windows[Win_input].redraw = 1; } void @@ -202,8 +208,8 @@ ui_redraw(void) { mvhline(LINES - 2, x, '-', COLS - x - rx); - ui_draw_nicklist(); - ui_draw_input(); + windows[Win_nicklist].redraw = 1; + windows[Win_input].redraw = 1; } void @@ -226,7 +232,6 @@ ui_draw_input(void) { } else waddnstr(windows[Win_input].window, p, 1); } wmove(windows[Win_input].window, 0, input.counter - offset); - wrefresh(windows[Win_input].window); } void @@ -245,5 +250,12 @@ ui_draw_nicklist(void) { /* TODO: colourize nicks */ wprintw(windows[Win_nicklist].window, "%c%s\n", p->priv, p->nick); } - wrefresh(windows[Win_nicklist].window); +} + +void +ui_select(struct Server *server, struct Channel *channel) { + selected.channel = channel; + selected.server = server; + selected.history = channel ? channel->history : server->history; + selected.name = channel ? channel->name : server->name; }