NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
ibar.c
Go to the documentation of this file.
1
62#include "config.h"
63#include <stdbool.h>
64#include "mutt/lib.h"
65#include "config/lib.h"
66#include "core/lib.h"
67#include "gui/lib.h"
68#include "lib.h"
69#include "color/lib.h"
70#include "private_data.h"
71#include "shared_data.h"
72#include "status.h"
73
78{
84};
85
89static int ibar_recalc(struct MuttWindow *win)
90{
91 char buf[1024] = { 0 };
92
93 struct IBarPrivateData *ibar_data = win->wdata;
94 struct IndexSharedData *shared = ibar_data->shared;
95 struct IndexPrivateData *priv = ibar_data->priv;
96
97 const char *c_status_format = cs_subset_string(shared->sub, "status_format");
98 menu_status_line(buf, sizeof(buf), shared, priv->menu, win->state.cols,
99 NONULL(c_status_format));
100
101 if (!mutt_str_equal(buf, ibar_data->status_format))
102 {
103 mutt_str_replace(&ibar_data->status_format, buf);
104 win->actions |= WA_REPAINT;
105 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
106 }
107
108 const bool c_ts_enabled = cs_subset_bool(shared->sub, "ts_enabled");
109 if (c_ts_enabled && TsSupported)
110 {
111 const char *c_ts_status_format = cs_subset_string(shared->sub, "ts_status_format");
112 menu_status_line(buf, sizeof(buf), shared, priv->menu, sizeof(buf),
113 NONULL(c_ts_status_format));
114 if (!mutt_str_equal(buf, ibar_data->ts_status_format))
115 {
116 mutt_str_replace(&ibar_data->ts_status_format, buf);
117 win->actions |= WA_REPAINT;
118 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
119 }
120
121 const char *c_ts_icon_format = cs_subset_string(shared->sub, "ts_icon_format");
122 menu_status_line(buf, sizeof(buf), shared, priv->menu, sizeof(buf),
123 NONULL(c_ts_icon_format));
124 if (!mutt_str_equal(buf, ibar_data->ts_icon_format))
125 {
126 mutt_str_replace(&ibar_data->ts_icon_format, buf);
127 win->actions |= WA_REPAINT;
128 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
129 }
130 }
131
132 return 0;
133}
134
138static int ibar_repaint(struct MuttWindow *win)
139{
140 struct IBarPrivateData *ibar_data = win->wdata;
141 struct IndexSharedData *shared = ibar_data->shared;
142
143 mutt_window_move(win, 0, 0);
146
147 mutt_window_move(win, 0, 0);
148 mutt_draw_statusline(win, win->state.cols, ibar_data->status_format,
149 mutt_str_len(ibar_data->status_format));
151
152 const bool c_ts_enabled = cs_subset_bool(shared->sub, "ts_enabled");
153 if (c_ts_enabled && TsSupported)
154 {
156 mutt_ts_icon(ibar_data->ts_icon_format);
157 }
158
159 mutt_debug(LL_DEBUG5, "repaint done\n");
160 return 0;
161}
162
167{
168 if (nc->event_type != NT_COLOR)
169 return 0;
170 if (!nc->global_data || !nc->event_data)
171 return -1;
172
173 struct EventColor *ev_c = nc->event_data;
174
175 // MT_COLOR_MAX is sent on `uncolor *`
176 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
177 (ev_c->cid != MT_COLOR_MAX))
178 {
179 return 0;
180 }
181
182 struct MuttWindow *win_ibar = nc->global_data;
183 win_ibar->actions |= WA_REPAINT;
184 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
185
186 return 0;
187}
188
193{
194 if (nc->event_type != NT_CONFIG)
195 return 0;
196 if (!nc->global_data || !nc->event_data)
197 return -1;
198
199 struct EventConfig *ev_c = nc->event_data;
200 if ((ev_c->name[0] != 's') && (ev_c->name[0] != 't'))
201 return 0;
202
203 if (!mutt_str_equal(ev_c->name, "status_format") &&
204 !mutt_str_equal(ev_c->name, "ts_enabled") &&
205 !mutt_str_equal(ev_c->name, "ts_icon_format") &&
206 !mutt_str_equal(ev_c->name, "ts_status_format"))
207 {
208 return 0;
209 }
210
211 struct MuttWindow *win_ibar = nc->global_data;
212 win_ibar->actions |= WA_RECALC;
213 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
214
215 return 0;
216}
217
228{
229 if (!nc->global_data)
230 return -1;
231
232 struct MuttWindow *win_ibar = nc->global_data;
233 win_ibar->actions |= WA_RECALC;
234 mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
235
236 return 0;
237}
238
242static int ibar_menu_observer(struct NotifyCallback *nc)
243{
244 if (nc->event_type != NT_MENU)
245 return 0;
246 if (!nc->global_data)
247 return -1;
248
249 struct MuttWindow *win_ibar = nc->global_data;
250 win_ibar->actions |= WA_RECALC;
251 mutt_debug(LL_DEBUG5, "menu done, request WA_RECALC\n");
252
253 return 0;
254}
255
260{
261 if (nc->event_type != NT_WINDOW)
262 return 0;
263 if (!nc->global_data)
264 return -1;
265
266 struct MuttWindow *win_ibar = nc->global_data;
267 struct EventWindow *ev_w = nc->event_data;
268 if (ev_w->win != win_ibar)
269 return 0;
270
272 {
273 win_ibar->actions |= WA_REPAINT;
274 mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
275 }
276 else if (nc->event_subtype == NT_WINDOW_DELETE)
277 {
278 struct MuttWindow *dlg = window_find_parent(win_ibar, WT_DLG_INDEX);
279 struct IndexSharedData *shared = dlg->wdata;
280
286
287 mutt_debug(LL_DEBUG5, "window delete done\n");
288 }
289
290 return 0;
291}
292
296static void ibar_data_free(struct MuttWindow *win, void **ptr)
297{
298 struct IBarPrivateData *ibar_data = *ptr;
299
300 FREE(&ibar_data->status_format);
301 FREE(&ibar_data->ts_status_format);
302 FREE(&ibar_data->ts_icon_format);
303
304 FREE(ptr);
305}
306
314 struct IndexPrivateData *priv)
315{
316 struct IBarPrivateData *ibar_data = mutt_mem_calloc(1, sizeof(struct IBarPrivateData));
317
318 ibar_data->shared = shared;
319 ibar_data->priv = priv;
320
321 return ibar_data;
322}
323
331struct MuttWindow *ibar_new(struct MuttWindow *parent, struct IndexSharedData *shared,
332 struct IndexPrivateData *priv)
333{
337
338 win_ibar->wdata = ibar_data_new(shared, priv);
339 win_ibar->wdata_free = ibar_data_free;
340 win_ibar->recalc = ibar_recalc;
341 win_ibar->repaint = ibar_repaint;
342
348
349 return win_ibar;
350}
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
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void mutt_draw_statusline(struct MuttWindow *win, int cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:916
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
static int ibar_menu_observer(struct NotifyCallback *nc)
Notification that a Menu has changed - Implements observer_t -.
Definition: ibar.c:242
static int ibar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: ibar.c:259
static int ibar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: ibar.c:192
static int ibar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: ibar.c:166
static int ibar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition: ibar.c:227
static int ibar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: ibar.c:89
static int ibar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: ibar.c:138
static void ibar_data_free(struct MuttWindow *win, void **ptr)
Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -.
Definition: ibar.c:296
Convenience wrapper for the gui headers.
static struct IBarPrivateData * ibar_data_new(struct IndexSharedData *shared, struct IndexPrivateData *priv)
Free the private data attached to the MuttWindow.
Definition: ibar.c:313
struct MuttWindow * ibar_new(struct MuttWindow *parent, struct IndexSharedData *shared, struct IndexPrivateData *priv)
Create the Index Bar (status)
Definition: ibar.c:331
Data shared between Index, Pager and Sidebar.
@ 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
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:567
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 * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
Definition: mutt_window.c:547
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
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:242
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_DLG_INDEX
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
@ 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_MENU
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:51
@ 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
Private state data for the Pager.
void menu_status_line(char *buf, size_t buflen, struct IndexSharedData *shared, struct Menu *menu, int cols, const char *fmt)
Create the status line.
Definition: status.c:445
GUI display a user-configurable status line.
Key value store.
#define NONULL(x)
Definition: string2.h:37
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: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
Data to draw the Index Bar.
Definition: ibar.c:78
char * ts_icon_format
Cached terminal icon string.
Definition: ibar.c:83
struct IndexSharedData * shared
Shared Index data.
Definition: ibar.c:79
char * ts_status_format
Cached terminal status string.
Definition: ibar.c:82
char * status_format
Cached screen status string.
Definition: ibar.c:81
struct IndexPrivateData * priv
Private Index data.
Definition: ibar.c:80
Private state data for the Index.
Definition: private_data.h:35
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:42
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:43
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)
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
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
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 cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
bool TsSupported
Terminal Setting is supported.
Definition: terminal.c:41
void mutt_ts_icon(char *str)
Set the icon in the terminal title bar.
Definition: terminal.c:115
void mutt_ts_status(char *str)
Set the text of the terminal title bar.
Definition: terminal.c:101