From: Richard Russon Date: Fri, 4 Oct 2019 10:41:00 +0000 (+0100) Subject: colour notifications X-Git-Tag: 2019-10-25~13^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2becefc72fd1d8b0d13a9c785470f13d39033cfc;p=neomutt colour notifications --- diff --git a/color.c b/color.c index 9ce56627d..575abde18 100644 --- a/color.c +++ b/color.c @@ -39,10 +39,8 @@ #include "color.h" #include "context.h" #include "globals.h" -#include "keymap.h" #include "mutt_commands.h" #include "mutt_curses.h" -#include "mutt_menu.h" #include "options.h" #include "pattern.h" #ifdef USE_SLANG_CURSES @@ -362,6 +360,7 @@ void mutt_colors_free(struct Colors **ptr) colors_clear(c); defs_free(c); quotes_free(c); + notify_free(&c->notify); FREE(ptr); } @@ -372,6 +371,7 @@ void mutt_colors_free(struct Colors **ptr) struct Colors *mutt_colors_new(void) { struct Colors *c = mutt_mem_calloc(1, sizeof(*c)); + c->notify = notify_new(c, NT_COLOR); quotes_init(c); defs_init(c); @@ -390,6 +390,7 @@ struct Colors *mutt_colors_new(void) start_color(); #endif + notify_set_parent(c->notify, NeoMutt->notify); return c; } @@ -823,6 +824,8 @@ static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, if (mutt_str_strcmp(buf->data, "*") == 0) { colors_clear(c); + struct EventColor ec = { false }; // Color reset/removed + notify_send(c->notify, NT_COLOR, MT_COLOR_MAX, (intptr_t) &ec); return MUTT_CMD_SUCCESS; } @@ -853,6 +856,8 @@ static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, // Simple colours c->defs[object] = A_NORMAL; + struct EventColor ec = { false }; // Color reset/removed + notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec); return MUTT_CMD_SUCCESS; } @@ -899,16 +904,10 @@ static enum CommandResult parse_uncolor(struct Buffer *buf, struct Buffer *s, else if (object == MT_COLOR_STATUS) changed |= do_uncolor(c, buf, s, &c->status_list, uncolor); - bool is_index = ((object == MT_COLOR_INDEX) || (object == MT_COLOR_INDEX_AUTHOR) || - (object == MT_COLOR_INDEX_FLAGS) || (object == MT_COLOR_INDEX_SUBJECT) || - (object == MT_COLOR_INDEX_TAG)); - - if (changed && is_index && !OptNoCurses) + if (changed) { - mutt_menu_set_redraw_full(MENU_MAIN); - /* force re-caching of index colors */ - for (int i = 0; Context && i < Context->mailbox->msg_count; i++) - Context->mailbox->emails[i]->pair = 0; + struct EventColor ec = { false }; // Color reset/removed + notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec); } return MUTT_CMD_SUCCESS; @@ -1280,27 +1279,22 @@ static enum CommandResult parse_color(struct Colors *c, struct Buffer *buf, stru else if (object == MT_COLOR_INDEX) { rc = add_pattern(c, &c->index_list, buf->data, true, fg, bg, attr, err, true, match); - mutt_menu_set_redraw_full(MENU_MAIN); } else if (object == MT_COLOR_INDEX_AUTHOR) { rc = add_pattern(c, &c->index_author_list, buf->data, true, fg, bg, attr, err, true, match); - mutt_menu_set_redraw_full(MENU_MAIN); } else if (object == MT_COLOR_INDEX_FLAGS) { rc = add_pattern(c, &c->index_flags_list, buf->data, true, fg, bg, attr, err, true, match); - mutt_menu_set_redraw_full(MENU_MAIN); } else if (object == MT_COLOR_INDEX_SUBJECT) { rc = add_pattern(c, &c->index_subject_list, buf->data, true, fg, bg, attr, err, true, match); - mutt_menu_set_redraw_full(MENU_MAIN); } else if (object == MT_COLOR_INDEX_TAG) { rc = add_pattern(c, &c->index_tag_list, buf->data, true, fg, bg, attr, err, true, match); - mutt_menu_set_redraw_full(MENU_MAIN); } else if (object == MT_COLOR_QUOTED) { @@ -1332,11 +1326,15 @@ static enum CommandResult parse_color(struct Colors *c, struct Buffer *buf, stru else { c->defs[object] = fgbgattr_to_color(c, fg, bg, attr); - if (object > MT_COLOR_INDEX_AUTHOR) - mutt_menu_set_redraw_full(MENU_MAIN); rc = MUTT_CMD_SUCCESS; } + if (rc == MUTT_CMD_SUCCESS) + { + struct EventColor ec = { true }; // Color set/added + notify_send(c->notify, NT_COLOR, object, (intptr_t) &ec); + } + return rc; } diff --git a/color.h b/color.h index 9d027c51a..d4c486cdc 100644 --- a/color.h +++ b/color.h @@ -145,6 +145,19 @@ struct Colors struct ColorList *user_colors; int num_user_colors; + + struct Notify *notify; ///< Notifications system +}; + +/** + * struct EventColor - An Event that happened to an Colour + * + * Observers of EventColor will be passed a type of #NT_COLOR and a subtype + * which describes the colour that changed, e.g. #MT_COLOR_SIDEBAR_HIGHLIGHT. + */ +struct EventColor +{ + bool set; ///< True if a colour has been set/added, false if reset/deleted }; int mutt_color_alloc (struct Colors *c, uint32_t fg, uint32_t bg); diff --git a/doxygen/doxygen.conf b/doxygen/doxygen.conf index 2d3d9531c..6dcb43cd5 100644 --- a/doxygen/doxygen.conf +++ b/doxygen/doxygen.conf @@ -1414,6 +1414,7 @@ PREDEFINED = \ DEBUG \ ENABLE_NLS \ HAVE_BDB \ + HAVE_COLOR \ HAVE_GDBM \ HAVE_KC \ HAVE_LMDB \ diff --git a/main.c b/main.c index b1d4dd06d..f24d16a99 100644 --- a/main.c +++ b/main.c @@ -839,8 +839,9 @@ int main(int argc, char *argv[], char *envp[]) notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_hist_observer, 0); notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_log_observer, 0); - notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_menu_observer, 0); + notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_menu_config_observer, 0); notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_reply_observer, 0); + notify_observer_add(Colors->notify, NT_COLOR, 0, mutt_menu_color_observer, 0); if (sendflags & SEND_POSTPONED) { diff --git a/menu.c b/menu.c index adfe2708e..dc948f003 100644 --- a/menu.c +++ b/menu.c @@ -1594,9 +1594,45 @@ int mutt_menu_loop(struct Menu *menu) } /** - * mutt_menu_observer - Listen for config changes affecting the menu - Implements ::observer_t() + * mutt_menu_color_observer - Listen for colour changes affecting the menu - Implements ::observer_t() */ -int mutt_menu_observer(struct NotifyCallback *nc) +int mutt_menu_color_observer(struct NotifyCallback *nc) +{ + if ((!nc) || (nc->event_type != NT_COLOR)) + return -1; + + int s = nc->event_subtype; + + bool simple = (s == MT_COLOR_INDEX_COLLAPSED) || (s == MT_COLOR_INDEX_DATE) || + (s == MT_COLOR_INDEX_LABEL) || (s == MT_COLOR_INDEX_NUMBER) || + (s == MT_COLOR_INDEX_SIZE) || (s == MT_COLOR_INDEX_TAGS); + bool lists = (s == MT_COLOR_ATTACH_HEADERS) || (s == MT_COLOR_BODY) || + (s == MT_COLOR_HEADER) || (s == MT_COLOR_INDEX) || + (s == MT_COLOR_INDEX_AUTHOR) || (s == MT_COLOR_INDEX_FLAGS) || + (s == MT_COLOR_INDEX_SUBJECT) || (s == MT_COLOR_INDEX_TAG); + + // The changes aren't relevant to the index menu + if (!simple && !lists) + return 0; + + struct EventColor *ec = (struct EventColor *) nc->event; + + // Colour deleted from a list + if (!ec->set && lists && Context && Context->mailbox) + { + // Force re-caching of index colors + for (int i = 0; i < Context->mailbox->msg_count; i++) + Context->mailbox->emails[i]->pair = 0; + } + + mutt_menu_set_redraw_full(MENU_MAIN); + return 0; +} + +/** + * mutt_menu_config_observer - Listen for config changes affecting the menu - Implements ::observer_t() + */ +int mutt_menu_config_observer(struct NotifyCallback *nc) { if (!nc) return -1; diff --git a/mutt/notify_type.h b/mutt/notify_type.h index 846ab8192..5ef1019c8 100644 --- a/mutt/notify_type.h +++ b/mutt/notify_type.h @@ -36,6 +36,7 @@ enum NotifyType NT_EMAIL, ///< Email has changed NT_WINDOW, ///< Window has changed NT_CONTEXT, ///< Context has changed + NT_COLOR, ///< Colour has changed }; #endif /* MUTT_LIB_NOTIFY_TYPE_H */ diff --git a/mutt_menu.h b/mutt_menu.h index 108274abe..01639f04b 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -187,6 +187,7 @@ void mutt_menu_set_current_redraw(MuttRedrawFlags redraw); void mutt_menu_set_redraw_full(enum MenuType menu); void mutt_menu_set_redraw(enum MenuType menu, MuttRedrawFlags redraw); -int mutt_menu_observer(struct NotifyCallback *nc); +int mutt_menu_color_observer (struct NotifyCallback *nc); +int mutt_menu_config_observer(struct NotifyCallback *nc); #endif /* MUTT_MENU_H */ diff --git a/mutt_window.c b/mutt_window.c index 880d16809..b320beae1 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -28,7 +28,6 @@ #include "config.h" #include -#include #include #include "mutt/mutt.h" #include "mutt_window.h" diff --git a/recvattach.c b/recvattach.c index a4c97b6d3..7ac0a3dcd 100644 --- a/recvattach.c +++ b/recvattach.c @@ -51,7 +51,6 @@ #include "keymap.h" #include "mailcap.h" #include "mutt_attach.h" -#include "mutt_logging.h" #include "mutt_menu.h" #include "mutt_parse.h" #include "mutt_window.h"