diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-04-11 11:03:24 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-04-11 11:04:23 +0200 |
| commit | be1fb4cc4edf9cc861831961cac1d0400a87db36 (patch) | |
| tree | 96ab40297d9558eb43b130cbd1392e5873489f11 | |
| parent | 3ea63f3951dd8e1c624966d6966ea8ca0e359b09 (diff) | |
| download | vis-be1fb4cc4edf9cc861831961cac1d0400a87db36.tar.gz vis-be1fb4cc4edf9cc861831961cac1d0400a87db36.tar.xz | |
Further ui separation, eliminate global state
| -rw-r--r-- | ui-curses.c | 49 | ||||
| -rw-r--r-- | 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; @@ -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"); |
