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

Window management. More...

#include "config.h"
#include <stdarg.h>
#include <string.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "mutt_window.h"
#include "curs_lib.h"
#include "mutt_curses.h"
#include "options.h"
#include "reflow.h"
#include "rootwin.h"
+ Include dependency graph for mutt_window.c:

Go to the source code of this file.

Functions

static bool window_was_visible (struct MuttWindow *win)
 Was the Window visible? More...
 
static void window_notify (struct MuttWindow *win)
 Notify observers of changes to a Window. More...
 
void window_notify_all (struct MuttWindow *win)
 Notify observers of changes to a Window and its children. More...
 
void window_set_visible (struct MuttWindow *win, bool visible)
 Set a Window visible or hidden. More...
 
struct MuttWindowmutt_window_new (enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
 Create a new Window. More...
 
void mutt_window_free (struct MuttWindow **ptr)
 Free a Window and its children. More...
 
void mutt_window_clearline (struct MuttWindow *win, int row)
 Clear a row of a Window. More...
 
void mutt_window_clrtoeol (struct MuttWindow *win)
 Clear to the end of the line. More...
 
void mutt_window_get_coords (struct MuttWindow *win, int *col, int *row)
 Get the cursor position in the Window. More...
 
int mutt_window_move (struct MuttWindow *win, int col, int row)
 Move the cursor in a Window. More...
 
int mutt_window_mvaddstr (struct MuttWindow *win, int col, int row, const char *str)
 Move the cursor and write a fixed string to a Window. More...
 
int mutt_window_mvprintw (struct MuttWindow *win, int col, int row, const char *fmt,...)
 Move the cursor and write a formatted string to a Window. More...
 
void mutt_window_reflow (struct MuttWindow *win)
 Resize a Window and its children. More...
 
int mutt_window_wrap_cols (int width, short wrap)
 Calculate the wrap column for a given screen width. More...
 
int mutt_window_addch (struct MuttWindow *win, int ch)
 Write one character to a Window. More...
 
int mutt_window_addnstr (struct MuttWindow *win, const char *str, int num)
 Write a partial string to a Window. More...
 
int mutt_window_addstr (struct MuttWindow *win, const char *str)
 Write a string to a Window. More...
 
int mutt_window_printf (struct MuttWindow *win, const char *fmt,...)
 Write a formatted string to a Window. More...
 
void mutt_window_add_child (struct MuttWindow *parent, struct MuttWindow *child)
 Add a child to Window. More...
 
struct MuttWindowmutt_window_remove_child (struct MuttWindow *parent, struct MuttWindow *child)
 Remove a child from a Window. More...
 
void mutt_winlist_free (struct MuttWindowList *head)
 Free a tree of Windows. More...
 
bool mutt_window_is_visible (struct MuttWindow *win)
 Is the Window visible? More...
 
struct MuttWindowwindow_find_child (struct MuttWindow *win, enum WindowType type)
 Recursively find a child Window of a given type. More...
 
struct MuttWindowwindow_find_parent (struct MuttWindow *win, enum WindowType type)
 Find a (grand-)parent of a Window by type. More...
 
static void window_recalc (struct MuttWindow *win)
 Recalculate a tree of Windows. More...
 
static void window_repaint (struct MuttWindow *win)
 Repaint a tree of Windows. More...
 
void window_redraw (struct MuttWindow *win)
 Reflow, recalc and repaint a tree of Windows. More...
 
bool window_is_focused (struct MuttWindow *win)
 Does the given Window have the focus? More...
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focussed Window. More...
 
struct MuttWindowwindow_set_focus (struct MuttWindow *win)
 Set the Window focus. More...
 
void mutt_window_clear (struct MuttWindow *win)
 Clear a Window. More...
 
const char * mutt_window_win_name (const struct MuttWindow *win)
 Get the name of a Window. More...
 
static void window_invalidate (struct MuttWindow *win)
 Mark a window as in need of repaint. More...
 
void window_invalidate_all (void)
 Mark all windows as in need of repaint. More...
 
bool window_status_on_top (struct MuttWindow *panel, struct ConfigSubset *sub)
 Organise windows according to config variable. More...
 

Variables

static const struct Mapping WindowNames []
 Lookups for Window Names. More...
 

Detailed Description

Window management.

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 mutt_window.c.

Function Documentation

◆ window_was_visible()

static bool window_was_visible ( struct MuttWindow win)
static

Was the Window visible?

Parameters
winWindow
Return values
trueThe Window was visible

Using the WindowState old, check if a Window used to be visible. For a Window to be visible, it must have been visible and its parent and grandparent, etc.

Definition at line 86 of file mutt_window.c.

87 {
88  if (!win)
89  return false;
90 
91  for (; win; win = win->parent)
92  {
93  if (!win->old.visible)
94  return false;
95  }
96 
97  return true;
98 }
bool visible
Window is visible.
Definition: mutt_window.h:59
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
+ Here is the caller graph for this function:

◆ window_notify()

static void window_notify ( struct MuttWindow win)
static

Notify observers of changes to a Window.

Parameters
winWindow

Definition at line 104 of file mutt_window.c.

105 {
106  if (!win->notify)
107  return;
108 
109  const struct WindowState *old = &win->old;
110  const struct WindowState *state = &win->state;
112 
113  const bool was_visible = window_was_visible(win);
114  const bool is_visible = mutt_window_is_visible(win);
115  if (was_visible != is_visible)
116  flags |= is_visible ? WN_VISIBLE : WN_HIDDEN;
117 
118  if ((state->row_offset != old->row_offset) || (state->col_offset != old->col_offset))
119  flags |= WN_MOVED;
120 
121  if (state->rows > old->rows)
122  flags |= WN_TALLER;
123  else if (state->rows < old->rows)
124  flags |= WN_SHORTER;
125 
126  if (state->cols > old->cols)
127  flags |= WN_WIDER;
128  else if (state->cols < old->cols)
129  flags |= WN_NARROWER;
130 
131  if (flags == WN_NO_FLAGS)
132  return;
133 
134  mutt_debug(LL_NOTIFY, "NT_WINDOW_STATE: %s, %p\n", mutt_window_win_name(win), win);
135  struct EventWindow ev_w = { win, flags };
137 }
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:190
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:132
static bool window_was_visible(struct MuttWindow *win)
Was the Window visible?
Definition: mutt_window.c:86
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:186
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:189
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
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
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:187
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
uint8_t WindowNotifyFlags
Changes to a MuttWindow.
Definition: mutt_window.h:185
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:188
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
The current, or old, state of a Window.
Definition: mutt_window.h:57
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
#define WN_MOVED
Window moved.
Definition: mutt_window.h:191
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_notify_all()

void window_notify_all ( struct MuttWindow win)

Notify observers of changes to a Window and its children.

Parameters
winWindow

Definition at line 143 of file mutt_window.c.

144 {
145  if (!win)
146  win = RootWindow;
147 
148  window_notify(win);
149 
150  struct MuttWindow *np = NULL;
151  TAILQ_FOREACH(np, &win->children, entries)
152  {
153  window_notify_all(np);
154  }
155  win->old = win->state;
156 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:104
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:143
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_set_visible()

void window_set_visible ( struct MuttWindow win,
bool  visible 
)

Set a Window visible or hidden.

Parameters
winWindow
visibleIf true, make Window visible, otherwise hidden

Definition at line 163 of file mutt_window.c.

164 {
165  if (!win)
166  win = RootWindow;
167 
168  win->state.visible = visible;
169 }
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
+ Here is the caller graph for this function:

◆ mutt_window_new()

struct MuttWindow* mutt_window_new ( enum WindowType  type,
enum MuttWindowOrientation  orient,
enum MuttWindowSize  size,
int  cols,
int  rows 
)

Create a new Window.

Parameters
typeWindow type, e.g. WT_ROOT
orientWindow orientation, e.g. MUTT_WIN_ORIENT_VERTICAL
sizeWindow size, e.g. MUTT_WIN_SIZE_MAXIMISE
colsInitial number of columns to allocate, can be MUTT_WIN_SIZE_UNLIMITED
rowsInitial number of rows to allocate, can be MUTT_WIN_SIZE_UNLIMITED
Return values
ptrNew Window

Definition at line 180 of file mutt_window.c.

182 {
183  struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow));
184 
185  win->type = type;
186  win->orient = orient;
187  win->size = size;
188  win->req_rows = rows;
189  win->req_cols = cols;
190  win->state.visible = true;
191  win->notify = notify_new();
192  TAILQ_INIT(&win->children);
193  return win;
194 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
#define TAILQ_INIT(head)
Definition: queue.h:765
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
short req_rows
Number of rows required.
Definition: mutt_window.h:125
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
short req_cols
Number of columns required.
Definition: mutt_window.h:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_free()

void mutt_window_free ( struct MuttWindow **  ptr)

Free a Window and its children.

Parameters
ptrWindow to free

Definition at line 200 of file mutt_window.c.

201 {
202  if (!ptr || !*ptr)
203  return;
204 
205  struct MuttWindow *win = *ptr;
206 
207  if (win->parent && (win->parent->focus == win))
208  win->parent->focus = NULL;
209 
210  mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win), win);
211  struct EventWindow ev_w = { win, WN_NO_FLAGS };
213 
215 
216  if (win->wdata_free && win->wdata)
217  win->wdata_free(win, &win->wdata); // Custom function to free private data
218 
219  notify_free(&win->notify);
220 
221  FREE(ptr);
222 }
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:186
Window is about to be deleted.
Definition: mutt_window.h:206
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:506
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
#define FREE(x)
Definition: memory.h:40
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
void * wdata
Private data.
Definition: mutt_window.h:145
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clearline()

void mutt_window_clearline ( struct MuttWindow win,
int  row 
)

Clear a row of a Window.

Parameters
winWindow
rowRow to clear

Definition at line 247 of file mutt_window.c.

248 {
249  mutt_window_move(win, 0, row);
251 }
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:259
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clrtoeol()

void mutt_window_clrtoeol ( struct MuttWindow win)

Clear to the end of the line.

Parameters
winWindow
Note
Assumes the cursor has already been positioned within the window.

Definition at line 259 of file mutt_window.c.

260 {
261  if (!win || !stdscr)
262  return;
263 
264  if ((win->state.col_offset + win->state.cols) == COLS)
265  clrtoeol();
266  else
267  {
268  int row = 0;
269  int col = 0;
270  getyx(stdscr, row, col);
271  int curcol = col;
272  while (curcol < (win->state.col_offset + win->state.cols))
273  {
274  addch(' ');
275  curcol++;
276  }
277  move(row, col);
278  }
279 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
+ Here is the caller graph for this function:

◆ mutt_window_get_coords()

void mutt_window_get_coords ( struct MuttWindow win,
int *  col,
int *  row 
)

Get the cursor position in the Window.

Parameters
[in]winWindow
[out]colColumn in Window
[out]rowRow in Window

Assumes the current position is inside the window. Otherwise it will happily return negative or values outside the window boundaries

Definition at line 290 of file mutt_window.c.

291 {
292  int x = 0;
293  int y = 0;
294 
295  getyx(stdscr, y, x);
296  if (col)
297  *col = x - win->state.col_offset;
298  if (row)
299  *row = y - win->state.row_offset;
300 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
+ Here is the caller graph for this function:

◆ mutt_window_move()

int mutt_window_move ( struct MuttWindow win,
int  col,
int  row 
)

Move the cursor in a Window.

Parameters
winWindow
colColumn to move to
rowRow to move to
Return values
OKSuccess
ERRError

Definition at line 310 of file mutt_window.c.

311 {
312  return move(win->state.row_offset + row, win->state.col_offset + col);
313 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
+ Here is the caller graph for this function:

◆ mutt_window_mvaddstr()

int mutt_window_mvaddstr ( struct MuttWindow win,
int  col,
int  row,
const char *  str 
)

Move the cursor and write a fixed string to a Window.

Parameters
winWindow to write to
colColumn to move to
rowRow to move to
strString to write
Return values
OKSuccess
ERRError

Definition at line 324 of file mutt_window.c.

325 {
326 #ifdef USE_SLANG_CURSES
327  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, (char *) str);
328 #else
329  return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, str);
330 #endif
331 }
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
+ Here is the caller graph for this function:

◆ mutt_window_mvprintw()

int mutt_window_mvprintw ( struct MuttWindow win,
int  col,
int  row,
const char *  fmt,
  ... 
)

Move the cursor and write a formatted string to a Window.

Parameters
winWindow to write to
colColumn to move to
rowRow to move to
fmtprintf format string
...printf arguments
Return values
numSuccess, characters written
ERRError, move failed

Definition at line 343 of file mutt_window.c.

344 {
345  int rc = mutt_window_move(win, col, row);
346  if (rc == ERR)
347  return rc;
348 
349  va_list ap;
350  va_start(ap, fmt);
351  rc = vw_printw(stdscr, fmt, ap);
352  va_end(ap);
353 
354  return rc;
355 }
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_reflow()

void mutt_window_reflow ( struct MuttWindow win)

Resize a Window and its children.

Parameters
winWindow to resize

Definition at line 361 of file mutt_window.c.

362 {
363  if (OptNoCurses)
364  return;
365 
366  if (!win)
367  win = RootWindow;
368 
369  mutt_debug(LL_DEBUG2, "entering\n");
370  window_reflow(win);
371  window_notify_all(win);
372 
373 #ifdef USE_DEBUG_WINDOW
374  debug_win_dump();
375 #endif
376 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:47
Log at debug level 2.
Definition: logging.h:41
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:143
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
void debug_win_dump(void)
Definition: window.c:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_wrap_cols()

int mutt_window_wrap_cols ( int  width,
short  wrap 
)

Calculate the wrap column for a given screen width.

Parameters
widthScreen width
wrapWrap config
Return values
numColumn that text should be wrapped at

The wrap variable can be negative, meaning there should be a right margin.

Definition at line 386 of file mutt_window.c.

387 {
388  if (wrap < 0)
389  return (width > -wrap) ? (width + wrap) : width;
390  if (wrap)
391  return (wrap < width) ? wrap : width;
392  return width;
393 }
+ Here is the caller graph for this function:

◆ mutt_window_addch()

int mutt_window_addch ( struct MuttWindow win,
int  ch 
)

Write one character to a Window.

Parameters
winWindow
chCharacter to write
Return values
0Success
-1Error

Definition at line 402 of file mutt_window.c.

403 {
404  return addch(ch);
405 }
+ Here is the caller graph for this function:

◆ mutt_window_addnstr()

int mutt_window_addnstr ( struct MuttWindow win,
const char *  str,
int  num 
)

Write a partial string to a Window.

Parameters
winWindow
strString
numMaximum number of characters to write
Return values
0Success
-1Error

Definition at line 415 of file mutt_window.c.

416 {
417  if (!str)
418  return -1;
419 
420 #ifdef USE_SLANG_CURSES
421  return addnstr((char *) str, num);
422 #else
423  return addnstr(str, num);
424 #endif
425 }
+ Here is the caller graph for this function:

◆ mutt_window_addstr()

int mutt_window_addstr ( struct MuttWindow win,
const char *  str 
)

Write a string to a Window.

Parameters
winWindow
strString
Return values
0Success
-1Error

Definition at line 434 of file mutt_window.c.

435 {
436  if (!str)
437  return -1;
438 
439 #ifdef USE_SLANG_CURSES
440  return addstr((char *) str);
441 #else
442  return addstr(str);
443 #endif
444 }
+ Here is the caller graph for this function:

◆ mutt_window_printf()

int mutt_window_printf ( struct MuttWindow win,
const char *  fmt,
  ... 
)

Write a formatted string to a Window.

Parameters
winWindow
fmtFormat string
...Arguments
Return values
numNumber of characters written

Definition at line 453 of file mutt_window.c.

454 {
455  va_list ap;
456  va_start(ap, fmt);
457  int rc = vw_printw(stdscr, fmt, ap);
458  va_end(ap);
459 
460  return rc;
461 }
+ Here is the caller graph for this function:

◆ mutt_window_add_child()

void mutt_window_add_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Add a child to Window.

Parameters
parentWindow to add to
childWindow to add

Definition at line 468 of file mutt_window.c.

469 {
470  if (!parent || !child)
471  return;
472 
473  TAILQ_INSERT_TAIL(&parent->children, child, entries);
474  child->parent = parent;
475 
476  notify_set_parent(child->notify, parent->notify);
477 
478  mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child), child);
479  struct EventWindow ev_w = { child, WN_NO_FLAGS };
480  notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
481 }
New Window has been added.
Definition: mutt_window.h:205
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:186
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_remove_child()

