NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
sbar.c
Go to the documentation of this file.
1
63#include "config.h"
64#include "mutt/lib.h"
65#include "core/lib.h"
66#include "lib.h"
67#include "color/lib.h"
68
73{
74 char *display;
75};
76
80static int sbar_recalc(struct MuttWindow *win)
81{
82 if (!win)
83 return -1;
84
85 win->actions |= WA_REPAINT;
86 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
87 return 0;
88}
89
93static int sbar_repaint(struct MuttWindow *win)
94{
95 struct SBarPrivateData *priv = win->wdata;
96
97 mutt_window_move(win, 0, 0);
98
100 mutt_window_move(win, 0, 0);
101 mutt_paddstr(win, win->state.cols, priv->display);
103
104 mutt_debug(LL_DEBUG5, "repaint done\n");
105 return 0;
106}
107
115{
116 if (nc->event_type != NT_COLOR)
117 return 0;
118 if (!nc->global_data)
119 return -1;
120
121 struct EventColor *ev_c = nc->event_data;
122
123 // MT_COLOR_MAX is sent on `uncolor *`
124 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
125 (ev_c->cid != MT_COLOR_MAX))
126 {
127 return 0;
128 }
129
130 struct MuttWindow *win_sbar = nc->global_data;
131
132 win_sbar->actions |= WA_REPAINT;
133 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
134
135 return 0;
136}
137
147{
148 if (nc->event_type != NT_WINDOW)
149 return 0;
150 if (!nc->global_data || !nc->event_data)
151 return -1;
152
153 struct MuttWindow *win_sbar = nc->global_data;
154 struct EventWindow *ev_w = nc->event_data;
155 if (ev_w->win != win_sbar)
156 return 0;
157
159 {
160 win_sbar->actions |= WA_REPAINT;
161 mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
162 }
163 else if (nc->event_subtype == NT_WINDOW_DELETE)
164 {
167 mutt_debug(LL_DEBUG5, "window delete done\n");
168 }
169
170 return 0;
171}
172
176static void sbar_wdata_free(struct MuttWindow *win, void **ptr)
177{
178 struct SBarPrivateData *priv = *ptr;
179
180 FREE(&priv->display);
181
182 FREE(ptr);
183}
184
189static struct SBarPrivateData *sbar_data_new(void)
190{
191 struct SBarPrivateData *sbar_data = mutt_mem_calloc(1, sizeof(struct SBarPrivateData));
192
193 return sbar_data;
194}
195
200struct MuttWindow *sbar_new(void)
201{
205
206 win_sbar->wdata = sbar_data_new();
207 win_sbar->wdata_free = sbar_wdata_free;
208 win_sbar->recalc = sbar_recalc;
209 win_sbar->repaint = sbar_repaint;
210
213
214 return win_sbar;
215}
216
224void sbar_set_title(struct MuttWindow *win, const char *title)
225{
226 if (!win || !win->wdata || (win->type != WT_STATUS_BAR))
227 return;
228
229 struct SBarPrivateData *priv = win->wdata;
230 mutt_str_replace(&priv->display, title);
231
232 win->actions |= WA_REPAINT;
233}
Color and attribute parsing.
@ MT_COLOR_MAX
Definition: color.h:89
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:71
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:54
Convenience wrapper for the core headers.
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:816
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int sbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: sbar.c:114
static int sbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: sbar.c:146
static int sbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: sbar.c:80
static int sbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: sbar.c:93
static void sbar_wdata_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -.
Definition: sbar.c:176
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
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: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
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:326
struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:65
struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:81
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:181
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:293
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:38
@ 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
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:47
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
struct MuttWindow * sbar_new(void)
Add the Simple Bar (status)
Definition: sbar.c:200
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
static struct SBarPrivateData * sbar_data_new(void)
Free the private data attached to the MuttWindow.
Definition: sbar.c:189
Key value store.
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
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
Private data for the Simple Bar.
Definition: sbar.c:73
char * display
Cached display string.
Definition: sbar.c:74
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60