NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
observer.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include "mutt/lib.h"
32#include "config/lib.h"
33#include "core/lib.h"
34#include "gui/lib.h"
35#include "lib.h"
36#include "color/lib.h"
37
41static int menu_color_observer(struct NotifyCallback *nc)
42{
43 if (nc->event_type != NT_COLOR)
44 return 0;
45 if (!nc->global_data || !nc->event_data)
46 return -1;
47
48 struct EventColor *ev_c = nc->event_data;
49
50 // MT_COLOR_MAX is sent on `uncolor *`
51 if ((ev_c->cid != MT_COLOR_NORMAL) && (ev_c->cid != MT_COLOR_INDICATOR) &&
52 (ev_c->cid != MT_COLOR_MAX))
53 {
54 return 0;
55 }
56
57 struct Menu *menu = nc->global_data;
58 struct MuttWindow *win = menu->win;
59
61 win->actions |= WA_REPAINT;
62 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT, MENU_REDRAW_FULL\n");
63
64 return 0;
65}
66
71{
72 if (nc->event_type != NT_CONFIG)
73 return 0;
74 if (!nc->global_data || !nc->event_data)
75 return -1;
76
77 struct EventConfig *ev_c = nc->event_data;
78 if (!mutt_str_startswith(ev_c->name, "arrow_") && !mutt_str_startswith(ev_c->name, "menu_"))
79 return 0;
80
81 if (mutt_str_equal(ev_c->name, "menu_scroll"))
82 return 0; // This doesn't affect the display
83
84 struct Menu *menu = nc->global_data;
85 menu_adjust(menu);
86
87 menu->redraw |= MENU_REDRAW_FULL;
88 menu->win->actions |= WA_RECALC;
89
90 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
91 return 0;
92}
93
98{
99 if (nc->event_type != NT_WINDOW)
100 return 0;
101 if (!nc->global_data || !nc->event_data)
102 return -1;
103
104 struct Menu *menu = nc->global_data;
105 struct MuttWindow *win = menu->win;
106 struct EventWindow *ev_w = nc->event_data;
107 if (ev_w->win != win)
108 return 0;
109
111 {
112 menu->page_len = win->state.rows;
113 menu->redraw |= MENU_REDRAW_FULL;
114
116 mutt_debug(LL_DEBUG5, "window state done, request MENU_REDRAW_INDEX, WA_REPAINT\n");
117 }
118 else if (nc->event_subtype == NT_WINDOW_DELETE)
119 {
123 msgwin_clear_text(NULL);
124 mutt_debug(LL_DEBUG5, "window delete done\n");
125 }
126
127 return 0;
128}
129
134void menu_add_observers(struct Menu *menu)
135{
136 struct MuttWindow *win = menu->win;
137
141}
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: notify.c:69
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:59
@ MT_COLOR_MAX
Definition: color.h:94
@ MT_COLOR_INDICATOR
Selected item in list.
Definition: color.h:54
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int menu_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: observer.c:97
static int menu_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: observer.c:70
static int menu_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: observer.c:41
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
void menu_adjust(struct Menu *menu)
Reapply the config to the Menu.
Definition: move.c:319
void menu_add_observers(struct Menu *menu)
Add the notification observers.
Definition: observer.c:134
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition: msgwin.c:519
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
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:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:109
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:229
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:228
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:110
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
Key value store.
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:238
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:239
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:82
int page_len
Number of entries per screen.
Definition: lib.h:84
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:126
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:131
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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