struct MuttWindow* mutt_window_remove_child ( struct MuttWindow parent,
struct MuttWindow child 
)

Remove a child from a Window.

Parameters
parentWindow to remove from
childWindow to remove

Definition at line 488 of file mutt_window.c.

489 {
490  if (!parent || !child)
491  return NULL;
492 
493  // A notification will be sent when the Window is freed
494  TAILQ_REMOVE(&parent->children, child, entries);
495  child->parent = NULL;
496 
497  notify_set_parent(child->notify, NULL);
498 
499  return child;
500 }
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_winlist_free()

void mutt_winlist_free ( struct MuttWindowList *  head)

Free a tree of Windows.

Parameters
headWindowList to free

Definition at line 506 of file mutt_window.c.

507 {
508  if (!head)
509  return;
510 
511  struct MuttWindow *np = NULL;
512  struct MuttWindow *tmp = NULL;
513  TAILQ_FOREACH_SAFE(np, head, entries, tmp)
514  {
515  TAILQ_REMOVE(head, np, entries);
517  mutt_window_free(&np);
518  }
519 }
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:200
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:506
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_is_visible()

bool mutt_window_is_visible ( struct MuttWindow win)

Is the Window visible?

Parameters
winWindow
Return values
trueThe Window is visible

For a Window to be visible, it must be visible and its parent and grandparent, etc.

Definition at line 529 of file mutt_window.c.

530 {
531  if (!win)
532  return false;
533 
534  for (; win; win = win->parent)
535  {
536  if (!win->state.visible)
537  return false;
538  }
539 
540  return true;
541 }
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
+ Here is the caller graph for this function:

◆ window_find_child()

struct MuttWindow* window_find_child ( struct MuttWindow win,
enum WindowType  type 
)

Recursively find a child Window of a given type.

Parameters
winWindow to start searching
typeWindow type to find, e.g. WT_STATUS_BAR
Return values
ptrMatching Window
NULLNo match

Definition at line 550 of file mutt_window.c.

551 {
552  if (!win)
553  return NULL;
554  if (win->type == type)
555  return win;
556 
557  struct MuttWindow *np = NULL;
558  struct MuttWindow *match = NULL;
559  TAILQ_FOREACH(np, &win->children, entries)
560  {
561  match = window_find_child(np, type);
562  if (match)
563  return match;
564  }
565 
566  return NULL;
567 }
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_find_parent()

struct MuttWindow* window_find_parent ( struct MuttWindow win,
enum WindowType  type 
)

Find a (grand-)parent of a Window by type.

Parameters
winWindow
typeWindow type, e.g. WT_DLG_INDEX
Return values
ptrWindow

