NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
observer.c File Reference

Menu notification observers. More...

#include "config.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "menu/lib.h"
+ Include dependency graph for observer.c:

Go to the source code of this file.

Functions

static int menu_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int menu_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int menu_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
void menu_add_observers (struct Menu *menu)
 Add the notification observers. More...
 

Detailed Description

Menu notification observers.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file observer.c.

Function Documentation

◆ menu_color_observer()

static int menu_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

Definition at line 39 of file observer.c.

40 {
41  if ((nc->event_type != NT_COLOR) || !nc->global_data || !nc->event_data)
42  return -1;
43 
44  struct EventColor *ev_c = nc->event_data;
45 
46  // MT_COLOR_MAX is sent on `uncolor *`
47  if ((ev_c->color != MT_COLOR_NORMAL) && (ev_c->color != MT_COLOR_INDICATOR) &&
48  (ev_c->color != MT_COLOR_MAX))
49  {
50  return 0;
51  }
52 
53  struct Menu *menu = nc->global_data;
54  struct MuttWindow *win = menu->win;
55 
56  menu->redraw = MENU_REDRAW_FULL;
57  win->actions |= WA_REPAINT;
58  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT, MENU_REDRAW_FULL\n");
59 
60  return 0;
61 }
Definition: lib.h:67
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
An Event that happened to a Colour.
Definition: color.h:122
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Plain text.
Definition: color.h:58
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Selected item in list.
Definition: color.h:54
enum ColorId color
Definition: color.h:124
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

◆ menu_config_observer()

static int menu_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 66 of file observer.c.

67 {
68  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
69  return -1;
70 
71  struct EventConfig *ev_c = nc->event_data;
72  if (!mutt_str_startswith(ev_c->name, "arrow_") && !mutt_str_startswith(ev_c->name, "menu_"))
73  return 0;
74 
75  if (mutt_str_equal(ev_c->name, "menu_scroll"))
76  return 0; // This doesn't affect the display
77 
78  struct Menu *menu = nc->global_data;
79  menu_adjust(menu);
80 
81  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
82  return 0;
83 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
Definition: lib.h:67
A config-change event.
Definition: subset.h:69
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_window_observer()

static int menu_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 88 of file observer.c.

89 {
90  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
91  return -1;
92 
93  struct Menu *menu = nc->global_data;
94  struct MuttWindow *win = menu->win;
95  struct EventWindow *ev_w = nc->event_data;
96  if (ev_w->win != win)
97  return 0;
98 
99  if (nc->event_subtype == NT_WINDOW_STATE)
100  {
101  menu->pagelen = win->state.rows;
102  menu->redraw |= MENU_REDRAW_FULL;
103 
104  win->actions |= WA_RECALC | WA_REPAINT;
106  "window state done, request MENU_REDRAW_INDEX, WA_REPAINT\n");
107  }
108  else if (nc->event_subtype == NT_WINDOW_DELETE)
109  {
113  mutt_debug(LL_DEBUG5, "window delete done\n");
114  }
115 
116  return 0;
117 }
Definition: lib.h:67
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
Window is about to be deleted.
Definition: mutt_window.h:206
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: color.c:1550
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
int pagelen
Number of entries per screen.
Definition: lib.h:74
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_add_observers()

void menu_add_observers ( struct Menu menu)

Add the notification observers.

Parameters
menuMenu

Definition at line 123 of file observer.c.

124 {
125  struct MuttWindow *win = menu->win;
126 
130 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
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
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: color.c:1540
+ Here is the call graph for this function:
+ Here is the caller graph for this function: