NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
ibar.c File Reference

Index Bar (status) More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "private_data.h"
#include "shared_data.h"
#include "status.h"
+ Include dependency graph for ibar.c:

Go to the source code of this file.

Data Structures

struct  IBarPrivateData
 Data to draw the Index Bar. More...
 

Functions

static int ibar_recalc (struct MuttWindow *win)
 Recalculate the Window data - Implements MuttWindow::recalc() -. More...
 
static int ibar_repaint (struct MuttWindow *win)
 Repaint the Window - Implements MuttWindow::repaint() -. More...
 
static int ibar_color_observer (struct NotifyCallback *nc)
 Notification that a Color has changed - Implements observer_t. More...
 
static int ibar_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t. More...
 
static int ibar_index_observer (struct NotifyCallback *nc)
 Notification that the Index has changed - Implements observer_t. More...
 
static int ibar_menu_observer (struct NotifyCallback *nc)
 Notification that a Menu has changed - Implements observer_t. More...
 
static int ibar_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t. More...
 
static void ibar_data_free (struct MuttWindow *win, void **ptr)
 Free the private data attached to the MuttWindow - Implements MuttWindow::wdata_free() -. More...
 
static struct IBarPrivateDataibar_data_new (struct IndexSharedData *shared, struct IndexPrivateData *priv)
 Free the private data attached to the MuttWindow. More...
 
struct MuttWindowibar_new (struct MuttWindow *parent, struct IndexSharedData *shared, struct IndexPrivateData *priv)
 Create the Index Bar (status) More...
 

Detailed Description

Index Bar (status)

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file ibar.c.

Function Documentation

◆ ibar_color_observer()

static int ibar_color_observer ( struct NotifyCallback nc)
static

Notification that a Color has changed - Implements observer_t.

Definition at line 172 of file ibar.c.

173 {
174  if ((nc->event_type != NT_COLOR) || !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->color != MT_COLOR_STATUS) && (ev_c->color != MT_COLOR_MAX))
181  return 0;
182 
183  struct MuttWindow *win_ibar = nc->global_data;
184  win_ibar->actions |= WA_REPAINT;
185  mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
186 
187  return 0;
188 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
An Event that happened to a Colour.
Definition: color.h:122
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
Status bar (takes a pattern)
Definition: color.h:75
enum ColorId color
Definition: color.h:124
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
+ Here is the caller graph for this function:

◆ ibar_config_observer()

static int ibar_config_observer ( struct NotifyCallback nc)
static

Notification that a Config Variable has changed - Implements observer_t.

Definition at line 193 of file ibar.c.

194 {
195  if ((nc->event_type != NT_CONFIG) || !nc->global_data || !nc->event_data)
196  return -1;
197 
198  struct EventConfig *ev_c = nc->event_data;
199  if ((ev_c->name[0] != 's') && (ev_c->name[0] != 't'))
200  return 0;
201 
202  if (!mutt_str_equal(ev_c->name, "status_format") &&
203  !mutt_str_equal(ev_c->name, "ts_enabled") &&
204  !mutt_str_equal(ev_c->name, "ts_icon_format") &&
205  !mutt_str_equal(ev_c->name, "ts_status_format"))
206  {
207  return 0;
208  }
209 
210  struct MuttWindow *win_ibar = nc->global_data;
211  win_ibar->actions |= WA_RECALC;
212  mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
213 
214  return 0;
215 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
A config-change event.
Definition: subset.h:69
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
Log at debug level 5.
Definition: logging.h:44
const char * name
Name of config item that changed.
Definition: subset.h:72
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ibar_index_observer()

static int ibar_index_observer ( struct NotifyCallback nc)
static

Notification that the Index has changed - Implements observer_t.

Definition at line 220 of file ibar.c.

221 {
222  if ((nc->event_type != NT_INDEX) || !nc->global_data)
223  return -1;
224 
225  struct MuttWindow *win_ibar = nc->global_data;
226  if (!win_ibar)
227  return 0;
228 
229  struct IndexSharedData *shared = nc->event_data;
230  if (!shared)
231  return 0;
232 
234  {
235  win_ibar->actions |= WA_RECALC;
236  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
237  }
238 
239  if (nc->event_subtype & NT_INDEX_EMAIL)
240  {
241  win_ibar->actions |= WA_RECALC;
242  mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
243  }
244 
245  return 0;
246 }
#define NT_INDEX_EMAIL
Email has changed.
Definition: lib.h:65
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
#define NT_INDEX_MAILBOX
Mailbox has changed.
Definition: lib.h:64
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
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void * event_data
Data from notify_send()
Definition: observer.h:44
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ ibar_menu_observer()

static int ibar_menu_observer ( struct NotifyCallback nc)
static

Notification that a Menu has changed - Implements observer_t.

Definition at line 251 of file ibar.c.

252 {
253  if ((nc->event_type != NT_MENU) || !nc->global_data)
254  return -1;
255 
256  struct MuttWindow *win_ibar = nc->global_data;
257  win_ibar->actions |= WA_RECALC;
258  mutt_debug(LL_DEBUG5, "menu done, request WA_RECALC\n");
259 
260  return 0;
261 }
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:49
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 5.
Definition: logging.h:44
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ ibar_window_observer()

static int ibar_window_observer ( struct NotifyCallback nc)
static

Notification that a Window has changed - Implements observer_t.

Definition at line 266 of file ibar.c.

267 {
268  if ((nc->event_type != NT_WINDOW) || !nc->global_data)
269  return -1;
270 
271  struct MuttWindow *win_ibar = nc->global_data;
272  struct EventWindow *ev_w = nc->event_data;
273  if (ev_w->win != win_ibar)
274  return 0;
275 
276  if (nc->event_subtype == NT_WINDOW_STATE)
277  {
278  win_ibar->actions |= WA_REPAINT;
279  mutt_debug(LL_DEBUG5, "window state done, request WA_REPAINT\n");
280  }
281  else if (nc->event_subtype == NT_WINDOW_DELETE)
282  {
283  struct MuttWindow *dlg = window_find_parent(win_ibar, WT_DLG_INDEX);
284  struct IndexSharedData *shared = dlg->wdata;
285 
290  notify_observer_remove(win_ibar->notify, ibar_window_observer, win_ibar);
291 
292  mutt_debug(LL_DEBUG5, "window delete done\n");
293  }
294 
295  return 0;
296 }
static int ibar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: ibar.c:266
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
An Event that happened to a Window.
Definition: mutt_window.h:215
Window is about to be deleted.
Definition: mutt_window.h:206
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
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
void * global_data
Data from notify_observer_add()
Definition: observer.h:45
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
struct MuttWindow * window_find_parent(struct MuttWindow *win, enum WindowType type)
Find a (grand-)parent of a Window by type.
Definition: mutt_window.c:575
static int ibar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: ibar.c:172
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
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
static int ibar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: ibar.c:220
bool notify_observer_remove(struct Notify *notify, observer_t callback, void *global_data)
Remove an observer from an object.
Definition: notify.c:228
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
Log at debug level 5.
Definition: logging.h:44
void * wdata
Private data.
Definition: mutt_window.h:145
static int ibar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: ibar.c:193
static int ibar_menu_observer(struct NotifyCallback *nc)
Notification that a Menu has changed - Implements observer_t.
Definition: ibar.c:251
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ibar_data_new()

static struct IBarPrivateData* ibar_data_new ( struct IndexSharedData shared,
struct IndexPrivateData priv 
)
static

Free the private data attached to the MuttWindow.

Definition at line 315 of file ibar.c.

317 {
318  struct IBarPrivateData *ibar_data = mutt_mem_calloc(1, sizeof(struct IBarPrivateData));
319 
320  ibar_data->shared = shared;
321  ibar_data->priv = priv;
322 
323  return ibar_data;
324 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct IndexSharedData * shared
Shared Index data.
Definition: ibar.c:80
struct IndexPrivateData * priv
Private Index data.
Definition: ibar.c:81
Data to draw the Index Bar.
Definition: ibar.c:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ibar_new()

struct MuttWindow* ibar_new ( struct MuttWindow parent,
struct IndexSharedData shared,
struct IndexPrivateData priv 
)

Create the Index Bar (status)

Parameters
parentParent Window
sharedShared Index data
privPrivate Index data
Return values
ptrNew Index Bar

Definition at line 333 of file ibar.c.

335 {
336  struct MuttWindow *win_ibar =
339 
340  win_ibar->wdata = ibar_data_new(shared, priv);
341  win_ibar->wdata_free = ibar_data_free;
342  win_ibar->recalc = ibar_recalc;
343  win_ibar->repaint = ibar_repaint;
344 
350 
351  return win_ibar;
352 }
static int ibar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: ibar.c:266
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
static int ibar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: ibar.c:141
Window uses all available vertical space.
Definition: mutt_window.h:38
Menu has changed, MenuRedrawFlags.
Definition: notify_type.h:49
static struct IBarPrivateData * ibar_data_new(struct IndexSharedData *shared, struct IndexPrivateData *priv)
Free the private data attached to the MuttWindow.
Definition: ibar.c:315
Container for Accounts, Notifications.
Definition: neomutt.h:36
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
Index data has changed, NotifyIndex, IndexSharedData.
Definition: notify_type.h:47
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h: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:301
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
Window has a fixed size.
Definition: mutt_window.h:47
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:39
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
static int ibar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: ibar.c:90
static int ibar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t.
Definition: ibar.c:172
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
static int ibar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t.
Definition: ibar.c:220
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
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
void * wdata
Private data.
Definition: mutt_window.h:145
static int ibar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: ibar.c:193
static int ibar_menu_observer(struct NotifyCallback *nc)
Notification that a Menu has changed - Implements observer_t.
Definition: ibar.c:251
+ Here is the call graph for this function:
+ Here is the caller graph for this function: