NeoMutt  2022-04-29-178-g3b62e6
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 "mutt_globals.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 (const struct MuttWindow *win)
 Does the given Window have the focus? More...
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focused 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 87 of file mutt_window.c.

88{
89 if (!win)
90 return false;
91
92 for (; win; win = win->parent)
93 {
94 if (!win->old.visible)
95 return false;
96 }
97
98 return true;
99}
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:128
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
bool visible
Window is visible.
Definition: mutt_window.h:59
+ 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 105 of file mutt_window.c.

106{
107 if (!win->notify)
108 return;
109
110 const struct WindowState *old = &win->old;
111 const struct WindowState *state = &win->state;
113
114 const bool was_visible = window_was_visible(win);
115 const bool is_visible = mutt_window_is_visible(win);
116 if (was_visible != is_visible)
117 flags |= is_visible ? WN_VISIBLE : WN_HIDDEN;
118
119 if ((state->row_offset != old->row_offset) || (state->col_offset != old->col_offset))
120 flags |= WN_MOVED;
121
122 if (state->rows > old->rows)
123 flags |= WN_TALLER;
124 else if (state->rows < old->rows)
125 flags |= WN_SHORTER;
126
127 if (state->cols > old->cols)
128 flags |= WN_WIDER;
129 else if (state->cols < old->cols)
130 flags |= WN_NARROWER;
131
132 if (flags == WN_NO_FLAGS)
133 return;
134
135 mutt_debug(LL_NOTIFY, "NT_WINDOW_STATE: %s, %p\n", mutt_window_win_name(win), win);
136 struct EventWindow ev_w = { win, flags };
138}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
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
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:131
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:501
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:710
static bool window_was_visible(struct MuttWindow *win)
Was the Window visible?
Definition: mutt_window.c:87
#define WN_MOVED
Window moved.
Definition: mutt_window.h:191
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
Definition: mutt_window.h:185
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:189
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:207
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:192
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:193
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:186
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:187
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:190
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:188
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:218
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
The current, or old, state of a Window.
Definition: mutt_window.h:58
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:63
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:62
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:

◆ 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 144 of file mutt_window.c.

145{
146 if (!win)
147 win = RootWindow;
148
149 window_notify(win);
150
151 struct MuttWindow *np = NULL;
152 TAILQ_FOREACH(np, &win->children, entries)
153 {
155 }
156 win->old = win->state;
157}
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:144
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
Definition: mutt_window.c:105
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:104
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 164 of file mutt_window.c.

165{
166 if (!win)
167 win = RootWindow;
168
169 win->state.visible = visible;
170}
+ 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 181 of file mutt_window.c.

183{
184 struct MuttWindow *win = mutt_mem_calloc(1, sizeof(struct MuttWindow));
185
186 win->type = type;
187 win->orient = orient;
188 win->size = size;
189 win->req_rows = rows;
190 win->req_cols = cols;
191 win->state.visible = true;
192 win->notify = notify_new();
193 TAILQ_INIT(&win->children);
194 return win;
195}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:60
#define TAILQ_INIT(head)
Definition: queue.h:765
short req_cols
Number of columns required.
Definition: mutt_window.h:124
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:130
short req_rows
Number of rows required.
Definition: mutt_window.h:125
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
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:

◆ mutt_window_free()

void mutt_window_free ( struct MuttWindow **  ptr)

Free a Window and its children.

Parameters
ptrWindow to free

Definition at line 201 of file mutt_window.c.

202{
203 if (!ptr || !*ptr)
204 return;
205
206 struct MuttWindow *win = *ptr;
207
208 if (win->parent && (win->parent->focus == win))
209 win->parent->focus = NULL;
210
211 mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win), win);
212 struct EventWindow ev_w = { win, WN_NO_FLAGS };
214
216
217 if (win->wdata_free && win->wdata)
218 win->wdata_free(win, &win->wdata); // Custom function to free private data
219
221
222 FREE(ptr);
223}
#define FREE(x)
Definition: memory.h:43
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:73
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:478
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:206
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:160
+ 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 230 of file mutt_window.c.

231{
232 mutt_window_move(win, 0, row);
234}
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
+ 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 242 of file mutt_window.c.

243{
244 if (!win || !stdscr)
245 return;
246
247 if ((win->state.col_offset + win->state.cols) == COLS)
248 clrtoeol();
249 else
250 {
251 int row = 0;
252 int col = 0;
253 getyx(stdscr, row, col);
254 int curcol = col;
255 while (curcol < (win->state.col_offset + win->state.cols))
256 {
257 addch(' ');
258 curcol++;
259 }
260 move(row, col);
261 }
262}
+ 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 273 of file mutt_window.c.