Definition at line 575 of file mutt_window.c.

576 {
577  for (; win; win = win->parent)
578  {
579  if (win->type == type)
580  return win;
581  }
582 
583  return NULL;
584 }
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the caller graph for this function:

◆ window_recalc()

static void window_recalc ( struct MuttWindow win)
static

Recalculate a tree of Windows.

Parameters
winWindow to start at

Definition at line 590 of file mutt_window.c.

591 {
592  if (!win || !win->state.visible)
593  return;
594 
595  if (win->recalc && (win->actions & WA_RECALC))
596  win->recalc(win);
597  win->actions &= ~WA_RECALC;
598 
599  struct MuttWindow *np = NULL;
600  TAILQ_FOREACH(np, &win->children, entries)
601  {
602  window_recalc(np);
603  }
604 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:590
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
+ Here is the caller graph for this function:

◆ window_repaint()

static void window_repaint ( struct MuttWindow win)
static

Repaint a tree of Windows.

Parameters
winWindow to start at

Definition at line 610 of file mutt_window.c.

611 {
612  if (!win || !win->state.visible)
613  return;
614 
615  if (win->repaint && (win->actions & WA_REPAINT))
616  win->repaint(win);
617  win->actions &= ~WA_REPAINT;
618 
619  struct MuttWindow *np = NULL;
620  TAILQ_FOREACH(np, &win->children, entries)
621  {
622  window_repaint(np);
623  }
624 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:610
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool visible
Window is visible.
Definition: mutt_window.h:59
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ Here is the caller graph for this function:

◆ window_redraw()

void window_redraw ( struct MuttWindow win)

Reflow, recalc and repaint a tree of Windows.

Parameters
winWindow to start at
Note
If win is NULL, all windows will be redrawn

Definition at line 632 of file mutt_window.c.

633 {
634  if (!win)
635  win = RootWindow;
636 
637  window_reflow(win);
638  window_notify_all(win);
639 
640  window_recalc(win);
641  window_repaint(win);
642  mutt_refresh();
643 }
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:610
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:115
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:222
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:590
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:143
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_is_focused()

bool window_is_focused ( struct MuttWindow win)

Does the given Window have the focus?

Parameters
winWindow to check
Return values
trueWindow has focus

Definition at line 650 of file mutt_window.c.

651 {
652  if (!win)
653  return false;
654 
656 
657  return (win_focus == win);
658 }
static struct MuttWindow * win_focus
Definition: window.c:36
struct MuttWindow * window_get_focus(void)
Get the currently focussed Window.
Definition: mutt_window.c:664
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_get_focus()

struct MuttWindow* window_get_focus ( void  )

Get the currently focussed Window.

Return values
ptrWindow with focus

Definition at line 664 of file mutt_window.c.

665 {
666  struct MuttWindow *win = RootWindow;
667 
668  while (win && win->focus)
669  win = win->focus;
670 
671  return win;
672 }
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
+ Here is the caller graph for this function:

◆ window_set_focus()

struct MuttWindow* window_set_focus ( struct MuttWindow win)

Set the Window focus.

Parameters
winWindow to focus
Return values
ptrOld focussed Window
NULLError, or focus not changed

Definition at line 680 of file mutt_window.c.

681 {
682  if (!win)
683  return NULL;
684 
685  struct MuttWindow *old_focus = window_get_focus();
686 
687  struct MuttWindow *parent = win->parent;
688  struct MuttWindow *child = win;
689 
690  // Set the chain of focus, all the way to the root
691  for (; parent; child = parent, parent = parent->parent)
692  parent->focus = child;
693 
694  // Find the most focussed Window
695  while (win && win->focus)
696  win = win->focus;
697 
698  if (win == old_focus)
699  return NULL;
700 
701  mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win), win);
702  struct EventWindow ev_w = { win, WN_NO_FLAGS };
704 #ifdef USE_DEBUG_WINDOW
705  debug_win_dump();
706 #endif
707  return old_focus;
708 }
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Log of notifications.
Definition: logging.h:45
An Event that happened to a Window.
Definition: mutt_window.h:215
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:186
Window focus has changed.
Definition: mutt_window.h:209
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
struct MuttWindow * focus
Focussed Window.
Definition: mutt_window.h:140
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * window_get_focus(void)
Get the currently focussed Window.
Definition: mutt_window.c:664
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
void debug_win_dump(void)
Definition: window.c:91
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:731
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_clear()

