From be1fb4cc4edf9cc861831961cac1d0400a87db36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 11 Apr 2015 11:03:24 +0200 Subject: Further ui separation, eliminate global state --- ui-curses.c | 49 +++++++++++++++++++++++++++++++++---------------- vis.c | 20 -------------------- 2 files changed, 33 insertions(+), 36 deletions(-) diff --git a/ui-curses.c b/ui-curses.c index 6012dc1..f92d787 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -77,6 +77,12 @@ struct UiCursesWin { enum UiOption options; /* display settings for this window */ }; +static volatile sig_atomic_t need_resize; /* TODO */ + +static void sigwinch_handler(int sig) { + need_resize = true; +} + static unsigned int color_hash(short fg, short bg) { if (fg == -1) fg = COLORS; @@ -231,22 +237,6 @@ static void ui_window_update(UiCursesWin *win) { wnoutrefresh(win->win); } -static void update(Ui *ui) { - UiCurses *uic = (UiCurses*)ui; - for (UiCursesWin *win = uic->windows; win; win = win->next) { - if (win != uic->selwin) - ui_window_update(win); - } - - if (uic->selwin) - ui_window_update(uic->selwin); - if (uic->prompt_title[0]) { - wnoutrefresh(uic->prompt_win->win); - ui_window_update(uic->prompt_win); - } - doupdate(); -} - static void arrange(Ui *ui, enum UiLayout layout) { UiCurses *uic = (UiCurses*)ui; uic->layout = layout; @@ -321,6 +311,26 @@ static void ui_resize(Ui *ui) { ui_resize_to(ui, width, height); } +static void update(Ui *ui) { + UiCurses *uic = (UiCurses*)ui; + if (need_resize) { + ui_resize(ui); + need_resize = false; + } + for (UiCursesWin *win = uic->windows; win; win = win->next) { + if (win != uic->selwin) + ui_window_update(win); + } + + if (uic->selwin) + ui_window_update(uic->selwin); + if (uic->prompt_title[0]) { + wnoutrefresh(uic->prompt_win->win); + ui_window_update(uic->prompt_win); + } + doupdate(); +} + static void ui_window_free(UiWin *w) { UiCursesWin *win = (UiCursesWin*)w; if (!win) @@ -559,6 +569,13 @@ Ui *ui_curses_new(void) { .color_get = color_get, }; + struct sigaction sa; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = sigwinch_handler; + sigaction(SIGWINCH, &sa, NULL); + sigaction(SIGCONT, &sa, NULL); + ui_resize(ui); return ui; diff --git a/vis.c b/vis.c index fe42677..014448e 100644 --- a/vis.c +++ b/vis.c @@ -150,7 +150,6 @@ typedef struct { /* command definitions for the ':'-prompt */ /** global variables */ static volatile bool running = true; /* exit main loop once this becomes false */ -static volatile sig_atomic_t need_resize; static Editor *vis; /* global editor instance, keeps track of all windows etc. */ static Mode *mode; /* currently active mode, used to search for keybindings */ static Mode *mode_prev; /* previsouly active user mode */ @@ -1925,19 +1924,6 @@ static void die(const char *errstr, ...) { exit(EXIT_FAILURE); } -static void sigwinch_handler(int sig) { - need_resize = true; -} - -static void setup() { - struct sigaction sa; - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sa.sa_handler = sigwinch_handler; - sigaction(SIGWINCH, &sa, NULL); - sigaction(SIGCONT, &sa, NULL); -} - static bool keymatch(Key *key0, Key *key1) { return (key0->str[0] && memcmp(key0->str, key1->str, sizeof(key1->str)) == 0) || (key0->code && key0->code == key1->code); @@ -2040,11 +2026,6 @@ static void mainloop() { editor_draw(vis); while (running) { - if (need_resize) { - editor_resize(vis); - need_resize = false; - } - fd_set fds; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); @@ -2089,7 +2070,6 @@ int main(int argc, char *argv[]) { } mode_prev = mode = config->mode; - setup(); if (!(vis = editor_new(ui_curses_new()))) die("Could not allocate editor core\n"); -- cgit v1.2.3