NeoMutt  2025-12-11-980-ge38c27
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
ibar.c
Go to the documentation of this file.
1
23
62
63#include "config.h"
64#include <stdbool.h>
65#include "mutt/lib.h"
66#include "config/lib.h"
67#include "core/lib.h"
68#include "gui/lib.h"
69#include "lib.h"
70#include "color/lib.h"
71#include "expando/lib.h"
72#include "private_data.h"
73#include "shared_data.h"
74#include "status.h"
75
87
91static int ibar_recalc(struct MuttWindow *win)
92{
93 struct Buffer *buf = buf_pool_get();
94
95 struct IBarPrivateData *ibar_data = win->wdata;
96 struct IndexSharedData *shared = ibar_data->shared;
97 struct IndexPrivateData *priv = ibar_data->priv;
99
100 const struct Expando *c_status_format = cs_subset_expando(shared->sub, "status_format");
101 menu_status_line(buf, shared, priv->menu, win->state.cols, c_status_format);
102
103 if (!mutt_str_equal(buf_string(buf), ibar_data->status_format))
104 {
105 mutt_str_replace(&ibar_data->status_format, buf_string(buf));
106 win->actions |= WA_REPAINT;
107 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
108 }
109
110 const bool c_ts_enabled = cs_subset_bool(shared->sub, "ts_enabled");
111 if (c_ts_enabled && mod_data && mod_data->ts_supported)
112 {
113 buf_reset(buf);
114 const struct Expando *c_ts_status_format = cs_subset_expando(shared->sub, "ts_status_format");
115 menu_status_line(buf, shared, priv->menu, -1, c_ts_status_format);
116 if (!mutt_str_equal(buf_string(buf), ibar_data->ts_status_format))
117 {
119 win->actions |= WA_REPAINT;
120 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
121 }
122
123 buf_reset(buf);
124 const struct Expando *c_ts_icon_format = cs_subset_expando(shared->sub, "ts_icon_format");
125 menu_status_line(buf, shared, priv->menu, -1, c_ts_icon_format);
126 if (!mutt_str_equal(buf_string(buf), ibar_data->ts_icon_format))
127 {
128 mutt_str_replace(&ibar_data->ts_icon_format, buf_string(buf));
129 win->actions |= WA_REPAINT;
130 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
131 }
132 }
133
134 buf_pool_release(&buf);
135 return 0;
136}
137
141static int ibar_repaint(struct MuttWindow *win)
142{
143 struct IBarPrivateData *ibar_data = win->wdata;
144 struct IndexSharedData *shared = ibar_data->shared;
145
146 mutt_window_move(win, 0, 0);
149
150 mutt_window_move(win, 0, 0);
151 mutt_draw_statusline(win, win->state.cols, ibar_data->status_format,
152 mutt_str_len(ibar_data->status_format));
154
155 const bool c_ts_enabled = cs_subset_bool(shared->sub, "ts_enabled");
157 if (c_ts_enabled && mod_data && mod_data->ts_supported)
158 {
160 mutt_ts_icon(ibar_data->ts_icon_format);
161 }
162
163 mutt_debug(LL_DEBUG5, "repaint done\n");
164 return 0;
165}
166
171{
172 if (nc->event_type != NT_COLOR)
173 return 0;
174 if (!nc->global_data || !nc->event_data)
175 return -1;
176
177 struct EventColor *ev_c = nc->event_data;
178
179 // MT_COLOR_MAX is sent on `uncolor *`
180 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
181 (ev_c->cid != MT_COLOR_MAX))
182 {
183 return 0;
184 }
185
186 struct MuttWindow *win_ibar = nc->global_data;
187 win_ibar->actions |= WA_REPAINT;
188 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
189
190 return 0;
191}
192
197{
198 if (nc->event_type != NT_CONFIG)
199 return 0;
200 if (!nc->global_data || !nc->event_data)
201 return -1;
202
203 struct EventConfig *ev_c = nc->event_data;
204 if (!ev_c->name)
205 return 0;
206 if ((ev_c->name[0] != 's') && (ev_c->name[0] != 't'))
207 return 0;
208
209 if (!mutt_str_equal(ev_c->name, "status_format") &&
210 !mutt_str_equal(ev_c->name, "ts_enabled") &&
211 !mutt_str_equal(ev_c->name, "ts_icon_format") &&
212 !mutt_str_equal(ev_c->name, "ts_status_format"))
213 {
214 return 0;
215 }
216
217 struct MuttWindow *win_ibar = nc->global_data;
218 win_ibar->actions |= WA_RECALC;
219 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
220
221 return 0;
222}
223
234{
235 if (!nc->global_data)
236 return -1;
237
238 struct MuttWindow *win_ibar = nc->global_data;
239 win_ibar->actions |= WA_RECALC;
240 mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
241
242 return 0;
243}
244
248static int ibar_menu_observer(struct NotifyCallback *nc)
249{
250 if (nc->event_type != NT_MENU)
251 return 0;
252 if (!nc->global_data)
253 return -1;
254
255 struct MuttWindow *win_ibar = nc->global_data;
256 win_ibar->actions |= WA_RECALC;
257 mutt_debug(LL_DEBUG5, "menu done, request WA_RECALC\n");
258
259 return 0;
260}
261
266{
267 if (nc->event_type != NT_WINDOW)
268 return 0;
269 if (!nc->global_data)
270 return -1;
271
272 struct MuttWindow *win_ibar = nc->global_data;
273 struct EventWindow *ev_w = nc->event_data;
274 if (ev_w->win != win_ibar)
275 return 0;
276
278 {
279 win_ibar->actions |= WA_REPAINT;
280 mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
281 }
282 else if (nc->event_subtype == NT_WINDOW_DELETE)
283 {
284 struct MuttWindow *dlg = window_find_parent(win_ibar, WT_DLG_INDEX);
285 if (!dlg)
286 return 0;
287 struct IndexSharedData *shared = dlg->wdata;
288
294
295 mutt_debug(LL_DEBUG5, "window delete done\n");
296 }
297
298 return 0;
299}
300
304static void ibar_data_free(struct MuttWindow *win, void **ptr)
305{
306 if (!ptr || !*ptr)
307 return;
308
309 struct IBarPrivateData *ibar_data = *ptr;
310
311 FREE(&ibar_data->status_format);
312 FREE(&ibar_data->ts_status_format);
313 FREE(&ibar_data->ts_icon_format);
314
315 FREE(ptr);
316}
317
325 struct IndexPrivateData *priv)
326{
327 struct IBarPrivateData *ibar_data = MUTT_MEM_CALLOC(1, struct IBarPrivateData);
328
329 ibar_data->shared = shared;
330 ibar_data->priv = priv;
331
332 return ibar_data;
333}
334
342struct MuttWindow *ibar_new(struct MuttWindow *parent, struct IndexSharedData *shared,
343 struct IndexPrivateData *priv)
344{
348
349 win_ibar->wdata = ibar_data_new(shared, priv);
350 win_ibar->wdata_free = ibar_data_free;
351 win_ibar->recalc = ibar_recalc;
352 win_ibar->repaint = ibar_repaint;
353
359
360 return win_ibar;
361}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:89
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition notify.c:73
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition notify.c:62
@ MT_COLOR_MAX
Definition color.h:97
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition color.h:78
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:53
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void mutt_draw_statusline(struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition dlg_index.c:980
Parse Expando string.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int ibar_menu_observer(struct NotifyCallback *nc)
Notification that a Menu has changed - Implements observer_t -.
Definition ibar.c:248
static int ibar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition ibar.c:265
static int ibar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition ibar.c:196
static int ibar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition ibar.c:170
static int ibar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition ibar.c:233
static int ibar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition ibar.c:91
static int ibar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition ibar.c:141
static void ibar_data_free(struct MuttWindow *win, void **ptr)
Free the private data - Implements MuttWindow::wdata_free() -.
Definition ibar.c:304
Convenience wrapper for the gui headers.
static struct IBarPrivateData * ibar_data_new(struct IndexSharedData *shared, struct IndexPrivateData *priv)
Create the private data for the Index Bar (status)
Definition ibar.c:324
struct MuttWindow * ibar_new(struct MuttWindow *parent, struct IndexSharedData *shared, struct IndexPrivateData *priv)
Create the Index Bar (status)
Definition ibar.c:342
GUI manage the main index (list of emails)
Private state data for the Index.
Data shared between Index, Pager and Sidebar.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
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:666
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
const 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:63
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the Colour ID.
Definition mutt_curses.c:79
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition mutt_window.h:86
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ WA_REPAINT
Redraw the contents of the Window.
@ WA_RECALC
Recalculate the contents of the Window.
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
@ NT_WINDOW_DELETE
Window is about to be deleted.
#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
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:666
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:58
@ NT_MENU
Menu has changed, MenuRedrawFlags.
Definition notify_type.h:52
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition notify_type.h:41
@ NT_ALL
Register for all notifications.
Definition notify_type.h:35
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
void menu_status_line(struct Buffer *buf, struct IndexSharedData *shared, struct Menu *menu, int max_cols, const struct Expando *exp)
Create the status line.
Definition status.c:51
GUI display a user-configurable status line.
String manipulation buffer.
Definition buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
An Event that happened to a Colour.
Definition notify2.h:52
enum ColorId cid
Colour ID that has changed.
Definition notify2.h:53
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.
struct MuttWindow * win
Window that changed.
Parsed Expando trees.
Definition expando.h:41
Gui private Module data.
Definition module_data.h:32
bool ts_supported
Terminal Setting is supported.
Definition module_data.h:41
Data to draw the Index Bar.
Definition ibar.c:80
char * ts_icon_format
Cached terminal icon string.
Definition ibar.c:85
struct IndexSharedData * shared
Shared Index data.
Definition ibar.c:81
char * ts_status_format
Cached terminal status string.
Definition ibar.c:84
char * status_format
Cached screen status string.
Definition ibar.c:83
struct IndexPrivateData * priv
Private Index data.
Definition ibar.c:82
Private state data for the Index.
struct Menu * menu
Menu controlling the index.
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct ConfigSubset * sub
Config set to use.
Definition shared_data.h:38
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition shared_data.h:44
int(* repaint)(struct MuttWindow *win)
struct WindowState state
Current state of the Window.
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
int(* recalc)(struct MuttWindow *win)
void(* wdata_free)(struct MuttWindow *win, void **ptr)
struct MuttWindow * parent
Parent Window.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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 cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition terminal.c:142
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition terminal.c:128