void mutt_window_clear ( struct MuttWindow win)

Clear a Window.

Parameters
winWindow

If the Window isn't visible, it won't be cleared.

Definition at line 716 of file mutt_window.c.

717 {
718  if (!mutt_window_is_visible(win))
719  return;
720 
721  for (int i = 0; i < win->state.rows; i++)
722  mutt_window_clearline(win, i);
723 }
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:247
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:529
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_win_name()

const char* mutt_window_win_name ( const struct MuttWindow win)

Get the name of a Window.

Parameters
winWindow
Return values
ptrString describing Window
NULLError, or unknown

Definition at line 731 of file mutt_window.c.

732 {
733  if (!win)
734  return "UNKNOWN";
735 
736  const char *name = mutt_map_get_name(win->type, WindowNames);
737  if (name)
738  return name;
739  return "UNKNOWN";
740 }
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
static const struct Mapping WindowNames[]
Lookups for Window Names.
Definition: mutt_window.c:45
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_invalidate()

static void window_invalidate ( struct MuttWindow win)
static

Mark a window as in need of repaint.

Parameters
winWindow to start at

Definition at line 746 of file mutt_window.c.

747 {
748  if (!win)
749  return;
750 
751  win->actions |= WA_REPAINT;
752 
753  struct MuttWindow *np = NULL;
754  TAILQ_FOREACH(np, &win->children, entries)
755  {
756  window_invalidate(np);
757  }
758 }
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:746
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ Here is the caller graph for this function:

