NeoMutt  2025-01-09-41-g086358
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 *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 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.
 
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 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:60
+ 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 *wstate = &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 ((wstate->row_offset != old->row_offset) || (wstate->col_offset != old->col_offset))
120 flags |= WN_MOVED;
121
122 if (wstate->rows > old->rows)
123 flags |= WN_TALLER;
124 else if (wstate->rows < old->rows)
125 flags |= WN_SHORTER;
126
127 if (wstate->cols > old->cols)
128 flags |= WN_WIDER;
129 else if (wstate->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),
136 (void *) win);
137 struct EventWindow ev_w = { win, flags };
139}
#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:123
bool mutt_window_is_visible(struct MuttWindow *win)
Is the Window visible?
Definition: mutt_window.c:474
const char * mutt_window_win_name(const struct MuttWindow *win)
Get the name of a Window.
Definition: mutt_window.c:697
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:214
uint8_t WindowNotifyFlags
Flags for Changes to a MuttWindow, e.g. WN_TALLER.
Definition: mutt_window.h:208
#define WN_WIDER
Window became wider.
Definition: mutt_window.h:212
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
#define WN_VISIBLE
Window became visible.
Definition: mutt_window.h:215
#define WN_HIDDEN
Window became hidden.
Definition: mutt_window.h:216
#define WN_NO_FLAGS
No flags are set.
Definition: mutt_window.h:209
#define WN_TALLER
Window became taller.
Definition: mutt_window.h:210
#define WN_NARROWER
Window became narrower.
Definition: mutt_window.h:213
#define WN_SHORTER
Window became shorter.
Definition: mutt_window.h:211
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
WindowNotifyFlags flags
Attributes of Window that changed.
Definition: mutt_window.h:241
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:59
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
short row_offset
Absolute on-screen row.
Definition: mutt_window.h:64
short col_offset
Absolute on-screen column.
Definition: mutt_window.h:63
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:62
+ 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 145 of file mutt_window.c.

146{
147 if (!win)
148 win = RootWindow;
149
150 window_notify(win);
151
152 struct MuttWindow *np = NULL;
153 TAILQ_FOREACH(np, &win->children, entries)
154 {
156 }
157 win->old = win->state;
158}
void window_notify_all(struct MuttWindow *win)
Notify observers of changes to a Window and its children.
Definition: mutt_window.c:145
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:782
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: rootwin.c:106
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 165 of file mutt_window.c.

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

184{
185 struct MuttWindow *win = MUTT_MEM_CALLOC(1, struct MuttWindow);
186
187 win->type = type;
188 win->orient = orient;
189 win->size = size;
190 win->req_rows = rows;
191 win->req_cols = cols;
192 win->state.visible = true;
193 win->notify = notify_new();
194 TAILQ_INIT(&win->children);
195 return win;
196}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
#define TAILQ_INIT(head)
Definition: queue.h:822
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 202 of file mutt_window.c.

203{
204 if (!ptr || !*ptr)
205 return;
206
207 struct MuttWindow *win = *ptr;
208
209 if (win->parent && (win->parent->focus == win))
210 win->parent->focus = NULL;
211
212 mutt_debug(LL_NOTIFY, "NT_WINDOW_DELETE: %s, %p\n", mutt_window_win_name(win),
213 (void *) win);
214 struct EventWindow ev_w = { win, WN_NO_FLAGS };
216
218
219 if (win->wdata_free && win->wdata)
220 win->wdata_free(win, &win->wdata); // Custom function to free private data
221
223
224 FREE(ptr);
225}
#define FREE(x)
Definition: memory.h:55
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:451
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
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:159
+ 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 232 of file mutt_window.c.

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

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

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

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

307{
308 if (OptNoCurses)
309 return;
310
311 if (!win)
312 win = RootWindow;
313
314 window_reflow(win);
316
317 // Allow Windows to resize themselves based on the first reflow
318 window_reflow(win);
320
321#ifdef USE_DEBUG_WINDOW
323#endif
324}
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 334 of file mutt_window.c.

335{
336 if (wrap < 0)
337 return (width > -wrap) ? (width + wrap) : width;
338 if (wrap)
339 return (wrap < width) ? wrap : width;
340 return width;
341}
+ 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 350 of file mutt_window.c.

351{
352 return addch(ch);
353}
+ 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 363 of file mutt_window.c.

364{
365 if (!str)
366 return -1;
367
368 return addnstr(str, num);
369}
+ 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 378 of file mutt_window.c.

379{
380 if (!str)
381 return -1;
382
383 return addstr(str);
384}
+ 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 393 of file mutt_window.c.

