NeoMutt  2024-10-02-37-gfa9146
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 "mutt_window.h"
#include "curs_lib.h"
#include "globals.h"
#include "mutt_curses.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?
 
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 *col, int *row)
 Get the cursor position in the Window.
 
int mutt_window_move (struct MuttWindow *win, int col, int row)
 Move the cursor in a Window.
 
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.
 
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.
 
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 MuttWindowList *head)
 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 focussed 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, struct ConfigSubset *sub)
 Organise windows according to config variable.
 

Variables

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

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}
struct WindowState old
Previous state of the Window.
Definition: mutt_window.h:127
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:134
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 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 *wstate = &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 ((wstate->row_offset != old->row_offset) || (wstate->col_offset != old->col_offset))
119 flags |= WN_MOVED;
120
121 if (wstate->rows > old->rows)
122 flags |= WN_TALLER;
123 else if (wstate->rows < old->rows)
124 flags |= WN_SHORTER;
125
126 if (wstate->cols > old->cols)
127 flags |= WN_WIDER;
128 else if (wstate->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),
135 (void *) win);
136 struct EventWindow ev_w = { win, flags };
138}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
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
static bool is_visible(struct Email *e)
Is the message visible?
Definition: mutt_thread.c:124
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:511
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:734
static bool window_was_visible(struct MuttWindow *win)
Was the Window visible?
Definition: mutt_window.c:86
#define WN_MOVED
Window moved.
Definition: mutt_window.h:213
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
Definition: mutt_window.h:207
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:211
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:229
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:214
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:215
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:208
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:209
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:212
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:210
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
An Event that happened to a Window.
Definition: mutt_window.h:238
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:239
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:240
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:126
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:137
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:104
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:106
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:135
+ 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:51
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
#define TAILQ_INIT(head)
Definition: queue.h:765
short req_cols
Number of columns required.
Definition: mutt_window.h:123
enum MuttWindowOrientation orient
Which direction the Window will expand.
Definition: mutt_window.h:129
short req_rows
Number of rows required.
Definition: mutt_window.h:124
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:130
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:143
+ 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),
212 (void *) win);
213 struct EventWindow ev_w = { win, WN_NO_FLAGS };
215
217
218 if (win->wdata_free && win->wdata)
219 win->wdata_free(win, &win->wdata); // Custom function to free private data
220
222
223 FREE(ptr);
224}
#define FREE(x)
Definition: memory.h:45
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
void mutt_winlist_free(struct MuttWindowList *head)
Free a tree of Windows.
Definition: mutt_window.c:488
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:228
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:139
void * wdata
Private data.
Definition: mutt_window.h:144
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:158
+ 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 231 of file mutt_window.c.

232{
233 mutt_window_move(win, 0, row);
235}
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:296
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:243
+ 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 243 of file mutt_window.c.

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

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

297{
298 return move(win->state.row_offset + row, win->state.col_offset + col);
299}
+ 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 310 of file mutt_window.c.

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

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

344{
345 if (OptNoCurses)
346 return;
347
348 if (!win)
349 win = RootWindow;
350
351 window_reflow(win);
353
354 // Allow Windows to resize themselves based on the first reflow
355 window_reflow(win);
357
358#ifdef USE_DEBUG_WINDOW
360#endif
361}
void debug_win_dump(void)
Definition: window.c:96
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:69
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 371 of file mutt_window.c.

372{
373 if (wrap < 0)
374 return (width > -wrap) ? (width + wrap) : width;
375 if (wrap)
376 return (wrap < width) ? wrap : width;
377 return width;
378}
+ 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 387 of file mutt_window.c.

388{
389 return addch(ch);
390}
+ 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 400 of file mutt_window.c.

401{
402 if (!str)
403 return -1;
404
405 return addnstr(str, num);
406}
+ 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 415 of file mutt_window.c.

416{
417 if (!str)
418 return -1;
419
420 return addstr(str);
421}
+ 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 430 of file mutt_window.c.

431{
432 va_list ap;
433 va_start(ap, fmt);
434 int rc = vw_printw(stdscr, fmt, ap);
435 va_end(ap);
436
437 return rc;
438}
+ 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 445 of file mutt_window.c.

446{
447 if (!parent || !child)
448 return;
449
450 TAILQ_INSERT_TAIL(&parent->children, child, entries);
451 child->parent = parent;
452
453 notify_set_parent(child->notify, parent->notify);
454
455 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child),
456 (void *) child);
457 struct EventWindow ev_w = { child, WN_NO_FLAGS };
458 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
459}
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.
Definition: mutt_window.h:227
#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 467 of file mutt_window.c.

468{
469 if (!parent || !child)
470 return NULL;
471
472 // A notification will be sent when the Window is freed
473 TAILQ_REMOVE(&parent->children, child, entries);
474 child->parent = NULL;
475
476 if (parent->focus == child)
477 parent->focus = NULL;
478
479 notify_set_parent(child->notify, NULL);
480
481 return child;
482}
#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 488 of file mutt_window.c.

