NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "core/lib.h"
#include "mutt_window.h"
#include "curs_lib.h"
#include "globals.h"
#include "module_data.h"
#include "mutt_curses.h"
#include "reflow.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?
 
static void window_notify (struct MuttWindow *win)
 Notify observers of changes to a Window.
 
void window_notify_all (struct MuttWindow *win)
 Notify observers of changes to a Window and its children.
 
void window_set_visible (struct MuttWindow *win, bool visible)
 Set a Window visible or hidden.
 
struct MuttWindowmutt_window_new (enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
 Create a new Window.
 
void mutt_window_free (struct MuttWindow **ptr)
 Free a Window and its children.
 
void mutt_window_clearline (struct MuttWindow *win, int row)
 Clear a row of a Window.
 
void mutt_window_clrtoeol (struct MuttWindow *win)
 Clear to the end of the line.
 
void mutt_window_get_coords (struct MuttWindow *win, int *row, int *col)
 Get the cursor position in the Window.
 
int mutt_window_move (struct MuttWindow *win, int row, int col)
 Move the cursor in a Window.
 
void mutt_window_reflow (struct MuttWindow *win)
 Resize a Window and its children.
 
int mutt_window_wrap_cols (int width, short wrap)
 Calculate the wrap column for a given screen width.
 
int mutt_window_addch (struct MuttWindow *win, int ch)
 Write one character to a Window.
 
int mutt_window_addnstr (struct MuttWindow *win, const char *str, int num)
 Write a partial string to a Window.
 
int mutt_window_addstr (struct MuttWindow *win, const char *str)
 Write a string to a Window.
 
int mutt_window_printf (struct MuttWindow *win, const char *fmt,...)
 Write a formatted string to a Window.
 
void mutt_window_add_child (struct MuttWindow *parent, struct MuttWindow *child)
 Add a child to Window.
 
struct MuttWindowmutt_window_remove_child (struct MuttWindow *parent, struct MuttWindow *child)
 Remove a child from a Window.
 
void mutt_winlist_free (struct MuttWindowArray *wa)
 Free a tree of Windows.
 
bool mutt_window_is_visible (struct MuttWindow *win)
 Is the Window visible?
 
struct MuttWindowwindow_find_child (struct MuttWindow *win, enum WindowType type)
 Recursively find a child Window of a given type.
 
struct MuttWindowwindow_find_parent (struct MuttWindow *win, enum WindowType type)
 Find a (grand-)parent of a Window by type.
 
static void window_recalc (struct MuttWindow *win)
 Recalculate a tree of Windows.
 
static void window_repaint (struct MuttWindow *win)
 Repaint a tree of Windows.
 
static void window_recursor (void)
 Recursor the focused Window.
 
void window_redraw (struct MuttWindow *win)
 Reflow, recalc and repaint a tree of Windows.
 
bool window_is_focused (const struct MuttWindow *win)
 Does the given Window have the focus?
 
struct MuttWindowwindow_get_focus (void)
 Get the currently focused Window.
 
struct MuttWindowwindow_set_focus (struct MuttWindow *win)
 Set the Window focus.
 
void mutt_window_clear (struct MuttWindow *win)
 Clear a Window.
 
const char * mutt_window_win_name (const struct MuttWindow *win)
 Get the name of a Window.
 
static void window_invalidate (struct MuttWindow *win)
 Mark a window as in need of repaint.
 
void window_invalidate_all (void)
 Mark all windows as in need of repaint.
 
bool window_status_on_top (struct MuttWindow *panel, const struct ConfigSubset *sub)
 Organise windows according to config variable.
 
bool mutt_window_swap (struct MuttWindow *parent, struct MuttWindow *win1, struct MuttWindow *win2)
 Swap the position of two windows.
 

Variables

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

Detailed Description

Window management.

Authors
  • Richard Russon
  • Dennis Schön

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

89{
90 if (!win)
91 return false;
92
93 for (; win; win = win->parent)
94 {
95 if (!win->old.visible)
96 return false;
97 }
98
99 return true;
100}
struct WindowState old
Previous state of the Window.
struct MuttWindow * parent
Parent Window.
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 106 of file mutt_window.c.

107{
108 if (!win->notify)
109 return;
110
111 const struct WindowState *old = &win->old;
112 const struct WindowState *wstate = &win->state;
114
115 const bool was_visible = window_was_visible(win);
116 const bool is_visible = mutt_window_is_visible(win);
117 if (was_visible != is_visible)
118 flags |= is_visible ? WN_VISIBLE : WN_HIDDEN;
119
120 if ((wstate->row_offset != old->row_offset) || (wstate->col_offset != old->col_offset))
121 flags |= WN_MOVED;
122
123 if (wstate->rows > old->rows)
124 flags |= WN_TALLER;
125 else if (wstate->rows < old->rows)
126 flags |= WN_SHORTER;
127
128 if (wstate->cols > old->cols)
129 flags |= WN_WIDER;
130 else if (wstate->cols < old->cols)
131 flags |= WN_NARROWER;
132
133 if (flags == WN_NO_FLAGS)
134 return;
135
136 mutt_debug(LL_NOTIFY, "NT_WINDOW_STATE: %s, %p\n", mutt_window_win_name(win),
137 (void *) win);
138 struct EventWindow ev_w = { win, flags };
140}
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static bool is_visible(struct Email *e)
Is the message visible?
Definition thread.c:120
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition notify.c:173
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
static bool window_was_visible(struct MuttWindow *win)
Was the Window visible?
Definition mutt_window.c:88
#define WN_MOVED
Window moved.
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
#define WN_WIDER
Window became wider.
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
#define WN_VISIBLE
Window became visible.
#define WN_HIDDEN
Window became hidden.
#define WN_NO_FLAGS
No flags are set.
#define WN_TALLER
Window became taller.
#define WN_NARROWER
Window became narrower.
#define WN_SHORTER
Window became shorter.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition notify_type.h:57
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
WindowNotifyFlags flags
Attributes of Window that changed.
struct WindowState state
Current state of the Window.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
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 146 of file mutt_window.c.

147{
148 if (!win)
149 {
151 win = mod_data ? mod_data->root_window : NULL;
152 }
153 if (!win)
154 return;
155
156 window_notify(win);
157
158 struct MuttWindow **wp = NULL;
159 ARRAY_FOREACH(wp, &win->children)
160 {
162 }
163 win->old = win->state;
164}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ MODULE_ID_GUI
ModuleGui, Graphical code
Definition module_api.h:45
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
static void window_notify(struct MuttWindow *win)
Notify observers of changes to a Window.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
Gui private Module data.
Definition module_data.h:32
struct MuttWindow * root_window
Parent of all Windows.
Definition module_data.h:40
struct MuttWindowArray children
Children Windows.
Container for Accounts, Notifications.
Definition neomutt.h:41
+ 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 171 of file mutt_window.c.

172{
173 if (!win)
174 {
176 win = mod_data ? mod_data->root_window : NULL;
177 }
178 if (!win)
179 return;
180
181 win->state.visible = visible;
182}
+ Here is the call graph for this function:
+ 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 193 of file mutt_window.c.

195{
196 struct MuttWindow *win = MUTT_MEM_CALLOC(1, struct MuttWindow);
197
198 win->type = type;
199 win->orient = orient;
200 win->size = size;
201 win->req_rows = rows;
202 win->req_cols = cols;
203 win->state.visible = true;
204 win->notify = notify_new();
205 ARRAY_INIT(&win->children);
206
207 win->actions |= WA_RECALC | WA_REPAINT;
208
209 return win;
210}
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
struct Notify * notify_new(void)
Create a new notifications handler.
Definition notify.c:62
#define WA_RECALC
Recalculate the contents of the Window.
#define WA_REPAINT
Redraw the contents of the Window.
short req_cols
Number of columns required.
enum MuttWindowOrientation orient
Which direction the Window will expand.
short req_rows
Number of rows required.
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
+ 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 216 of file mutt_window.c.

217{
218 if (!ptr || !*ptr)
219 return;
220
221 struct MuttWindow *win = *ptr;
222
223 if (win->parent && (win->parent->focus == win))
224 win->parent->focus = NULL;
225
226 mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win),
227 (void *) win);
228 struct EventWindow ev_w = { win, WN_NO_FLAGS };
230
232
233 if (win->wdata_free && win->wdata)
234 win->wdata_free(win, &win->wdata); // Custom function to free private data
235
237
238 FREE(ptr);
239}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition notify.c:75
void mutt_winlist_free(struct MuttWindowArray *wa)
Free a tree of Windows.
@ NT_WINDOW_DELETE
Window is about to be deleted.
struct MuttWindow * focus
Focused Window.
void * wdata
Private data.
void(* wdata_free)(struct MuttWindow *win, void **ptr)
+ 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 246 of file mutt_window.c.

247{
248 mutt_window_move(win, row, 0);
250}
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
+ 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 258 of file mutt_window.c.

259{
260 if (!win || !stdscr)
261 return;
262
263 if ((win->state.col_offset + win->state.cols) == COLS)
264 {
265 clrtoeol();
266 }
267 else
268 {
269 int row = 0;
270 int col = 0;
271 getyx(stdscr, row, col);
272 int curcol = col;
273 while (curcol < (win->state.col_offset + win->state.cols))
274 {
275 addch(' ');
276 curcol++;
277 }
278 move(row, col);
279 }
280}
+ Here is the caller graph for this function:

◆ mutt_window_get_coords()

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

Get the cursor position in the Window.

Parameters
[in]winWindow
[out]rowRow in Window
[out]colColumn 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 291 of file mutt_window.c.

292{
293 int x = 0;
294 int y = 0;
295
296 getyx(stdscr, y, x);
297 if (col)
298 *col = x - win->state.col_offset;
299 if (row)
300 *row = y - win->state.row_offset;
301}
+ Here is the caller graph for this function:

◆ mutt_window_move()

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

Move the cursor in a Window.

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

Definition at line 311 of file mutt_window.c.

312{
313 return move(win->state.row_offset + row, win->state.col_offset + col);
314}
+ 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 320 of file mutt_window.c.