394{
395 va_list ap;
396 va_start(ap, fmt);
397 int rc = vw_printw(stdscr, fmt, ap);
398 va_end(ap);
399
400 return rc;
401}
+ 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 408 of file mutt_window.c.

409{
410 if (!parent || !child)
411 return;
412
413 TAILQ_INSERT_TAIL(&parent->children, child, entries);
414 child->parent = parent;
415
416 notify_set_parent(child->notify, parent->notify);
417
418 mutt_debug(LL_NOTIFY, "NT_WINDOW_NEW: %s, %p\n", mutt_window_win_name(child),
419 (void *) child);
420 struct EventWindow ev_w = { child, WN_NO_FLAGS };
421 notify_send(child->notify, NT_WINDOW, NT_WINDOW_ADD, &ev_w);
422}
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:228
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:866
+ 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 430 of file mutt_window.c.

431{
432 if (!parent || !child)
433 return NULL;
434
435 // A notification will be sent when the Window is freed
436 TAILQ_REMOVE(&parent->children, child, entries);
437 child->parent = NULL;
438
439 if (parent->focus == child)
440 parent->focus = NULL;
441
442 notify_set_parent(child->notify, NULL);
443
444 return child;
445}
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:901
+ 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 451 of file mutt_window.c.

452{
453 if (!head)
454 return;
455
456 struct MuttWindow *np = NULL;
457 struct MuttWindow *tmp = NULL;
458 TAILQ_FOREACH_SAFE(np, head, entries, tmp)
459 {
460 TAILQ_REMOVE(head, np, entries);
462 mutt_window_free(&np);
463 }
464}
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:792
+ 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 474 of file mutt_window.c.

475{
476 if (!win)
477 return false;
478
479 for (; win; win = win->parent)
480 {
481 if (!win->state.visible)
482 return false;
483 }
484
485 return true;
486}
+ 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 495 of file mutt_window.c.

496{
497 if (!win)
498 return NULL;
499 if (win->type == type)
500 return win;
501
502 struct MuttWindow *np = NULL;
503 struct MuttWindow *match = NULL;
504 TAILQ_FOREACH(np, &win->children, entries)
505 {
506 match = window_find_child(np, type);
507 if (match)
508 return match;
509 }
510
511 return NULL;
512}
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:495
+ 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 520 of file mutt_window.c.

521{
522 for (; win; win = win->parent)
523 {
524 if (win->type == type)
525 return win;
526 }
527
528 return NULL;
529}
+ 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 535 of file mutt_window.c.

536{
537 if (!win || !win->state.visible)
538 return;
539
540 if (win->recalc && (win->actions & WA_RECALC))
541 win->recalc(win);
542 win->actions &= ~WA_RECALC;
543
544 struct MuttWindow *np = NULL;
545 TAILQ_FOREACH(np, &win->children, entries)
546 {
547 window_recalc(np);
548 }
549}
static void window_recalc(struct MuttWindow *win)
Recalculate a tree of Windows.
Definition: mutt_window.c:535
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
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 555 of file mutt_window.c.

556{
557 if (!win || !win->state.visible)
558 return;
559
560 if (win->repaint && (win->actions & WA_REPAINT))
561 win->repaint(win);
562 win->actions &= ~WA_REPAINT;
563
564 struct MuttWindow *np = NULL;
565 TAILQ_FOREACH(np, &win->children, entries)
566 {
567 window_repaint(np);
568 }
569}
static void window_repaint(struct MuttWindow *win)
Repaint a tree of Windows.
Definition: mutt_window.c:555
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
+ 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 577 of file mutt_window.c.

578{
579 // Give the focussed window an opportunity to set the cursor position
580 struct MuttWindow *win = window_get_focus();
581 if (!win)
582 return;
583
584 if (win->recursor && win->recursor(win))
585 return;
586
588}
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:630
bool(* recursor)(struct MuttWindow *win)
Definition: mutt_window.h:205
+ 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 596 of file mutt_window.c.

597{
598 if (!win)
599 win = RootWindow;
600
601 window_reflow(win);
603
604 window_recalc(win);
605 window_repaint(win);
607
608 mutt_refresh();
609}
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:577
+ 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 616 of file mutt_window.c.

617{
618 if (!win)
619 return false;
620
621 struct MuttWindow *win_focus = window_get_focus();
622
623 return (win_focus == win);
624}
+ 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 630 of file mutt_window.c.

631{
632 struct MuttWindow *win = RootWindow;
633
634 while (win && win->focus)
635 win = win->focus;
636
637 return win;
638}
+ 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 646 of file mutt_window.c.