489{
490 if (!head)
491 return;
492
493 struct MuttWindow *np = NULL;
494 struct MuttWindow *tmp = NULL;
495 TAILQ_FOREACH_SAFE(np, head, entries, tmp)
496 {
497 TAILQ_REMOVE(head, np, entries);
499 mutt_window_free(&np);
500 }
501}
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 511 of file mutt_window.c.

512{
513 if (!win)
514 return false;
515
516 for (; win; win = win->parent)
517 {
518 if (!win->state.visible)
519 return false;
520 }
521
522 return true;
523}
+ 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 532 of file mutt_window.c.

533{
534 if (!win)
535 return NULL;
536 if (win->type == type)
537 return win;
538
539 struct MuttWindow *np = NULL;
540 struct MuttWindow *match = NULL;
541 TAILQ_FOREACH(np, &win->children, entries)
542 {
543 match = window_find_child(np, type);
544 if (match)
545 return match;
546 }
547
548 return NULL;
549}
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:532
+ 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 557 of file mutt_window.c.

558{
559 for (; win; win = win->parent)
560 {
561 if (win->type == type)
562 return win;
563 }
564
565 return NULL;
566}
+ 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 572 of file mutt_window.c.

573{
574 if (!win || !win->state.visible)
575 return;
576
577 if (win->recalc && (win->actions & WA_RECALC))
578 win->recalc(win);
579 win->actions &= ~WA_RECALC;
580
581 struct MuttWindow *np = NULL;
582 TAILQ_FOREACH(np, &win->children, entries)
583 {
584 window_recalc(np);
585 }
586}
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:572
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:109
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:172
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:131
+ 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 592 of file mutt_window.c.

593{
594 if (!win || !win->state.visible)
595 return;
596
597 if (win->repaint && (win->actions & WA_REPAINT))
598 win->repaint(win);
599 win->actions &= ~WA_REPAINT;
600
601 struct MuttWindow *np = NULL;
602 TAILQ_FOREACH(np, &win->children, entries)
603 {
604 window_repaint(np);
605 }
606}
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:592
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:110
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:186
+ 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 focussed Window.

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

Definition at line 614 of file mutt_window.c.

615{
616 // Give the focussed window an opportunity to set the cursor position
617 struct MuttWindow *win = window_get_focus();
618 if (!win)
619 return;
620
621 if (win->recursor && win->recursor(win))
622 return;
623
625}
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.
Definition: mutt_window.c:667
bool(* recursor)(struct MuttWindow *win)
Definition: mutt_window.h:204
+ 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 633 of file mutt_window.c.

634{
635 if (!win)
636 win = RootWindow;
637
638 window_reflow(win);
640
641 window_recalc(win);
642 window_repaint(win);
644
645 mutt_refresh();
646}
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:78
static void window_recursor(void)
Recursor the focussed Window.
Definition: mutt_window.c:614
+ 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 653 of file mutt_window.c.

654{
655 if (!win)
656 return false;
657
658 struct MuttWindow *win_focus = window_get_focus();
659
660 return (win_focus == win);
661}
+ 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 667 of file mutt_window.c.

668{
669 struct MuttWindow *win = RootWindow;
670
671 while (win && win->focus)
672 win = win->focus;
673
674 return win;
675}
+ 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 683 of file mutt_window.c.

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

720{
721 if (!mutt_window_is_visible(win))
722 return;
723
724 for (int i = 0; i < win->state.rows; i++)
725 mutt_window_clearline(win, i);
726}
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:231
+ 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 734 of file mutt_window.c.

735{
736 if (!win)
737 return "UNKNOWN";
738
739 const char *name = mutt_map_get_name(win->type, WindowNames);
740 if (name)
741 return name;
742 return "UNKNOWN";
743}
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
+ 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 749 of file mutt_window.c.

750{
751 if (!win)
752 return;
753
754 win->actions |= WA_RECALC | WA_REPAINT;
755
756 struct MuttWindow *np = NULL;
757 TAILQ_FOREACH(np, &win->children, entries)
758 {
760 }
761}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:749
+ 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 766 of file mutt_window.c.

767{
769 clearok(stdscr, true);
770 keypad(stdscr, true);
771}
+ 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 783 of file mutt_window.c.

784{
785 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
786
787 struct MuttWindow *win = TAILQ_FIRST(&panel->children);
788
789 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
790 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
791 {
792 return false;
793 }
794
795 if (c_status_on_top)
796 {
797 win = TAILQ_LAST(&panel->children, MuttWindowList);
798 TAILQ_REMOVE(&panel->children, win, entries);
799 TAILQ_INSERT_HEAD(&panel->children, win, entries);
800 }
801 else
802 {
803 TAILQ_REMOVE(&panel->children, win, entries);
804 TAILQ_INSERT_TAIL(&panel->children, win, entries);
805 }
806
807 mutt_window_reflow(panel);
809 return true;
810}
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.
Definition: mutt_window.c:343
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:766
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:101
#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 45 of file mutt_window.c.