From: Kevin McCarthy Date: Sat, 4 Jun 2016 18:32:03 +0000 (-0700) Subject: Sidebar clean up: building and drawing logic. X-Git-Tag: neomutt-20160822~137 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cd023d0d5e88114cc9f296560cd2743bf192e02;p=neomutt Sidebar clean up: building and drawing logic. Fix the autoconf/makefile.am changes to be consistent. Create a global SidebarNeedsRedraw to indicate a redraw is needed, instead of putting sb_draw() everywhere in the code. Create a menu_redraw_sidebar() function and use the REDRAW_SIDEBAR flag instead of piggy-backing it inside the index loop. Fix curs_main.c and pager.c to be a bit cleaner by using the global and REDRAW_SIDEBAR. Start to clean up some of the buffy code, but this needs to refactored and fixed. --- diff --git a/Makefile.am b/Makefile.am index f2f67cf44..b874d943b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,7 +56,7 @@ EXTRA_mutt_SOURCES = account.c bcache.c crypt-gpgme.c crypt-mod-pgp-classic.c \ mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \ mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \ pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \ - smime.c smtp.c utf8.c wcwidth.c \ + sidebar.c smime.c smtp.c utf8.c wcwidth.c \ bcache.h browser.h hcache.h mbyte.h mutt_idna.h remailer.h url.h EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \ @@ -71,18 +71,12 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \ mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \ README.SSL smime.h group.h \ muttbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh \ - ChangeLog mkchangelog.sh mutt_idna.h \ + ChangeLog mkchangelog.sh mutt_idna.h sidebar.h OPS.sidebar \ snprintf.c regex.c crypt-gpgme.h hcachever.sh.in \ txt2c.c txt2c.sh version.sh check_sec.sh EXTRA_SCRIPTS = smime_keys -if BUILD_SIDEBAR -mutt_SOURCES += sidebar.c sidebar.h -endif - -EXTRA_DIST += OPS.SIDEBAR - mutt_dotlock_SOURCES = mutt_dotlock.c mutt_dotlock_LDADD = $(LIBOBJS) mutt_dotlock_DEPENDENCIES = $(LIBOBJS) @@ -137,8 +131,8 @@ keymap_defs.h: $(OPS) $(srcdir)/gen_defs keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs rm -f $@ - $(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.PGP \ - $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \ + $(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP \ + $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \ > keymap_alldefs.h reldate.h: $(srcdir)/ChangeLog diff --git a/buffy.c b/buffy.c index 325a2d743..02e338b2f 100644 --- a/buffy.c +++ b/buffy.c @@ -409,41 +409,41 @@ static int buffy_maildir_hasnew (BUFFY* mailbox) static void buffy_maildir_update_dir (BUFFY *mailbox, const char *dir) { - char path[_POSIX_PATH_MAX] = ""; - DIR *dirp = NULL; - struct dirent *de = NULL; - char *p = NULL; - int read; + char path[_POSIX_PATH_MAX] = ""; + DIR *dirp = NULL; + struct dirent *de = NULL; + char *p = NULL; - snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir); + snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir); - dirp = opendir (path); - if (!dirp) { - mailbox->magic = 0; - return; - } + dirp = opendir (path); + if (!dirp) + { + mailbox->magic = 0; + return; + } - while ((de = readdir (dirp)) != NULL) { - if (*de->d_name == '.') - continue; - - /* Matches maildir_parse_flags logic */ - read = 0; - mailbox->msg_count++; - p = strstr (de->d_name, ":2,"); - if (p) { - p += 3; - if (strchr (p, 'S')) - read = 1; - if (strchr (p, 'F')) - mailbox->msg_flagged++; - } - if (!read) { - mailbox->msg_unread++; - } - } + while ((de = readdir (dirp)) != NULL) + { + if (*de->d_name == '.') + continue; - closedir (dirp); + /* Matches maildir_parse_flags logic */ + mailbox->msg_count++; + p = strstr (de->d_name, ":2,"); + if (p) + { + p += 3; + if (strchr (p, 'T')) + continue; + if (!strchr (p, 'S')) + mailbox->msg_unread++; + if (strchr (p, 'F')) + mailbox->msg_flagged++; + } + } + + closedir (dirp); } /** @@ -470,9 +470,6 @@ buffy_maildir_update (BUFFY *mailbox) buffy_maildir_update_dir (mailbox, "cur"); mailbox->sb_last_checked = time (NULL); - - /* make sure the updates are actually put on screen */ - sb_draw(); } #endif @@ -525,24 +522,22 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) void buffy_mbox_update (BUFFY *mailbox, struct stat *sb) { - CONTEXT *ctx = NULL; + CONTEXT *ctx = NULL; - if (!option (OPTSIDEBAR)) - return; - if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0)) - return; /* no check necessary */ - - ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL); - if (ctx) { - mailbox->msg_count = ctx->msgcount; - mailbox->msg_unread = ctx->unread; - mailbox->msg_flagged = ctx->flagged; - mailbox->sb_last_checked = time (NULL); - mx_close_mailbox (ctx, 0); - } + if (!option (OPTSIDEBAR)) + return; + if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0)) + return; /* no check necessary */ - /* make sure the updates are actually put on screen */ - sb_draw(); + ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL); + if (ctx) + { + mailbox->msg_count = ctx->msgcount; + mailbox->msg_unread = ctx->unread; + mailbox->msg_flagged = ctx->flagged; + mailbox->sb_last_checked = time (NULL); + mx_close_mailbox (ctx, 0); + } } #endif @@ -641,10 +636,8 @@ int mutt_buffy_check (int force) case MUTT_MH: #ifdef USE_SIDEBAR - if (sb_should_refresh()) { + if (should_refresh) mh_buffy_update (tmp); - sb_set_update_time(); - } #endif mh_buffy(tmp); if (tmp->new) @@ -662,7 +655,10 @@ int mutt_buffy_check (int force) } #ifdef USE_SIDEBAR if (should_refresh) - sb_set_update_time(); + { + SidebarNeedsRedraw = 1; + sb_set_update_time(); + } #endif BuffyDoneTime = BuffyTime; diff --git a/configure.ac b/configure.ac index f8d71a199..df29887d4 100644 --- a/configure.ac +++ b/configure.ac @@ -177,12 +177,11 @@ fi AC_ARG_ENABLE(sidebar, AC_HELP_STRING([--enable-sidebar], [Enable Sidebar support]), [ if test x$enableval = xyes ; then - AC_DEFINE(USE_SIDEBAR,1,[ Define if you want support for the sidebar. ]) + AC_DEFINE(USE_SIDEBAR, 1, [Define if you want support for the sidebar.]) OPS="$OPS \$(srcdir)/OPS.SIDEBAR" - need_sidebar="yes" + MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS sidebar.o" fi ]) -AM_CONDITIONAL(BUILD_SIDEBAR, test x$need_sidebar = xyes) AC_ARG_WITH(mixmaster, AS_HELP_STRING([--with-mixmaster@<:@=PATH@:>@],[Include Mixmaster support]), [if test "$withval" != no diff --git a/curs_main.c b/curs_main.c index e138906c7..f18debbd5 100644 --- a/curs_main.c +++ b/curs_main.c @@ -609,31 +609,24 @@ int mutt_index_menu (void) do_buffy_notify = 1; } -#ifdef USE_SIDEBAR - if (option (OPTSIDEBAR)) - menu->redraw |= REDRAW_SIDEBAR; -#endif - if (op != -1) mutt_curs_set (0); if (menu->redraw & REDRAW_FULL) { menu_redraw_full (menu); -#ifdef USE_SIDEBAR - sb_draw(); -#endif mutt_show_error (); } -#ifdef USE_SIDEBAR - else if (menu->redraw & REDRAW_SIDEBAR) { - sb_draw(); - menu->redraw &= ~REDRAW_SIDEBAR; - } -#endif if (menu->menu == MENU_MAIN) { +#ifdef USE_SIDEBAR + if (menu->redraw & REDRAW_SIDEBAR || SidebarNeedsRedraw) + { + sb_set_buffystats (Context); + menu_redraw_sidebar (menu); + } +#endif if (Context && Context->hdrs && !(menu->current >= Context->vcount)) { menu_check_recenter (menu); @@ -654,9 +647,6 @@ int mutt_index_menu (void) menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); mutt_window_move (MuttStatusWindow, 0, 0); SETCOLOR (MT_COLOR_STATUS); -#ifdef USE_SIDEBAR - sb_set_buffystats (Context); -#endif mutt_paddstr (MuttStatusWindow->cols, buf); NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; @@ -1116,9 +1106,6 @@ int mutt_index_menu (void) break; CHECK_MSGCOUNT; -#ifdef USE_SIDEBAR - CHECK_VISIBLE; -#endif CHECK_READONLY; { int oldvcount = Context->vcount; @@ -1208,28 +1195,29 @@ int mutt_index_menu (void) break; } } +#ifdef USE_SIDEBAR + else if (op == OP_SIDEBAR_OPEN) + { + const char *path = sb_get_highlight(); + if (!path || !*path) + break; + strncpy (buf, path, sizeof (buf)); + } +#endif else { mutt_buffy (buf, sizeof (buf)); -#ifdef USE_SIDEBAR - if (op == OP_SIDEBAR_OPEN) { - const char *path = sb_get_highlight(); - if (!path) - break; - strncpy (buf, path, sizeof (buf)); - } else -#endif - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) - { - if (menu->menu == MENU_PAGER) - { - op = OP_DISPLAY_MESSAGE; - continue; - } - else - break; - } + if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) + { + if (menu->menu == MENU_PAGER) + { + op = OP_DISPLAY_MESSAGE; + continue; + } + else + break; + } if (!buf[0]) { mutt_window_clearline (MuttMessageWindow, 0); diff --git a/flags.c b/flags.c index 2d404f60f..82e486471 100644 --- a/flags.c +++ b/flags.c @@ -25,10 +25,6 @@ #include "sort.h" #include "mx.h" -#ifdef USE_SIDEBAR -#include "sidebar.h" -#endif - void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) { int changed = h->changed; @@ -259,7 +255,12 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) } if (update) + { mutt_set_header_color(ctx, h); +#ifdef USE_SIDEBAR + SidebarNeedsRedraw = 1; +#endif + } /* if the message status has changed, we need to invalidate the cached * search results so that any future search will match the current status @@ -267,9 +268,6 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) */ if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged)) h->searched = 0; -#ifdef USE_SIDEBAR - sb_draw(); -#endif } void mutt_tag_set_flag (int flag, int bf) diff --git a/globals.h b/globals.h index cf8c5f0cc..05a3e11f7 100644 --- a/globals.h +++ b/globals.h @@ -220,12 +220,11 @@ WHERE short ScoreThresholdDelete; WHERE short ScoreThresholdRead; WHERE short ScoreThresholdFlag; -/* This isn't excluded from the build because it's too entwined in the code. - * For now. */ -WHERE short SidebarWidth; #ifdef USE_SIDEBAR +WHERE short SidebarWidth; WHERE short SidebarRefreshTime; WHERE LIST *SidebarWhitelist INITVAL(0); +WHERE int SidebarNeedsRedraw INITVAL (0); #endif #ifdef USE_IMAP diff --git a/keymap.c b/keymap.c index 301ef6537..8b8b972b5 100644 --- a/keymap.c +++ b/keymap.c @@ -457,9 +457,6 @@ int km_dokey (int menu) } #endif - /* update sidebar stats */ - mutt_buffy_check(0); - timeout (i * 1000); tmp = mutt_getch(); timeout (-1); diff --git a/menu.c b/menu.c index a8be371dc..86bbed437 100644 --- a/menu.c +++ b/menu.c @@ -217,6 +217,9 @@ void menu_redraw_full (MUTTMENU *menu) mutt_show_error (); menu->redraw = REDRAW_INDEX | REDRAW_STATUS; +#ifdef USE_SIDEBAR + menu->redraw |= REDRAW_SIDEBAR; +#endif } void menu_redraw_status (MUTTMENU *menu) @@ -231,6 +234,14 @@ void menu_redraw_status (MUTTMENU *menu) menu->redraw &= ~REDRAW_STATUS; } +#ifdef USE_SIDEBAR +void menu_redraw_sidebar (MUTTMENU *menu) +{ + SidebarNeedsRedraw = 0; + sb_draw (); +} +#endif + void menu_redraw_index (MUTTMENU *menu) { char buf[LONG_STRING]; @@ -238,9 +249,6 @@ void menu_redraw_index (MUTTMENU *menu) int do_color; int attr; -#ifdef USE_SIDEBAR - sb_draw(); -#endif for (i = menu->top; i < menu->top + menu->pagelen; i++) { if (i < menu->max) @@ -843,6 +851,10 @@ int menu_redraw (MUTTMENU *menu) if (menu->redraw & REDRAW_STATUS) menu_redraw_status (menu); +#ifdef USE_SIDEBAR + if (menu->redraw & REDRAW_SIDEBAR || SidebarNeedsRedraw) + menu_redraw_sidebar (menu); +#endif if (menu->redraw & REDRAW_INDEX) menu_redraw_index (menu); else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNCH)) diff --git a/mutt_menu.h b/mutt_menu.h index bf5522c07..b229fd45e 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -90,6 +90,9 @@ typedef struct menu_t void mutt_menu_init (void); void menu_jump (MUTTMENU *); void menu_redraw_full (MUTTMENU *); +#ifdef USE_SIDEBAR +void menu_redraw_sidebar (MUTTMENU *); +#endif void menu_redraw_index (MUTTMENU *); void menu_redraw_status (MUTTMENU *); void menu_redraw_motion (MUTTMENU *); diff --git a/pager.c b/pager.c index 06bed3abf..d99075275 100644 --- a/pager.c +++ b/pager.c @@ -1671,9 +1671,6 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) /* clear() doesn't optimize screen redraws */ move (0, 0); clrtobot (); -#ifdef USE_SIDEBAR - sb_draw(); -#endif if (IsHeader (extra) && Context->vcount + 1 < PagerIndexLines) indexlen = Context->vcount + 1; @@ -1767,6 +1764,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) } redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS; +#ifdef USE_SIDEBAR + redraw |= REDRAW_SIDEBAR; +#endif mutt_show_error (); } @@ -1785,6 +1785,14 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) } } +#ifdef USE_SIDEBAR + if ((redraw & REDRAW_SIDEBAR) || SidebarNeedsRedraw) + { + SidebarNeedsRedraw = 0; + sb_draw (); + } +#endif + if ((redraw & REDRAW_BODY) || topline != oldtopline) { do { @@ -2543,12 +2551,8 @@ search_next: ch = 0; } - if (option (OPTFORCEREDRAWPAGER)) { + if (option (OPTFORCEREDRAWPAGER)) redraw = REDRAW_FULL; -#ifdef USE_SIDEBAR - sb_draw(); -#endif - } unset_option (OPTFORCEREDRAWINDEX); unset_option (OPTFORCEREDRAWPAGER); break; diff --git a/sidebar.c b/sidebar.c index 6f8093d43..26f5460c5 100644 --- a/sidebar.c +++ b/sidebar.c @@ -843,7 +843,7 @@ sb_change_mailbox (int op) default: return; } - sb_draw(); + SidebarNeedsRedraw = 1; } /**