647{
648 if (!win)
649 return NULL;
650
651 struct MuttWindow *old_focus = window_get_focus();
652
653 struct MuttWindow *parent = win->parent;
654 struct MuttWindow *child = win;
655
656 // Set the chain of focus, all the way to the root
657 for (; parent; child = parent, parent = parent->parent)
658 parent->focus = child;
659
660 win->focus = NULL;
661
662 if (win == old_focus)
663 return NULL;
664
665 mutt_debug(LL_NOTIFY, "NT_WINDOW_FOCUS: %s, %p\n", mutt_window_win_name(win),
666 (void *) win);
667 struct EventWindow ev_w = { win, WN_NO_FLAGS };
669#ifdef USE_DEBUG_WINDOW
671#endif
672
673 return old_focus;
674}
@ NT_WINDOW_FOCUS
Window focus has changed.
Definition: mutt_window.h:232
+ 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 682 of file mutt_window.c.

683{
684 if (!mutt_window_is_visible(win))
685 return;
686
687 for (int i = 0; i < win->state.rows; i++)
688 mutt_window_clearline(win, i);
689}
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:232
+ 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 697 of file mutt_window.c.

698{
699 if (!win)
700 return "UNKNOWN";
701
702 const char *name = mutt_map_get_name(win->type, WindowNames);
703 if (name)
704 return name;
705 return "UNKNOWN";
706}
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 712 of file mutt_window.c.

713{
714 if (!win)
715 return;
716
717 win->actions |= WA_RECALC | WA_REPAINT;
718
719 struct MuttWindow *np = NULL;
720 TAILQ_FOREACH(np, &win->children, entries)
721 {
723 }
724}
static void window_invalidate(struct MuttWindow *win)
Mark a window as in need of repaint.
Definition: mutt_window.c:712
+ 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 729 of file mutt_window.c.

730{
732 clearok(stdscr, true);
733 keypad(stdscr, true);
734}
+ 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 746 of file mutt_window.c.

747{
748 const bool c_status_on_top = cs_subset_bool(sub, "status_on_top");
749
750 struct MuttWindow *win = TAILQ_FIRST(&panel->children);
751
752 if ((c_status_on_top && (win->type == WT_STATUS_BAR)) ||
753 (!c_status_on_top && (win->type != WT_STATUS_BAR)))
754 {
755 return false;
756 }
757
758 if (c_status_on_top)
759 {
760 win = TAILQ_LAST(&panel->children, MuttWindowList);
761 TAILQ_REMOVE(&panel->children, win, entries);
762 TAILQ_INSERT_HEAD(&panel->children, win, entries);
763 }
764 else
765 {
766 TAILQ_REMOVE(&panel->children, win, entries);
767 TAILQ_INSERT_TAIL(&panel->children, win, entries);
768 }
769
770 mutt_window_reflow(panel);
772 return true;
773}
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:306
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:729
@ 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:780
#define TAILQ_LAST(head, headname)
Definition: queue.h:876
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:853
+ 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 782 of file mutt_window.c.

784{
785 if (!parent || !win1 || !win2)
786 return false;
787
788 // ensure both windows are children of the parent
789 if (win1->parent != parent || win2->parent != parent)
790 return false;
791
792 struct MuttWindow *win1_next = TAILQ_NEXT(win1, entries);
793 if (win1_next == win2)
794 {
795 // win1 is directly in front of win2, move it behind
796 TAILQ_REMOVE(&parent->children, win1, entries);
797 TAILQ_INSERT_AFTER(&parent->children, win2, win1, entries);
798 return true;
799 }
800
801 struct MuttWindow *win2_next = TAILQ_NEXT(win2, entries);
802 if (win2_next == win1)
803 {
804 // win2 is directly in front of win1, move it behind
805 TAILQ_REMOVE(&parent->children, win2, entries);
806 TAILQ_INSERT_AFTER(&parent->children, win1, win2, entries);
807 return true;
808 }
809
810 TAILQ_REMOVE(&parent->children, win1, entries);
811 TAILQ_REMOVE(&parent->children, win2, entries);
812
813 if (win1_next)
814 TAILQ_INSERT_BEFORE(win1_next, win2, entries);
815 else
816 TAILQ_INSERT_TAIL(&parent->children, win2, entries);
817
818 if (win2_next)
819 TAILQ_INSERT_BEFORE(win2_next, win1, entries);
820 else
821 TAILQ_INSERT_TAIL(&parent->children, win1, entries);
822
823 return true;
824}
#define TAILQ_NEXT(elm, field)
Definition: queue.h:889
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:843
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
Definition: queue.h:828
+ 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.