274{
275 int x = 0;
276 int y = 0;
277
278 getyx(stdscr, y, x);
279 if (col)
280 *col = x - win->state.col_offset;
281 if (row)
282 *row = y - win->state.row_offset;
283}
+ 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 293 of file mutt_window.c.

294{
295 return move(win->state.row_offset + row, win->state.col_offset + col);
296}
+ 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 307 of file mutt_window.c.

308{
309 return mvaddstr(win->state.row_offset + row, win->state.col_offset + col, str);
310}
+ 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 322 of file mutt_window.c.

323{
324 int rc = mutt_window_move(win, col, row);
325 if (rc == ERR)
326 return rc;
327
328 va_list ap;
329 va_start(ap, fmt);
330 rc = vw_printw(stdscr, fmt, ap);
331 va_end(ap);
332
333 return rc;
334}
+ 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 340 of file mutt_window.c.

341{
342 if (OptNoCurses)
343 return;
344
345 if (!win)
346 win = RootWindow;
347
348 mutt_debug(LL_DEBUG2, "entering\n");
349 window_reflow(win);
351
352#ifdef USE_DEBUG_WINDOW
354#endif
355}
void debug_win_dump(void)
Definition: window.c:95
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53
void window_reflow(struct MuttWindow *win)
Reflow Windows.
Definition: reflow.c:220
+ 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 365 of file mutt_window.c.

366{
367 if (wrap < 0)
368 return (width > -wrap) ? (width + wrap) : width;
369 if (wrap)
370 return (wrap < width) ? wrap : width;
371 return width;
372}
+ 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 381 of file mutt_window.c.

382{
383 return addch(ch);
384}
+ 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 394 of file mutt_window.c.

395{
396 if (!str)
397 return -1;
398
399 return addnstr(str, num);
400}
+ 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 409 of file mutt_window.c.

410{
411 if (!str)
412 return -1;
413
414 return addstr(str);
415}
+ 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 424 of file mutt_window.c.

425{
426 va_list ap;
427 va_start(ap, fmt);
428 int rc = vw_printw(stdscr, fmt, ap);
429 va_end(ap);
430
431 return rc;
432}
+ 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 439 of file mutt_window.c.

440{
441 if (!parent || !child)
442 return;
443
444 TAILQ_INSERT_TAIL(&parent->children, child, entries);
445 child->parent = parent;
446
447 notify_set_parent(child->notify, parent->notify);
448
449 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child), child);
450 struct EventWindow ev_w = { child, WN_NO_FLAGS };
451 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
452}
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
@ NT_WINDOW_ADD
New Window has been added.
Definition: mutt_window.h:205
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
+ 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
Return values
ptrChild Window

Definition at line 460 of file mutt_window.c.

461{
462 if (!parent || !child)
463 return NULL;
464
465 // A notification will be sent when the Window is freed
466 TAILQ_REMOVE(&parent->children, child, entries);
467 child->parent = NULL;
468
469 notify_set_parent(child->notify, NULL);
470
471 return child;
472}
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
+ 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 478 of file mutt_window.c.

479{
480 if (!head)
481 return;
482
483 struct MuttWindow *np = NULL;
484 struct MuttWindow *tmp = NULL;
485 TAILQ_FOREACH_SAFE(np, head, entries, tmp)
486 {
487 TAILQ_REMOVE(head, np, entries);
489 mutt_window_free(&np);
490 }
491}
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:201
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:735
+ 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 501 of file mutt_window.c.

502{
503 if (!win)
504 return false;
505
506 for (; win; win = win->parent)
507 {
508 if (!win->state.visible)
509 return false;
510 }
511
512 return true;
513}
+ 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 522 of file mutt_window.c.

523{
524 if (!win)
525 return NULL;
526 if (win->type == type)
527 return win;
528
529 struct MuttWindow *np = NULL;
530 struct MuttWindow *match = NULL;
531 TAILQ_FOREACH(np, &win->children, entries)
532 {
533 match = window_find_child(np, type);
534 if (match)
535 return match;
536 }
537
538 return NULL;
539}
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:522
+ 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 547 of file mutt_window.c.

548{
549 for (; win; win = win->parent)
550 {
551 if (win->type == type)
552 return win;
553 }
554
555 return NULL;
556}
+ 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 562 of file mutt_window.c.

