NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
observer.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include "mutt/lib.h"
31 #include "config/lib.h"
32 #include "core/lib.h"
33 #include "gui/lib.h"
34 #include "color/lib.h"
35 #include "menu/lib.h"
36 
40 static int menu_color_observer(struct NotifyCallback *nc)
41 {
42  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
43  return -1;
44 
45  struct EventColor *ev_c = nc->event_data;
46 
47  // MT_COLOR_MAX is sent on `uncolor *`
48  if ((ev_c->color != MT_COLOR_NORMAL) && (ev_c->color != MT_COLOR_INDICATOR) &&
49  (ev_c->color != MT_COLOR_MAX))
50  {
51  return 0;
52  }
53 
54  struct Menu *menu = nc->global_data;
55  struct MuttWindow *win = menu->win;
56 
57  menu->redraw = MENU_REDRAW_FULL;
58  win->actions |= WA_REPAINT;
59  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT, MENU_REDRAW_FULL\n");
60 
61  return 0;
62 }
63 
67 static int menu_config_observer(struct NotifyCallback *nc)
68 {
69  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
70  return -1;
71 
72  struct EventConfig *ev_c = nc->event_data;
73  if (!mutt_str_startswith(ev_c->name, "arrow_") && !mutt_str_startswith(ev_c->name, "menu_"))
74  return 0;
75 
76  if (mutt_str_equal(ev_c->name, "menu_scroll"))
77  return 0; // This doesn't affect the display
78 
79  struct Menu *menu = nc->global_data;
80  menu_adjust(menu);
81 
82  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
83  return 0;
84 }
85 
89 static int menu_window_observer(struct NotifyCallback *nc)
90 {
91  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
92  return -1;
93 
94  struct Menu *menu = nc->global_data;
95  struct MuttWindow *win = menu->win;
96  struct EventWindow *ev_w = nc->event_data;
97  if (ev_w->win != win)
98  return 0;
99 
100  if (nc->event_subtype == NT_WINDOW_STATE)
101  {
102  menu->pagelen = win->state.rows;
103  menu->redraw |= MENU_REDRAW_FULL;
104 
107  "window state done, request MENU_REDRAW_INDEX, WA_REPAINT\n");
108  }
109  else if (nc->event_subtype == NT_WINDOW_DELETE)
110  {
114  mutt_debug(LL_DEBUG5, "window delete done\n");
115  }
116 
117  return 0;
118 }
119 
124 void menu_add_observers(struct Menu *menu)
125 {
126  struct MuttWindow *win = menu->win;
127 
131 }
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: notify.c:67
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:57
@ MT_COLOR_MAX
Definition: color.h:88
@ MT_COLOR_INDICATOR
Selected item in list.
Definition: color.h:49
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:53
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int menu_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:89
static int menu_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:67
static int menu_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: observer.c:40
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:55
void menu_adjust(struct Menu *menu)
Reapply the config to the Menu.
Definition: move.c:308
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition: observer.c:124
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:158
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:206
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId color
Colour that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:70
const char * name
Name of config item that changed.
Definition: subset.h:72
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Definition: lib.h:67
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:74
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:70
int pagelen
Number of entries per screen.
Definition: lib.h:72
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61