NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
sbar.c
Go to the documentation of this file.
1
63#include "config.h"
64#include "mutt/lib.h"
65#include "sbar.h"
66#include "color/lib.h"
67#include "curs_lib.h"
68#include "mutt_curses.h"
69#include "mutt_window.h"
70
75{
76 char *display;
77};
78
82static int sbar_recalc(struct MuttWindow *win)
83{
84 if (!win)
85 return -1;
86
87 win->actions |= WA_REPAINT;
88 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
89 return 0;
90}
91
95static int sbar_repaint(struct MuttWindow *win)
96{
97 struct SBarPrivateData *priv = win->wdata;
98
99 mutt_window_move(win, 0, 0);
100
102 mutt_window_move(win, 0, 0);
103 mutt_paddstr(win, win->state.cols, priv->display);
105
106 mutt_debug(LL_DEBUG5, "repaint done\n");
107 return 0;
108}
109
117{
118 if (nc->event_type != NT_COLOR)
119 return 0;
120 if (!nc->global_data)
121 return -1;
122
123 struct EventColor *ev_c = nc->event_data;
124
125 // MT_COLOR_MAX is sent on `uncolor *`
126 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
127 (ev_c->cid != MT_COLOR_MAX))
128 {
129 return 0;
130 }
131
132 struct MuttWindow *win_sbar = nc->global_data;
133
134 win_sbar->actions |= WA_REPAINT;
135 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
136
137 return 0;
138}
139
149{
150 if (nc->event_type != NT_WINDOW)
151 return 0;
152 if (!nc->global_data || !nc->event_data)
153 return -1;
154
155 struct MuttWindow *win_sbar = nc->global_data;
156 struct EventWindow *ev_w = nc->event_data;
157 if (ev_w->win != win_sbar)
158 return 0;
159
161 {
162 win_sbar->actions |= WA_REPAINT;
163 mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
164 }
165 else if (nc->event_subtype == NT_WINDOW_DELETE)
166 {
169 mutt_debug(LL_DEBUG5, "window delete done\n");
170 }
171
172 return 0;
173}
174
178static void sbar_wdata_free(struct MuttWindow *win, void **ptr)
179{
180 if (!ptr || !*ptr)
181 return;
182
183 struct SBarPrivateData *priv = *ptr;
184
185 FREE(&priv->display);
186
187 FREE(ptr);
188}
189
194static struct SBarPrivateData *sbar_data_new(void)
195{
196 return MUTT_MEM_CALLOC(1, struct SBarPrivateData);
197}
198
203struct MuttWindow *sbar_new(void)
204{
208
209 win_sbar->wdata = sbar_data_new();
210 win_sbar->wdata_free = sbar_wdata_free;
211 win_sbar->recalc = sbar_recalc;
212 win_sbar->repaint = sbar_repaint;
213
216
217 return win_sbar;
218}
219
227void sbar_set_title(struct MuttWindow *win, const char *title)
228{
229 if (!win || !win->wdata || (win->type != WT_STATUS_BAR))
230 return;
231
232 struct SBarPrivateData *priv = win->wdata;
233 mutt_str_replace(&priv->display, title);
234
235 win->actions |= WA_REPAINT;
236}
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_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:341
GUI miscellaneous curses (window drawing) routines.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int sbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: sbar.c:116
static int sbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: sbar.c:148
static int sbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: sbar.c:82
static int sbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: sbar.c:95
static void sbar_wdata_free(struct MuttWindow *win, void **ptr)
Free the private data of the Simple Bar - Implements MuttWindow::wdata_free() -.
Definition: sbar.c:178
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define FREE(x)
Definition: memory.h:55
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
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
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
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
Define wrapper functions around Curses.
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:296
Window management.
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:101
@ 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: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
#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:57
@ 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:203
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:227
static struct SBarPrivateData * sbar_data_new(void)
Create the private data for the Simple Bar.
Definition: sbar.c:194
Simple Bar.
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:238
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:239
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:186
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:126
void * wdata
Private data.
Definition: mutt_window.h:144
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:172
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:158
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:131
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:143
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:75
char * display
Cached display string.
Definition: sbar.c:76
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60