From: Pierre Habouzit Date: Mon, 13 Aug 2007 14:09:29 +0000 (+0200) Subject: Make layout windows visible, makes the whole thing way simpler. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=b2c8662dd3e1d14ed817e9e166f1fd223a5b4754;p=apps%2Fmadmutt.git Make layout windows visible, makes the whole thing way simpler. Signed-off-by: Pierre Habouzit --- diff --git a/lib-ui/layout.c b/lib-ui/layout.c index 7b46036..50fd0b6 100644 --- a/lib-ui/layout.c +++ b/lib-ui/layout.c @@ -26,11 +26,7 @@ # include #endif -static struct { - int rows, cols; - WINDOW *sidebar; - WINDOW *main; -} layout; +WINDOW *sidebar_w, *main_w; void mutt_need_hard_redraw(void) { @@ -54,8 +50,10 @@ void mutt_refresh(void) /* else */ wrefresh(stdscr); - if (layout.sidebar) - wrefresh(layout.sidebar); + if (sidebar_w) + wrefresh(sidebar_w); + wrefresh(main_w); + main_w = NULL; } void mutt_endwin(const char *msg) @@ -63,13 +61,13 @@ void mutt_endwin(const char *msg) if (!option(OPTNOCURSES)) { CLEARLINE(LINES - 1); - if (layout.sidebar) { - delwin(layout.sidebar); - layout.sidebar = NULL; + if (sidebar_w) { + delwin(sidebar_w); + sidebar_w = NULL; } - if (layout.main) { - delwin(layout.main); - layout.main = NULL; + if (main_w) { + delwin(main_w); + main_w = NULL; } wattrset(stdscr, A_NORMAL); @@ -90,31 +88,29 @@ void ui_layout_init(void) mutt_error = mutt_curses_error; mutt_message = mutt_curses_message; - getmaxyx(stdscr, layout.rows, layout.cols); + main_w = newwin(LINES - 1, COLS, 0, 0); } void ui_layout_resize(void) { if (SigWinch) { - int fd; + int fd, rows = -1, cols = -1; struct winsize w; - layout.rows = layout.cols = -1; - if ((fd = open("/dev/tty", O_RDONLY)) != -1) { if (ioctl(fd, TIOCGWINSZ, &w) != -1) { - layout.rows = w.ws_row; - layout.cols = w.ws_col; + rows = w.ws_row; + cols = w.ws_col; } close(fd); } - if (layout.rows <= 0) { - layout.rows = atoi(getenv("LINES") ?: "24"); + if (rows <= 0) { + rows = atoi(getenv("LINES") ?: "24"); } - if (layout.cols <= 0) { - layout.cols = atoi(getenv("COLUMNS") ?: "80"); + if (cols <= 0) { + cols = atoi(getenv("COLUMNS") ?: "80"); } - resizeterm(layout.rows, layout.cols); + resizeterm(rows, cols); SigWinch = 0; /* force a real complete redraw. */ clearok(stdscr, true); @@ -123,24 +119,27 @@ void ui_layout_resize(void) WINDOW *ui_layout_sidebar_w(void) { - if (option(OPTMBOXPANE) && SidebarWidth > 1 && SidebarWidth < layout.cols) + if (option(OPTMBOXPANE) && SidebarWidth > 1 && SidebarWidth < COLS) { int sw, sh; - if (!layout.sidebar) { - layout.sidebar = newwin(layout.rows - 1, SidebarWidth, 0, 0); + if (!sidebar_w) { + sidebar_w = newwin(LINES - 1, SidebarWidth, 0, 0); + wresize(main_w, LINES - 1, COLS - SidebarWidth); } - getmaxyx(layout.sidebar, sh, sw); + getmaxyx(sidebar_w, sh, sw); - if (sh != layout.rows - 1 || sw != SidebarWidth) { - wresize(layout.sidebar, layout.rows - 1, SidebarWidth); + if (sh != LINES - 1 || sw != SidebarWidth) { + wresize(sidebar_w, LINES - 1, SidebarWidth); + wresize(main_w, LINES - 1, COLS - SidebarWidth); } } else { - if (layout.sidebar) { - delwin(layout.sidebar); - layout.sidebar = NULL; + if (sidebar_w) { + delwin(sidebar_w); + sidebar_w = NULL; + wresize(main_w, LINES - 1, COLS); } } - return layout.sidebar; + return sidebar_w; } diff --git a/lib-ui/layout.h b/lib-ui/layout.h index 7bc2161..b6e1446 100644 --- a/lib-ui/layout.h +++ b/lib-ui/layout.h @@ -20,6 +20,8 @@ #ifndef MUTT_LIB_UI_LAYOUT_H #define MUTT_LIB_UI_LAYOUT_H +extern WINDOW *sidebar_w, *main_w; + void ui_layout_init(void); void ui_layout_resize(void); @@ -29,4 +31,16 @@ void mutt_need_hard_redraw(void); void mutt_refresh(void); void mutt_endwin(const char *); +static inline int ui_get_width(WINDOW *w) { + int x, y; + getmaxyx(w, y, x); + return y; +} + +static inline int ui_get_height(WINDOW *w) { + int x, y; + getmaxyx(w, y, x); + return x; +} + #endif diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 0ca8ce9..6f35e48 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -175,7 +175,7 @@ sidebar_number_format(char* dest, ssize_t destlen, int sidebar_need_count(void) { - return ui_layout_sidebar_w() && !m_strisempty(SidebarNumberFormat); + return sidebar_w && !m_strisempty(SidebarNumberFormat); } /* print single item