◆ window_invalidate_all()

void window_invalidate_all ( void  )

Mark all windows as in need of repaint.

Definition at line 763 of file mutt_window.c.

764 {
766  clearok(stdscr, true);
767  keypad(stdscr, true);
768 }
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:746
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:105
+ Here is the call graph for this function:

◆ window_status_on_top()

bool window_status_on_top ( struct MuttWindow panel,
struct ConfigSubset sub 
)

Organise windows according to config variable.

Parameters
panelWindow containing WT_MENU and WT_STATUS_BAR
subConfig Subset
Return values
trueWindow order was changed

Set the positions of two Windows based on a config variable $status_on_top.

Note
The children are expected to have types: WT_MENU, WT_STATUS_BAR

Definition at line 780 of file mutt_window.c.

781 {
782  const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
783 
784  struct MuttWindow *win_first = TAILQ_FIRST(&panel->children);
785 
786  if ((c_status_on_top && (win_first->type == WT_STATUS_BAR)) ||
787  (!c_status_on_top && (win_first->type != WT_STATUS_BAR)))
788  {
789  return false;
790  }
791 
792  TAILQ_REMOVE(&panel->children, win_first, entries);
793  TAILQ_INSERT_TAIL(&panel->children, win_first, entries);
794 
795  mutt_window_reflow(panel);
796  mutt_debug(LL_DEBUG5, "config done, request WA_REFLOW\n");
797  return true;
798 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define TAILQ_FIRST(head)
Definition: queue.h:723
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:361
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
Log at debug level 5.
Definition: logging.h:44
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:144
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ WindowNames

const struct Mapping WindowNames[]
static

Lookups for Window Names.

Definition at line 45 of file mutt_window.c.