321{
322 if (!OptGui)
323 return;
324
325 if (!win)
326 {
328 win = mod_data ? mod_data->root_window : NULL;
329 }
330 if (!win)
331 return;
332
333 window_reflow(win);
335
336 // Allow Windows to resize themselves based on the first reflow
337 window_reflow(win);
339
340#ifdef USE_DEBUG_WINDOW
342#endif
343}
void debug_win_dump(void)
Dump all windows to debug output.
Definition window.c:116
bool OptGui
(pseudo) when the gui (and curses) are started
Definition globals.c:48
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 353 of file mutt_window.c.

354{
355 if (wrap < 0)
356 return (width > -wrap) ? (width + wrap) : width;
357 if (wrap)
358 return (wrap < width) ? wrap : width;
359 return width;
360}
+ 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 369 of file mutt_window.c.

370{
371 return addch(ch);
372}
+ 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 382 of file mutt_window.c.

383{
384 if (!str)
385 return -1;
386
387 return addnstr(str, num);
388}
+ 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 397 of file mutt_window.c.

398{
399 if (!str)
400 return -1;
401
402 return addstr(str);
403}
+ 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 412 of file mutt_window.c.

413{
414 va_list ap;
415 va_start(ap, fmt);
416 int rc = vw_printw(stdscr, fmt, ap);
417 va_end(ap);
418
419 return rc;
420}
+ 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 427 of file mutt_window.c.

428{
429 if (!parent || !child)
430 return;
431
432 ARRAY_ADD(&parent->children, child);
433 child->parent = parent;
434
435 notify_set_parent(child->notify, parent->notify);
436
437 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child),
438 (void *) child);
439 struct EventWindow ev_w = { child, WN_NO_FLAGS };
440 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
441}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition notify.c:95
@ NT_WINDOW_ADD
New Window has been added.
+ 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 449 of file mutt_window.c.