563{
564 if (!win || !win->state.visible)
565 return;
566
567 if (win->recalc && (win->actions & WA_RECALC))
568 win->recalc(win);
569 win->actions &= ~WA_RECALC;
570
571 struct MuttWindow *np = NULL;
572 TAILQ_FOREACH(np, &win->children, entries)
573 {
574 window_recalc(np);
575 }
576}
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:562
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:171
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
+ Here is the call graph for this function:
+ 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 582 of file mutt_window.c.

583{
584 if (!win || !win->state.visible)
585 return;
586
587 if (win->repaint && (win->actions & WA_REPAINT))
588 win->repaint(win);
589 win->actions &= ~WA_REPAINT;
590
591 struct MuttWindow *np = NULL;
592 TAILQ_FOREACH(np, &win->children, entries)
593 {
594 window_repaint(np);
595 }
596}
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:582
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:182
+ Here is the call graph for this function:
+ 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 604 of file mutt_window.c.

605{
606 if (!win)
607 win = RootWindow;
608
609 if (SigWinch)
610 {
611 SigWinch = false;
614 }
615
616 window_reflow(win);
618
619 window_recalc(win);
620 window_repaint(win);
621 mutt_refresh();
622}
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:140
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size (CURSES)
Definition: resize.c:73
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:70
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:742
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_is_focused()

bool window_is_focused ( const struct MuttWindow win)

Does the given Window have the focus?

Parameters
winWindow to check
Return values
trueWindow has focus

Definition at line 629 of file mutt_window.c.

630{
631 if (!win)
632 return false;
633
635
636 return (win_focus == win);
637}
static struct MuttWindow * win_focus
Definition: window.c:38
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:643
+ 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 focused Window.

Return values
ptrWindow with focus

Definition at line 643 of file mutt_window.c.

644{
645 struct MuttWindow *win = RootWindow;
646
647 while (win && win->focus)
648 win = win->focus;
649
650 return win;
651}
+ 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 focused Window
NULLError, or focus not changed

Definition at line 659 of file mutt_window.c.

660{
661 if (!win)
662 return NULL;
663
664 struct MuttWindow *old_focus = window_get_focus();
665
666 struct MuttWindow *parent = win->parent;
667 struct MuttWindow *child = win;
668
669 // Set the chain of focus, all the way to the root
670 for (; parent; child = parent, parent = parent->parent)
671 parent->focus = child;
672
673 // Find the most focused Window
674 while (win && win->focus)
675 win = win->focus;
676
677 if (win == old_focus)
678 return NULL;
679
680 mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win), win);
681 struct EventWindow ev_w = { win, WN_NO_FLAGS };
683#ifdef USE_DEBUG_WINDOW
685#endif
686 return old_focus;
687}
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:209
+ 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 695 of file mutt_window.c.

696{
697 if (!mutt_window_is_visible(win))
698 return;
699
700 for (int i = 0; i < win->state.rows; i++)
701 mutt_window_clearline(win, i);
702}
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:230
+ 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 710 of file mutt_window.c.

711{
712 if (!win)
713 return "UNKNOWN";
714
715 const char *name = mutt_map_get_name(win->type, WindowNames);
716 if (name)
717 return name;
718 return "UNKNOWN";
719}
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:46
+ 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 725 of file mutt_window.c.

726{
727 if (!win)
728 return;
729
730 win->actions |= WA_RECALC | WA_REPAINT;
731
732 struct MuttWindow *np = NULL;
733 TAILQ_FOREACH(np, &win->children, entries)
734 {
736 }
737}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:725
+ Here is the call graph for this function:
+ 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 742 of file mutt_window.c.

743{
745 clearok(stdscr, true);
746 keypad(stdscr, true);
747}
+ Here is the call graph for this function:
+ Here is the caller 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 759 of file mutt_window.c.

760{
761 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
762
763 struct MuttWindow *win = TAILQ_FIRST(&panel->children);
764
765 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
766 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
767 {
768 return false;
769 }
770
771 if (c_status_on_top)
772 {
773 win = TAILQ_LAST(&panel->children, MuttWindowList);
774 TAILQ_REMOVE(&panel->children, win, entries);
775 TAILQ_INSERT_HEAD(&panel->children, win, entries);
776 }
777 else
778 {
779 TAILQ_REMOVE(&panel->children, win, entries);
780 TAILQ_INSERT_TAIL(&panel->children, win, entries);
781 }
782
783 mutt_window_reflow(panel);
785 return true;
786}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:340
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_LAST(head, headname)
Definition: queue.h:819
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
+ 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 46 of file mutt_window.c.