Fix the autoconf/makefile.am 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 and pager to be a bit cleaner by using the flag and REDRAW_SIDEBAR. Start to clean up some of the buffy code, but this needs to refactored and fixed. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1464744516 25200 # Tue May 31 18:28:36 2016 -0700 # Node ID 717a06441fafe2c72ef607fc282226b1a1cac654 # Parent a20a351eb8aebad75dbd5ad7e9898a6537bdc47b Clean up building, sidebar draw logic. Fix the autoconf/makefile.am 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 and pager to be a bit cleaner by using the flag 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 --- a/Makefile.am +++ b/Makefile.am @@ -51,43 +51,37 @@ AM_CPPFLAGS=-I. -I$(top_srcdir) $(IMAP_INCLUDES) $(GPGME_CFLAGS) -Iintl EXTRA_mutt_SOURCES = account.c bcache.c crypt-gpgme.c crypt-mod-pgp-classic.c \ crypt-mod-pgp-gpgme.c crypt-mod-smime-classic.c \ crypt-mod-smime-gpgme.c dotlock.c gnupgparse.c hcache.c md5.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 \ configure account.h \ attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \ globals.h hash.h history.h init.h keymap.h mutt_crypt.h \ mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \ mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \ mx.h pager.h pgp.h pop.h protos.h rfc1524.h rfc2047.h \ rfc2231.h rfc822.h rfc3676.h sha1.h sort.h mime.types VERSION prepare \ _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \ 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) pgpring_SOURCES = pgppubring.c pgplib.c lib.c extlib.c sha1.c md5.c pgppacket.c ascii.c pgpring_LDADD = $(LIBOBJS) $(INTLLIBS) pgpring_DEPENDENCIES = $(LIBOBJS) $(INTLDEPS) @@ -132,18 +126,18 @@ cp $(srcdir)/smime_keys.pl smime_keys chmod +x smime_keys keymap_defs.h: $(OPS) $(srcdir)/gen_defs $(srcdir)/gen_defs $(OPS) > keymap_defs.h 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 echo 'const char *ReleaseDate = "'`head -n 1 $(srcdir)/ChangeLog | LC_ALL=C cut -d ' ' -f 1`'";' > reldate.h.tmp; \ cmp -s reldate.h.tmp reldate.h || cp reldate.h.tmp reldate.h; \ rm reldate.h.tmp # The '#undef ENABLE_NLS' is to work around an automake ordering issue: diff --git a/buffy.c b/buffy.c --- a/buffy.c +++ b/buffy.c @@ -404,51 +404,51 @@ * Look through one directory of a maildir mailbox. The directory could * be either "new" or "cur". * * Count how many new, or flagged, messages there are. */ 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; + 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++; - } - } + /* 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); + closedir (dirp); } /** * buffy_maildir_update - Update messages counts for a maildir mailbox * @mailbox: BUFFY representing a maildir mailbox * * Open a mailbox directories and update our record of how many new, or * flagged, messages there are. @@ -465,19 +465,16 @@ buffy_maildir_update_dir (mailbox, "new"); if (mailbox->msg_count) { mailbox->new = 1; } buffy_maildir_update_dir (mailbox, "cur"); mailbox->sb_last_checked = time (NULL); - - /* make sure the updates are actually put on screen */ - sb_draw(); } #endif /* returns 1 if mailbox has new mail */ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) { int rc = 0; @@ -520,34 +517,32 @@ * * Open a mbox file and update our record of how many new, or flagged, * messages there are. If the mailbox hasn't changed since the last call, * the function does nothing. */ 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 */ + 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); - } - - /* 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 int mutt_buffy_check (int force) { BUFFY *tmp; struct stat sb; struct stat contex_sb; @@ -636,20 +631,18 @@ buffy_maildir_update (tmp); #endif if (buffy_maildir_hasnew (tmp) > 0) BuffyCount++; break; 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) BuffyCount++; break; } } else if (option(OPTCHECKMBOXSIZE) && Context && Context->path) @@ -657,17 +650,20 @@ if (!tmp->new) tmp->notified = 0; else if (!tmp->notified) BuffyNotify++; } #ifdef USE_SIDEBAR if (should_refresh) - sb_set_update_time(); + { + SidebarNeedsRedraw = 1; + sb_set_update_time(); + } #endif BuffyDoneTime = BuffyTime; return (BuffyCount); } int mutt_buffy_list (void) { diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -172,22 +172,21 @@ if test x$have_smime != xno ; then AC_DEFINE(CRYPT_BACKEND_CLASSIC_SMIME, 1, [Define if you want classic S/MIME support.]) MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS smime.o crypt-mod-smime-classic.o" SMIMEAUX_TARGET="smime_keys" 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 then if test -x "$withval" then MIXMASTER="$withval" else diff --git a/curs_main.c b/curs_main.c --- a/curs_main.c +++ b/curs_main.c @@ -604,41 +604,34 @@ if (option (OPTBEEPNEW)) beep(); } } else 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); if (menu->redraw & REDRAW_INDEX) { menu_redraw_index (menu); menu->redraw |= REDRAW_STATUS; @@ -649,19 +642,16 @@ menu_redraw_current (menu); } if (menu->redraw & REDRAW_STATUS) { 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; if (option(OPTTSENABLED) && TSSupported) { menu_status_line (buf, sizeof (buf), menu, NONULL (TSStatusFormat)); mutt_ts_status(buf); menu_status_line (buf, sizeof (buf), menu, NONULL (TSIconFormat)); @@ -1203,38 +1193,39 @@ mutt_pretty_mailbox (buf, sizeof (buf)); mutt_buffy (buf, sizeof (buf)); if (!buf[0]) { mutt_error _("No mailboxes have new mail"); 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); break; } } mutt_expand_path (buf, sizeof (buf)); diff --git a/flags.c b/flags.c --- a/flags.c +++ b/flags.c @@ -20,20 +20,16 @@ # include "config.h" #endif #include "mutt.h" #include "mutt_curses.h" #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; int deleted = ctx->deleted; int tagged = ctx->tagged; int flagged = ctx->flagged; int update = 0; @@ -254,27 +250,29 @@ update = 1; h->tagged = 0; if (upd_ctx) ctx->tagged--; } break; } 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 * of this message and not what it was at the time it was last searched. */ 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) { int j; for (j = 0; j < Context->vcount; j++) if (Context->hdrs[Context->v2r[j]]->tagged) diff --git a/globals.h b/globals.h --- a/globals.h +++ b/globals.h @@ -215,22 +215,21 @@ WHERE short Wrap; WHERE short WrapHeaders; WHERE short WriteInc; 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. */ +#ifdef USE_SIDEBAR WHERE short SidebarWidth; -#ifdef USE_SIDEBAR WHERE short SidebarRefreshTime; WHERE LIST *SidebarWhitelist INITVAL(0); +WHERE int SidebarNeedsRedraw INITVAL (0); #endif #ifdef USE_IMAP WHERE short ImapKeepalive; WHERE short ImapPipelineDepth; #endif /* flags for received signals */ diff --git a/keymap.c b/keymap.c --- a/keymap.c +++ b/keymap.c @@ -452,19 +452,16 @@ if (tmp.ch != -2 || SigWinch) goto gotkey; i -= ImapKeepalive; imap_keepalive (); } } #endif - /* update sidebar stats */ - mutt_buffy_check(0); - timeout (i * 1000); tmp = mutt_getch(); timeout (-1); /* hide timeouts from line editor */ if (menu == MENU_EDITOR && tmp.ch == -2) continue; diff --git a/menu.c b/menu.c --- a/menu.c +++ b/menu.c @@ -212,40 +212,48 @@ NORMAL_COLOR; } menu->offset = 0; menu->pagelen = menu->indexwin->rows; mutt_show_error (); menu->redraw = REDRAW_INDEX | REDRAW_STATUS; +#ifdef USE_SIDEBAR + menu->redraw |= REDRAW_SIDEBAR; +#endif } void menu_redraw_status (MUTTMENU *menu) { char buf[STRING]; snprintf (buf, sizeof (buf), MUTT_MODEFMT, menu->title); SETCOLOR (MT_COLOR_STATUS); mutt_window_move (menu->statuswin, 0, 0); mutt_paddstr (menu->statuswin->cols, buf); NORMAL_COLOR; 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]; int i; 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) { attr = menu->color(i); menu_make_entry (buf, sizeof (buf), menu, i); menu_pad_string (menu, buf, sizeof (buf)); @@ -838,16 +846,20 @@ return (OP_REDRAW); } if (!menu->dialog) menu_check_recenter (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)) menu_redraw_motion (menu); else if (menu->redraw == REDRAW_CURRENT) menu_redraw_current (menu); if (menu->dialog) diff --git a/mutt_menu.h b/mutt_menu.h --- a/mutt_menu.h +++ b/mutt_menu.h @@ -85,16 +85,19 @@ int oldcurrent; /* for driver use only. */ int searchDir; /* direction of search */ int tagged; /* number of tagged entries */ } MUTTMENU; 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 *); void menu_redraw_current (MUTTMENU *); int menu_redraw (MUTTMENU *); void menu_first_entry (MUTTMENU *); void menu_last_entry (MUTTMENU *); void menu_top_page (MUTTMENU *); diff --git a/pager.c b/pager.c --- a/pager.c +++ b/pager.c @@ -1666,19 +1666,16 @@ { #if ! (defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)) mutt_reflow_windows (); #endif NORMAL_COLOR; /* 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; else indexlen = PagerIndexLines; indicator = indexlen / 3; @@ -1762,16 +1759,19 @@ index->top = index->max - index->pagelen; else index->top = index->current - indicator; menu_redraw_index(index); } redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS; +#ifdef USE_SIDEBAR + redraw |= REDRAW_SIDEBAR; +#endif mutt_show_error (); } if (redraw & REDRAW_SIGWINCH) { i = -1; j = -1; while (display_line (fp, &last_pos, &lineInfo, ++i, &lastLine, &maxLine, @@ -1780,16 +1780,24 @@ if (!lineInfo[i].continuation && ++j == lines) { topline = i; if (!SearchFlag) break; } } +#ifdef USE_SIDEBAR + if ((redraw & REDRAW_SIDEBAR) || SidebarNeedsRedraw) + { + SidebarNeedsRedraw = 0; + sb_draw (); + } +#endif + if ((redraw & REDRAW_BODY) || topline != oldtopline) { do { mutt_window_move (pager_window, 0, 0); curline = oldtopline = topline; lines = 0; force_redraw = 0; @@ -2538,22 +2546,18 @@ j--; if (j > 0) topline++; } ch = 0; } - if (option (OPTFORCEREDRAWPAGER)) { + if (option (OPTFORCEREDRAWPAGER)) redraw = REDRAW_FULL; -#ifdef USE_SIDEBAR - sb_draw(); -#endif - } unset_option (OPTFORCEREDRAWINDEX); unset_option (OPTFORCEREDRAWPAGER); break; case OP_FLAG_MESSAGE: CHECK_MODE(IsHeader (extra)); CHECK_READONLY; /* L10N: CHECK_ACL */ diff --git a/sidebar.c b/sidebar.c --- a/sidebar.c +++ b/sidebar.c @@ -838,17 +838,17 @@ return; } else { HilBuffy = b; } break; default: return; } - sb_draw(); + SidebarNeedsRedraw = 1; } /** * sb_set_buffystats - Update the BUFFY's message counts from the CONTEXT * @ctx: A mailbox CONTEXT * * Given a mailbox CONTEXT, find a matching mailbox BUFFY and copy the message * counts into it.
signature.asc
Description: PGP signature