450{
451 if (!parent || !child)
452 return NULL;
453
454 // A notification will be sent when the Window is freed
455 struct MuttWindow **wp = NULL;
457 {
458 if (*wp == child)
459 {
461 break;
462 }
463 }
464 child->parent = NULL;
465
466 if (parent->focus == child)
467 parent->focus = NULL;
468
469 notify_set_parent(child->notify, NULL);
470
471 return child;
472}
#define ARRAY_REMOVE(head, elem)
Remove an entry from the array, shifting down the subsequent entries.
Definition array.h:355
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_winlist_free()

void mutt_winlist_free ( struct MuttWindowArray * wa)

Free a tree of Windows.

Parameters
waWindowArray to free

Definition at line 478 of file mutt_window.c.

479{
480 if (!wa)
481 return;
482
483 struct MuttWindow **wp = NULL;
484 ARRAY_FOREACH(wp, wa)
485 {
486 struct MuttWindow *win = *wp;
488 mutt_window_free(&win);
489 }
490 ARRAY_FREE(wa);
491}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
+ 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 **wp = NULL;
530 struct MuttWindow *match = NULL;
531 ARRAY_FOREACH(wp, &win->children)
532 {
533 match = window_find_child(*wp, 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.
+ 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 **wp = NULL;
572 ARRAY_FOREACH(wp, &win->children)
573 {
574 window_recalc(*wp);
575 }
576}
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
int(* recalc)(struct MuttWindow *win)
+ 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 **wp = NULL;
592 ARRAY_FOREACH(wp, &win->children)
593 {
594 window_repaint(*wp);
595 }
596}
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
int(* repaint)(struct MuttWindow *win)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ window_recursor()

static void window_recursor ( void )
static

Recursor the focused Window.

Give the focused Window an opportunity to set the position and visibility of its cursor.

Definition at line 604 of file mutt_window.c.

605{
606 // Give the focused window an opportunity to set the cursor position
607 struct MuttWindow *win = window_get_focus();
608 if (!win)
609 return;
610
611 if (win->recursor && win->recursor(win))
612 return;
613
615}
enum MuttCursorState mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition mutt_curses.c:94
@ MUTT_CURSOR_INVISIBLE
Hide the cursor.
Definition mutt_curses.h:65
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
bool(* recursor)(struct MuttWindow *win)
+ 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 623 of file mutt_window.c.

624{
625 if (!win)
626 {
628 win = mod_data ? mod_data->root_window : NULL;
629 }
630 if (!win)
631 return;
632
633 window_reflow(win);
635
636 window_recalc(win);
637 window_repaint(win);
639
640 mutt_refresh();
641}
void mutt_refresh(void)
Force a refresh of the screen.
Definition curs_lib.c:79
static void window_recursor(void)
Recursor the focused Window.
+ 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 648 of file mutt_window.c.

649{
650 if (!win)
651 return false;
652
653 struct MuttWindow *win_focus = window_get_focus();
654
655 return (win_focus == win);
656}
+ 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 662 of file mutt_window.c.

663{
665 struct MuttWindow *win = mod_data ? mod_data->root_window : NULL;
666
667 while (win && win->focus)
668 win = win->focus;
669
670 return win;
671}
+ Here is the call graph for this function:
+ 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 679 of file mutt_window.c.

680{
681 if (!win)
682 return NULL;
683
684 struct MuttWindow *old_focus = window_get_focus();
685
686 struct MuttWindow *parent = win->parent;
687 struct MuttWindow *child = win;
688
689 // Set the chain of focus, all the way to the root
690 for (; parent; child = parent, parent = parent->parent)
691 parent->focus = child;
692
693 win->focus = NULL;
694
695 if (win == old_focus)
696 return NULL;
697
698 mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win),
699 (void *) win);
700 struct EventWindow ev_w = { win, WN_NO_FLAGS };
702#ifdef USE_DEBUG_WINDOW
704#endif
705
706 return old_focus;
707}
@ NT_WINDOW_FOCUS
Window focus has changed.
+ 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 715 of file mutt_window.c.

