NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
sbar.c
Go to the documentation of this file.
1 
65 #include "config.h"
66 #include "mutt/lib.h"
67 #include "core/lib.h"
68 #include "lib.h"
69 
74 {
75  char *display;
76 };
77 
81 static int sbar_recalc(struct MuttWindow *win)
82 {
83  if (!win)
84  return -1;
85 
86  win->actions |= WA_REPAINT;
87  mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
88  return 0;
89 }
90 
94 static int sbar_repaint(struct MuttWindow *win)
95 {
96  if (!mutt_window_is_visible(win))
97  return 0;
98 
99  struct SBarPrivateData *priv = win->wdata;
100 
101  mutt_window_move(win, 0, 0);
102 
104  mutt_window_move(win, 0, 0);
105  mutt_paddstr(win, win->state.cols, priv->display);
107 
108  mutt_debug(LL_DEBUG5, "repaint done\n");
109  return 0;
110 }
111 
118 static int sbar_color_observer(struct NotifyCallback *nc)
119 {
120  if ((nc->event_type != NT_COLOR) || !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->color != MT_COLOR_STATUS) && (ev_c->color != MT_COLOR_MAX))
127  return 0;
128 
129  struct MuttWindow *win_sbar = nc->global_data;
130 
131  win_sbar->actions |= WA_REPAINT;
132  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
133 
134  return 0;
135 }
136 
145 static int sbar_window_observer(struct NotifyCallback *nc)
146 {
147  if ((nc->event_type != NT_WINDOW) || !nc->global_data || !nc->event_data)
148  return -1;
149 
150  struct MuttWindow *win_sbar = nc->global_data;
151  struct EventWindow *ev_w = nc->event_data;
152  if (ev_w->win != win_sbar)
153  return 0;
154 
155  if (nc->event_subtype == NT_WINDOW_STATE)
156  {
157  win_sbar->actions |= WA_REPAINT;
158  mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
159  }
160  else if (nc->event_subtype == NT_WINDOW_DELETE)
161  {
163  notify_observer_remove(win_sbar->notify, sbar_window_observer, win_sbar);
164  mutt_debug(LL_DEBUG5, "window delete done\n");
165  }
166 
167  return 0;
168 }
169 
173 static void sbar_wdata_free(struct MuttWindow *win, void **ptr)
174 {
175  struct SBarPrivateData *priv = *ptr;
176 
177  FREE(&priv->display);
178 
179  FREE(ptr);
180 }
181 
185 static struct SBarPrivateData *sbar_data_new(void)
186 {
187  struct SBarPrivateData *sbar_data = mutt_mem_calloc(1, sizeof(struct SBarPrivateData));
188 
189  return sbar_data;
190 }
191 
198 {
199  struct MuttWindow *win_sbar =
202 
203  win_sbar->wdata = sbar_data_new();
204  win_sbar->wdata_free = sbar_wdata_free;
205  win_sbar->recalc = sbar_recalc;
206  win_sbar->repaint = sbar_repaint;
207 
210 
211  return win_sbar;
212 }
213 
221 void sbar_set_title(struct MuttWindow *win, const char *title)
222 {
223  if (!win || !win->wdata || (win->type != WT_STATUS_BAR))
224  return;
225 
226  struct SBarPrivateData *priv = win->wdata;
227  mutt_str_replace(&priv->display, title);
228 
229  win->actions |= WA_REPAINT;
230 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
static int sbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: sbar.c:145
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
Data passed to a notification function.
Definition: observer.h:39
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Colour.
Definition: color.h:122
An Event that happened to a Window.
Definition: mutt_window.h:215
Window uses all available vertical space.
Definition: mutt_window.h:38
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
struct MuttWindow * sbar_new(struct MuttWindow *parent)
Add the Simple Bar (status)
Definition: sbar.c:197
Window is about to be deleted.
Definition: mutt_window.h:206
char * display
Cached display string.
Definition: sbar.c:75
static int sbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: sbar.c:94
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Convenience wrapper for the core headers.
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window has a fixed size.
Definition: mutt_window.h:47
Plain text.
Definition: color.h:58
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
static int sbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: sbar.c:81
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
Status bar (takes a pattern)
Definition: color.h:75
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
static int sbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: sbar.c:118
enum ColorId color
Definition: color.h:124
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:173
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
Private data for the Simple Bar.
Definition: sbar.c:73
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
#define FREE(x)
Definition: memory.h:40
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
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:180
Log at debug level 5.
Definition: logging.h:44
Convenience wrapper for the library headers.
void * wdata
Private data.
Definition: mutt_window.h:145
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
static struct SBarPrivateData * sbar_data_new(void)
Free the private data attached to the MuttWindow.
Definition: sbar.c:185
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:890