716{
717 if (!mutt_window_is_visible(win))
718 return;
719
720 for (int i = 0; i < win->state.rows; i++)
721 mutt_window_clearline(win, i);
722}
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
+ 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 730 of file mutt_window.c.

731{
732 if (!win)
733 return "UNKNOWN";
734
735 const char *name = mutt_map_get_name(win->type, WindowNames);
736 if (name)
737 return name;
738 return "UNKNOWN";
739}
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:47
+ 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 745 of file mutt_window.c.

746{
747 if (!win)
748 return;
749
750 win->actions |= WA_RECALC | WA_REPAINT;
751
752 struct MuttWindow **wp = NULL;
753 ARRAY_FOREACH(wp, &win->children)
754 {
756 }
757}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
+ 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 762 of file mutt_window.c.

763{
765 window_invalidate(mod_data ? mod_data->root_window : NULL);
766 clearok(stdscr, true);
767 keypad(stdscr, true);
768}
+ 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,
const 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 **wp_first = ARRAY_FIRST(&panel->children);
785 if (!wp_first)
786 return false;
787
788 struct MuttWindow *win = *wp_first;
789
790 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
791 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
792 {
793 return false;
794 }
795
796 if (c_status_on_top)
797 {
798 // Move last window to front
799 struct MuttWindow **wp_last = ARRAY_LAST(&panel->children);
800 if (wp_last)
801 {
802 win = *wp_last;
803 ARRAY_REMOVE(&panel->children, wp_last);
804 ARRAY_INSERT(&panel->children, 0, win);
805 }
806 }
807 else
808 {
809 // Move first window to end
810 ARRAY_REMOVE(&panel->children, wp_first);
811 ARRAY_ADD(&panel->children, win);
812 }
813
814 mutt_window_reflow(panel);
816 return true;
817}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#define ARRAY_INSERT(head, idx, elem)
Insert an element into the, shifting up the subsequent entries.
Definition array.h:338
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition array.h:145
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
void window_invalidate_all(void)
Mark all windows as in need of repaint.
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_window_swap()

bool mutt_window_swap ( struct MuttWindow * parent,
struct MuttWindow * win1,
struct MuttWindow * win2 )

Swap the position of two windows.

Parameters
parentParent Window
win1Window
win2Window
Return values
trueWindows were switched

Definition at line 826 of file mutt_window.c.

828{
829 if (!parent || !win1 || !win2)
830 return false;
831
832 // ensure both windows are children of the parent
833 if (win1->parent != parent || win2->parent != parent)
834 return false;
835
836 // Find indices of both windows
837 int idx1 = -1;
838 int idx2 = -1;
839 struct MuttWindow **wp = NULL;
840 int idx = 0;
842 {
843 if (*wp == win1)
844 idx1 = idx;
845 if (*wp == win2)
846 idx2 = idx;
847 if ((idx1 != -1) && (idx2 != -1))
848 break; // Early exit when both windows found
849 idx++;
850 }
851
852 if (idx1 == -1 || idx2 == -1)
853 return false;
854
855 // Swap the pointers in the array
856 struct MuttWindow **ptr1 = ARRAY_GET(&parent->children, idx1);
857 struct MuttWindow **ptr2 = ARRAY_GET(&parent->children, idx2);
858 if (ptr1 && ptr2)
859 {
860 struct MuttWindow *tmp = *ptr1;
861 *ptr1 = *ptr2;
862 *ptr2 = tmp;
863 }
864
865 return true;
866}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
+ Here is the caller graph for this function:

Variable Documentation

◆ WindowNames

const struct Mapping WindowNames[]
static

Lookups for Window Names.

Definition at line 47 of file mutt_window.c.

47 {
48 // clang-format off
49 { "WT_ALL_DIALOGS", WT_ALL_DIALOGS },
50 { "WT_CONTAINER", WT_CONTAINER },
51 { "WT_CUSTOM", WT_CUSTOM },
52 { "WT_DLG_ALIAS", WT_DLG_ALIAS },
53 { "WT_DLG_ATTACH", WT_DLG_ATTACH },
54 { "WT_DLG_AUTOCRYPT", WT_DLG_AUTOCRYPT },
55 { "WT_DLG_BROWSER", WT_DLG_BROWSER },
56 { "WT_DLG_CERTIFICATE", WT_DLG_CERTIFICATE },
57 { "WT_DLG_COMPOSE", WT_DLG_COMPOSE },
58 { "WT_DLG_GPGME", WT_DLG_GPGME },
59 { "WT_DLG_HISTORY", WT_DLG_HISTORY },
60 { "WT_DLG_INDEX", WT_DLG_INDEX },
61 { "WT_DLG_PAGER", WT_DLG_PAGER },
62 { "WT_DLG_PATTERN", WT_DLG_PATTERN },
63 { "WT_DLG_PGP", WT_DLG_PGP },
64 { "WT_DLG_POSTPONE", WT_DLG_POSTPONE },
65 { "WT_DLG_QUERY", WT_DLG_QUERY },
66 { "WT_DLG_SMIME", WT_DLG_SMIME },
67 { "WT_HELP_BAR", WT_HELP_BAR },
68 { "WT_INDEX", WT_INDEX },
69 { "WT_MENU", WT_MENU },
70 { "WT_MESSAGE", WT_MESSAGE },
71 { "WT_PAGER", WT_PAGER },
72 { "WT_ROOT", WT_ROOT },
73 { "WT_SIDEBAR", WT_SIDEBAR },
74 { "WT_STATUS_BAR", WT_STATUS_BAR },
75 { NULL, 0 },
76 // clang-format on
77};
@ WT_CUSTOM
Window with a custom drawing function.
Definition mutt_window.h:94
@ WT_ROOT
Parent of All Windows.
Definition mutt_window.h:72
@ WT_DLG_ALIAS
Alias Dialog, dlg_alias()
Definition mutt_window.h:77
@ WT_ALL_DIALOGS
Container for All Dialogs (nested Windows)
Definition mutt_window.h:74
@ WT_DLG_BROWSER
Browser Dialog, dlg_browser()
Definition mutt_window.h:80
@ WT_MESSAGE
Window for messages/errors.
Definition mutt_window.h:98
@ WT_DLG_SMIME
Smime Dialog, dlg_smime()
Definition mutt_window.h:91
@ WT_DLG_QUERY
Query Dialog, dlg_query()
Definition mutt_window.h:90
@ WT_DLG_HISTORY
History Dialog, dlg_history()
Definition mutt_window.h:85
@ WT_DLG_PGP
Pgp Dialog, dlg_pgp()
Definition mutt_window.h:88
@ WT_CONTAINER
Invisible shaping container Window.
Definition mutt_window.h:73
@ WT_DLG_CERTIFICATE
Certificate Dialog, dlg_certificate()
Definition mutt_window.h:81
@ WT_DLG_COMPOSE
Compose Dialog, dlg_compose()
Definition mutt_window.h:82
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition mutt_window.h:86
@ WT_PAGER
A panel containing the Pager Window.
Definition mutt_window.h:99
@ WT_DLG_GPGME
GPGME Dialog, dlg_gpgme()
Definition mutt_window.h:83
@ WT_HELP_BAR
Help Bar containing list of useful key bindings.
Definition mutt_window.h:95
@ WT_DLG_POSTPONE
Postpone Dialog, dlg_postpone()
Definition mutt_window.h:89
@ WT_INDEX
A panel containing the Index Window.
Definition mutt_window.h:96
@ WT_DLG_ATTACH
Attach Dialog, dlg_attach()
Definition mutt_window.h:78
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
@ WT_DLG_PAGER
Pager Dialog, dlg_pager()
Definition mutt_window.h:84
@ WT_DLG_AUTOCRYPT
Autocrypt Dialog, dlg_autocrypt()
Definition mutt_window.h:79
@ WT_MENU
An Window containing a Menu.
Definition mutt_window.h:97
@ WT_DLG_PATTERN
Pattern Dialog, dlg_pattern()
Definition mutt_window.h:87